Skip to content

Commit 2fab4bb

Browse files
committed
initial streamtubes commit (squashed)
1 parent b6fc59d commit 2fab4bb

18 files changed

+2067
-43
lines changed

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Core.register([
2525
require('./pie'),
2626
require('./contour'),
2727
require('./scatter3d'),
28+
require('./streamtubes'),
2829
require('./surface'),
2930
require('./mesh3d'),
3031
require('./scattergeo'),

lib/streamtubes.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, 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+
module.exports = require('../src/traces/streamtubes');

src/traces/mesh3d/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Mesh3D.colorbar = require('../heatmap/colorbar');
1717
Mesh3D.plot = require('./convert');
1818

1919
Mesh3D.moduleType = 'trace';
20-
Mesh3D.name = 'mesh3d',
20+
Mesh3D.name = 'mesh3d';
2121
Mesh3D.basePlotModule = require('../../plots/gl3d');
2222
Mesh3D.categories = ['gl3d'];
2323
Mesh3D.meta = {
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright 2012-2016, 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+
10+
'use strict';
11+
12+
var hasColorscale = require('../../components/colorscale/has_colorscale');
13+
var colorscaleDefaults = require('../../components/colorscale/defaults');
14+
15+
16+
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
17+
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
18+
19+
var markerColor = (traceIn.marker || {}).color;
20+
21+
coerce('line.color', defaultColor);
22+
if(hasColorscale(traceIn, 'line')) {
23+
colorscaleDefaults(
24+
traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'}
25+
);
26+
} else {
27+
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
28+
defaultColor);
29+
}
30+
31+
32+
coerce('line.width');
33+
};

src/traces/scatter/line_defaults.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,13 @@
99

1010
'use strict';
1111

12-
var hasColorscale = require('../../components/colorscale/has_colorscale');
13-
var colorscaleDefaults = require('../../components/colorscale/defaults');
12+
var basicLineDefaults = require('./basic_line_defaults');
1413

1514

1615
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
1716
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
1817

19-
var markerColor = (traceIn.marker || {}).color;
18+
basicLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
2019

21-
coerce('line.color', defaultColor);
22-
if(hasColorscale(traceIn, 'line')) {
23-
colorscaleDefaults(
24-
traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'}
25-
);
26-
} else {
27-
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
28-
defaultColor);
29-
}
30-
31-
32-
coerce('line.width');
3320
coerce('line.dash');
3421
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2012-2016, 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+
10+
'use strict';
11+
12+
var hasColorscale = require('../../components/colorscale/has_colorscale');
13+
var colorscaleDefaults = require('../../components/colorscale/defaults');
14+
15+
var subTypes = require('./subtypes');
16+
17+
18+
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
19+
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
20+
var isBubble = subTypes.isBubble(traceIn),
21+
lineColor = !Array.isArray(traceIn.line) ? (traceIn.line || {}).color : undefined;
22+
23+
if(lineColor) defaultColor = lineColor;
24+
25+
coerce('marker.opacity', isBubble ? 0.7 : 1);
26+
coerce('marker.size');
27+
28+
coerce('marker.color', defaultColor);
29+
if(hasColorscale(traceIn, 'marker')) {
30+
colorscaleDefaults(
31+
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
32+
);
33+
}
34+
35+
if(isBubble) {
36+
coerce('marker.sizeref');
37+
coerce('marker.sizemin');
38+
coerce('marker.sizemode');
39+
}
40+
41+
return lineColor;
42+
};

src/traces/scatter/marker_defaults.js

+7-19
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,22 @@
99

1010
'use strict';
1111

12+
var markerBasicDefaults = require('./marker_basic_defaults');
1213
var Color = require('../../components/color');
1314
var hasColorscale = require('../../components/colorscale/has_colorscale');
1415
var colorscaleDefaults = require('../../components/colorscale/defaults');
1516

1617
var subTypes = require('./subtypes');
1718

18-
1919
// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
2020
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
21-
var isBubble = subTypes.isBubble(traceIn),
22-
lineColor = !Array.isArray(traceIn.line) ? (traceIn.line || {}).color : undefined,
23-
defaultMLC;
2421

25-
if(lineColor) defaultColor = lineColor;
22+
var defaultMLC;
2623

27-
coerce('marker.symbol');
28-
coerce('marker.opacity', isBubble ? 0.7 : 1);
29-
coerce('marker.size');
24+
var isBubble = subTypes.isBubble(traceIn)
25+
var lineColor = markerBasicDefaults(traceIn, traceOut, defaultColor, layout, coerce);
3026

31-
coerce('marker.color', defaultColor);
32-
if(hasColorscale(traceIn, 'marker')) {
33-
colorscaleDefaults(
34-
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
35-
);
36-
}
27+
coerce('marker.symbol');
3728

3829
// if there's a line with a different color than the marker, use
3930
// that line color as the default marker line color
@@ -45,6 +36,7 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout
4536
else defaultMLC = Color.defaultLine;
4637

4738
coerce('marker.line.color', defaultMLC);
39+
4840
if(hasColorscale(traceIn, 'marker.line')) {
4941
colorscaleDefaults(
5042
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
@@ -53,9 +45,5 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout
5345

5446
coerce('marker.line.width', isBubble ? 1 : 0);
5547

56-
if(isBubble) {
57-
coerce('marker.sizeref');
58-
coerce('marker.sizemin');
59-
coerce('marker.sizemode');
60-
}
48+
6149
};

src/traces/scatter3d/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module.exports = {
112112
},
113113
colorAttributes('line')
114114
),
115-
marker: extendFlat({}, { // Parity with scatter.js?
115+
marker: extendFlat({}, {
116116
symbol: {
117117
valType: 'enumerated',
118118
values: Object.keys(MARKER_SYMBOLS),

src/traces/streamtubes/attributes.js

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* Copyright 2012-2016, 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 scatterAttrs = require('../scatter/attributes');
12+
var colorAttributes = require('../../components/colorscale/color_attributes');
13+
14+
var extendFlat = require('../../lib/extend').extendFlat;
15+
16+
var scatterLineAttrs = scatterAttrs.line,
17+
scatterMarkerAttrs = scatterAttrs.marker;
18+
19+
function makeProjectionAttr(axLetter) {
20+
return {
21+
show: {
22+
valType: 'boolean',
23+
role: 'info',
24+
dflt: false,
25+
description: [
26+
'Sets whether or not projections are shown along the',
27+
axLetter, 'axis.'
28+
].join(' ')
29+
},
30+
opacity: {
31+
valType: 'number',
32+
role: 'style',
33+
min: 0,
34+
max: 1,
35+
dflt: 1,
36+
description: 'Sets the projection color.'
37+
},
38+
scale: {
39+
valType: 'number',
40+
role: 'style',
41+
min: 0,
42+
max: 10,
43+
dflt: 2 / 3,
44+
description: [
45+
'Sets the scale factor determining the size of the',
46+
'projection marker points.'
47+
].join(' ')
48+
}
49+
};
50+
}
51+
52+
module.exports = {
53+
x: {
54+
valType: 'data_array',
55+
description: 'Sets the x coordinates.'
56+
},
57+
y: {
58+
valType: 'data_array',
59+
description: 'Sets the y coordinates.'
60+
},
61+
z: {
62+
valType: 'data_array',
63+
description: 'Sets the z coordinates.'
64+
},
65+
text: extendFlat({}, scatterAttrs.text, {
66+
description: [
67+
'Sets text elements associated with each (x,y,z) triplet.',
68+
'If a single string, the same string appears over',
69+
'all the data points.',
70+
'If an array of string, the items are mapped in order to the',
71+
'this trace\'s (x,y,z) coordinates.'
72+
].join(' ')
73+
}),
74+
mode: extendFlat({}, scatterAttrs.mode, // shouldn't this be on-par with 2D?
75+
{dflt: 'lines+markers'}),
76+
projection: {
77+
x: makeProjectionAttr('x'),
78+
y: makeProjectionAttr('y'),
79+
z: makeProjectionAttr('z')
80+
},
81+
connectgaps: scatterAttrs.connectgaps,
82+
line: extendFlat({}, {
83+
width: scatterLineAttrs.width,
84+
connectionradius: extendFlat({}, scatterMarkerAttrs.size, {
85+
dflt: 1,
86+
description: 'Sets the radius of the line connection. Either a number, or an array with as many elements as the number of points.'
87+
}),
88+
showscale: {
89+
valType: 'boolean',
90+
role: 'info',
91+
dflt: false,
92+
description: [
93+
'Has an effect only if `line.color` is set to a numerical array.',
94+
'Determines whether or not a colorbar is displayed.'
95+
].join(' ')
96+
}
97+
},
98+
colorAttributes('line')
99+
),
100+
marker: extendFlat({}, {
101+
size: extendFlat({}, scatterMarkerAttrs.size, {dflt: 8}),
102+
sizeref: scatterMarkerAttrs.sizeref,
103+
sizemin: scatterMarkerAttrs.sizemin,
104+
sizemode: scatterMarkerAttrs.sizemode,
105+
opacity: extendFlat({}, scatterMarkerAttrs.opacity, {
106+
arrayOk: false,
107+
description: [
108+
'Sets the marker opacity.',
109+
'Note that the marker opacity for scatter3d traces',
110+
'must be a scalar value for performance reasons.',
111+
'To set a blending opacity value',
112+
'(i.e. which is not transparent), set *marker.color*',
113+
'to an rgba color and use its alpha channel.'
114+
].join(' ')
115+
}),
116+
showscale: scatterMarkerAttrs.showscale
117+
},
118+
colorAttributes('marker')
119+
),
120+
textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center'}),
121+
textfont: scatterAttrs.textfont,
122+
_nestedModules: {
123+
'marker.colorbar': 'Colorbar'
124+
}
125+
};

src/traces/streamtubes/calc.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright 2012-2016, 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 arraysToCalcdata = require('../scatter/arrays_to_calcdata');
12+
var calcColorscales = require('../scatter/colorscale_calc');
13+
14+
15+
/**
16+
* This is a kludge to put the array attributes into
17+
* calcdata the way Scatter.plot does, so that legends and
18+
* popovers know what to do with them.
19+
*/
20+
module.exports = function calc(gd, trace) {
21+
var cd = [{x: false, y: false, trace: trace, t: {}}];
22+
23+
arraysToCalcdata(cd);
24+
calcColorscales(trace);
25+
26+
return cd;
27+
};

0 commit comments

Comments
 (0)