Code Monkey home page Code Monkey logo

d3-sankey's People

Contributors

acro-takanori avatar mohamed-salah avatar takanorig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

d3-sankey's Issues

Minor changes needed to support d3.v4

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]);
         });

having TypeError: Cannot set property 'chart' of undefined

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.

Adding a new node: Example CFO

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.