Skip to content

Commit 8b5af93

Browse files
committed
first cut splom attributes and defaults
1 parent 29ca0ed commit 8b5af93

File tree

3 files changed

+253
-1
lines changed

3 files changed

+253
-1
lines changed

src/plots/plots.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ plots.supplyDefaults = function(gd) {
364364
// clear the lists of trace and baseplot modules, and subplots
365365
newFullLayout._modules = [];
366366
newFullLayout._basePlotModules = [];
367-
newFullLayout._subplots = emptySubplotLists();
367+
var subplots = newFullLayout._subplots = emptySubplotLists();
368+
var splomAxes = newFullLayout._splomAxes = {x: {}, y: {}};
368369

369370
// then do the data
370371
newFullLayout._globalTransforms = (gd._context || {}).globalTransforms;

src/traces/splom/attributes.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var scatterGlAttrs = require('../scattergl/attributes');
12+
var cartesianIdRegex = require('../../plots/cartesian/constants').idRegex;
13+
14+
function makeAxesValObject(axLetter) {
15+
return {
16+
valType: 'info_array',
17+
freeLength: true,
18+
role: 'info',
19+
editType: 'calc',
20+
items: {
21+
valType: 'enumerated',
22+
values: [cartesianIdRegex[axLetter].toString(), ''],
23+
editType: 'plot'
24+
},
25+
description: [
26+
'..'
27+
].join(' ')
28+
};
29+
}
30+
31+
module.exports = {
32+
dimensions: {
33+
_isLinkedToArray: 'dimension',
34+
35+
visible: {
36+
valType: 'boolean',
37+
role: 'info',
38+
dflt: true,
39+
editType: 'calc',
40+
description: ''
41+
},
42+
label: {
43+
valType: 'string',
44+
role: 'info',
45+
editType: 'calc',
46+
description: ''
47+
},
48+
values: {
49+
valType: 'data_array',
50+
role: 'info',
51+
editType: 'calc+clearAxisTypes',
52+
description: [
53+
''
54+
].join(' ')
55+
},
56+
57+
// TODO should add an attribute to pin down x only vars and y only vars
58+
// like https://seaborn.pydata.org/generated/seaborn.pairplot.html
59+
// x_vars and y_vars
60+
61+
editType: 'calc+clearAxisTypes',
62+
description: [
63+
'..'
64+
].join(' ')
65+
},
66+
67+
mode: scatterGlAttrs.mode,
68+
text: scatterGlAttrs.text,
69+
70+
marker: scatterGlAttrs.marker,
71+
72+
line: scatterGlAttrs.line,
73+
connectgaps: scatterGlAttrs.connectgaps,
74+
75+
xdirection: {
76+
valType: 'enumerated',
77+
values: ['right', 'left'],
78+
dflt: 'right',
79+
role: 'info',
80+
editType: 'plot',
81+
description: ''
82+
},
83+
ydirection: {
84+
valType: 'enumerated',
85+
values: ['top', 'bottom'],
86+
dflt: 'bottom',
87+
role: 'info',
88+
editType: 'plot',
89+
description: ''
90+
},
91+
92+
xaxes: makeAxesValObject('x'),
93+
yaxes: makeAxesValObject('y'),
94+
95+
showdiagonal: {
96+
valType: 'boolean',
97+
role: 'info',
98+
dflt: true,
99+
editType: 'plot',
100+
description: ''
101+
},
102+
showupperhalf: {
103+
valType: 'boolean',
104+
role: 'info',
105+
dflt: true,
106+
editType: 'plot',
107+
description: ''
108+
},
109+
showlowerhalf: {
110+
valType: 'boolean',
111+
role: 'info',
112+
dflt: true,
113+
editType: 'plot',
114+
description: ''
115+
},
116+
117+
selected: scatterGlAttrs.selected,
118+
unselected: scatterGlAttrs.unselected,
119+
120+
opacity: scatterGlAttrs.opacity
121+
};

src/traces/splom/defaults.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
13+
var attributes = require('./attributes');
14+
var subTypes = require('../scatter/subtypes');
15+
var handleMarkerDefaults = require('../scatter/marker_defaults');
16+
var handleLineDefaults = require('../scatter/line_defaults');
17+
var PTS_LINESONLY = require('../scatter/constants').PTS_LINESONLY;
18+
var OPEN_RE = /-open/;
19+
20+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
21+
function coerce(attr, dflt) {
22+
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
23+
}
24+
25+
var dimLength = handleDimensionsDefaults(traceIn, traceOut);
26+
if(!dimLength) {
27+
traceOut.visible = false;
28+
return;
29+
}
30+
31+
coerce('mode', traceOut._commonLength < PTS_LINESONLY ? 'lines+markers' : 'lines');
32+
coerce('text');
33+
34+
if(subTypes.hasLines(traceOut)) {
35+
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
36+
coerce('connectgaps');
37+
}
38+
39+
if(subTypes.hasMarkers(traceOut)) {
40+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce);
41+
42+
var isOpen = OPEN_RE.test(traceOut.marker.symbol);
43+
var isBubble = subTypes.isBubble(traceOut);
44+
coerce('marker.line.width', isOpen || isBubble ? 1 : 0);
45+
}
46+
47+
coerce('xdirection');
48+
coerce('ydirection');
49+
50+
handleAxisDefaults(traceIn, traceOut, layout, coerce);
51+
52+
coerce('showdiagonal');
53+
coerce('showupperhalf');
54+
coerce('showlowerhalf');
55+
56+
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
57+
};
58+
59+
function handleDimensionsDefaults(traceIn, traceOut) {
60+
var dimensionsIn = traceIn.dimensions;
61+
if(!Array.isArray(dimensionsIn)) return 0;
62+
63+
var dimLength = dimensionsIn.length;
64+
var commonLength = 0;
65+
var dimensionsOut = traceOut.dimensions = new Array(dimLength);
66+
var dimIn;
67+
var dimOut;
68+
var i;
69+
70+
function coerce(attr, dflt) {
71+
return Lib.coerce(dimIn, dimOut, attributes.dimensions, attr, dflt);
72+
}
73+
74+
for(i = 0; i < dimLength; i++) {
75+
dimIn = dimensionsIn[i];
76+
dimOut = dimensionsOut[i] = {};
77+
78+
var visible = coerce('visible');
79+
if(!visible) continue;
80+
81+
var values = coerce('values');
82+
if(!values || !values.length) {
83+
dimOut.visible = false;
84+
continue;
85+
}
86+
87+
coerce('label');
88+
89+
commonLength = Math.max(commonLength, values.length);
90+
dimOut._index = i;
91+
}
92+
93+
for(i = 0; i < dimLength; i++) {
94+
dimOut = dimensionsOut[i];
95+
if(dimOut.visible) dimOut._length = commonLength;
96+
}
97+
98+
traceOut._commonLength = commonLength;
99+
100+
return dimensionsOut.length;
101+
}
102+
103+
function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
104+
var dimensions = traceOut.dimensions;
105+
var dimLength = dimensions.length;
106+
var xaxesDflt = new Array(dimLength);
107+
var yaxesDflt = new Array(dimLength);
108+
var i;
109+
110+
for(i = 0; i < dimLength; i++) {
111+
xaxesDflt[i] = 'x' + (i ? i + 1 : '');
112+
yaxesDflt[i] = 'y' + (i ? i + 1 : '');
113+
}
114+
115+
var xaxes = coerce('xaxes', xaxesDflt);
116+
var yaxes = coerce('yaxes', yaxesDflt);
117+
118+
for(i = 0; i < dimLength; i++) {
119+
var dim = dimensions[i];
120+
var xa = xaxes[i];
121+
var ya = yaxes[i];
122+
123+
if(!(xa in layout._splomAxes.x)) {
124+
layout._splomAxes.x[xa] = dim.label || '';
125+
}
126+
if(!(ya in layout._splomAxes.y)) {
127+
layout._splomAxes.y[ya] = dim.label || '';
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)