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

Remove pattern from funnel attributes and add tests for histogram and barpolar #5537

Merged
merged 9 commits into from
Apr 21, 2021
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
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 @@ -6,6 +6,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 @@ -40,54 +41,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 @@ -75,7 +75,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 @@ -108,3 +108,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