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

pie : add Pattern #6601

Merged
merged 11 commits into from
May 30, 2023
1 change: 1 addition & 0 deletions draftlogs/6601_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- add pattern to pie trace type [[#6601](https://github.com/plotly/plotly.js/pull/6601)]
4 changes: 2 additions & 2 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd) {
if('mc' in d) {
fillColor = d.mcc = fns.markerScale(d.mc);
} else {
fillColor = marker.color || 'rgba(0,0,0,0)';
fillColor = marker.color || marker.colors || 'rgba(0,0,0,0)';
}

if(fns.selectedColorFn) {
Expand Down Expand Up @@ -766,7 +766,7 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd) {
patternBGColor, patternFGColor, patternFGOpacity
);
} else {
Color.fill(sel, fillColor);
Lib.isArrayOrTypedArray(fillColor) ? Color.fill(sel, fillColor[d.i]) : Color.fill(sel, fillColor);
}

if(lineWidth) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ module.exports = function style(s, gd, legend) {

var d0Mod = Lib.minExtend(d0, {trace: tMod});

stylePie(pts, d0Mod, tMod);
stylePie(pts, d0Mod, tMod, gd);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/traces/pie/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplat
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;

var extendFlat = require('../../lib/extend').extendFlat;
var pattern = require('../../components/drawing/attributes').pattern;

var textFontAttrs = fontAttrs({
editType: 'plot',
Expand Down Expand Up @@ -89,6 +90,7 @@ module.exports = {
},
editType: 'calc'
},
pattern: pattern,
editType: 'calc'
},

Expand Down
7 changes: 6 additions & 1 deletion src/traces/pie/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var Lib = require('../../lib');
var attributes = require('./attributes');
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleText = require('../bar/defaults').handleText;
var coercePattern = require('../../lib').coercePattern;

function handleLabelsAndValues(labels, values) {
var hasLabels = Array.isArray(labels);
Expand Down Expand Up @@ -64,7 +65,11 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
var lineWidth = coerce('marker.line.width');
if(lineWidth) coerce('marker.line.color');

coerce('marker.colors');
var markerColors = coerce('marker.colors');
coercePattern(coerce, 'marker.pattern', markerColors);
// push the marker colors (with s) to the foreground colors, to work around logic in the drawing pattern code on marker.color (without s, which is okay for a bar trace)
if(!traceOut.marker.pattern.fgcolor && traceIn.marker !== undefined) traceOut.marker.pattern.fgcolor = traceIn.marker.colors;
thierryVergult marked this conversation as resolved.
Show resolved Hide resolved
if(!traceOut.marker.pattern.bgcolor) traceOut.marker.pattern.bgcolor = layout.paper_bgcolor;

coerce('scalegroup');
// TODO: hole needs to be coerced to the same value within a scaleegroup
Expand Down
2 changes: 1 addition & 1 deletion src/traces/pie/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function style(gd) {
traceSelection.style({opacity: trace.opacity});

traceSelection.selectAll('path.surface').each(function(pt) {
d3.select(this).call(styleOne, pt, trace);
d3.select(this).call(styleOne, pt, trace, gd);
});
});
};
21 changes: 19 additions & 2 deletions src/traces/pie/style_one.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@

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

module.exports = function styleOne(s, pt, trace) {
module.exports = function styleOne(s, pt, trace, gd) {
var line = trace.marker.line;
var lineColor = castOption(line.color, pt.pts) || Color.defaultLine;
var lineWidth = castOption(line.width, pt.pts) || 0;

// some temporary console statements, for later debugging, needs to be removed once the assembler below gets clean
// console.log('styleOne - s0', s[0], s[0][0], '__data__', s[0][0].__data__);
// console.log( 's0 iiiiiiiii pie : ', (s[0][0].__data__.i !== undefined ? s[0][0].__data__.i : 'nope'));
// console.log( 's0 iiiiiiiii legend : ', (s[0][0].__data__[0] !== undefined ? s[0][0].__data__[0].i : 'nope'));
// console.log( 'pie style_one: s', s, 'trace', trace, 'gd', gd);

// to do: rework this assembler code in a next iteration.
if(s[0][0].__data__.i === undefined) {
// coming from a legend
s[0][0].__data__.i = s[0][0].__data__[0].i;
}
// console.log( 's0 - i : ', s[0][0].__data__['i']);

Drawing.pointStyle(s, trace, gd);
// to do : push into s.style d3 logic

s.style('stroke-width', lineWidth)
.call(Color.fill, pt.color)
// .call(Color.fill, pt.color)
.call(Color.stroke, lineColor);
};