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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 12 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 25 additions & 16 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)