Skip to content

Commit

Permalink
Merge pull request #38 from soumak77/refactor-text-logic
Browse files Browse the repository at this point in the history
get D3 version 4 to render
  • Loading branch information
germanattanasio authored Mar 26, 2018
2 parents e5b6b8c + 0695efb commit 93ed48e
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 563 deletions.
38 changes: 32 additions & 6 deletions src/d3-renderers/visutil.js → src/d3-renderers/utils.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function expandOrFoldSector(d3, g, d, self) {
function expandOrFoldSector(g, d, d3elem) {
if (d.expand !== null && d.depth > 1) {
//ignore root node and first level sectors
if (d.expand === 0) {
if (d.children) d3.select(self).attr('opacity', 1);
if (d.children) d3elem.attr('opacity', 1);
g.filter(function(a) {
if (a.parent)
return a.parent.id === d.id;
return getValue(a.parent, 'id') === getValue(d, 'id');
})
.attr('visibility', 'visible');
d.expand = 1;
} else {
//if the sector is expanded
if (d.children)
d3.select(self).attr('opacity', 1);
d3elem.attr('opacity', 1);
hideSector(d, g);
}
}
Expand All @@ -21,7 +21,7 @@ function expandOrFoldSector(d3, g, d, self) {
function hideSector(d, g) {
g.filter(function(a) {
if (a.parent)
return a.parent.id === d.id;
return getValue(a.parent, 'id') === getValue(d, 'id');
})
.attr('visibility', 'hidden')
.attr('opacity', 1)
Expand All @@ -47,8 +47,34 @@ function isLocatedBottom(d) {
return bottom;
}

function getValue(d, prop) {
return d.data ? d.data[prop] : d[prop];
}

function getBarLengthFactor(d) {
var bar_length_factor = 10 / (d.depth - 2);

//different bar_length factors
if (d.parent) {
if (d.parent.parent) {
if (getValue(d.parent.parent, 'id') === 'needs' || getValue(d.parent.parent, 'id') === 'values') {
bar_length_factor = 1;
}
if (d.parent.parent.parent) {
if (getValue(d.parent.parent.parent, 'id') === 'personality') {
bar_length_factor = 1;
}
}
}
}

return bar_length_factor;
}

module.exports = {
isLocatedBottom: isLocatedBottom,
arc: arc,
expandOrFoldSector: expandOrFoldSector
expandOrFoldSector: expandOrFoldSector,
getValue: getValue,
getBarLengthFactor: getBarLengthFactor
};
Loading

0 comments on commit 93ed48e

Please sign in to comment.