Skip to content

Commit 999acd6

Browse files
committed
Merge branch 'master' into js-not-json
2 parents 6b99bb2 + f11f116 commit 999acd6

39 files changed

+1248
-946
lines changed

src/components/colorscale/attributes.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ module.exports = {
3434
colorscale: {
3535
valType: 'colorscale',
3636
role: 'style',
37-
description: 'Sets the colorscale.'
37+
description: [
38+
'Sets the colorscale.',
39+
'The colorscale must be an array containing',
40+
'arrays mapping a normalized value to an',
41+
'rgb, rgba, hex, hsl, hsv, or named color string.',
42+
'At minimum, a mapping for the lowest (0) and highest (1)',
43+
'values are required. For example,',
44+
'`[[0, \'rgb(0,0,255)\', [1, \'rgb(255,0,0)\']]`.',
45+
'To control the bounds of the colorscale in z space,',
46+
'use zmin and zmax'
47+
].join(' ')
3848
},
3949
autocolorscale: {
4050
valType: 'boolean',

src/components/drawing/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ var Plotly = require('../../plotly');
1313
var d3 = require('d3');
1414
var isNumeric = require('fast-isnumeric');
1515

16+
var subTypes = require('../../traces/scatter/subtypes');
17+
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
18+
1619
var drawing = module.exports = {};
1720

1821
// -----------------------------------------------------
@@ -175,14 +178,14 @@ drawing.pointStyle = function(s, trace) {
175178
// only scatter & box plots get marker path and opacity
176179
// bars, histograms don't
177180
if(Plotly.Plots.traceIs(trace, 'symbols')) {
178-
var sizeFn = Plotly.Scatter.getBubbleSizeFn(trace);
181+
var sizeFn = makeBubbleSizeFn(trace);
179182

180183
s.attr('d', function(d) {
181184
var r;
182185

183186
// handle multi-trace graph edit case
184187
if(d.ms==='various' || marker.size==='various') r = 3;
185-
else r = Plotly.Scatter.isBubble(trace) ?
188+
else r = subTypes.isBubble(trace) ?
186189
sizeFn(d.ms) : (marker.size || 6) / 2;
187190

188191
// store the calculated size so hover can use it

src/components/errorbars/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
1312
var d3 = require('d3');
1413
var isNumeric = require('fast-isnumeric');
1514

15+
var Lib = require('../../lib');
16+
var Color = require('../color');
17+
var subTypes = require('../../traces/scatter/subtypes');
18+
19+
1620
var errorBars = module.exports = {};
1721

1822
errorBars.attributes = require('./attributes');
@@ -70,13 +74,13 @@ errorBars.plot = function(gd, plotinfo, cd) {
7074
var trace = d[0].trace,
7175
xObj = trace.error_x,
7276
yObj = trace.error_y,
73-
sparse = Plotly.Scatter.hasMarkers(trace) &&
77+
sparse = subTypes.hasMarkers(trace) &&
7478
trace.marker.maxdisplayed>0;
7579

7680
if(!yObj.visible && !xObj.visible) return;
7781

7882
d3.select(this).selectAll('g')
79-
.data(Plotly.Lib.identity)
83+
.data(Lib.identity)
8084
.enter().append('g')
8185
.each(function(d){
8286
coords = errorcoords(d, xa, ya);
@@ -121,13 +125,13 @@ errorBars.style = function(gd){
121125

122126
eb.selectAll('g path.yerror')
123127
.style('stroke-width', yObj.thickness+'px')
124-
.call(Plotly.Color.stroke, yObj.color);
128+
.call(Color.stroke, yObj.color);
125129

126130
if(xObj.copy_ystyle) xObj = yObj;
127131

128132
eb.selectAll('g path.xerror')
129133
.style('stroke-width', xObj.thickness+'px')
130-
.call(Plotly.Color.stroke, xObj.color);
134+
.call(Color.stroke, xObj.color);
131135
});
132136
};
133137

src/components/legend/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
var Plotly = require('../../plotly');
1313
var d3 = require('d3');
1414

15+
var subTypes = require('../../traces/scatter/subtypes');
1516
var styleOne = require('../../traces/pie/style_one');
1617

1718
var legend = module.exports = {};
@@ -80,7 +81,7 @@ legend.supplyLayoutDefaults = function(layoutIn, layoutOut, fullData) {
8081
legend.lines = function(d){
8182
var trace = d[0].trace,
8283
showFill = trace.visible && trace.fill && trace.fill!=='none',
83-
showLine = Plotly.Scatter.hasLines(trace);
84+
showLine = subTypes.hasLines(trace);
8485

8586
var fill = d3.select(this).select('.legendfill').selectAll('path')
8687
.data(showFill ? [d] : []);
@@ -100,9 +101,9 @@ legend.lines = function(d){
100101
legend.points = function(d){
101102
var d0 = d[0],
102103
trace = d0.trace,
103-
showMarkers = Plotly.Scatter.hasMarkers(trace),
104-
showText = Plotly.Scatter.hasText(trace),
105-
showLines = Plotly.Scatter.hasLines(trace);
104+
showMarkers = subTypes.hasMarkers(trace),
105+
showText = subTypes.hasText(trace),
106+
showLines = subTypes.hasLines(trace);
106107

107108
var dMod, tMod;
108109

src/components/modebar/buttons.js

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ function handleCartesian(gd, ev) {
259259
);
260260
}
261261
Plotly.Fx.supplyLayoutDefaults(gd.layout, fullLayout, gd._fullData);
262+
Plotly.Fx.init(gd);
262263
}
263264
});
264265
}

src/plotly.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ exports.register = function register(_modules) {
8484
}
8585
};
8686

87-
88-
exports.register(require('./traces/scatter'));
89-
9087
// Scatter is the only trace included by default
91-
exports.Scatter = Plots.getModule('scatter');
88+
exports.register(require('./traces/scatter'));
9289

9390
// plot api
9491
require('./plot_api/plot_api');
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 Lib = require('../../lib');
13+
14+
15+
// arrayOk attributes, merge them into calcdata array
16+
module.exports = function arraysToCalcdata(cd) {
17+
var trace = cd[0].trace,
18+
marker = trace.marker;
19+
20+
Lib.mergeArray(trace.text, cd, 'tx');
21+
Lib.mergeArray(trace.textposition, cd, 'tp');
22+
if(trace.textfont) {
23+
Lib.mergeArray(trace.textfont.size, cd, 'ts');
24+
Lib.mergeArray(trace.textfont.color, cd, 'tc');
25+
Lib.mergeArray(trace.textfont.family, cd, 'tf');
26+
}
27+
28+
if(marker && marker.line) {
29+
var markerLine = marker.line;
30+
Lib.mergeArray(marker.opacity, cd, 'mo');
31+
Lib.mergeArray(marker.symbol, cd, 'mx');
32+
Lib.mergeArray(marker.color, cd, 'mc');
33+
Lib.mergeArray(markerLine.color, cd, 'mlc');
34+
Lib.mergeArray(markerLine.width, cd, 'mlw');
35+
}
36+
};

src/traces/scatter/attributes.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
var Drawing = require('../../components/drawing');
1212

13-
var PTS_LINESONLY = 20; // TODO put in constants/
13+
var constants = require('./constants');
14+
1415

1516
module.exports = {
1617
x: {
@@ -76,15 +77,15 @@ module.exports = {
7677
},
7778
mode: {
7879
valType: 'flaglist',
79-
flags: ['lines','markers','text'],
80+
flags: ['lines', 'markers', 'text'],
8081
extras: ['none'],
8182
role: 'info',
8283
description: [
8384
'Determines the drawing mode for this scatter trace.',
8485
'If the provided `mode` includes *text* then the `text` elements',
8586
'appear at the coordinates. Otherwise, the `text` elements',
8687
'appear on hover.',
87-
'If there are less than ' + PTS_LINESONLY + ' points,',
88+
'If there are less than ' + constants.PTS_LINESONLY + ' points,',
8889
'then the default is *lines+markers*. Otherwise, *lines*.'
8990
].join(' ')
9091
},
@@ -246,8 +247,15 @@ module.exports = {
246247
valType: 'colorscale',
247248
role: 'style',
248249
description: [
249-
'Has only an effect if `marker.color` is set to a numerical array.',
250-
'Sets the colorscale.'
250+
'Sets the colorscale.',
251+
'The colorscale must be an array containing',
252+
'arrays mapping a normalized value to an',
253+
'rgb, rgba, hex, hsl, hsv, or named color string.',
254+
'At minimum, a mapping for the lowest (0) and highest (1)',
255+
'values are required. For example,',
256+
'`[[0, \'rgb(0,0,255)\', [1, \'rgb(255,0,0)\']]`.',
257+
'To control the bounds of the colorscale in color space,',
258+
'use cmin and cmax'
251259
].join(' ')
252260
},
253261
cauto: {

src/traces/scatter/calc.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 isNumeric = require('fast-isnumeric');
13+
14+
var Axes = require('../../plots/cartesian/axes');
15+
var Lib = require('../../lib');
16+
17+
var subTypes = require('./subtypes');
18+
var calcMarkerColorscale = require('./marker_colorscale_calc');
19+
20+
21+
module.exports = function calc(gd, trace) {
22+
var xa = Axes.getFromId(gd, trace.xaxis || 'x'),
23+
ya = Axes.getFromId(gd, trace.yaxis || 'y');
24+
Lib.markTime('in Scatter.calc');
25+
26+
var x = xa.makeCalcdata(trace, 'x');
27+
Lib.markTime('finished convert x');
28+
29+
var y = ya.makeCalcdata(trace, 'y');
30+
Lib.markTime('finished convert y');
31+
32+
var serieslen = Math.min(x.length, y.length),
33+
marker,
34+
s,
35+
i;
36+
37+
// cancel minimum tick spacings (only applies to bars and boxes)
38+
xa._minDtick = 0;
39+
ya._minDtick = 0;
40+
41+
if(x.length > serieslen) x.splice(serieslen, x.length - serieslen);
42+
if(y.length > serieslen) y.splice(serieslen, y.length - serieslen);
43+
44+
// check whether bounds should be tight, padded, extended to zero...
45+
// most cases both should be padded on both ends, so start with that.
46+
var xOptions = {padded: true},
47+
yOptions = {padded: true};
48+
49+
if(subTypes.hasMarkers(trace)) {
50+
51+
// Treat size like x or y arrays --- Run d2c
52+
// this needs to go before ppad computation
53+
marker = trace.marker;
54+
s = marker.size;
55+
56+
if (Array.isArray(s)) {
57+
// I tried auto-type but category and dates dont make much sense.
58+
var ax = {type: 'linear'};
59+
Axes.setConvert(ax);
60+
s = ax.makeCalcdata(trace.marker, 'size');
61+
if(s.length > serieslen) s.splice(serieslen, s.length - serieslen);
62+
}
63+
64+
var sizeref = 1.6 * (trace.marker.sizeref || 1),
65+
markerTrans;
66+
if(trace.marker.sizemode === 'area') {
67+
markerTrans = function(v) {
68+
return Math.max(Math.sqrt((v || 0) / sizeref), 3);
69+
};
70+
}
71+
else {
72+
markerTrans = function(v) {
73+
return Math.max((v || 0) / sizeref, 3);
74+
};
75+
}
76+
xOptions.ppad = yOptions.ppad = Array.isArray(s) ?
77+
s.map(markerTrans) : markerTrans(s);
78+
}
79+
80+
calcMarkerColorscale(trace);
81+
82+
// TODO: text size
83+
84+
// include zero (tight) and extremes (padded) if fill to zero
85+
// (unless the shape is closed, then it's just filling the shape regardless)
86+
if(((trace.fill === 'tozerox') ||
87+
((trace.fill === 'tonextx') && gd.firstscatter)) &&
88+
((x[0] !== x[serieslen - 1]) || (y[0] !== y[serieslen - 1]))) {
89+
xOptions.tozero = true;
90+
}
91+
92+
// if no error bars, markers or text, or fill to y=0 remove x padding
93+
else if(!trace.error_y.visible && (
94+
['tonexty', 'tozeroy'].indexOf(trace.fill) !== -1 ||
95+
(!subTypes.hasMarkers(trace) && !subTypes.hasText(trace))
96+
)) {
97+
xOptions.padded = false;
98+
xOptions.ppad = 0;
99+
}
100+
101+
// now check for y - rather different logic, though still mostly padded both ends
102+
// include zero (tight) and extremes (padded) if fill to zero
103+
// (unless the shape is closed, then it's just filling the shape regardless)
104+
if(((trace.fill === 'tozeroy') || ((trace.fill === 'tonexty') && gd.firstscatter)) &&
105+
((x[0] !== x[serieslen - 1]) || (y[0] !== y[serieslen - 1]))) {
106+
yOptions.tozero = true;
107+
}
108+
109+
// tight y: any x fill
110+
else if(['tonextx', 'tozerox'].indexOf(trace.fill) !== -1) {
111+
yOptions.padded = false;
112+
}
113+
114+
Lib.markTime('ready for Axes.expand');
115+
Axes.expand(xa, x, xOptions);
116+
Lib.markTime('done expand x');
117+
Axes.expand(ya, y, yOptions);
118+
Lib.markTime('done expand y');
119+
120+
// create the "calculated data" to plot
121+
var cd = new Array(serieslen);
122+
for(i = 0; i < serieslen; i++) {
123+
cd[i] = (isNumeric(x[i]) && isNumeric(y[i])) ?
124+
{x: x[i], y: y[i]} : {x: false, y: false};
125+
}
126+
127+
// this has migrated up from arraysToCalcdata as we have a reference to 's' here
128+
if (typeof s !== undefined) Lib.mergeArray(s, cd, 'ms');
129+
130+
gd.firstscatter = false;
131+
return cd;
132+
};

0 commit comments

Comments
 (0)