Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a138ebd

Browse files
etpinardarchmoj
authored andcommitted
adapt waterfall legend to new *marker* styles ...
- add logic to not show 'totals' part in legend item when waterfall trace does not show totals bars fixup bar / waterfall styles
1 parent dee39dc commit a138ebd

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/components/legend/style.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -244,39 +244,32 @@ module.exports = function style(s, gd) {
244244

245245
function styleWaterfalls(d) {
246246
var trace = d[0].trace;
247-
if(trace.type !== 'waterfall') return d;
248247

249-
var barpath = d3.select(this).select('g.legendpoints')
250-
.selectAll('path.legendbar')
251-
.data(Registry.traceIs(trace, 'bar') ? [d, d, d] : []);
252-
barpath.enter().append('path').classed('legendbar', true)
253-
.attr('d', function(_, i) {
254-
return (
255-
(i === 0) ? 'M-6,-6V6H0Z' :
256-
(i === 1) ? 'M6,6V-6H0Z' : 'M6,6H0L-6,-6H-0Z'
257-
);
258-
})
259-
.attr('transform', 'translate(20,0)');
260-
barpath.exit().remove();
261-
262-
barpath.each(function(d, i) {
263-
264-
var container = trace.marker || trace[
265-
(i % 3 === 0) ? 'increasing' :
266-
(i % 3 === 1) ? 'decreasing' : 'totals'
267-
];
248+
var ptsData = [];
249+
if(trace.type === 'waterfall' && trace.visible) {
250+
ptsData = d[0].hasTotals ?
251+
[['increasing', 'M-6,-6V6H0Z'], ['totals', 'M6,6H0L-6,-6H-0Z'], ['decreasing', 'M6,6V-6H0Z']] :
252+
[['increasing', 'M-6,-6V6H6Z'], ['decreasing', 'M6,6V-6H-6Z']];
253+
}
268254

269-
var line = container.line || {};
255+
var pts = d3.select(this).select('g.legendpoints')
256+
.selectAll('path.legendwaterfall')
257+
.data(ptsData);
258+
pts.enter().append('path').classed('legendwaterfall', true)
259+
.attr('transform', 'translate(20,0)')
260+
.style('stroke-miterlimit', 1);
261+
pts.exit().remove();
270262

271-
var p = d3.select(this);
272-
var d0 = d[0];
273-
var w = (d0.mlw + 1 || line.width + 1) - 1;
263+
pts.each(function(dd) {
264+
var pt = d3.select(this);
265+
var cont = trace[dd[0]].marker;
274266

275-
p.style('stroke-width', w + 'px')
276-
.call(Color.fill, container.color);
267+
pt.attr('d', dd[1])
268+
.style('stroke-width', cont.line.width + 'px')
269+
.call(Color.fill, cont.color);
277270

278-
if(w) {
279-
p.call(Color.stroke, container.color);
271+
if(cont.line.width) {
272+
pt.call(Color.stroke, cont.line.color);
280273
}
281274
});
282275
}

src/traces/bar/style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var attributeOutsideTextFont = attributes.outsidetextfont;
2121
var helpers = require('./helpers');
2222

2323
function style(gd, cd) {
24-
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.bars');
24+
var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.barlayer').selectAll('g.trace');
2525
var barcount = s.size();
2626
var fullLayout = gd._fullLayout;
2727

src/traces/waterfall/calc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ module.exports = function calc(gd, trace) {
4040
// set position and size (as well as for waterfall total size)
4141
var previousSum = 0;
4242
var newSize;
43+
// trace-wide flags
44+
var hasTotals = false;
4345

4446
for(var i = 0; i < serieslen; i++) {
4547
var amount = size[i] || 0;
@@ -70,11 +72,16 @@ module.exports = function calc(gd, trace) {
7072
previousSum += newSize;
7173
}
7274

75+
if(cdi.dir === 'totals') {
76+
hasTotals = true;
77+
}
78+
7379
if(trace.ids) {
7480
cdi.id = String(trace.ids[i]);
7581
}
7682
}
7783

84+
cd[0].hasTotals = hasTotals;
7885

7986
mergeArray(trace.text, cd, 'tx');
8087
mergeArray(trace.hovertext, cd, 'htx');

0 commit comments

Comments
 (0)