Skip to content

Commit acc7d81

Browse files
authored
Merge pull request #2525 from plotly/react-finance-precursor
React finance precursor
2 parents 3d65de3 + c2b11dc commit acc7d81

27 files changed

+434
-418
lines changed

src/plot_api/plot_api.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -2429,8 +2429,14 @@ function diffData(gd, oldFullData, newFullData, immutable) {
24292429
gd: gd
24302430
};
24312431

2432+
2433+
var seenUIDs = {};
2434+
24322435
for(i = 0; i < oldFullData.length; i++) {
2433-
trace = newFullData[i];
2436+
trace = newFullData[i]._fullInput;
2437+
if(seenUIDs[trace.uid]) continue;
2438+
seenUIDs[trace.uid] = 1;
2439+
24342440
diffOpts.autoranged = trace.xaxis ? (
24352441
Axes.getFromId(gd, trace.xaxis).autorange ||
24362442
Axes.getFromId(gd, trace.yaxis).autorange

src/plots/plots.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ plots.supplyDefaults = function(gd) {
380380
if(_module.cleanData) _module.cleanData(newFullData);
381381
}
382382

383-
if(oldFullData.length === newData.length) {
383+
if(oldFullData.length === newFullData.length) {
384384
for(i = 0; i < newFullData.length; i++) {
385385
relinkPrivateKeys(newFullData[i], oldFullData[i]);
386386
}
@@ -2364,14 +2364,15 @@ plots.doCalcdata = function(gd, traces) {
23642364
// clear stuff that should recomputed in 'regular' loop
23652365
if(hasCalcTransform) clearAxesCalc(axList);
23662366

2367-
// 'regular' loop
2368-
for(i = 0; i < fullData.length; i++) {
2369-
var cd = [];
2370-
2367+
function calci(i, isContainer) {
23712368
trace = fullData[i];
2369+
_module = trace._module;
2370+
2371+
if(!!_module.isContainer !== isContainer) return;
2372+
2373+
var cd = [];
23722374

23732375
if(trace.visible === true) {
2374-
_module = trace._module;
23752376

23762377
// keep ref of index-to-points map object of the *last* enabled transform,
23772378
// this index-to-points map object is required to determine the calcdata indices
@@ -2406,6 +2407,11 @@ plots.doCalcdata = function(gd, traces) {
24062407
calcdata[i] = cd;
24072408
}
24082409

2410+
// 'regular' loop - make sure container traces (eg carpet) calc before
2411+
// contained traces (eg contourcarpet)
2412+
for(i = 0; i < fullData.length; i++) calci(i, true);
2413+
for(i = 0; i < fullData.length; i++) calci(i, false);
2414+
24092415
Registry.getComponentMethod('fx', 'calc')(gd);
24102416
};
24112417

src/traces/candlestick/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2323
}
2424

2525
var len = handleOHLC(traceIn, traceOut, coerce, layout);
26-
if(len === 0) {
26+
if(!len) {
2727
traceOut.visible = false;
2828
return;
2929
}

src/traces/candlestick/transform.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ function makeTrace(traceIn, state, direction) {
6060
xaxis: traceIn.xaxis,
6161
yaxis: traceIn.yaxis,
6262

63-
transforms: helpers.makeTransform(traceIn, state, direction)
63+
transforms: helpers.makeTransform(traceIn, state, direction),
64+
_inputLength: traceIn._inputLength
6465
};
6566

6667
// the rest of below may not have been coerced
@@ -99,7 +100,7 @@ exports.calcTransform = function calcTransform(gd, trace, opts) {
99100
low = trace.low,
100101
close = trace.close;
101102

102-
var len = open.length,
103+
var len = trace._inputLength,
103104
x = [],
104105
y = [];
105106

src/traces/carpet/axis_defaults.js

+3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
103103
handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);
104104
}
105105

106+
// we need some of the other functions setConvert attaches, but for
107+
// path finding, override pixel scaling to simple passthrough (identity)
106108
setConvert(containerOut, options.fullLayout);
109+
containerOut.c2p = Lib.identity;
107110

108111
var dfltColor = coerce('color', options.dfltColor);
109112
// if axis.color was provided, use it for fonts too; otherwise,

src/traces/carpet/calc.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,42 @@
1111
var Axes = require('../../plots/cartesian/axes');
1212
var cheaterBasis = require('./cheater_basis');
1313
var arrayMinmax = require('./array_minmax');
14-
var map2dArray = require('./map_2d_array');
1514
var calcGridlines = require('./calc_gridlines');
1615
var calcLabels = require('./calc_labels');
1716
var calcClipPath = require('./calc_clippath');
1817
var clean2dArray = require('../heatmap/clean_2d_array');
1918
var smoothFill2dArray = require('./smooth_fill_2d_array');
19+
var hasColumns = require('./has_columns');
20+
var convertColumnData = require('../heatmap/convert_column_xyz');
21+
var setConvert = require('./set_convert');
2022

2123
module.exports = function calc(gd, trace) {
22-
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
23-
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
24+
var xa = Axes.getFromId(gd, trace.xaxis);
25+
var ya = Axes.getFromId(gd, trace.yaxis);
2426
var aax = trace.aaxis;
2527
var bax = trace.baxis;
26-
var a = trace._a = trace.a;
27-
var b = trace._b = trace.b;
2828

29-
var t = {};
30-
var x;
29+
var x = trace.x;
3130
var y = trace.y;
31+
var cols = [];
32+
if(x && !hasColumns(x)) cols.push('x');
33+
if(y && !hasColumns(y)) cols.push('y');
34+
35+
if(cols.length) {
36+
convertColumnData(trace, aax, bax, 'a', 'b', cols);
37+
}
38+
39+
var a = trace._a = trace._a || trace.a;
40+
var b = trace._b = trace._b || trace.b;
41+
x = trace._x || trace.x;
42+
y = trace._y || trace.y;
43+
44+
var t = {};
3245

3346
if(trace._cheater) {
3447
var avals = aax.cheatertype === 'index' ? a.length : a;
3548
var bvals = bax.cheatertype === 'index' ? b.length : b;
3649
x = cheaterBasis(avals, bvals, trace.cheaterslope);
37-
} else {
38-
x = trace.x;
3950
}
4051

4152
trace._x = x = clean2dArray(x);
@@ -48,13 +59,11 @@ module.exports = function calc(gd, trace) {
4859
smoothFill2dArray(x, a, b);
4960
smoothFill2dArray(y, a, b);
5061

62+
setConvert(trace);
63+
5164
// create conversion functions that depend on the data
5265
trace.setScale();
5366

54-
// Convert cartesian-space x/y coordinates to screen space pixel coordinates:
55-
t.xp = trace.xp = map2dArray(trace.xp, x, xa.c2p);
56-
t.yp = trace.yp = map2dArray(trace.yp, y, ya.c2p);
57-
5867
// This is a rather expensive scan. Nothing guarantees monotonicity,
5968
// so we need to scan through all data to get proper ranges:
6069
var xrange = arrayMinmax(x);
@@ -78,8 +87,8 @@ module.exports = function calc(gd, trace) {
7887

7988
// Enumerate the gridlines, both major and minor, and store them on the trace
8089
// object:
81-
calcGridlines(trace, t, 'a', 'b');
82-
calcGridlines(trace, t, 'b', 'a');
90+
calcGridlines(trace, 'a', 'b');
91+
calcGridlines(trace, 'b', 'a');
8392

8493
// Calculate the text labels for each major gridline and store them on the
8594
// trace object:
@@ -88,7 +97,7 @@ module.exports = function calc(gd, trace) {
8897

8998
// Tabulate points for the four segments that bound the axes so that we can
9099
// map to pixel coordinates in the plot function and create a clip rect:
91-
t.clipsegments = calcClipPath(trace.xctrl, trace.yctrl, aax, bax);
100+
t.clipsegments = calcClipPath(trace._xctrl, trace._yctrl, aax, bax);
92101

93102
t.x = x;
94103
t.y = y;

src/traces/carpet/calc_gridlines.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@
1111
var Axes = require('../../plots/cartesian/axes');
1212
var extendFlat = require('../../lib/extend').extendFlat;
1313

14-
module.exports = function calcGridlines(trace, cd, axisLetter, crossAxisLetter) {
14+
module.exports = function calcGridlines(trace, axisLetter, crossAxisLetter) {
1515
var i, j, j0;
1616
var eps, bounds, n1, n2, n, value, v;
1717
var j1, v0, v1, d;
1818

19-
var data = trace[axisLetter];
19+
var data = trace['_' + axisLetter];
2020
var axis = trace[axisLetter + 'axis'];
2121

2222
var gridlines = axis._gridlines = [];
2323
var minorgridlines = axis._minorgridlines = [];
2424
var boundarylines = axis._boundarylines = [];
2525

26-
var crossData = trace[crossAxisLetter];
26+
var crossData = trace['_' + crossAxisLetter];
2727
var crossAxis = trace[crossAxisLetter + 'axis'];
2828

2929
if(axis.tickmode === 'array') {
3030
axis.tickvals = data.slice();
3131
}
3232

33-
var xcp = trace.xctrl;
34-
var ycp = trace.yctrl;
33+
var xcp = trace._xctrl;
34+
var ycp = trace._yctrl;
3535
var nea = xcp[0].length;
3636
var neb = xcp.length;
37-
var na = trace.a.length;
38-
var nb = trace.b.length;
37+
var na = trace._a.length;
38+
var nb = trace._b.length;
3939

4040
Axes.prepTicks(axis);
4141

src/traces/carpet/defaults.js

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
var Lib = require('../../lib');
1313
var handleXYDefaults = require('./xy_defaults');
1414
var handleABDefaults = require('./ab_defaults');
15-
var setConvert = require('./set_convert');
1615
var attributes = require('./attributes');
1716
var colorAttrs = require('../../components/color/attributes');
1817

@@ -49,8 +48,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, dfltColor, fullLayou
4948
// and i goes from 0 to a.length - 1.
5049
var len = handleXYDefaults(traceIn, traceOut, coerce);
5150

52-
setConvert(traceOut);
53-
5451
if(traceOut._cheater) {
5552
coerce('cheaterslope');
5653
}

src/traces/carpet/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Carpet.supplyDefaults = require('./defaults');
1616
Carpet.plot = require('./plot');
1717
Carpet.calc = require('./calc');
1818
Carpet.animatable = true;
19+
Carpet.isContainer = true; // so carpet traces get `calc` before other traces
1920

2021
Carpet.moduleType = 'trace';
2122
Carpet.name = 'carpet';

src/traces/carpet/map_2d_array.js

-45
This file was deleted.

src/traces/carpet/set_convert.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var createJDerivativeEvaluator = require('./create_j_derivative_evaluator');
2525
* p: screen-space pixel coordinates
2626
*/
2727
module.exports = function setConvert(trace) {
28-
var a = trace.a;
29-
var b = trace.b;
30-
var na = trace.a.length;
31-
var nb = trace.b.length;
28+
var a = trace._a;
29+
var b = trace._b;
30+
var na = a.length;
31+
var nb = b.length;
3232
var aax = trace.aaxis;
3333
var bax = trace.baxis;
3434

@@ -60,10 +60,6 @@ module.exports = function setConvert(trace) {
6060
return a < amin || a > amax || b < bmin || b > bmax;
6161
};
6262

63-
// XXX: ONLY PASSTHRU. ONLY. No, ONLY.
64-
aax.c2p = function(v) { return v; };
65-
bax.c2p = function(v) { return v; };
66-
6763
trace.setScale = function() {
6864
var x = trace._x;
6965
var y = trace._y;
@@ -72,18 +68,18 @@ module.exports = function setConvert(trace) {
7268
// an expanded basis of control points. Note in particular that it overwrites the existing
7369
// basis without creating a new array since that would potentially thrash the garbage
7470
// collector.
75-
var result = computeControlPoints(trace.xctrl, trace.yctrl, x, y, aax.smoothing, bax.smoothing);
76-
trace.xctrl = result[0];
77-
trace.yctrl = result[1];
71+
var result = computeControlPoints(trace._xctrl, trace._yctrl, x, y, aax.smoothing, bax.smoothing);
72+
trace._xctrl = result[0];
73+
trace._yctrl = result[1];
7874

7975
// This step is the second step in the process, but it's somewhat simpler. It just unrolls
8076
// some logic since it would be unnecessarily expensive to compute both interpolations
8177
// nearly identically but separately and to include a bunch of linear vs. bicubic logic in
8278
// every single call.
83-
trace.evalxy = createSplineEvaluator([trace.xctrl, trace.yctrl], na, nb, aax.smoothing, bax.smoothing);
79+
trace.evalxy = createSplineEvaluator([trace._xctrl, trace._yctrl], na, nb, aax.smoothing, bax.smoothing);
8480

85-
trace.dxydi = createIDerivativeEvaluator([trace.xctrl, trace.yctrl], aax.smoothing, bax.smoothing);
86-
trace.dxydj = createJDerivativeEvaluator([trace.xctrl, trace.yctrl], aax.smoothing, bax.smoothing);
81+
trace.dxydi = createIDerivativeEvaluator([trace._xctrl, trace._yctrl], aax.smoothing, bax.smoothing);
82+
trace.dxydj = createJDerivativeEvaluator([trace._xctrl, trace._yctrl], aax.smoothing, bax.smoothing);
8783
};
8884

8985
/*

src/traces/carpet/xy_defaults.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,11 @@
99

1010
'use strict';
1111

12-
var hasColumns = require('./has_columns');
13-
var convertColumnData = require('../heatmap/convert_column_xyz');
14-
1512
module.exports = function handleXYDefaults(traceIn, traceOut, coerce) {
16-
var cols = [];
1713
var x = coerce('x');
18-
19-
var needsXTransform = x && !hasColumns(x);
20-
if(needsXTransform) cols.push('x');
21-
22-
traceOut._cheater = !x;
23-
2414
var y = coerce('y');
2515

26-
var needsYTransform = y && !hasColumns(y);
27-
if(needsYTransform) cols.push('y');
28-
29-
if(!x && !y) return;
30-
31-
if(cols.length) {
32-
convertColumnData(traceOut, traceOut.aaxis, traceOut.baxis, 'a', 'b', cols);
33-
}
16+
traceOut._cheater = !x;
3417

35-
return true;
18+
return !!x || !!y;
3619
};

src/traces/contour/empty_pathinfo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function emptyPathinfo(contours, plotinfo, cd0) {
2121
var pathinfo = [];
2222
var end = endPlus(contoursFinal);
2323

24-
var carpet = cd0.trace.carpetTrace;
24+
var carpet = cd0.trace._carpetTrace;
2525

2626
var basePathinfo = carpet ? {
2727
// store axes so we can convert to px

0 commit comments

Comments
 (0)