Skip to content

Commit

Permalink
Merge pull request #2525 from plotly/react-finance-precursor
Browse files Browse the repository at this point in the history
React finance precursor
  • Loading branch information
alexcjohnson committed Apr 5, 2018
2 parents 3d65de3 + c2b11dc commit acc7d81
Show file tree
Hide file tree
Showing 27 changed files with 434 additions and 418 deletions.
8 changes: 7 additions & 1 deletion src/plot_api/plot_api.js
Expand Up @@ -2429,8 +2429,14 @@ function diffData(gd, oldFullData, newFullData, immutable) {
gd: gd
};


var seenUIDs = {};

for(i = 0; i < oldFullData.length; i++) {
trace = newFullData[i];
trace = newFullData[i]._fullInput;
if(seenUIDs[trace.uid]) continue;
seenUIDs[trace.uid] = 1;

diffOpts.autoranged = trace.xaxis ? (
Axes.getFromId(gd, trace.xaxis).autorange ||
Axes.getFromId(gd, trace.yaxis).autorange
Expand Down
18 changes: 12 additions & 6 deletions src/plots/plots.js
Expand Up @@ -380,7 +380,7 @@ plots.supplyDefaults = function(gd) {
if(_module.cleanData) _module.cleanData(newFullData);
}

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

// 'regular' loop
for(i = 0; i < fullData.length; i++) {
var cd = [];

function calci(i, isContainer) {
trace = fullData[i];
_module = trace._module;

if(!!_module.isContainer !== isContainer) return;

var cd = [];

if(trace.visible === true) {
_module = trace._module;

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

// 'regular' loop - make sure container traces (eg carpet) calc before
// contained traces (eg contourcarpet)
for(i = 0; i < fullData.length; i++) calci(i, true);
for(i = 0; i < fullData.length; i++) calci(i, false);

Registry.getComponentMethod('fx', 'calc')(gd);
};

Expand Down
2 changes: 1 addition & 1 deletion src/traces/candlestick/defaults.js
Expand Up @@ -23,7 +23,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

var len = handleOHLC(traceIn, traceOut, coerce, layout);
if(len === 0) {
if(!len) {
traceOut.visible = false;
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/traces/candlestick/transform.js
Expand Up @@ -60,7 +60,8 @@ function makeTrace(traceIn, state, direction) {
xaxis: traceIn.xaxis,
yaxis: traceIn.yaxis,

transforms: helpers.makeTransform(traceIn, state, direction)
transforms: helpers.makeTransform(traceIn, state, direction),
_inputLength: traceIn._inputLength
};

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

var len = open.length,
var len = trace._inputLength,
x = [],
y = [];

Expand Down
3 changes: 3 additions & 0 deletions src/traces/carpet/axis_defaults.js
Expand Up @@ -103,7 +103,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);
}

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

var dfltColor = coerce('color', options.dfltColor);
// if axis.color was provided, use it for fonts too; otherwise,
Expand Down
41 changes: 25 additions & 16 deletions src/traces/carpet/calc.js
Expand Up @@ -11,31 +11,42 @@
var Axes = require('../../plots/cartesian/axes');
var cheaterBasis = require('./cheater_basis');
var arrayMinmax = require('./array_minmax');
var map2dArray = require('./map_2d_array');
var calcGridlines = require('./calc_gridlines');
var calcLabels = require('./calc_labels');
var calcClipPath = require('./calc_clippath');
var clean2dArray = require('../heatmap/clean_2d_array');
var smoothFill2dArray = require('./smooth_fill_2d_array');
var hasColumns = require('./has_columns');
var convertColumnData = require('../heatmap/convert_column_xyz');
var setConvert = require('./set_convert');

module.exports = function calc(gd, trace) {
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
var xa = Axes.getFromId(gd, trace.xaxis);
var ya = Axes.getFromId(gd, trace.yaxis);
var aax = trace.aaxis;
var bax = trace.baxis;
var a = trace._a = trace.a;
var b = trace._b = trace.b;

var t = {};
var x;
var x = trace.x;
var y = trace.y;
var cols = [];
if(x && !hasColumns(x)) cols.push('x');
if(y && !hasColumns(y)) cols.push('y');

if(cols.length) {
convertColumnData(trace, aax, bax, 'a', 'b', cols);
}

var a = trace._a = trace._a || trace.a;
var b = trace._b = trace._b || trace.b;
x = trace._x || trace.x;
y = trace._y || trace.y;

var t = {};

if(trace._cheater) {
var avals = aax.cheatertype === 'index' ? a.length : a;
var bvals = bax.cheatertype === 'index' ? b.length : b;
x = cheaterBasis(avals, bvals, trace.cheaterslope);
} else {
x = trace.x;
}

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

setConvert(trace);

// create conversion functions that depend on the data
trace.setScale();

// Convert cartesian-space x/y coordinates to screen space pixel coordinates:
t.xp = trace.xp = map2dArray(trace.xp, x, xa.c2p);
t.yp = trace.yp = map2dArray(trace.yp, y, ya.c2p);

// This is a rather expensive scan. Nothing guarantees monotonicity,
// so we need to scan through all data to get proper ranges:
var xrange = arrayMinmax(x);
Expand All @@ -78,8 +87,8 @@ module.exports = function calc(gd, trace) {

// Enumerate the gridlines, both major and minor, and store them on the trace
// object:
calcGridlines(trace, t, 'a', 'b');
calcGridlines(trace, t, 'b', 'a');
calcGridlines(trace, 'a', 'b');
calcGridlines(trace, 'b', 'a');

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

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

t.x = x;
t.y = y;
Expand Down
14 changes: 7 additions & 7 deletions src/traces/carpet/calc_gridlines.js
Expand Up @@ -11,31 +11,31 @@
var Axes = require('../../plots/cartesian/axes');
var extendFlat = require('../../lib/extend').extendFlat;

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

var data = trace[axisLetter];
var data = trace['_' + axisLetter];
var axis = trace[axisLetter + 'axis'];

var gridlines = axis._gridlines = [];
var minorgridlines = axis._minorgridlines = [];
var boundarylines = axis._boundarylines = [];

var crossData = trace[crossAxisLetter];
var crossData = trace['_' + crossAxisLetter];
var crossAxis = trace[crossAxisLetter + 'axis'];

if(axis.tickmode === 'array') {
axis.tickvals = data.slice();
}

var xcp = trace.xctrl;
var ycp = trace.yctrl;
var xcp = trace._xctrl;
var ycp = trace._yctrl;
var nea = xcp[0].length;
var neb = xcp.length;
var na = trace.a.length;
var nb = trace.b.length;
var na = trace._a.length;
var nb = trace._b.length;

Axes.prepTicks(axis);

Expand Down
3 changes: 0 additions & 3 deletions src/traces/carpet/defaults.js
Expand Up @@ -12,7 +12,6 @@
var Lib = require('../../lib');
var handleXYDefaults = require('./xy_defaults');
var handleABDefaults = require('./ab_defaults');
var setConvert = require('./set_convert');
var attributes = require('./attributes');
var colorAttrs = require('../../components/color/attributes');

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

setConvert(traceOut);

if(traceOut._cheater) {
coerce('cheaterslope');
}
Expand Down
1 change: 1 addition & 0 deletions src/traces/carpet/index.js
Expand Up @@ -16,6 +16,7 @@ Carpet.supplyDefaults = require('./defaults');
Carpet.plot = require('./plot');
Carpet.calc = require('./calc');
Carpet.animatable = true;
Carpet.isContainer = true; // so carpet traces get `calc` before other traces

Carpet.moduleType = 'trace';
Carpet.name = 'carpet';
Expand Down
45 changes: 0 additions & 45 deletions src/traces/carpet/map_2d_array.js

This file was deleted.

24 changes: 10 additions & 14 deletions src/traces/carpet/set_convert.js
Expand Up @@ -25,10 +25,10 @@ var createJDerivativeEvaluator = require('./create_j_derivative_evaluator');
* p: screen-space pixel coordinates
*/
module.exports = function setConvert(trace) {
var a = trace.a;
var b = trace.b;
var na = trace.a.length;
var nb = trace.b.length;
var a = trace._a;
var b = trace._b;
var na = a.length;
var nb = b.length;
var aax = trace.aaxis;
var bax = trace.baxis;

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

// XXX: ONLY PASSTHRU. ONLY. No, ONLY.
aax.c2p = function(v) { return v; };
bax.c2p = function(v) { return v; };

trace.setScale = function() {
var x = trace._x;
var y = trace._y;
Expand All @@ -72,18 +68,18 @@ module.exports = function setConvert(trace) {
// an expanded basis of control points. Note in particular that it overwrites the existing
// basis without creating a new array since that would potentially thrash the garbage
// collector.
var result = computeControlPoints(trace.xctrl, trace.yctrl, x, y, aax.smoothing, bax.smoothing);
trace.xctrl = result[0];
trace.yctrl = result[1];
var result = computeControlPoints(trace._xctrl, trace._yctrl, x, y, aax.smoothing, bax.smoothing);
trace._xctrl = result[0];
trace._yctrl = result[1];

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

trace.dxydi = createIDerivativeEvaluator([trace.xctrl, trace.yctrl], aax.smoothing, bax.smoothing);
trace.dxydj = createJDerivativeEvaluator([trace.xctrl, trace.yctrl], aax.smoothing, bax.smoothing);
trace.dxydi = createIDerivativeEvaluator([trace._xctrl, trace._yctrl], aax.smoothing, bax.smoothing);
trace.dxydj = createJDerivativeEvaluator([trace._xctrl, trace._yctrl], aax.smoothing, bax.smoothing);
};

/*
Expand Down
21 changes: 2 additions & 19 deletions src/traces/carpet/xy_defaults.js
Expand Up @@ -9,28 +9,11 @@

'use strict';

var hasColumns = require('./has_columns');
var convertColumnData = require('../heatmap/convert_column_xyz');

module.exports = function handleXYDefaults(traceIn, traceOut, coerce) {
var cols = [];
var x = coerce('x');

var needsXTransform = x && !hasColumns(x);
if(needsXTransform) cols.push('x');

traceOut._cheater = !x;

var y = coerce('y');

var needsYTransform = y && !hasColumns(y);
if(needsYTransform) cols.push('y');

if(!x && !y) return;

if(cols.length) {
convertColumnData(traceOut, traceOut.aaxis, traceOut.baxis, 'a', 'b', cols);
}
traceOut._cheater = !x;

return true;
return !!x || !!y;
};
2 changes: 1 addition & 1 deletion src/traces/contour/empty_pathinfo.js
Expand Up @@ -21,7 +21,7 @@ module.exports = function emptyPathinfo(contours, plotinfo, cd0) {
var pathinfo = [];
var end = endPlus(contoursFinal);

var carpet = cd0.trace.carpetTrace;
var carpet = cd0.trace._carpetTrace;

var basePathinfo = carpet ? {
// store axes so we can convert to px
Expand Down

0 comments on commit acc7d81

Please sign in to comment.