Skip to content

Commit cc1c2b0

Browse files
authored
Merge pull request plotly#5537 from plotly/followup-5520
Remove pattern from funnel attributes and add tests for histogram and barpolar
2 parents 296dbfb + 4de929d commit cc1c2b0

File tree

11 files changed

+285
-182
lines changed

11 files changed

+285
-182
lines changed

src/components/drawing/attributes.js

+49
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,52 @@ exports.dash = {
1515
'or a dash length list in px (eg *5px,10px,2px,2px*).'
1616
].join(' ')
1717
};
18+
19+
exports.pattern = {
20+
shape: {
21+
valType: 'enumerated',
22+
values: ['', '/', '\\', 'x', '-', '|', '+', '.'],
23+
dflt: '',
24+
arrayOk: true,
25+
editType: 'style',
26+
description: [
27+
'Sets the shape of the pattern fill.',
28+
'By default, no pattern is used for filling the area.',
29+
].join(' ')
30+
},
31+
bgcolor: {
32+
valType: 'color',
33+
arrayOk: true,
34+
editType: 'style',
35+
description: [
36+
'Sets the background color of the pattern fill.',
37+
'Defaults to a transparent background.',
38+
].join(' ')
39+
},
40+
size: {
41+
valType: 'number',
42+
min: 0,
43+
dflt: 8,
44+
arrayOk: true,
45+
editType: 'style',
46+
description: [
47+
'Sets the size of unit squares of the pattern fill in pixels,',
48+
'which corresponds to the interval of repetition of the pattern.',
49+
].join(' ')
50+
},
51+
solidity: {
52+
valType: 'number',
53+
min: 0,
54+
max: 1,
55+
dflt: 0.3,
56+
arrayOk: true,
57+
editType: 'style',
58+
description: [
59+
'Sets the solidity of the pattern fill.',
60+
'Solidity is roughly the fraction of the area filled by the pattern.',
61+
'Solidity of 0 shows only the background color without pattern',
62+
'and solidty of 1 shows only the foreground color without pattern.',
63+
].join(' ')
64+
},
65+
editType: 'style'
66+
};

src/lib/coerce.js

+12
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,18 @@ exports.coerceFont = function(coerce, attr, dfltObj) {
424424
return out;
425425
};
426426

427+
/*
428+
* Shortcut to coerce the pattern attributes
429+
*/
430+
exports.coercePattern = function(coerce, attr) {
431+
var shape = coerce(attr + '.shape');
432+
if(shape) {
433+
coerce(attr + '.size');
434+
coerce(attr + '.bgcolor');
435+
coerce(attr + '.solidity');
436+
}
437+
};
438+
427439
/** Coerce shortcut for 'hoverinfo'
428440
* handling 1-vs-multi-trace dflt logic
429441
*

src/lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ lib.valObjectMeta = coerceModule.valObjectMeta;
3535
lib.coerce = coerceModule.coerce;
3636
lib.coerce2 = coerceModule.coerce2;
3737
lib.coerceFont = coerceModule.coerceFont;
38+
lib.coercePattern = coerceModule.coercePattern;
3839
lib.coerceHoverinfo = coerceModule.coerceHoverinfo;
3940
lib.coerceSelectionMarkerOpacity = coerceModule.coerceSelectionMarkerOpacity;
4041
lib.validate = coerceModule.validate;

src/traces/bar/attributes.js

+2-48
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var texttemplateAttrs = require('../../plots/template_attributes').texttemplateA
77
var colorScaleAttrs = require('../../components/colorscale/attributes');
88
var fontAttrs = require('../../plots/font_attributes');
99
var constants = require('./constants');
10+
var pattern = require('../../components/drawing/attributes').pattern;
1011

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

@@ -41,54 +42,7 @@ var marker = extendFlat({
4142
editType: 'style',
4243
description: 'Sets the opacity of the bars.'
4344
},
44-
pattern: {
45-
shape: {
46-
valType: 'enumerated',
47-
values: ['', '/', '\\', 'x', '-', '|', '+', '.'],
48-
dflt: '',
49-
arrayOk: true,
50-
editType: 'style',
51-
description: [
52-
'Sets the shape of the pattern fill.',
53-
'By default, no pattern is used for filling the area.',
54-
].join(' ')
55-
},
56-
bgcolor: {
57-
valType: 'color',
58-
arrayOk: true,
59-
editType: 'style',
60-
description: [
61-
'Sets the background color of the pattern fill.',
62-
'Defaults to a transparent background.',
63-
].join(' ')
64-
},
65-
size: {
66-
valType: 'number',
67-
min: 0,
68-
dflt: 8,
69-
arrayOk: true,
70-
editType: 'style',
71-
description: [
72-
'Sets the size of unit squares of the pattern fill in pixels,',
73-
'which corresponds to the interval of repetition of the pattern.',
74-
].join(' ')
75-
},
76-
solidity: {
77-
valType: 'number',
78-
min: 0,
79-
max: 1,
80-
dflt: 0.3,
81-
arrayOk: true,
82-
editType: 'style',
83-
description: [
84-
'Sets the solidity of the pattern fill.',
85-
'Solidity is roughly proportional to the ratio of the area filled by the pattern.',
86-
'Solidity of 0 shows only the background color without pattern',
87-
'and solidty of 1 shows only the foreground color without pattern.',
88-
].join(' ')
89-
},
90-
editType: 'style'
91-
}
45+
pattern: pattern
9246
});
9347

9448
module.exports = {

src/traces/bar/style_defaults.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var Color = require('../../components/color');
44
var hasColorscale = require('../../components/colorscale/helpers').hasColorscale;
55
var colorscaleDefaults = require('../../components/colorscale/defaults');
6+
var coercePattern = require('../../lib').coercePattern;
67

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

2425
coerce('marker.line.width');
2526
coerce('marker.opacity');
26-
var patternShape = coerce('marker.pattern.shape');
27-
if(patternShape) {
28-
coerce('marker.pattern.bgcolor');
29-
coerce('marker.pattern.size');
30-
coerce('marker.pattern.solidity');
31-
}
27+
coercePattern(coerce, 'marker.pattern');
28+
3229
coerce('selected.marker.color');
3330
coerce('unselected.marker.color');
3431
};

src/traces/funnel/attributes.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = {
7878
offset: extendFlat({}, barAttrs.offset, {arrayOk: false}),
7979
width: extendFlat({}, barAttrs.width, {arrayOk: false}),
8080

81-
marker: barAttrs.marker,
81+
marker: funnelMarker(),
8282

8383
connector: {
8484
fillcolor: {
@@ -111,3 +111,9 @@ module.exports = {
111111
offsetgroup: barAttrs.offsetgroup,
112112
alignmentgroup: barAttrs.alignmentgroup
113113
};
114+
115+
function funnelMarker() {
116+
var marker = extendFlat({}, barAttrs.marker);
117+
delete marker.pattern;
118+
return marker;
119+
}
-153 KB
Binary file not shown.

test/image/baselines/pattern_bars.png

168 KB
Loading

test/image/mocks/bar_patternfill.json

-125
This file was deleted.

0 commit comments

Comments
 (0)