Skip to content

Commit 9335168

Browse files
committed
move pattern to drawing and make a lib fn to coerce it
1 parent b0d186d commit 9335168

File tree

6 files changed

+72
-60
lines changed

6 files changed

+72
-60
lines changed

src/components/drawing/attributes.js

Lines changed: 49 additions & 0 deletions
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 proportional to the ratio 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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,22 @@ 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 out = {};
432+
433+
out.shape = coerce(attr + '.shape');
434+
if(out.shape) {
435+
out.size = coerce(attr + '.size');
436+
out.bgcolor = coerce(attr + '.bgcolor');
437+
out.solidity = coerce(attr + '.solidity');
438+
}
439+
440+
return out;
441+
};
442+
427443
/** Coerce shortcut for 'hoverinfo'
428444
* handling 1-vs-multi-trace dflt logic
429445
*

src/lib/index.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var texttemplateAttrs = require('../../plots/template_attributes').texttemplateA
66
var colorScaleAttrs = require('../../components/colorscale/attributes');
77
var fontAttrs = require('../../plots/font_attributes');
88
var constants = require('./constants');
9+
var pattern = require('../../components/drawing/attributes').pattern;
910

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

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

9347
module.exports = {

src/traces/bar/style_defaults.js

Lines changed: 3 additions & 6 deletions
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/defaults.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
4848
var markerColor = coerce('marker.color', defaultColor);
4949
coerce('marker.line.color', Color.defaultLine);
5050
coerce('marker.line.width');
51-
var patternShape = coerce('marker.pattern.shape');
52-
if(patternShape) {
53-
coerce('marker.pattern.bgcolor');
54-
coerce('marker.pattern.size');
55-
coerce('marker.pattern.solidity');
56-
}
51+
Lib.coercePattern(coerce, 'marker.pattern');
5752

5853
var connectorVisible = coerce('connector.visible');
5954
if(connectorVisible) {

0 commit comments

Comments
 (0)