Skip to content

Carpet plot rebase #1595

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 23 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eee837f
Add ensure array lib function to allocate/resize
rreusser Apr 13, 2017
5a0b788
Add axis cartesian axis visibility option
rreusser Apr 13, 2017
89e095e
Add measureText function to drawing
rreusser Apr 13, 2017
e1a0417
Tweak showscale to allow unset (instead of strictly false)
rreusser Apr 13, 2017
620cd43
Contour plot lines to use non-scaling stroke
rreusser Apr 13, 2017
728a6f4
Genericize heatmap xyz variable names
rreusser Apr 13, 2017
c2994e7
More carefully track legend trace isolation indices
rreusser Apr 13, 2017
fe9850c
Add optional overrides to contour handleStyleDefaults
rreusser Apr 13, 2017
d1f2258
Genericize tolerances in find_all_paths to make way for carpet
rreusser Apr 13, 2017
4bcf438
Add flag to disable scatter marker culling (needed for carpet)
rreusser Apr 13, 2017
6b896d8
Tweak contour colorscale logic since carpet may set infinities
rreusser Apr 13, 2017
b8c71e1
Add group to plot
rreusser Apr 13, 2017
e4971ef
Carpet plots
rreusser Apr 13, 2017
c98553a
make rreusser's carpet tests pass
etpinard Apr 13, 2017
71b96f3
add a few carpet interaction tests
etpinard Apr 13, 2017
bc1c5c8
:hocho: arraytools dep (sorry @bpostlethwaite)
etpinard Apr 14, 2017
9c76d7a
exit early in axis defaults when visible is false
etpinard Apr 14, 2017
85d6b8a
add axis `visible: false` mock
etpinard Apr 14, 2017
54f092d
implement axis visible in 3D
etpinard Apr 14, 2017
d9cb011
add 3d axis `visible: false` mock
etpinard Apr 14, 2017
f1e8aee
Merge pull request #1596 from plotly/carpet-test-etienne
etpinard Apr 17, 2017
bc0f890
extendFlat -> slice
etpinard Apr 17, 2017
c2a7092
Merge pull request #1599 from plotly/axis-visible-3d
etpinard Apr 17, 2017
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
11 changes: 11 additions & 0 deletions lib/carpet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('../src/traces/carpet');
11 changes: 11 additions & 0 deletions lib/contourcarpet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('../src/traces/contourcarpet');
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Plotly.register([

require('./scattermapbox'),

require('./carpet'),
require('./scattercarpet'),
require('./contourcarpet'),

require('./ohlc'),
require('./candlestick')
]);
Expand Down
11 changes: 11 additions & 0 deletions lib/scattercarpet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = require('../src/traces/scattercarpet');
10 changes: 10 additions & 0 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,13 @@ drawing.setPointGroupScale = function(selection, x, y) {

return scale;
};

drawing.measureText = function(tester, text, font) {
var dummyText = tester.append('text')
.text(text)
.call(drawing.font, font);

var bbox = drawing.bBox(dummyText.node());
dummyText.remove();
return bbox;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see why you did it this way, but it seems a little redundant, we're making a new node only to clone it in the global tester, then we delete them both. If this ends up getting called a lot, for performance we may want to break up drawing.bBox in such a way that this element can get created in the global tester in the first place.

Copy link
Contributor Author

@rreusser rreusser Apr 13, 2017

Choose a reason for hiding this comment

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

That makes sense. I didn't appreciate that the tester was also cloning it. And to add to that, it looks like I only ended up using it in one place. 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(but on the plus side, to answer your question, at least it doesn't end up getting called a lot 😄 )

8 changes: 7 additions & 1 deletion src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ function handleClick(g, gd, numClicks) {

for(i = 0; i < fullData.length; i++) {
allTraces.push(i);
// Allow the legendonly state through for *all* trace types (including
// carpet for which it's overridden with true/false in supplyDefaults)
traceVisibility.push('legendonly');
}

Expand Down Expand Up @@ -542,7 +544,11 @@ function handleClick(g, gd, numClicks) {
if(sameAsLast) {
traceVisibility = true;
}
Plotly.restyle(gd, 'visible', traceVisibility, allTraces);
var visibilityUpdates = [];
for(i = 0; i < fullData.length; i++) {
visibilityUpdates.push(allTraces[i]);
}
Plotly.restyle(gd, 'visible', traceVisibility, visibilityUpdates);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function styleLines(d) {
showFill = trace.visible && trace.fill && trace.fill !== 'none',
showLine = subTypes.hasLines(trace);

if(trace && trace._module && trace._module.name === 'contourcarpet') {
showLine = trace.contours.showlines;
showFill = trace.contours.coloring === 'fill';
}

var fill = d3.select(this).select('.legendfill').selectAll('path')
.data(showFill ? [d] : []);
fill.enter().append('path').classed('js-fill', true);
Expand Down
27 changes: 27 additions & 0 deletions src/lib/ensure_array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

/*
* Ensures an array has the right amount of storage space. If it doesn't
* exist, it creates an array. If it does exist, it returns it if too
* short or truncates it in-place.
*
* The goal is to just reuse memory to avoid a bit of excessive garbage
* collection.
*/
module.exports = function ensureArray(out, n) {
if(!Array.isArray(out)) out = [];

// If too long, truncate. (If too short, it will grow
// automatically so we don't care about that case)
out.length = n;
Copy link
Collaborator

Choose a reason for hiding this comment

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

huh, never knew you could resize this way!

Copy link
Contributor Author

@rreusser rreusser Apr 13, 2017

Choose a reason for hiding this comment

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

Best I can tell, it's actually robust and supported across platforms. It's possible it does weird things internally (like not actually de-allocating that memory. I saw a while ago some discussion of the various internal string apis and string data structures in js. Hint: it's not straightforward). The main goal was to just overwrite the carpet spline stuff rather than allocating everything from scratch every time since that adds up to lots of garbage collection.

Copy link
Contributor

@etpinard etpinard Apr 13, 2017

Choose a reason for hiding this comment

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

From https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/length

The array length property sets or returns the number of elements in an array.

That's right, [..] sets or returns [..].

It's not a read-only property like one might assume.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(best-case scenario though is that it actually truncates in-place without actually copying. I mean maybe copies, but slice() definitely copies.)


return out;
};
1 change: 1 addition & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lib.isArray = require('./is_array');
lib.mod = require('./mod');
lib.toLogRange = require('./to_log_range');
lib.relinkPrivateKeys = require('./relink_private');
lib.ensureArray = require('./ensure_array');

var coerceModule = require('./coerce');
lib.valObjects = coerceModule.valObjects;
Expand Down
34 changes: 31 additions & 3 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ function _restyle(gd, aobj, _traces) {
'autobinx', 'nbinsx', 'xbins', 'xbins.start', 'xbins.end', 'xbins.size',
'autobiny', 'nbinsy', 'ybins', 'ybins.start', 'ybins.end', 'ybins.size',
'autocontour', 'ncontours', 'contours', 'contours.coloring',
'contours.operation', 'contours.value', 'contours.type', 'contours.value[0]', 'contours.value[1]',
'error_y', 'error_y.visible', 'error_y.value', 'error_y.type',
'error_y.traceref', 'error_y.array', 'error_y.symmetric',
'error_y.arrayminus', 'error_y.valueminus', 'error_y.tracerefminus',
Expand All @@ -1311,9 +1312,31 @@ function _restyle(gd, aobj, _traces) {
'line.showscale', 'line.cauto', 'line.autocolorscale', 'line.reversescale',
'marker.line.showscale', 'marker.line.cauto', 'marker.line.autocolorscale', 'marker.line.reversescale',
'xcalendar', 'ycalendar',
'cumulative', 'cumulative.enabled', 'cumulative.direction', 'cumulative.currentbin'
'cumulative', 'cumulative.enabled', 'cumulative.direction', 'cumulative.currentbin',
'a0', 'da', 'b0', 'db', 'atype', 'btype',
'cheaterslope', 'carpet', 'sum',
];

var carpetAxisAttributes = [
'color', 'smoothing', 'title', 'titlefont', 'titlefont.size', 'titlefont.family',
'titlefont.color', 'titleoffset', 'type', 'autorange', 'rangemode', 'range',
'fixedrange', 'cheatertype', 'tickmode', 'nticks', 'tickvals', 'ticktext',
'ticks', 'mirror', 'ticklen', 'tickwidth', 'tickcolor', 'showticklabels',
'tickfont', 'tickfont.size', 'tickfont.family', 'tickfont.color', 'tickprefix',
'showtickprefix', 'ticksuffix', 'showticksuffix', 'showexponent', 'exponentformat',
'separatethousands', 'tickformat', 'categoryorder', 'categoryarray', 'labelpadding',
'labelprefix', 'labelsuffix', 'labelfont', 'labelfont.family', 'labelfont.size',
'labelfont.color', 'showline', 'linecolor', 'linewidth', 'gridcolor', 'gridwidth',
'showgrid', 'minorgridcount', 'minorgridwidth', 'minorgridcolor', 'startline',
'startlinecolor', 'startlinewidth', 'endline', 'endlinewidth', 'endlinecolor',
'tick0', 'dtick', 'arraytick0', 'arraydtick', 'hoverformat', 'tickangle'
];

for(i = 0; i < carpetAxisAttributes.length; i++) {
recalcAttrs.push('aaxis.' + carpetAxisAttributes[i]);
recalcAttrs.push('baxis.' + carpetAxisAttributes[i]);
}

for(i = 0; i < traces.length; i++) {
if(Registry.traceIs(fullData[traces[i]], 'box')) {
recalcAttrs.push('name');
Expand Down Expand Up @@ -1657,9 +1680,14 @@ function _restyle(gd, aobj, _traces) {
doextra(axlist.map(rangeAttr), [0, 1], 0);
}
flags.docalc = true;

} else if(replotAttrs.indexOf(aiAboveArray) !== -1) {
flags.doplot = true;
} else if(aiAboveArray.indexOf('aaxis') === 0 || aiAboveArray.indexOf('baxis') === 0) {
flags.doplot = true;
} else if(autorangeAttrs.indexOf(aiAboveArray) !== -1) {
flags.docalcAutorange = true;
}
else if(replotAttrs.indexOf(aiAboveArray) !== -1) flags.doplot = true;
else if(autorangeAttrs.indexOf(aiAboveArray) !== -1) flags.docalcAutorange = true;
}

// do we need to force a recalc?
Expand Down
2 changes: 2 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,8 @@ axes.doTicks = function(gd, axid, skipTitle) {
ticksign = ticksign.map(function(v) { return -v; });
}

if(!ax.visible) return;

// remove zero lines, grid lines, and inside ticks if they're within
// 1 pixel of the end
// The key case here is removing zero lines when the axis bound is zero.
Expand Down
2 changes: 2 additions & 0 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
return Lib.coerce2(containerIn, containerOut, layoutAttributes, attr, dflt);
}

coerce('visible', !options.cheateronly);

var axType = containerOut.type;

if(axType === 'date') {
Expand Down
5 changes: 5 additions & 0 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ function hover(gd, evt, subplot) {
if(!cd || !cd[0] || !cd[0].trace || cd[0].trace.visible !== true) continue;

trace = cd[0].trace;

// Explicitly bail out for these two. I don't know how to otherwise prevent
// the rest of this function from running and failing
if(['carpet', 'contourcarpet'].indexOf(trace._module.name) !== -1) continue;

subplotId = getSubplot(trace);
subploti = subplots.indexOf(subplotId);

Expand Down
6 changes: 5 additions & 1 deletion src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
// Skip trace if whitelist provided and it's not whitelisted:
// if (Array.isArray(traces) && traces.indexOf(i) === -1) continue;
if(trace.xaxis + trace.yaxis === subplot) {
// XXX: Should trace carpet dependencies. Only replot all carpet plots if the carpet
// axis has actually changed:
//
// If this trace is specifically requested, add it to the list:
if(traces.indexOf(trace.index) !== -1) {
if(traces.indexOf(trace.index) !== -1 || trace.carpet) {
// Okay, so example: traces 0, 1, and 2 have fill = tonext. You animate
// traces 0 and 2. Trace 1 also needs to be updated, otherwise its fill
// is outdated. So this retroactively adds the previous trace if the
Expand Down Expand Up @@ -300,6 +303,7 @@ function makeSubplotLayer(plotinfo) {
joinLayer(parent, 'g', 'imagelayer');
joinLayer(parent, 'g', 'maplayer');
joinLayer(parent, 'g', 'barlayer');
joinLayer(parent, 'g', 'carpetlayer');
joinLayer(parent, 'g', 'boxlayer');
joinLayer(parent, 'g', 'scatterlayer');
}
Expand Down
9 changes: 9 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ var constants = require('./constants');


module.exports = {
visible: {
valType: 'boolean',
role: 'info',
description: [
'A single toggle to hide the axis while preserving interaction like dragging.',
'Default is true when a cheater plot is present on the axis, otherwise',
'false'
].join(' ')
},
color: {
valType: 'color',
dflt: colorAttrs.defaultLine,
Expand Down
20 changes: 19 additions & 1 deletion src/plots/cartesian/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
yaListCartesian = [],
xaListGl2d = [],
yaListGl2d = [],
xaListCheater = [],
xaListNonCheater = [],
outerTicks = {},
noGrids = {},
i;
Expand All @@ -51,6 +53,21 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
var xaName = axisIds.id2name(trace.xaxis),
yaName = axisIds.id2name(trace.yaxis);

// 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(xaName) Lib.pushUnique(xaListNonCheater, xaName);
}

// The above check for definitely-not-cheater is not adequate. This
// second list tracks which axes *could* be a cheater so that the
// full condition triggering hiding is:
// *could* be a cheater and *is not definitely visible*
if(trace.type === 'carpet' && trace._cheater) {
if(xaName) Lib.pushUnique(xaListCheater, xaName);
}

// add axes implied by traces
if(xaName && listX.indexOf(xaName) === -1) listX.push(xaName);
if(yaName && listY.indexOf(yaName) === -1) listY.push(yaName);
Expand Down Expand Up @@ -168,7 +185,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
showGrid: !noGrids[axName],
data: fullData,
bgColor: bgColor,
calendar: layoutOut.calendar
calendar: layoutOut.calendar,
cheateronly: axLetter === 'x' && (xaListCheater.indexOf(axName) !== -1 && xaListNonCheater.indexOf(axName) === -1)
};

handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);
Expand Down
1 change: 1 addition & 0 deletions src/plots/gl3d/layout/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var extendFlat = require('../../../lib/extend').extendFlat;


module.exports = {
visible: axesAttrs.visible,
Copy link
Contributor

Choose a reason for hiding this comment

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

visible for 3D axes doesn't actually works, correct?

I think you had to put it in there so that supplyDefaults doesn't error out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, correct. Was contemplating the best option as was working back through that. Correct though, it was just to make them not fail.

Copy link
Contributor Author

@rreusser rreusser Apr 13, 2017

Choose a reason for hiding this comment

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

Perhaps the right answer is not to remove the attribute and avoid supplying that default in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

scene.?axis.visible: false would be a nice option too. So I don't think it's worth changing the logic. Opening a new issue about implementing ?axis.visible in 3D will suffice.

Copy link
Contributor

Choose a reason for hiding this comment

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

done in #1599

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh wow, nice!

Copy link
Contributor

Choose a reason for hiding this comment

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

#1599 is now merged in this PR.

showspikes: {
valType: 'boolean',
role: 'info',
Expand Down
48 changes: 42 additions & 6 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayou
var query = (
'.hm' + oldUid +
',.contour' + oldUid +
',.carpet' + oldUid +
',#clip' + oldUid +
',.trace' + oldUid
);
Expand Down Expand Up @@ -632,6 +633,7 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
};

plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
var i, fullTrace, trace;
var modules = fullLayout._modules = [],
basePlotModules = fullLayout._basePlotModules = [],
cnt = 0;
Expand All @@ -650,9 +652,12 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
cnt++;
}

for(var i = 0; i < dataIn.length; i++) {
var trace = dataIn[i],
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i);
var carpetIndex = {};
var carpetDependents = [];

for(i = 0; i < dataIn.length; i++) {
trace = dataIn[i];
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i);

fullTrace.index = i;
fullTrace._input = trace;
Expand Down Expand Up @@ -689,6 +694,31 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {

pushModule(fullTrace);
}

if(Registry.traceIs(fullTrace, 'carpetAxis')) {
carpetIndex[fullTrace.carpet] = fullTrace;
}

if(Registry.traceIs(fullTrace, 'carpetDependent')) {
carpetDependents.push(i);
}
}

for(i = 0; i < carpetDependents.length; i++) {
fullTrace = dataOut[carpetDependents[i]];

if(!fullTrace.visible) continue;

var carpetAxis = carpetIndex[fullTrace.carpet];
fullTrace._carpet = carpetAxis;

if(!carpetAxis || !carpetAxis.visible) {
fullTrace.visible = false;
continue;
}

fullTrace.xaxis = carpetAxis.xaxis;
fullTrace.yaxis = carpetAxis.yaxis;
}
};

Expand Down Expand Up @@ -811,6 +841,11 @@ plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInInde
// gets overwritten in pie, geo and ternary modules
coerce('hoverinfo', (layout._dataLength === 1) ? 'x+y+z+text' : undefined);

if(plots.traceIs(traceOut, 'showLegend')) {
coerce('showlegend');
coerce('legendgroup');
}

// TODO add per-base-plot-module trace defaults step

if(_module) _module.supplyDefaults(traceIn, traceOut, defaultColor, layout);
Expand All @@ -823,9 +858,10 @@ plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInInde
coerceSubplotAttr('gl2d', 'xaxis');
coerceSubplotAttr('gl2d', 'yaxis');

if(plots.traceIs(traceOut, 'showLegend')) {
coerce('showlegend');
coerce('legendgroup');
if(plots.traceIs(traceOut, 'notLegendIsolatable')) {
// This clears out the legendonly state for traces like carpet that
// cannot be isolated in the legend
traceOut.visible = !!traceOut.visible;
}

plots.supplyTransformDefaults(traceIn, traceOut, layout);
Expand Down
Loading