Skip to content

Commit

Permalink
Merge pull request #5537 from plotly/followup-5520
Browse files Browse the repository at this point in the history
Remove pattern from funnel attributes and add tests for histogram and barpolar
  • Loading branch information
archmoj authored Apr 21, 2021
2 parents 296dbfb + 4de929d commit cc1c2b0
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 182 deletions.
49 changes: 49 additions & 0 deletions src/components/drawing/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,52 @@ exports.dash = {
'or a dash length list in px (eg *5px,10px,2px,2px*).'
].join(' ')
};

exports.pattern = {
shape: {
valType: 'enumerated',
values: ['', '/', '\\', 'x', '-', '|', '+', '.'],
dflt: '',
arrayOk: true,
editType: 'style',
description: [
'Sets the shape of the pattern fill.',
'By default, no pattern is used for filling the area.',
].join(' ')
},
bgcolor: {
valType: 'color',
arrayOk: true,
editType: 'style',
description: [
'Sets the background color of the pattern fill.',
'Defaults to a transparent background.',
].join(' ')
},
size: {
valType: 'number',
min: 0,
dflt: 8,
arrayOk: true,
editType: 'style',
description: [
'Sets the size of unit squares of the pattern fill in pixels,',
'which corresponds to the interval of repetition of the pattern.',
].join(' ')
},
solidity: {
valType: 'number',
min: 0,
max: 1,
dflt: 0.3,
arrayOk: true,
editType: 'style',
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.',
].join(' ')
},
editType: 'style'
};
12 changes: 12 additions & 0 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,18 @@ exports.coerceFont = function(coerce, attr, dfltObj) {
return out;
};

/*
* Shortcut to coerce the pattern attributes
*/
exports.coercePattern = function(coerce, attr) {
var shape = coerce(attr + '.shape');
if(shape) {
coerce(attr + '.size');
coerce(attr + '.bgcolor');
coerce(attr + '.solidity');
}
};

/** Coerce shortcut for 'hoverinfo'
* handling 1-vs-multi-trace dflt logic
*
Expand Down
1 change: 1 addition & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ lib.valObjectMeta = coerceModule.valObjectMeta;
lib.coerce = coerceModule.coerce;
lib.coerce2 = coerceModule.coerce2;
lib.coerceFont = coerceModule.coerceFont;
lib.coercePattern = coerceModule.coercePattern;
lib.coerceHoverinfo = coerceModule.coerceHoverinfo;
lib.coerceSelectionMarkerOpacity = coerceModule.coerceSelectionMarkerOpacity;
lib.validate = coerceModule.validate;
Expand Down
50 changes: 2 additions & 48 deletions src/traces/bar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var texttemplateAttrs = require('../../plots/template_attributes').texttemplateA
var colorScaleAttrs = require('../../components/colorscale/attributes');
var fontAttrs = require('../../plots/font_attributes');
var constants = require('./constants');
var pattern = require('../../components/drawing/attributes').pattern;

var extendFlat = require('../../lib/extend').extendFlat;

Expand Down Expand Up @@ -41,54 +42,7 @@ var marker = extendFlat({
editType: 'style',
description: 'Sets the opacity of the bars.'
},
pattern: {
shape: {
valType: 'enumerated',
values: ['', '/', '\\', 'x', '-', '|', '+', '.'],
dflt: '',
arrayOk: true,
editType: 'style',
description: [
'Sets the shape of the pattern fill.',
'By default, no pattern is used for filling the area.',
].join(' ')
},
bgcolor: {
valType: 'color',
arrayOk: true,
editType: 'style',
description: [
'Sets the background color of the pattern fill.',
'Defaults to a transparent background.',
].join(' ')
},
size: {
valType: 'number',
min: 0,
dflt: 8,
arrayOk: true,
editType: 'style',
description: [
'Sets the size of unit squares of the pattern fill in pixels,',
'which corresponds to the interval of repetition of the pattern.',
].join(' ')
},
solidity: {
valType: 'number',
min: 0,
max: 1,
dflt: 0.3,
arrayOk: true,
editType: 'style',
description: [
'Sets the solidity of the pattern fill.',
'Solidity is roughly proportional to the ratio 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.',
].join(' ')
},
editType: 'style'
}
pattern: pattern
});

module.exports = {
Expand Down
9 changes: 3 additions & 6 deletions src/traces/bar/style_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var Color = require('../../components/color');
var hasColorscale = require('../../components/colorscale/helpers').hasColorscale;
var colorscaleDefaults = require('../../components/colorscale/defaults');
var coercePattern = require('../../lib').coercePattern;

module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout) {
coerce('marker.color', defaultColor);
Expand All @@ -23,12 +24,8 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, default

coerce('marker.line.width');
coerce('marker.opacity');
var patternShape = coerce('marker.pattern.shape');
if(patternShape) {
coerce('marker.pattern.bgcolor');
coerce('marker.pattern.size');
coerce('marker.pattern.solidity');
}
coercePattern(coerce, 'marker.pattern');

coerce('selected.marker.color');
coerce('unselected.marker.color');
};
8 changes: 7 additions & 1 deletion src/traces/funnel/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
offset: extendFlat({}, barAttrs.offset, {arrayOk: false}),
width: extendFlat({}, barAttrs.width, {arrayOk: false}),

marker: barAttrs.marker,
marker: funnelMarker(),

connector: {
fillcolor: {
Expand Down Expand Up @@ -111,3 +111,9 @@ module.exports = {
offsetgroup: barAttrs.offsetgroup,
alignmentgroup: barAttrs.alignmentgroup
};

function funnelMarker() {
var marker = extendFlat({}, barAttrs.marker);
delete marker.pattern;
return marker;
}
Binary file removed test/image/baselines/bar_patternfill.png
Binary file not shown.
Binary file added test/image/baselines/pattern_bars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 0 additions & 125 deletions test/image/mocks/bar_patternfill.json

This file was deleted.

Loading

0 comments on commit cc1c2b0

Please sign in to comment.