diff --git a/src/traces/bar/hover.js b/src/traces/bar/hover.js index 696ec89a55b..f1fe8d8cc82 100644 --- a/src/traces/bar/hover.js +++ b/src/traces/bar/hover.js @@ -67,7 +67,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { if(trace.orientation === 'h') { pointData.x0 = pointData.x1 = xa.c2p(di.x, true); - pointData.xLabelVal = di.s; + pointData.xLabelVal = di.b + di.s; pointData.y0 = ya.c2p(barPos(di) - barDelta, true); pointData.y1 = ya.c2p(barPos(di) + barDelta, true); @@ -75,7 +75,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) { } else { pointData.y0 = pointData.y1 = ya.c2p(di.y, true); - pointData.yLabelVal = di.s; + pointData.yLabelVal = di.b + di.s; pointData.x0 = xa.c2p(barPos(di) - barDelta, true); pointData.x1 = xa.c2p(barPos(di) + barDelta, true); diff --git a/src/traces/bar/set_positions.js b/src/traces/bar/set_positions.js index fd5edd0487f..c34adab1b02 100644 --- a/src/traces/bar/set_positions.js +++ b/src/traces/bar/set_positions.js @@ -485,8 +485,8 @@ function stackBars(gd, sa, sieve) { if(!isNumeric(bar.s)) continue; // stack current bar and get previous sum - var barBase = sieve.put(bar.p, bar.s), - barTop = barBase + bar.s; + var barBase = sieve.put(bar.p, bar.b + bar.s), + barTop = barBase + bar.b + bar.s; // store the bar base and top in each calcdata item bar.b = barBase; @@ -524,7 +524,7 @@ function sieveBars(gd, sa, sieve) { for(var j = 0; j < trace.length; j++) { var bar = trace[j]; - if(isNumeric(bar.s)) sieve.put(bar.p, bar.s); + if(isNumeric(bar.s)) sieve.put(bar.p, bar.b + bar.s); } } } diff --git a/test/image/baselines/bar_attrs_group_norm.png b/test/image/baselines/bar_attrs_group_norm.png index f209c383e66..53a17a1353a 100644 Binary files a/test/image/baselines/bar_attrs_group_norm.png and b/test/image/baselines/bar_attrs_group_norm.png differ diff --git a/test/image/mocks/bar_attrs_group_norm.json b/test/image/mocks/bar_attrs_group_norm.json index f08d1d8e8b5..0f6c54b2886 100644 --- a/test/image/mocks/bar_attrs_group_norm.json +++ b/test/image/mocks/bar_attrs_group_norm.json @@ -1,12 +1,12 @@ { "data":[ { - "base":4, - "x":[3,2,1,0], + "base":[100,40,25,10], + "x":[-50,10,25,40], "type":"bar" }, { - "base":[7,6,5,4], - "x":[1,2,3,4], + "base":[0,60,75,90], + "x":[50,-10,-25,-40], "type":"bar" } ], @@ -14,6 +14,6 @@ "height":400, "width":400, "barmode":"group", - "barnorm":"percent" + "barnorm":"fraction" } } diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index d9d93fc48d9..a67ee339cf7 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -453,6 +453,27 @@ describe('Bar.setPositions', function() { assertPointField(cd, 'y', [[0.75, 0.50, 0.25], [0.25, 0.50, 0.75]]); }); + it('should honor barnorm (group+base case)', function() { + var gd = mockBarPlot([{ + base: [3, 2, 1], + y: [0, 0, 0] + }, { + y: [1, 2, 3] + }], { + bargap: 0, + barmode: 'group', + barnorm: 'fraction' + }); + + expect(gd._fullLayout.barnorm).toBe('fraction'); + + var cd = gd.calcdata; + assertPointField(cd, 'b', [[0.75, 0.50, 0.25], [0, 0, 0]]); + assertPointField(cd, 's', [[0, 0, 0], [0.25, 0.50, 0.75]]); + assertPointField(cd, 'x', [[-0.25, 0.75, 1.75], [0.25, 1.25, 2.25]]); + assertPointField(cd, 'y', [[0.75, 0.50, 0.25], [0.25, 0.50, 0.75]]); + }); + it('should honor barnorm (stack case)', function() { var gd = mockBarPlot([{ y: [3, 2, 1] @@ -753,17 +774,34 @@ describe('bar hover', function() { }); it('should return the correct hover point data (case y)', function() { - var out = _hover(gd, 185.645, 0.15, 'y'); + var out = _hover(gd, 0.75, 0.15, 'y'), + subplot = gd._fullLayout._plots.xy, + xa = subplot.xaxis, + ya = subplot.yaxis, + barDelta = 1 * 0.8 / 2, + x0 = xa.c2p(0.5, true), + x1 = x0, + y0 = ya.c2p(0 - barDelta, true), + y1 = ya.c2p(0 + barDelta, true); - expect(out.style).toEqual([0, '#1f77b4', 75, 0]); - assertPos(out.pos, [182.88, 182.88, 214.5, 170.5]); + expect(out.style).toEqual([0, '#1f77b4', 0.5, 0]); + assertPos(out.pos, [x0, x1, y0, y1]); }); it('should return the correct hover point data (case closest)', function() { - var out = _hover(gd, 135.88, -0.15, 'closest'); - - expect(out.style).toEqual([0, '#1f77b4', 75, 0]); - assertPos(out.pos, [182.88, 182.88, 214.5, 192.5]); + var out = _hover(gd, 0.75, -0.15, 'closest'), + subplot = gd._fullLayout._plots.xy, + xa = subplot.xaxis, + ya = subplot.yaxis, + barDelta = 1 * 0.8 / 2 / 2, + barPos = 0 - 1 * 0.8 / 2 + barDelta, + x0 = xa.c2p(0.5, true), + x1 = x0, + y0 = ya.c2p(barPos - barDelta, true), + y1 = ya.c2p(barPos + barDelta, true); + + expect(out.style).toEqual([0, '#1f77b4', 0.5, 0]); + assertPos(out.pos, [x0, x1, y0, y1]); }); });