Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add patterns to icicle and treemap traces #6626

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion draftlogs/6601_add.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- add pattern to pie and funnelarea traces [[#6601](https://github.com/plotly/plotly.js/pull/6601), [#6619](https://github.com/plotly/plotly.js/pull/6619)],
- add pattern to pie, funnelarea, sunburst, icicle and treemap traces [[#6601](https://github.com/plotly/plotly.js/pull/6601), [#6619](https://github.com/plotly/plotly.js/pull/6619), [#6622](https://github.com/plotly/plotly.js/pull/6622), [#6626](https://github.com/plotly/plotly.js/pull/6626)],
with thanks to @thierryVergult for the contribution!
1 change: 0 additions & 1 deletion draftlogs/6622_add.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/traces/funnelarea/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}
traceOut._length = len;

handleMarkerDefaults(traceIn, traceOut, layout, coerce, 'funnelarea');
handleMarkerDefaults(traceIn, traceOut, layout, coerce);

coerce('scalegroup');

Expand Down
3 changes: 3 additions & 0 deletions src/traces/icicle/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var sunburstAttrs = require('../sunburst/attributes');
var treemapAttrs = require('../treemap/attributes');
var constants = require('../treemap/constants');
var extendFlat = require('../../lib/extend').extendFlat;
var pattern = require('../../components/drawing/attributes').pattern;

module.exports = {
labels: sunburstAttrs.labels,
Expand Down Expand Up @@ -61,6 +62,8 @@ module.exports = {

line: sunburstAttrs.marker.line,

pattern: pattern,

editType: 'calc'
},
colorScaleAttrs('marker', {
Expand Down
5 changes: 2 additions & 3 deletions src/traces/icicle/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Color = require('../../components/color');
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleText = require('../bar/defaults').handleText;
var TEXTPAD = require('../bar/constants').TEXTPAD;
var handleMarkerDefaults = require('../pie/defaults').handleMarkerDefaults;

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

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

coerce('marker.colors');
var withColorscale = traceOut._hasColorscale = (
hasColorscale(traceIn, 'marker', 'colors') ||
(traceIn.marker || {}).coloraxis // N.B. special logic to consider "values" colorscales
Expand Down
2 changes: 1 addition & 1 deletion src/traces/icicle/draw_descendants.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
})
.call(helpers.setSliceCursor, gd, { isTransitioning: gd._transitioning });

slicePath.call(styleOne, pt, trace, {
slicePath.call(styleOne, pt, trace, gd, {
hovered: false
});

Expand Down
9 changes: 5 additions & 4 deletions src/traces/icicle/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var d3 = require('@plotly/d3');
var Color = require('../../components/color');
var Lib = require('../../lib');
var resizeText = require('../bar/uniform_text').resizeText;
var fillOne = require('../sunburst/fill_one');

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

gTrace.selectAll('path.surface').each(function(pt) {
d3.select(this).call(styleOne, pt, trace);
d3.select(this).call(styleOne, pt, trace, gd);
});
});
}

function styleOne(s, pt, trace) {
function styleOne(s, pt, trace, gd) {
var cdi = pt.data.data;
var isLeaf = !pt.children;
var ptNumber = cdi.i;
var lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
var lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;

s.style('stroke-width', lineWidth)
.call(Color.fill, cdi.color)
s.call(fillOne, pt, trace, gd)
.style('stroke-width', lineWidth)
.call(Color.stroke, lineColor)
.style('opacity', isLeaf ? trace.leaf.opacity : null);
}
Expand Down
11 changes: 8 additions & 3 deletions src/traces/pie/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ function handleLabelsAndValues(labels, values) {
};
}

function handleMarkerDefaults(traceIn, traceOut, layout, coerce, isFunnelarea) {
function handleMarkerDefaults(traceIn, traceOut, layout, coerce, isPie) {
var lineWidth = coerce('marker.line.width');
if(lineWidth) coerce('marker.line.color', isFunnelarea ? layout.paper_bgcolor : undefined);
if(lineWidth) {
coerce('marker.line.color',
isPie ? undefined :
layout.paper_bgcolor // case of funnelarea, sunburst, icicle, treemap
);
}

var markerColors = coerce('marker.colors');
coercePattern(coerce, 'marker.pattern', markerColors);
Expand Down Expand Up @@ -73,7 +78,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
}
traceOut._length = len;

handleMarkerDefaults(traceIn, traceOut, layout, coerce);
handleMarkerDefaults(traceIn, traceOut, layout, coerce, true);

coerce('scalegroup');
// TODO: hole needs to be coerced to the same value within a scaleegroup
Expand Down
16 changes: 16 additions & 0 deletions src/traces/pie/fill_one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var Drawing = require('../../components/drawing');

module.exports = function fillOne(s, pt, trace, gd) {
// enforce the point color, when colors (with s) & the pattern shape are missing.
// 'abuse' the color attribute, used in the Drawing component for bar trace type.
var marker = trace.marker;
if(marker.pattern) {
if(!marker.colors || !marker.pattern.shape) marker.color = pt.color;
} else {
marker.color = pt.color;
}

Drawing.pointStyle(s, trace, gd, pt);
};
7 changes: 3 additions & 4 deletions src/traces/pie/style_one.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Color = require('../../components/color');
var castOption = require('./helpers').castOption;
var Drawing = require('../../components/drawing');
var fillOne = require('./fill_one');

module.exports = function styleOne(s, pt, trace, gd) {
var line = trace.marker.line;
Expand All @@ -18,8 +18,7 @@ module.exports = function styleOne(s, pt, trace, gd) {
marker.color = pt.color;
}

Drawing.pointStyle(s, trace, gd, pt);

s.style('stroke-width', lineWidth)
s.call(fillOne, pt, trace, gd)
.style('stroke-width', lineWidth)
.call(Color.stroke, lineColor);
};
2 changes: 1 addition & 1 deletion src/traces/sunburst/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('level');
coerce('maxdepth');

handleMarkerDefaults(traceIn, traceOut, layout, coerce, 'sunburst');
handleMarkerDefaults(traceIn, traceOut, layout, coerce);

var withColorscale = traceOut._hasColorscale = (
hasColorscale(traceIn, 'marker', 'colors') ||
Expand Down
26 changes: 26 additions & 0 deletions src/traces/sunburst/fill_one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var Drawing = require('../../components/drawing');
var Color = require('../../components/color');

module.exports = function fillOne(s, pt, trace, gd, fadedColor) {
var cdi = pt.data.data;
var ptNumber = cdi.i;

var color = fadedColor || cdi.color;

if(gd && ptNumber >= 0) {
pt.i = cdi.i;

var marker = trace.marker;
if(marker.pattern) {
if(!marker.colors || !marker.pattern.shape) marker.color = color;
} else {
marker.color = color;
}

Drawing.pointStyle(s, trace, gd, pt);
} else {
Color.fill(s, color);
}
};
4 changes: 2 additions & 2 deletions src/traces/sunburst/fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module.exports = function attachFxHandlers(sliceTop, entry, gd, cd, opts) {

if(isTreemapOrIcicle) {
var slice = sliceTop.select('path.surface');
opts.styleOne(slice, pt, traceNow, {
opts.styleOne(slice, pt, traceNow, gd, {
hovered: true
});
}
Expand Down Expand Up @@ -207,7 +207,7 @@ module.exports = function attachFxHandlers(sliceTop, entry, gd, cd, opts) {

if(isTreemapOrIcicle) {
var slice = sliceTop.select('path.surface');
opts.styleOne(slice, pt, traceNow, {
opts.styleOne(slice, pt, traceNow, gd, {
hovered: false
});
}
Expand Down
20 changes: 3 additions & 17 deletions src/traces/sunburst/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var d3 = require('@plotly/d3');
var Color = require('../../components/color');
var Lib = require('../../lib');
var resizeText = require('../bar/uniform_text').resizeText;
var Drawing = require('../../components/drawing');
var fillOne = require('./fill_one');

function style(gd) {
var s = gd._fullLayout._sunburstlayer.selectAll('.trace');
Expand All @@ -30,22 +30,8 @@ function styleOne(s, pt, trace, gd) {
var lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
var lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;

if(gd && ptNumber >= 0) {
pt.i = cdi.i;

var marker = trace.marker;
if(marker.pattern) {
if(!marker.colors || !marker.pattern.shape) marker.color = cdi.color;
} else {
marker.color = cdi.color;
}

Drawing.pointStyle(s, trace, gd, pt);
} else {
Color.fill(s, cdi.color);
}

s.style('stroke-width', lineWidth)
s.call(fillOne, pt, trace, gd)
.style('stroke-width', lineWidth)
.call(Color.stroke, lineColor)
.style('opacity', isLeaf ? trace.leaf.opacity : null);
}
Expand Down
3 changes: 3 additions & 0 deletions src/traces/treemap/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var pieAttrs = require('../pie/attributes');
var sunburstAttrs = require('../sunburst/attributes');
var constants = require('./constants');
var extendFlat = require('../../lib/extend').extendFlat;
var pattern = require('../../components/drawing/attributes').pattern;

module.exports = {
labels: sunburstAttrs.labels,
Expand Down Expand Up @@ -123,6 +124,8 @@ module.exports = {

colors: sunburstAttrs.marker.colors,

pattern: pattern,

depthfade: {
valType: 'enumerated',
values: [true, false, 'reversed'],
Expand Down
8 changes: 3 additions & 5 deletions src/traces/treemap/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Color = require('../../components/color');
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleText = require('../bar/defaults').handleText;
var TEXTPAD = require('../bar/constants').TEXTPAD;
var handleMarkerDefaults = require('../pie/defaults').handleMarkerDefaults;

var Colorscale = require('../../components/colorscale');
var hasColorscale = Colorscale.hasColorscale;
Expand Down Expand Up @@ -64,18 +65,15 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('textposition');
var bottomText = traceOut.textposition.indexOf('bottom') !== -1;

var lineWidth = coerce('marker.line.width');
if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);

var colors = coerce('marker.colors');
handleMarkerDefaults(traceIn, traceOut, layout, coerce);
var withColorscale = traceOut._hasColorscale = (
hasColorscale(traceIn, 'marker', 'colors') ||
(traceIn.marker || {}).coloraxis // N.B. special logic to consider "values" colorscales
);
if(withColorscale) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
} else {
coerce('marker.depthfade', !(colors || []).length);
coerce('marker.depthfade', !(traceOut.marker.colors || []).length);
}

var headerSize = traceOut.textfont.size * 2;
Expand Down
2 changes: 1 addition & 1 deletion src/traces/treemap/draw_ancestors.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports = function drawAncestors(gd, cd, entry, slices, opts) {
isTransitioning: gd._transitioning
});

slicePath.call(styleOne, pt, trace, {
slicePath.call(styleOne, pt, trace, gd, {
hovered: false
});

Expand Down
2 changes: 1 addition & 1 deletion src/traces/treemap/draw_descendants.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
})
.call(helpers.setSliceCursor, gd, { isTransitioning: gd._transitioning });

slicePath.call(styleOne, pt, trace, {
slicePath.call(styleOne, pt, trace, gd, {
hovered: false
});

Expand Down
9 changes: 5 additions & 4 deletions src/traces/treemap/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var Color = require('../../components/color');
var Lib = require('../../lib');
var helpers = require('../sunburst/helpers');
var resizeText = require('../bar/uniform_text').resizeText;
var fillOne = require('../sunburst/fill_one');

function style(gd) {
var s = gd._fullLayout._treemaplayer.selectAll('.trace');
Expand All @@ -18,14 +19,14 @@ function style(gd) {
gTrace.style('opacity', trace.opacity);

gTrace.selectAll('path.surface').each(function(pt) {
d3.select(this).call(styleOne, pt, trace, {
d3.select(this).call(styleOne, pt, trace, gd, {
hovered: false
});
});
});
}

function styleOne(s, pt, trace, opts) {
function styleOne(s, pt, trace, gd, opts) {
var hovered = (opts || {}).hovered;
var cdi = pt.data.data;
var ptNumber = cdi.i;
Expand Down Expand Up @@ -80,8 +81,8 @@ function styleOne(s, pt, trace, opts) {
}
}

s.style('stroke-width', lineWidth)
.call(Color.fill, fillColor)
s.call(fillOne, pt, trace, gd, fillColor)
.style('stroke-width', lineWidth)
.call(Color.stroke, lineColor)
.style('opacity', opacity);
}
Expand Down
Binary file modified test/image/baselines/zz-sunburst_pattern.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading