d3 / d3-shape

Graphical primitives for visualization, such as lines and areas.
https://d3js.org/d3-shape
ISC License
2.47k stars 305 forks source link

stackOffsetDiverging: 0 values are converted as positive #140

Closed dsvanidze closed 4 years ago

dsvanidze commented 5 years ago

https://github.com/d3/d3-shape/blob/b8279d6b4914dac7799ef6953aac24e92c2b5dab/src/offset/diverging.js#L5

Hi,

I had a problem with y values in diverging barcharts. If dy == 0, it is converted as positive datapoints group. But 0 is neither positive nor negative. Therefore is group of negative datapoints, where value is 0, not more correct converted. I changed in your example some data values to 0 and you can see results: https://jsfiddle.net/oy21nzq0/1/ . Negative datapoints had in your example cherries and dates. You can see in console d3.stack() converted arrays for each group. I.e. for cherries look likes this:

0: (2) [5760, 5760, data: {…}]
1: (2) [-960, 0, data: {…}]
2: (2) [1600, 1600, data: {…}]
3: (2) [-640, 0, data: {…}]

how you see 0 and 2 are not correct. Both are positive. Correct is below:

0: (2) [0, 0, data: {…}]
1: (2) [-960, 0, data: {…}]
2: (2) [0, 0, data: {…}]
3: (2) [-640, 0, data: {…}]

I fixed this problem, where I changed d3.stackOffsetDiverging https://jsfiddle.net/oy21nzq0/ . Please Check this FIX and say, if it's a good solution.

Best Regards Davit

mbostock commented 4 years ago

Fixed in bf15db4a8db7ce393db6d6d77bdf953e4e78b13d.