Skip to content

Commit 88c7954

Browse files
Merge remote-tracking branch 'origin/master' into PlotlyPromisePolyfill
2 parents fa20db2 + 34619d6 commit 88c7954

File tree

7 files changed

+139
-15
lines changed

7 files changed

+139
-15
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"data": [
3+
{
4+
"y": [
5+
0.75,
6+
5.25,
7+
5.5,
8+
6,
9+
6.2,
10+
6.6,
11+
6.8,
12+
7,
13+
7.2,
14+
7.5,
15+
7.5,
16+
7.75,
17+
8.15,
18+
8.15,
19+
8.65,
20+
8.93,
21+
9.2,
22+
9.5,
23+
10,
24+
10.25,
25+
11.5,
26+
12,
27+
16,
28+
20.9,
29+
22.3,
30+
23.25
31+
],
32+
"type": "box",
33+
"marker": {
34+
"outliercolor": "green"
35+
},
36+
"uid": "511258"
37+
}
38+
],
39+
"layout": {
40+
"xaxis": {
41+
"type": "category",
42+
"range": [
43+
-0.5,
44+
0.5
45+
],
46+
"autorange": true
47+
},
48+
"yaxis": {
49+
"type": "linear",
50+
"range": [
51+
-0.5,
52+
24.5
53+
],
54+
"autorange": true
55+
},
56+
"height": 450,
57+
"width": 1000,
58+
"autosize": true
59+
}
60+
}
12.1 KB
Loading

shelly/plotlyjs/static/plotlyjs/src/boxes.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ boxes.attributes = {
135135
marker: {
136136
outliercolor: {
137137
valType: 'color',
138-
dflt: 'rgba(0,0,0,0)',
138+
dflt: 'rgba(0, 0, 0, 0)',
139139
role: 'style',
140140
description: 'Sets the color of the outlier sample points.'
141141
},
@@ -155,7 +155,10 @@ boxes.attributes = {
155155
outliercolor: {
156156
valType: 'color',
157157
role: 'style',
158-
description: 'Sets the border line color of the outlier sample points.'
158+
description: [
159+
'Sets the border line color of the outlier sample points.',
160+
'Defaults to marker.color'
161+
].join(' ')
159162
},
160163
outlierwidth: {
161164
valType: 'number',
@@ -252,7 +255,13 @@ boxes.supplyDefaults = function(traceIn, traceOut, defaultColor) {
252255

253256
coerce('whiskerwidth');
254257
coerce('boxmean');
255-
var boxpoints = coerce('boxpoints');
258+
259+
var outlierColorDflt = Plotly.Lib.coerce2(traceIn, traceOut, boxes.attributes, 'marker.outliercolor'),
260+
lineoutliercolor = coerce('marker.line.outliercolor'),
261+
boxpoints = outlierColorDflt ||
262+
lineoutliercolor ? coerce('boxpoints', 'suspectedoutliers') :
263+
coerce('boxpoints');
264+
256265
if(boxpoints) {
257266
coerce('jitter', boxpoints==='all' ? 0.3 : 0);
258267
coerce('pointpos', boxpoints==='all' ? -1.5 : 0);
@@ -265,8 +274,7 @@ boxes.supplyDefaults = function(traceIn, traceOut, defaultColor) {
265274
coerce('marker.line.width');
266275

267276
if(boxpoints==='suspectedoutliers') {
268-
coerce('marker.outliercolor');
269-
coerce('marker.line.outliercolor', traceOut.marker.color);
277+
coerce('marker.line.outliercolor', traceOut.marker.color)
270278
coerce('marker.line.outlierwidth');
271279
}
272280
}

shelly/plotlyjs/static/plotlyjs/src/contour.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ contour.supplyDefaults = function(traceIn, traceOut, defaultColor, layout) {
124124
return Plotly.Lib.coerce(traceIn, traceOut, contour.attributes, attr, dflt);
125125
}
126126

127-
var contourstart = coerce('contours.start'),
128-
contourend = coerce('contours.end'),
129-
validcont = contourstart!==undefined && contourend!==undefined,
130-
autocontour = validcont ? coerce('autocontour', false) : coerce('autocontour');
127+
var contourStart = Plotly.Lib.coerce2(traceIn, traceOut, contour.attributes, 'contours.start'),
128+
contourEnd = Plotly.Lib.coerce2(traceIn, traceOut, contour.attributes, 'contours.end'),
129+
autocontour = contourStart && contourEnd ? coerce('autocontour', false) : coerce('autocontour');
131130
if(autocontour) coerce('ncontours');
132131
else coerce('contours.size');
133132

shelly/plotlyjs/static/plotlyjs/src/histogram.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Plotly.Plots.register(Plotly.Heatmap, 'histogram2d',
4040
// histogram has its own calc function,
4141
// but uses Bars.plot to display
4242
// and Bars.setPositions for stacking and grouping
43-
4443
function makeBinsAttr(axLetter) {
4544
return {
4645
start: {
@@ -218,13 +217,12 @@ histogram.supplyDefaults = function(traceIn, traceOut) {
218217
binDirections.forEach(function(binDirection){
219218
// data being binned - note that even though it's a little weird,
220219
// it's possible to have bins without data, if there's inferred data
221-
var binstrt = coerce(binDirection + 'bins.start'),
222-
binend = coerce(binDirection + 'bins.end'),
223-
validbin = binstrt!==undefined && binend!==undefined,
224-
autobin = validbin ?
220+
var binstrt = Plotly.Lib.coerce(traceIn, traceOut, histogram.attributes, binDirection + 'bins.start'),
221+
binend = Plotly.Lib.coerce(traceIn, traceOut, histogram.attributes, binDirection + 'bins.end'),
222+
autobin = binstrt && binend ?
225223
coerce('autobin' + binDirection, false) :
226224
coerce('autobin' + binDirection);
227-
225+
228226
if(autobin) coerce('nbins' + binDirection);
229227
else coerce(binDirection + 'bins.size');
230228
});

shelly/plotlyjs/static/plotlyjs/src/lib/lib.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,14 @@ lib.coerce = function(containerIn, containerOut, attributes, attribute, dflt) {
16521652
return propOut.get();
16531653
};
16541654

1655+
// use coerce to get attibute value if user input is valid, return attribute default
1656+
// if user input it not valid or retun false if there is no user input.
1657+
lib.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {
1658+
var propIn = lib.nestedProperty(containerIn, attribute),
1659+
propOut = lib.coerce(containerIn, containerOut, attributes, attribute, dflt);
1660+
return propIn.get() ? propOut : false;
1661+
};
1662+
16551663
// shortcut to coerce the three font attributes
16561664
// 'coerce' is a lib.coerce wrapper with implied first three arguments
16571665
lib.coerceFont = function(coerce, attr, dfltObj) {

shelly/plotlyjs/static/plotlyjs/tests/lib_test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,57 @@ describe('Test lib.js:', function() {
494494
});
495495
});
496496

497+
describe('coerce2', function() {
498+
var coerce2 = Plotly.Lib.coerce2,
499+
out;
500+
501+
it('should set a value and return the value it sets when user input is valid', function() {
502+
var colVal = 'red',
503+
sizeVal = 14,
504+
attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
505+
testSize: {valType: 'number', dflt: 20}}},
506+
obj = {testMarker: {testColor: colVal, testSize: sizeVal}},
507+
outObj = {},
508+
colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'),
509+
sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
510+
511+
expect(colOut).toBe(colVal);
512+
expect(colOut).toBe(outObj.testMarker.testColor);
513+
expect(sizeOut).toBe(sizeVal);
514+
expect(sizeOut).toBe(outObj.testMarker.testSize);
515+
});
516+
517+
it('should set and return the default if the user input is not valid', function() {
518+
var colVal = 'r',
519+
sizeVal = 'aaaaah!',
520+
attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
521+
testSize: {valType: 'number', dflt: 20}}},
522+
obj = {testMarker: {testColor: colVal, testSize: sizeVal}},
523+
outObj = {},
524+
colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'),
525+
sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
526+
527+
expect(colOut).toBe('rgba(0, 0, 0, 0)');
528+
expect(sizeOut).toBe(outObj.testMarker.testSize);
529+
expect(sizeOut).toBe(20);
530+
expect(sizeOut).toBe(outObj.testMarker.testSize);
531+
});
532+
533+
it('should return false if there is no user input', function() {
534+
var colVal = null,
535+
sizeVal = null,
536+
attrs = {testMarker: {testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
537+
testSize: {valType: 'number', dflt: 20}}},
538+
obj = {testMarker: {testColor: colVal, testSize: sizeVal}},
539+
outObj = {},
540+
colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor'),
541+
sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
542+
543+
expect(colOut).toBe(false);
544+
expect(sizeOut).toBe(false);
545+
});
546+
});
547+
497548
describe('info_array valType', function() {
498549
var infoArrayAttrs = {
499550
range: {

0 commit comments

Comments
 (0)