Skip to content

Commit

Permalink
feat: fix fishbone issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 27, 2020
1 parent dc63e87 commit 2492d64
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
79 changes: 39 additions & 40 deletions projects/ledge-render/src/lib/chart/ledge-fish-bone/fishbone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const fishbone = () => {
// .on('tick', _tick);

const forceLayout = d3.forceSimulation()
.force('link', d3.forceLink().distance(_linkDistance).strength(0.1))
.on('tick', _tick as any);
.force('link', d3.forceLink().distance(_linkDistance))
.on('tick', _tick);

const fb1 = $ => {
/*
Expand Down Expand Up @@ -105,11 +105,9 @@ const fishbone = () => {
// create the links
link = $.selectAll('.link')
.data(dataLinks);
console.log(link);

link.enter().append('line');

link
link.enter()
.append('line')
.attr('class', (d) => {
return 'link link-' + d.depth;
})
Expand All @@ -129,13 +127,12 @@ const fishbone = () => {
(d) => {
return 'node' + (d.root ? ' root' : '');
})
.append('text');
.append('text')

node.select('text')
.attr(
'class', (d) => {
return 'label-' + d.depth;
})
.attr('class', (d) => {
console.log(d);
return 'label-' + d.depth;
})
.attr('stroke', (d) => {
if (d.color) {
return d.color;
Expand Down Expand Up @@ -278,24 +275,25 @@ const fishbone = () => {
}


function _linePosition($) {
$.attr('x1', (d) => {
return d.source.x;
});
$.attr('y1', (d) => {
return d.source.y;
});
$.attr('x2', (d) => {
return d.target.x;
});
$.attr('y2', (d) => {
return d.target.y;
});
function updateLink(linkNode) {
linkNode
.attr('x1', (d) => {
return d.source.x;
})
.attr('y1', (d) => {
return d.source.y;
})
.attr('x2', (d) => {
return d.target.x;
})
.attr('y2', (d) => {
return d.target.y;
});
}


function _nodePosition($) {
$.attr('transform', d => 'translate(' + d.x + ',' + d.y + ')');
function updateNode(n) {
n.attr('transform', d => 'translate(' + d.x + ',' + d.y + ')');
}


Expand Down Expand Up @@ -359,8 +357,8 @@ const fishbone = () => {
});

// actually apply all changes
node.call(_nodePosition);
link.call(_linePosition);
node.call(updateNode);
link.call(updateLink);
}

// the d3.fishbone() public API
Expand All @@ -372,37 +370,38 @@ const fishbone = () => {
fb1.margin = (_) => {
// how big is the whitespace around the diagram?
// if (!arguments.length) {
// return marginSize;
return marginSize;
// }
marginSize = _;
return my;
// marginSize = _;
// return my;
};

fb1.children = (_) => {
// how will children be sought from each node?
// if (!arguments.length) {
// return children;
return children;
// }
children = _;
return my;
// children = _;
// return my;
};

fb1.label = (_) => {
// how will a label be sought from each node?
// if (!arguments.length) {
// return label;
// }
label = _;
return my;
return label;
// label = _;
// return my;
};

fb1._perNodeTick = (_) => {
// what custom rules should be done per node?
// if (!arguments.length) {
// return perNodeTick;
return perNodeTick;
// }
perNodeTick = _;
return my;
// perNodeTick = _;
// return my;
};

return fb1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ export class LedgeFishBoneComponent implements OnInit, AfterViewInit {
const fb = fishbone();
d3.select(this.chart.nativeElement)
.append('svg')
.attr('width', 1200).attr('height', 800)
.datum(data)
.call(fb.defaultArrow)
.call(fb);

fb.force().restart();
fb.force().restart();
}

}

0 comments on commit 2492d64

Please sign in to comment.