Skip to content

Commit de15ad1

Browse files
committed
simplify contourcarpet supplyDefaults
1 parent 3d17792 commit de15ad1

File tree

11 files changed

+155
-169
lines changed

11 files changed

+155
-169
lines changed

src/components/legend/style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = function style(s, gd) {
6666

6767
if(trace && trace._module && trace._module.name === 'contourcarpet') {
6868
showLine = trace.contours.showlines;
69-
showFill = trace.contours.coloring === 'fill';
69+
showFill = trace.contours.coloring === 'fill' || trace.contours.type === 'constraint';
7070
}
7171

7272
var fill = d3.select(this).select('.legendfill').selectAll('path')

src/traces/contourcarpet/constants.js renamed to src/constants/filter_ops.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
'use strict';
1010

1111
module.exports = {
12-
INEQUALITY_OPS: ['=', '<', '>=', '>', '<='],
12+
COMPARISON_OPS: ['=', '!=', '<', '>=', '>', '<='],
13+
COMPARISON_OPS2: ['=', '<', '>=', '>', '<='],
1314
INTERVAL_OPS: ['[]', '()', '[)', '(]', '][', ')(', '](', ')['],
1415
SET_OPS: ['{}', '}{']
1516
};

src/traces/contour/attributes.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ var dash = require('../../components/drawing/attributes').dash;
1616
var fontAttrs = require('../../plots/font_attributes');
1717
var extendFlat = require('../../lib/extend').extendFlat;
1818

19+
var filterOps = require('../../constants/filter_ops');
20+
var COMPARISON_OPS2 = filterOps.COMPARISON_OPS2;
21+
var INTERVAL_OPS = filterOps.INTERVAL_OPS;
22+
var SET_OPS = filterOps.SET_OPS;
23+
1924
var scatterLineAttrs = scatterAttrs.line;
2025

2126
module.exports = extendFlat({
@@ -67,6 +72,19 @@ module.exports = extendFlat({
6772
},
6873

6974
contours: {
75+
type: {
76+
valType: 'enumerated',
77+
values: ['levels', 'constraint'],
78+
dflt: 'levels',
79+
role: 'info',
80+
editType: 'calc',
81+
description: [
82+
'If `levels`, the data is represented as a contour plot with multiple',
83+
'levels displayed. If `constraint`, the data is represented as constraints',
84+
'with the invalid region shaded as specified by the `operation` and',
85+
'`value` parameters.'
86+
].join(' ')
87+
},
7088
start: {
7189
valType: 'number',
7290
dflt: null,
@@ -155,6 +173,60 @@ module.exports = extendFlat({
155173
'https://github.com/d3/d3-format/blob/master/README.md#locale_format.'
156174
].join(' ')
157175
},
176+
operation: {
177+
valType: 'enumerated',
178+
values: [].concat(COMPARISON_OPS2).concat(INTERVAL_OPS).concat(SET_OPS),
179+
role: 'info',
180+
dflt: '=',
181+
editType: 'calc',
182+
description: [
183+
'Sets the filter operation.',
184+
185+
'*=* keeps items equal to `value`',
186+
187+
'*<* keeps items less than `value`',
188+
'*<=* keeps items less than or equal to `value`',
189+
190+
'*>* keeps items greater than `value`',
191+
'*>=* keeps items greater than or equal to `value`',
192+
193+
'*[]* keeps items inside `value[0]` to value[1]` including both bounds`',
194+
'*()* keeps items inside `value[0]` to value[1]` excluding both bounds`',
195+
'*[)* keeps items inside `value[0]` to value[1]` including `value[0]` but excluding `value[1]',
196+
'*(]* keeps items inside `value[0]` to value[1]` excluding `value[0]` but including `value[1]',
197+
198+
'*][* keeps items outside `value[0]` to value[1]` and equal to both bounds`',
199+
'*)(* keeps items outside `value[0]` to value[1]`',
200+
'*](* keeps items outside `value[0]` to value[1]` and equal to `value[0]`',
201+
'*)[* keeps items outside `value[0]` to value[1]` and equal to `value[1]`'
202+
].join(' ')
203+
},
204+
value: {
205+
valType: 'any',
206+
dflt: 0,
207+
role: 'info',
208+
editType: 'calc',
209+
description: [
210+
'Sets the value or values by which to filter by.',
211+
212+
'Values are expected to be in the same type as the data linked',
213+
'to *target*.',
214+
215+
'When `operation` is set to one of the comparison values',
216+
'(' + COMPARISON_OPS2 + ')',
217+
'*value* is expected to be a number or a string.',
218+
219+
'When `operation` is set to one of the interval value',
220+
'(' + INTERVAL_OPS + ')',
221+
'*value* is expected to be 2-item array where the first item',
222+
'is the lower bound and the second item is the upper bound.',
223+
224+
'When `operation`, is set to one of the set value',
225+
'(' + SET_OPS + ')',
226+
'*value* is expected to be an array with as many items as',
227+
'the desired set elements.'
228+
].join(' ')
229+
},
158230
editType: 'calc',
159231
impliedEdits: {'autocontour': false}
160232
},

src/traces/contour/contours_defaults.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
'use strict';
1010

11-
var Lib = require('../../lib');
12-
var attributes = require('./attributes');
13-
14-
module.exports = function handleContourDefaults(traceIn, traceOut, coerce) {
15-
var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start');
16-
var contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end');
11+
module.exports = function handleContourDefaults(traceIn, traceOut, coerce, coerce2) {
12+
var contourStart = coerce2('contours.start');
13+
var contourEnd = coerce2('contours.end');
1714
var missingEnd = (contourStart === false) || (contourEnd === false);
1815

1916
// normally we only need size if autocontour is off. But contour.calc

src/traces/contour/defaults.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2323
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2424
}
2525

26+
function coerce2(attr) {
27+
return Lib.coerce2(traceIn, traceOut, attributes, attr);
28+
}
29+
2630
var len = handleXYZDefaults(traceIn, traceOut, coerce, layout);
2731
if(!len) {
2832
traceOut.visible = false;
@@ -32,6 +36,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3236
coerce('text');
3337
coerce('connectgaps', hasColumns(traceOut));
3438

35-
handleContoursDefaults(traceIn, traceOut, coerce);
39+
handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
3640
handleStyleDefaults(traceIn, traceOut, coerce, layout);
3741
};

src/traces/contourcarpet/attributes.js

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var colorbarAttrs = require('../../components/colorbar/attributes');
1818
var extendFlat = require('../../lib/extend').extendFlat;
1919

2020
var scatterLineAttrs = scatterAttrs.line;
21-
var constants = require('./constants');
2221

2322
module.exports = extendFlat({}, {
2423
carpet: {
@@ -59,19 +58,7 @@ module.exports = extendFlat({}, {
5958
ncontours: contourAttrs.ncontours,
6059

6160
contours: {
62-
type: {
63-
valType: 'enumerated',
64-
values: ['levels', 'constraint'],
65-
dflt: 'levels',
66-
role: 'info',
67-
editType: 'calc',
68-
description: [
69-
'If `levels`, the data is represented as a contour plot with multiple',
70-
'levels displayed. If `constraint`, the data is represented as constraints',
71-
'with the invalid region shaded as specified by the `operation` and',
72-
'`value` parameters.'
73-
].join(' ')
74-
},
61+
type: contourContourAttrs.type,
7562
start: contourContourAttrs.start,
7663
end: contourContourAttrs.end,
7764
size: contourContourAttrs.size,
@@ -93,61 +80,10 @@ module.exports = extendFlat({}, {
9380
showlabels: contourContourAttrs.showlabels,
9481
labelfont: contourContourAttrs.labelfont,
9582
labelformat: contourContourAttrs.labelformat,
96-
operation: {
97-
valType: 'enumerated',
98-
values: [].concat(constants.INEQUALITY_OPS).concat(constants.INTERVAL_OPS).concat(constants.SET_OPS),
99-
role: 'info',
100-
dflt: '=',
101-
editType: 'calc',
102-
description: [
103-
'Sets the filter operation.',
104-
105-
'*=* keeps items equal to `value`',
106-
107-
'*<* keeps items less than `value`',
108-
'*<=* keeps items less than or equal to `value`',
109-
110-
'*>* keeps items greater than `value`',
111-
'*>=* keeps items greater than or equal to `value`',
112-
113-
'*[]* keeps items inside `value[0]` to value[1]` including both bounds`',
114-
'*()* keeps items inside `value[0]` to value[1]` excluding both bounds`',
115-
'*[)* keeps items inside `value[0]` to value[1]` including `value[0]` but excluding `value[1]',
116-
'*(]* keeps items inside `value[0]` to value[1]` excluding `value[0]` but including `value[1]',
117-
118-
'*][* keeps items outside `value[0]` to value[1]` and equal to both bounds`',
119-
'*)(* keeps items outside `value[0]` to value[1]`',
120-
'*](* keeps items outside `value[0]` to value[1]` and equal to `value[0]`',
121-
'*)[* keeps items outside `value[0]` to value[1]` and equal to `value[1]`'
122-
].join(' ')
123-
},
124-
value: {
125-
valType: 'any',
126-
dflt: 0,
127-
role: 'info',
128-
editType: 'calc',
129-
description: [
130-
'Sets the value or values by which to filter by.',
131-
132-
'Values are expected to be in the same type as the data linked',
133-
'to *target*.',
134-
135-
'When `operation` is set to one of the inequality values',
136-
'(' + constants.INEQUALITY_OPS + ')',
137-
'*value* is expected to be a number or a string.',
138-
139-
'When `operation` is set to one of the interval value',
140-
'(' + constants.INTERVAL_OPS + ')',
141-
'*value* is expected to be 2-item array where the first item',
142-
'is the lower bound and the second item is the upper bound.',
143-
144-
'When `operation`, is set to one of the set value',
145-
'(' + constants.SET_OPS + ')',
146-
'*value* is expected to be an array with as many items as',
147-
'the desired set elements.'
148-
].join(' ')
149-
},
150-
editType: 'calc'
83+
operation: contourContourAttrs.operation,
84+
value: contourContourAttrs.value,
85+
editType: 'calc',
86+
impliedEdits: {'autocontour': false}
15187
},
15288

15389
line: {

src/traces/contourcarpet/constraint_mapping.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var constants = require('./constants');
11+
var filterOps = require('../../constants/filter_ops');
1212
var isNumeric = require('fast-isnumeric');
1313

1414
// This syntax conforms to the existing filter transform syntax, but we don't care
@@ -41,13 +41,13 @@ function coerceValue(operation, value) {
4141
return isNumeric(value) ? (+value) : null;
4242
}
4343

44-
if(constants.INEQUALITY_OPS.indexOf(operation) !== -1) {
44+
if(filterOps.COMPARISON_OPS2.indexOf(operation) !== -1) {
4545
coercedValue = hasArrayValue ? coerce(value[0]) : coerce(value);
46-
} else if(constants.INTERVAL_OPS.indexOf(operation) !== -1) {
46+
} else if(filterOps.INTERVAL_OPS.indexOf(operation) !== -1) {
4747
coercedValue = hasArrayValue ?
4848
[coerce(value[0]), coerce(value[1])] :
4949
[coerce(value), coerce(value)];
50-
} else if(constants.SET_OPS.indexOf(operation) !== -1) {
50+
} else if(filterOps.SET_OPS.indexOf(operation) !== -1) {
5151
coercedValue = hasArrayValue ? value.map(coerce) : [coerce(value)];
5252
}
5353

0 commit comments

Comments
 (0)