Skip to content

Commit d31839e

Browse files
authored
Merge pull request #6622 from thierryVergult/sunburstPattern
add pattern to sunburst
2 parents 7829f2f + 2d34832 commit d31839e

File tree

9 files changed

+154
-7
lines changed

9 files changed

+154
-7
lines changed

draftlogs/6622_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add pattern to sunburst trace type [[#6622](https://github.com/plotly/plotly.js/pull/6622)]

src/components/drawing/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd, pt) {
755755
var perPointPattern = d.mcc ||
756756
Lib.isArrayOrTypedArray(markerPattern.shape) ||
757757
Lib.isArrayOrTypedArray(markerPattern.bgcolor) ||
758+
Lib.isArrayOrTypedArray(markerPattern.fgcolor) ||
758759
Lib.isArrayOrTypedArray(markerPattern.size) ||
759760
Lib.isArrayOrTypedArray(markerPattern.solidity);
760761

src/traces/sunburst/attributes.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var domainAttrs = require('../../plots/domain').attributes;
99
var pieAttrs = require('../pie/attributes');
1010
var constants = require('./constants');
1111
var extendFlat = require('../../lib/extend').extendFlat;
12+
var pattern = require('../../components/drawing/attributes').pattern;
1213

1314
module.exports = {
1415
labels: {
@@ -113,6 +114,7 @@ module.exports = {
113114
width: extendFlat({}, pieAttrs.marker.line.width, {dflt: 1}),
114115
editType: 'calc'
115116
},
117+
pattern: pattern,
116118
editType: 'calc'
117119
},
118120
colorScaleAttrs('marker', {

src/traces/sunburst/defaults.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Lib = require('../../lib');
44
var attributes = require('./attributes');
55
var handleDomainDefaults = require('../../plots/domain').defaults;
66
var handleText = require('../bar/defaults').handleText;
7+
var handleMarkerDefaults = require('../pie/defaults').handleMarkerDefaults;
78

89
var Colorscale = require('../../components/colorscale');
910
var hasColorscale = Colorscale.hasColorscale;
@@ -32,10 +33,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3233
coerce('level');
3334
coerce('maxdepth');
3435

35-
var lineWidth = coerce('marker.line.width');
36-
if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);
36+
handleMarkerDefaults(traceIn, traceOut, layout, coerce, 'sunburst');
3737

38-
coerce('marker.colors');
3938
var withColorscale = traceOut._hasColorscale = (
4039
hasColorscale(traceIn, 'marker', 'colors') ||
4140
(traceIn.marker || {}).coloraxis // N.B. special logic to consider "values" colorscales

src/traces/sunburst/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function plotOne(gd, cd, element, transitionOpts) {
256256
isTransitioning: gd._transitioning
257257
});
258258

259-
slicePath.call(styleOne, pt, trace);
259+
slicePath.call(styleOne, pt, trace, gd);
260260

261261
var sliceTextGroup = Lib.ensureSingle(sliceTop, 'g', 'slicetext');
262262
var sliceText = Lib.ensureSingle(sliceTextGroup, 'text', '', function(s) {

src/traces/sunburst/style.js

+18-3
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 Drawing = require('../../components/drawing');
78

89
function style(gd) {
910
var s = gd._fullLayout._sunburstlayer.selectAll('.trace');
@@ -17,20 +18,34 @@ 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

33+
if(gd && ptNumber >= 0) {
34+
pt.i = cdi.i;
35+
36+
var marker = trace.marker;
37+
if(marker.pattern) {
38+
if(!marker.colors || !marker.pattern.shape) marker.color = cdi.color;
39+
} else {
40+
marker.color = cdi.color;
41+
}
42+
43+
Drawing.pointStyle(s, trace, gd, pt);
44+
} else {
45+
Color.fill(s, cdi.color);
46+
}
47+
3248
s.style('stroke-width', lineWidth)
33-
.call(Color.fill, cdi.color)
3449
.call(Color.stroke, lineColor)
3550
.style('opacity', isLeaf ? trace.leaf.opacity : null);
3651
}
37.8 KB
Loading
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"data": [
3+
{
4+
"type": "sunburst",
5+
"textinfo": "label",
6+
"labels": ["Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
7+
"parents": ["Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
8+
"domain": {"x": [0, 0.5]},
9+
"marker": {
10+
"colors": [ "orange", "steelblue", "steelblue", "steelblue", "green", "red", "red", "purple"]
11+
}
12+
},
13+
{
14+
"type": "sunburst",
15+
"textinfo": "none",
16+
"labels": ["Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
17+
"parents": ["Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
18+
"domain": {"x": [0.5, 1]},
19+
"marker": {
20+
"colors": [ "orange", "steelblue", "lightgrey", "lightgrey", "green", "red", "lightgrey", "purple"],
21+
"pattern": {
22+
"shape": ".",
23+
"size": 4
24+
},
25+
"line": {
26+
"color": "lightgrey"
27+
}
28+
}
29+
}
30+
],
31+
"layout": {
32+
"title": { "text": "sunburst with pattern"},
33+
"width": 800,
34+
"height": 400
35+
}
36+
}

test/plot-schema.json

+93
Original file line numberDiff line numberDiff line change
@@ -67493,6 +67493,99 @@
6749367493
"valType": "string"
6749467494
}
6749567495
},
67496+
"pattern": {
67497+
"bgcolor": {
67498+
"arrayOk": true,
67499+
"description": "When there is no colorscale sets the color of background pattern fill. Defaults to a `marker.color` background when `fillmode` is *overlay*. Otherwise, defaults to a transparent background.",
67500+
"editType": "style",
67501+
"valType": "color"
67502+
},
67503+
"bgcolorsrc": {
67504+
"description": "Sets the source reference on Chart Studio Cloud for `bgcolor`.",
67505+
"editType": "none",
67506+
"valType": "string"
67507+
},
67508+
"description": "Sets the pattern within the marker.",
67509+
"editType": "style",
67510+
"fgcolor": {
67511+
"arrayOk": true,
67512+
"description": "When there is no colorscale sets the color of foreground pattern fill. Defaults to a `marker.color` background when `fillmode` is *replace*. Otherwise, defaults to dark grey or white to increase contrast with the `bgcolor`.",
67513+
"editType": "style",
67514+
"valType": "color"
67515+
},
67516+
"fgcolorsrc": {
67517+
"description": "Sets the source reference on Chart Studio Cloud for `fgcolor`.",
67518+
"editType": "none",
67519+
"valType": "string"
67520+
},
67521+
"fgopacity": {
67522+
"description": "Sets the opacity of the foreground pattern fill. Defaults to a 0.5 when `fillmode` is *overlay*. Otherwise, defaults to 1.",
67523+
"editType": "style",
67524+
"max": 1,
67525+
"min": 0,
67526+
"valType": "number"
67527+
},
67528+
"fillmode": {
67529+
"description": "Determines whether `marker.color` should be used as a default to `bgcolor` or a `fgcolor`.",
67530+
"dflt": "replace",
67531+
"editType": "style",
67532+
"valType": "enumerated",
67533+
"values": [
67534+
"replace",
67535+
"overlay"
67536+
]
67537+
},
67538+
"role": "object",
67539+
"shape": {
67540+
"arrayOk": true,
67541+
"description": "Sets the shape of the pattern fill. By default, no pattern is used for filling the area.",
67542+
"dflt": "",
67543+
"editType": "style",
67544+
"valType": "enumerated",
67545+
"values": [
67546+
"",
67547+
"/",
67548+
"\\",
67549+
"x",
67550+
"-",
67551+
"|",
67552+
"+",
67553+
"."
67554+
]
67555+
},
67556+
"shapesrc": {
67557+
"description": "Sets the source reference on Chart Studio Cloud for `shape`.",
67558+
"editType": "none",
67559+
"valType": "string"
67560+
},
67561+
"size": {
67562+
"arrayOk": true,
67563+
"description": "Sets the size of unit squares of the pattern fill in pixels, which corresponds to the interval of repetition of the pattern.",
67564+
"dflt": 8,
67565+
"editType": "style",
67566+
"min": 0,
67567+
"valType": "number"
67568+
},
67569+
"sizesrc": {
67570+
"description": "Sets the source reference on Chart Studio Cloud for `size`.",
67571+
"editType": "none",
67572+
"valType": "string"
67573+
},
67574+
"solidity": {
67575+
"arrayOk": true,
67576+
"description": "Sets the solidity of the pattern fill. Solidity is roughly the fraction of the area filled by the pattern. Solidity of 0 shows only the background color without pattern and solidty of 1 shows only the foreground color without pattern.",
67577+
"dflt": 0.3,
67578+
"editType": "style",
67579+
"max": 1,
67580+
"min": 0,
67581+
"valType": "number"
67582+
},
67583+
"soliditysrc": {
67584+
"description": "Sets the source reference on Chart Studio Cloud for `solidity`.",
67585+
"editType": "none",
67586+
"valType": "string"
67587+
}
67588+
},
6749667589
"reversescale": {
6749767590
"description": "Reverses the color mapping if true. Has an effect only if colors is set to a numerical array. If true, `marker.cmin` will correspond to the last color in the array and `marker.cmax` will correspond to the first color.",
6749867591
"dflt": false,

0 commit comments

Comments
 (0)