Skip to content

Commit e6d74e2

Browse files
committed
add patterns to icicle and treemap
1 parent d31839e commit e6d74e2

20 files changed

+301
-53
lines changed

src/traces/funnelarea/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3333
}
3434
traceOut._length = len;
3535

36-
handleMarkerDefaults(traceIn, traceOut, layout, coerce, 'funnelarea');
36+
handleMarkerDefaults(traceIn, traceOut, layout, coerce);
3737

3838
coerce('scalegroup');
3939

src/traces/icicle/attributes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var sunburstAttrs = require('../sunburst/attributes');
1010
var treemapAttrs = require('../treemap/attributes');
1111
var constants = require('../treemap/constants');
1212
var extendFlat = require('../../lib/extend').extendFlat;
13+
var pattern = require('../../components/drawing/attributes').pattern;
1314

1415
module.exports = {
1516
labels: sunburstAttrs.labels,
@@ -61,6 +62,8 @@ module.exports = {
6162

6263
line: sunburstAttrs.marker.line,
6364

65+
pattern: pattern,
66+
6467
editType: 'calc'
6568
},
6669
colorScaleAttrs('marker', {

src/traces/icicle/defaults.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Color = require('../../components/color');
66
var handleDomainDefaults = require('../../plots/domain').defaults;
77
var handleText = require('../bar/defaults').handleText;
88
var TEXTPAD = require('../bar/constants').TEXTPAD;
9+
var handleMarkerDefaults = require('../pie/defaults').handleMarkerDefaults;
910

1011
var Colorscale = require('../../components/colorscale');
1112
var hasColorscale = Colorscale.hasColorscale;
@@ -59,10 +60,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5960
});
6061
coerce('textposition');
6162

62-
var lineWidth = coerce('marker.line.width');
63-
if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);
63+
handleMarkerDefaults(traceIn, traceOut, layout, coerce);
6464

65-
coerce('marker.colors');
6665
var withColorscale = traceOut._hasColorscale = (
6766
hasColorscale(traceIn, 'marker', 'colors') ||
6867
(traceIn.marker || {}).coloraxis // N.B. special logic to consider "values" colorscales

src/traces/icicle/draw_descendants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
163163
})
164164
.call(helpers.setSliceCursor, gd, { isTransitioning: gd._transitioning });
165165

166-
slicePath.call(styleOne, pt, trace, {
166+
slicePath.call(styleOne, pt, trace, gd, {
167167
hovered: false
168168
});
169169

src/traces/icicle/style.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var d3 = require('@plotly/d3');
44
var Color = require('../../components/color');
55
var Lib = require('../../lib');
66
var resizeText = require('../bar/uniform_text').resizeText;
7+
var fillOne = require('../sunburst/fill_one');
78

89
function style(gd) {
910
var s = gd._fullLayout._iciclelayer.selectAll('.trace');
@@ -17,20 +18,20 @@ function style(gd) {
1718
gTrace.style('opacity', trace.opacity);
1819

1920
gTrace.selectAll('path.surface').each(function(pt) {
20-
d3.select(this).call(styleOne, pt, trace);
21+
d3.select(this).call(styleOne, pt, trace, gd);
2122
});
2223
});
2324
}
2425

25-
function styleOne(s, pt, trace) {
26+
function styleOne(s, pt, trace, gd) {
2627
var cdi = pt.data.data;
2728
var isLeaf = !pt.children;
2829
var ptNumber = cdi.i;
2930
var lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
3031
var lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;
3132

32-
s.style('stroke-width', lineWidth)
33-
.call(Color.fill, cdi.color)
33+
s.call(fillOne, pt, trace, gd)
34+
.style('stroke-width', lineWidth)
3435
.call(Color.stroke, lineColor)
3536
.style('opacity', isLeaf ? trace.leaf.opacity : null);
3637
}

src/traces/pie/defaults.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ function handleLabelsAndValues(labels, values) {
3636
};
3737
}
3838

39-
function handleMarkerDefaults(traceIn, traceOut, layout, coerce, isFunnelarea) {
39+
function handleMarkerDefaults(traceIn, traceOut, layout, coerce, isPie) {
4040
var lineWidth = coerce('marker.line.width');
41-
if(lineWidth) coerce('marker.line.color', isFunnelarea ? layout.paper_bgcolor : undefined);
41+
if(lineWidth) {
42+
coerce('marker.line.color',
43+
isPie ? undefined :
44+
layout.paper_bgcolor // case of funnelarea, sunburst, icicle, treemap
45+
);
46+
}
4247

4348
var markerColors = coerce('marker.colors');
4449
coercePattern(coerce, 'marker.pattern', markerColors);
@@ -73,7 +78,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
7378
}
7479
traceOut._length = len;
7580

76-
handleMarkerDefaults(traceIn, traceOut, layout, coerce);
81+
handleMarkerDefaults(traceIn, traceOut, layout, coerce, true);
7782

7883
coerce('scalegroup');
7984
// TODO: hole needs to be coerced to the same value within a scaleegroup

src/traces/pie/fill_one.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
var Drawing = require('../../components/drawing');
4+
5+
module.exports = function fillOne(s, pt, trace, gd) {
6+
// enforce the point color, when colors (with s) & the pattern shape are missing.
7+
// 'abuse' the color attribute, used in the Drawing component for bar trace type.
8+
var marker = trace.marker;
9+
if(marker.pattern) {
10+
if(!marker.colors || !marker.pattern.shape) marker.color = pt.color;
11+
} else {
12+
marker.color = pt.color;
13+
}
14+
15+
Drawing.pointStyle(s, trace, gd, pt);
16+
};

src/traces/pie/style_one.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var Color = require('../../components/color');
44
var castOption = require('./helpers').castOption;
5-
var Drawing = require('../../components/drawing');
5+
var fillOne = require('./fill_one');
66

77
module.exports = function styleOne(s, pt, trace, gd) {
88
var line = trace.marker.line;
@@ -18,8 +18,7 @@ module.exports = function styleOne(s, pt, trace, gd) {
1818
marker.color = pt.color;
1919
}
2020

21-
Drawing.pointStyle(s, trace, gd, pt);
22-
23-
s.style('stroke-width', lineWidth)
21+
s.call(fillOne, pt, trace, gd)
22+
.style('stroke-width', lineWidth)
2423
.call(Color.stroke, lineColor);
2524
};

src/traces/sunburst/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3333
coerce('level');
3434
coerce('maxdepth');
3535

36-
handleMarkerDefaults(traceIn, traceOut, layout, coerce, 'sunburst');
36+
handleMarkerDefaults(traceIn, traceOut, layout, coerce);
3737

3838
var withColorscale = traceOut._hasColorscale = (
3939
hasColorscale(traceIn, 'marker', 'colors') ||

src/traces/sunburst/fill_one.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
var Drawing = require('../../components/drawing');
4+
var Color = require('../../components/color');
5+
6+
module.exports = function fillOne(s, pt, trace, gd, fadedColor) {
7+
var cdi = pt.data.data;
8+
var ptNumber = cdi.i;
9+
10+
var color = fadedColor || cdi.color;
11+
12+
if(gd && ptNumber >= 0) {
13+
pt.i = cdi.i;
14+
15+
var marker = trace.marker;
16+
if(marker.pattern) {
17+
if(!marker.colors || !marker.pattern.shape) marker.color = color;
18+
} else {
19+
marker.color = color;
20+
}
21+
22+
Drawing.pointStyle(s, trace, gd, pt);
23+
} else {
24+
Color.fill(s, color);
25+
}
26+
};

0 commit comments

Comments
 (0)