Skip to content

Recycled commits from abandoned fast trace toggle PRs #2860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
69dc0c4
DRY and small pref boost for scattergl
etpinard Jul 31, 2018
41ad08a
push trace module into fullLayout._modules even if visible:false
etpinard Jul 23, 2018
9c8ba02
fill in list of visible:true module in fullLayout._visibleModules
etpinard Jul 23, 2018
8ef5cb3
fix and :lock: splom trace visible toggling
etpinard Jul 23, 2018
cf0b19d
sub fail -> failTest
etpinard Jul 26, 2018
9cc5fbe
add scatter visibility restyles tests
etpinard Jul 25, 2018
dfada6a
add bar autorange tests & move 'b' init to setPositions
etpinard Jul 26, 2018
be44366
add findExtremes
etpinard Jul 25, 2018
ad1ac1f
adapt getAutoRange and doAutoRange to trace _extremes
etpinard Jul 25, 2018
769c160
fill trace._extremes with findExtremes in calc
etpinard Jul 25, 2018
736ab69
replace Axex.expand -> findExtremes in annotations and shapes
etpinard Jul 25, 2018
6194457
:hocho: ax._min / ax._max logic for rangeslider
etpinard Jul 25, 2018
8cd06ae
adapt enforceConstraints to new per trace/item _extremes
etpinard Jul 25, 2018
2a745de
adapt polar to new per trace/item _extremes
etpinard Jul 25, 2018
82d4bcc
adapt gl2d to findExtremes
etpinard Jul 26, 2018
29db388
:hocho: Axes.expand & adapt test for findExtremes
etpinard Jul 26, 2018
72f06a6
improve concatExtremes perf
etpinard Jul 27, 2018
a0bfaf3
collapse trace extremes before getAutorange
etpinard Jul 30, 2018
33b4085
mv repeat -> Lib.repeat
etpinard Aug 1, 2018
d233f3b
fix and :lock: _extremes in polar tranformed traces
etpinard Aug 1, 2018
89aebd1
fix typos in :books:
etpinard Aug 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/annotations/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ function handleAnnotationDefaults(annIn, annOut, fullLayout) {
// xref, yref
var axRef = Axes.coerceRef(annIn, annOut, gdMock, axLetter, '', 'paper');

if(axRef !== 'paper') {
var ax = Axes.getFromId(gdMock, axRef);
ax._annIndices.push(annOut._index);
}

// x, y
Axes.coercePosition(annOut, gdMock, coerce, axRef, axLetter, 0.5);

Expand Down
1 change: 1 addition & 0 deletions src/components/shapes/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {

if(axRef !== 'paper') {
ax = Axes.getFromId(gdMock, axRef);
ax._shapeIndices.push(shapeOut._index);
r2pos = helpers.rangeToShapePosition(ax);
pos2r = helpers.shapePositionToRange(ax);
}
Expand Down
84 changes: 29 additions & 55 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ var isNumeric = require('fast-isnumeric');
var Lib = require('../../lib');
var FP_SAFE = require('../../constants/numerical').FP_SAFE;

var Registry = require('../../registry');

module.exports = {
getAutoRange: getAutoRange,
makePadFn: makePadFn,
Expand All @@ -31,16 +29,17 @@ module.exports = {
*
* getAutoRange uses return values from findExtremes where:
*
* {
* val: calcdata value,
* pad: extra pixels beyond this value,
* extrapad: bool, does this point want 5% extra padding
* }
*
* @param {object} gd:
* graph div object with filled in fullData and fullLayout,
* graph div object with filled-in fullData and fullLayout, in particular
* with filled-in '_extremes' containers:
* {
* val: calcdata value,
* pad: extra pixels beyond this value,
* extrapad: bool, does this point want 5% extra padding
* }
* @param {object} ax:
* full axis object
* full axis object, in particular with filled-in '_traceIndices'
* and '_annIndices' / '_shapeIndices' if applicable
* @return {array}
* an array of [min, max]. These are calcdata for log and category axes
* and data for linear and date axes.
Expand All @@ -55,8 +54,9 @@ function getAutoRange(gd, ax) {
var newRange = [];

var getPad = makePadFn(ax);
var minArray = concatExtremes(gd, ax, 'min');
var maxArray = concatExtremes(gd, ax, 'max');
var extremes = concatExtremes(gd, ax);
var minArray = extremes.min;
var maxArray = extremes.max;

if(minArray.length === 0 || maxArray.length === 0) {
return Lib.simpleMap(ax.range, ax.r2l);
Expand Down Expand Up @@ -189,57 +189,31 @@ function makePadFn(ax) {
return function getPad(pt) { return pt.pad + (pt.extrapad ? extrappad : 0); };
}

function concatExtremes(gd, ax, ext) {
var i;
var out = [];

function concatExtremes(gd, ax) {
var axId = ax._id;
var fullData = gd._fullData;
var fullLayout = gd._fullLayout;
var minArray = [];
var maxArray = [];

for(i = 0; i < fullData.length; i++) {
var trace = fullData[i];
var extremes = trace._extremes;

if(trace.visible === true) {
if(Registry.traceIs(trace, 'cartesian') || Registry.traceIs(trace, 'gl2d')) {
var axId = ax._id;
if(extremes[axId]) {
out = out.concat(extremes[axId][ext]);
}
} else if(Registry.traceIs(trace, 'polar')) {
if(trace.subplot === ax._subplot) {
out = out.concat(extremes[ax._name][ext]);
}
function _concat(cont, indices) {
for(var i = 0; i < indices.length; i++) {
var item = cont[indices[i]];
var extremes = (item._extremes || {})[axId];
if(item.visible === true && extremes) {
minArray = minArray.concat(extremes.min);
maxArray = maxArray.concat(extremes.max);
}
}
}

var fullLayout = gd._fullLayout;
var annotations = fullLayout.annotations;
var shapes = fullLayout.shapes;

if(Array.isArray(annotations)) {
out = out.concat(concatComponentExtremes(annotations, ax, ext));
}
if(Array.isArray(shapes)) {
out = out.concat(concatComponentExtremes(shapes, ax, ext));
}

return out;
}
_concat(fullData, ax._traceIndices);
_concat(fullLayout.annotations || [], ax._annIndices || []);
_concat(fullLayout.shapes || [], ax._shapeIndices || []);

function concatComponentExtremes(items, ax, ext) {
var out = [];
var axId = ax._id;
var letter = axId.charAt(0);
// TODO collapse more!

for(var i = 0; i < items.length; i++) {
var d = items[i];
var extremes = d._extremes;
if(d.visible && d[letter + 'ref'] === axId && extremes[axId]) {
out = out.concat(extremes[axId][ext]);
}
}
return out;
return {min: minArray, max: maxArray};
}

function doAutoRange(gd, ax) {
Expand Down
5 changes: 3 additions & 2 deletions src/plots/cartesian/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,19 @@ exports.enforce = function enforceAxisConstraints(gd) {
updateDomain(ax, factor);
ax.setScale();
var m = Math.abs(ax._m);
var extremes = concatExtremes(gd, ax);
var minArray = extremes.min;
var maxArray = extremes.max;
var newVal;
var k;

var minArray = concatExtremes(gd, ax, 'min');
for(k = 0; k < minArray.length; k++) {
newVal = minArray[k].val - getPad(minArray[k]) / m;
if(newVal > outerMin && newVal < rangeMin) {
rangeMin = newVal;
}
}

var maxArray = concatExtremes(gd, ax, 'max');
for(k = 0; k < maxArray.length; k++) {
newVal = maxArray[k].val + getPad(maxArray[k]) / m;
if(newVal < outerMax && newVal > rangeMax) {
Expand Down
72 changes: 51 additions & 21 deletions src/plots/cartesian/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

'use strict';

var Registry = require('../../registry');
var Lib = require('../../lib');
var Color = require('../../components/color');
var Template = require('../../plot_api/plot_template');
Expand All @@ -20,31 +19,57 @@ var handleTypeDefaults = require('./type_defaults');
var handleAxisDefaults = require('./axis_defaults');
var handleConstraintDefaults = require('./constraint_defaults');
var handlePositionDefaults = require('./position_defaults');

var axisIds = require('./axis_ids');
var id2name = axisIds.id2name;
var name2id = axisIds.name2id;

var Registry = require('../../registry');
var traceIs = Registry.traceIs;
var getComponentMethod = Registry.getComponentMethod;

function appendList(cont, k, item) {
if(Array.isArray(cont[k])) cont[k].push(item);
else cont[k] = [item];
}

module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
var ax2traces = {};
var xaCheater = {};
var xaNonCheater = {};
var outerTicks = {};
var noGrids = {};
var i;
var i, j;

// look for axes in the data
for(i = 0; i < fullData.length; i++) {
var trace = fullData[i];

if(!Registry.traceIs(trace, 'cartesian') && !Registry.traceIs(trace, 'gl2d')) {
continue;
if(!traceIs(trace, 'cartesian') && !traceIs(trace, 'gl2d')) continue;

var xaName;
if(trace.xaxis) {
xaName = id2name(trace.xaxis);
appendList(ax2traces, xaName, trace);
} else if(trace.xaxes) {
for(j = 0; j < trace.xaxes.length; j++) {
appendList(ax2traces, id2name(trace.xaxes[j]), trace);
}
}

var xaName = axisIds.id2name(trace.xaxis);
var yaName = axisIds.id2name(trace.yaxis);
var yaName;
if(trace.yaxis) {
yaName = id2name(trace.yaxis);
appendList(ax2traces, yaName, trace);
} else if(trace.yaxes) {
for(j = 0; j < trace.yaxes.length; j++) {
appendList(ax2traces, id2name(trace.yaxes[j]), trace);
}
}

// Two things trigger axis visibility:
// 1. is not carpet
// 2. carpet that's not cheater
if(!Registry.traceIs(trace, 'carpet') || (trace.type === 'carpet' && !trace._cheater)) {
if(!traceIs(trace, 'carpet') || (trace.type === 'carpet' && !trace._cheater)) {
if(xaName) xaNonCheater[xaName] = 1;
}

Expand All @@ -57,22 +82,22 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
}

// check for default formatting tweaks
if(Registry.traceIs(trace, '2dMap')) {
outerTicks[xaName] = true;
outerTicks[yaName] = true;
if(traceIs(trace, '2dMap')) {
outerTicks[xaName] = 1;
outerTicks[yaName] = 1;
}

if(Registry.traceIs(trace, 'oriented')) {
if(traceIs(trace, 'oriented')) {
var positionAxis = trace.orientation === 'h' ? yaName : xaName;
noGrids[positionAxis] = true;
noGrids[positionAxis] = 1;
}
}

var subplots = layoutOut._subplots;
var xIds = subplots.xaxis;
var yIds = subplots.yaxis;
var xNames = Lib.simpleMap(xIds, axisIds.id2name);
var yNames = Lib.simpleMap(yIds, axisIds.id2name);
var xNames = Lib.simpleMap(xIds, id2name);
var yNames = Lib.simpleMap(yIds, id2name);
var axNames = xNames.concat(yNames);

// plot_bgcolor only makes sense if there's a (2D) plot!
Expand Down Expand Up @@ -108,7 +133,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
var axName2 = list[j];

if(axName2 !== axName && !(layoutIn[axName2] || {}).overlaying) {
out.push(axisIds.name2id(axName2));
out.push(name2id(axName2));
}
}

Expand All @@ -127,7 +152,12 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
axLayoutIn = layoutIn[axName];
axLayoutOut = Template.newContainer(layoutOut, axName, axLetter + 'axis');

handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, fullData, axName);
var traces = ax2traces[axName] || [];
axLayoutOut._traceIndices = traces.map(function(t) { return t._expandedIndex; });
axLayoutOut._annIndices = [];
axLayoutOut._shapeIndices = [];

handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, traces, axName);

var overlayableAxes = getOverlayableAxes(axLetter, axName);

Expand All @@ -136,7 +166,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
font: layoutOut.font,
outerTicks: outerTicks[axName],
showGrid: !noGrids[axName],
data: fullData,
data: traces,
bgColor: bgColor,
calendar: layoutOut.calendar,
automargin: true,
Expand Down Expand Up @@ -173,8 +203,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
}

// quick second pass for range slider and selector defaults
var rangeSliderDefaults = Registry.getComponentMethod('rangeslider', 'handleDefaults');
var rangeSelectorDefaults = Registry.getComponentMethod('rangeselector', 'handleDefaults');
var rangeSliderDefaults = getComponentMethod('rangeslider', 'handleDefaults');
var rangeSelectorDefaults = getComponentMethod('rangeselector', 'handleDefaults');

for(i = 0; i < xNames.length; i++) {
axName = xNames[i];
Expand All @@ -201,7 +231,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
axLayoutIn = layoutIn[axName];
axLayoutOut = layoutOut[axName];

var anchoredAxis = layoutOut[axisIds.id2name(axLayoutOut.anchor)];
var anchoredAxis = layoutOut[id2name(axLayoutOut.anchor)];

var fixedRangeDflt = (
anchoredAxis &&
Expand Down
1 change: 1 addition & 0 deletions src/plots/polar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
// propagate the template.
var axOut = contOut[axName] = {};
axOut._id = axOut._name = axName;
axOut._traceIndices = subplotData.map(function(t) { return t.index; });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cartesian you use t._expandedIndex - should it be the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed and 🔒 in d233f3b


var dataAttr = constants.axisName2dataArray[axName];
var axType = handleAxisTypeDefaults(axIn, axOut, coerceAxis, subplotData, dataAttr);
Expand Down
1 change: 0 additions & 1 deletion src/plots/polar/polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ proto.updateLayout = function(fullLayout, polarLayout) {
proto.doAutoRange = function(fullLayout, polarLayout) {
var radialLayout = polarLayout.radialaxis;
var ax = this.radialAxis;
ax._subplot = this.id;

setScale(ax, radialLayout, fullLayout);
doAutoRange(this.gd, ax);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatterpolar/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = function calc(gd, trace) {
}

var ppad = calcMarkerSize(trace, len);
trace._extremes.radialaxis = Axes.findExtremes(radialAxis, rArray, {ppad: ppad});
trace._extremes.x = Axes.findExtremes(radialAxis, rArray, {ppad: ppad});

calcColorscale(trace);
arraysToCalcdata(cd, trace);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatterpolargl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function calc(container, trace) {
stash.r = rArray;
stash.theta = thetaArray;

trace._extremes.radialaxis = Axes.findExtremes(radialAxis, rArray, {tozero: true});
trace._extremes.x = Axes.findExtremes(radialAxis, rArray, {tozero: true});

return [{x: false, y: false, t: stash, trace: trace}];
}
Expand Down
22 changes: 16 additions & 6 deletions test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ describe('Test annotations', function() {
layoutOut._has = Plots._hasPlotType.bind(layoutOut);
layoutOut._subplots = {xaxis: ['x', 'x2'], yaxis: ['y', 'y2']};
['xaxis', 'yaxis', 'xaxis2', 'yaxis2'].forEach(function(axName) {
if(!layoutOut[axName]) layoutOut[axName] = {type: 'linear', range: [0, 1]};
if(!layoutOut[axName]) {
layoutOut[axName] = {
type: 'linear',
range: [0, 1],
_annIndices: []
};
}
Axes.setConvert(layoutOut[axName]);
});

Expand Down Expand Up @@ -90,7 +96,11 @@ describe('Test annotations', function() {
};

var layoutOut = {
xaxis: { type: 'date', range: ['2000-01-01', '2016-01-01'] }
xaxis: {
type: 'date',
range: ['2000-01-01', '2016-01-01'],
_annIndices: []
}
};

_supply(layoutIn, layoutOut);
Expand Down Expand Up @@ -128,10 +138,10 @@ describe('Test annotations', function() {
};

var layoutOut = {
xaxis: {type: 'linear', range: [0, 1]},
yaxis: {type: 'date', range: ['2000-01-01', '2018-01-01']},
xaxis2: {type: 'log', range: [1, 2]},
yaxis2: {type: 'category', range: [0, 1]}
xaxis: {type: 'linear', range: [0, 1], _annIndices: []},
yaxis: {type: 'date', range: ['2000-01-01', '2018-01-01'], _annIndices: []},
xaxis2: {type: 'log', range: [1, 2], _annIndices: []},
yaxis2: {type: 'category', range: [0, 1], _annIndices: []}
};

_supply(layoutIn, layoutOut);
Expand Down
Loading