Skip to content

Commit 6757bee

Browse files
committed
split up scatter methods into separate files
1 parent 6337313 commit 6757bee

File tree

9 files changed

+705
-581
lines changed

9 files changed

+705
-581
lines changed
Lines changed: 36 additions & 0 deletions
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/calc.js

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

src/traces/scatter/clean_data.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
13+
module.exports = function cleanData(fullData) {
14+
var i,
15+
tracei,
16+
filli,
17+
j,
18+
tracej;
19+
20+
// remove opacity for any trace that has a fill or is filled to
21+
for(i = 0; i < fullData.length; i++) {
22+
tracei = fullData[i];
23+
filli = tracei.fill;
24+
if(filli==='none' || (tracei.type !== 'scatter')) continue;
25+
tracei.opacity = undefined;
26+
27+
if(filli === 'tonexty' || filli === 'tonextx') {
28+
for(j = i - 1; j >= 0; j--) {
29+
tracej = fullData[j];
30+
if((tracej.type === 'scatter') &&
31+
(tracej.xaxis === tracei.xaxis) &&
32+
(tracej.yaxis === tracei.yaxis)) {
33+
tracej.opacity = undefined;
34+
break;
35+
}
36+
}
37+
}
38+
}
39+
};

0 commit comments

Comments
 (0)