hazemhagrass / d3-sankey Goto Github PK
View Code? Open in Web Editor NEWD3 Implementation for Sankey chart with angular directives
D3 Implementation for Sankey chart with angular directives
Hi,
d3-sankey code does not seem to work out-of-the-box with d3 version 4 due to changes in d3 api.
Tweaks below make demo work for me.
@@ -315,7 +319,7 @@ d3.sankeyChart = function (data, options
self.staticLinkColor = options.staticLinkColor ? options.staticLinkColor : '#000';
self.formatNumber = d3.format(',.0f');
self.format = d => `${self.formatNumber(d)}`;
- self.color = d3.scale.category20();
+ self.color = d3.scaleOrdinal(d3.schemeCategory20);
let canvas, svg, sankey, link, path, node = null;
@@ -352,10 +356,8 @@ d3.sankeyChart = function (data, options
.attr('class', 'link')
.attr('d', path)
.style('stroke-width', d => Math.max(1, d.dy))
- .style({
- fill: 'none',
- 'stroke-opacity': 0.15
- })
+ .style('fill', 'none')
+ .style('stroke-opacity', 0.15)
.style('stroke', function (d) {
let color = self.staticLinkColor ? self.staticLinkColor : '#000';
color = self.dynamicLinkColor ? self.color(d.source.name.replace(/ .*/, '')) : color;
@@ -384,9 +386,10 @@ d3.sankeyChart = function (data, options
.enter().append('g')
.attr('class', 'node')
.attr('transform', d => `translate(${d.x}, ${d.y})`)
- .call(d3.behavior.drag()
- .origin(d => d)
- .on('dragstart', function () {
+
+ .call(d3.drag()
+ .subject(d => d)
+ .on('start', function () {
this.parentNode.appendChild(this);
})
.on('drag', dragmove));
@@ -398,12 +401,10 @@ d3.sankeyChart = function (data, options
d.color = self.color(d.name.replace(/ .*/, ''));
return d.color;
})
- .style({
- stroke: 'none',
- cursor: 'move',
- 'fill-opacity': 0.9,
- 'shape-rendering': 'crispEdges'
- })
+ .style('stroke', 'none')
+ .style('cursor', 'move')
+ .style('fill-opacity', 0.9)
+ .style('shape-rendering', 'crispEdges')
.append('title')
.text(d => `${d.name}\n${self.format(d.value)}`);
@@ -413,10 +414,8 @@ d3.sankeyChart = function (data, options
.attr('dy', '.35em')
.attr('text-anchor', 'end')
.attr('transform', null)
- .style({
- 'pointer-events': 'none',
- 'text-shadow': '0 1px 0 #fff'
- })
+ .style('pointer-events', 'none')
+ .style('text-shadow', '0 1px 0 #fff')
.text(d => d.name)
.filter(d => d.x < self.innerWidth / 2)
.attr('x', 6 + sankey.nodeWidth())
@@ -426,19 +425,19 @@ d3.sankeyChart = function (data, options
self.renderTrafficInLinks = function () {
const linkExtent = d3.extent(data.links, d => d.value);
- const frequencyScale = d3.scale.linear()
+ const frequencyScale = d3.scaleLinear()
.domain(linkExtent)
.range([0.05, 1]);
/* const particleSize = */
- d3.scale.linear()
+ d3.scaleLinear()
.domain(linkExtent)
.range([1, 5]);
data.links.forEach(currentLink => {
currentLink.freq = frequencyScale(currentLink.value);
currentLink.particleSize = 2;
- currentLink.particleColor = d3.scale.linear().domain([0, 1])
+ currentLink.particleColor = d3.scaleLinear().domain([0, 1])
.range([currentLink.source.color, currentLink.target.color]);
});
With Angular directive link for same source and target node not working.
eg: one of link is as {"source":4,"target":4,"value":5}
Could you please have look on below url here you can see link can be point to same soure and target node.
https://sankey.csaladen.es/
Hi,
I am using ng-sankey chart in my application. It was work fine for yesterday. But now i am getting this issue TypeError: Cannot set property 'chart' of undefined
at d3.sankey.directive.js:30.
Please let me know whats the issue. Waiting for your reply.
Many Thanks,
S Tejeswini.
Any idea how to make the demo work inside Angular 5 project?
Hello Team,
Trying to implement on the angular side.
If i have to add a new node for example "CFO" and the it needs to appear in the same line as COO and CTO, what procedure do i need to adopt?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.