Skip to content

[WIP] Carpet plots #1239

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

Closed
wants to merge 143 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
5ad7bb9
Carpet scaffolding
rreusser Dec 1, 2016
7e6858a
Start building cheater supplydfeaults
rreusser Dec 6, 2016
752d268
First signs of life with carpet
rreusser Dec 7, 2016
5c302aa
First cut at base carpet axis trace type
rreusser Dec 8, 2016
256ff18
Work out a lot of details of spline evaluation
rreusser Dec 10, 2016
1c064fc
Work out carpet interpolation
rreusser Dec 13, 2016
3199d70
Tweak grid defaults
rreusser Dec 14, 2016
2016ae2
Tweak gridline code
rreusser Dec 14, 2016
ce290ae
Fix tons of interpolation bugs
rreusser Dec 15, 2016
4e4c093
Fix carpet label details
rreusser Dec 15, 2016
5aa52ce
Very rough carpet scatter trace
rreusser Dec 15, 2016
2883068
Add cheater mock
rreusser Dec 15, 2016
c29fdf7
Add quick hover labels
rreusser Dec 16, 2016
e384d80
Continue on carpets
rreusser Jan 10, 2017
b394ca1
Merge branch 'master' into carpet-plots
rreusser Jan 10, 2017
6c8154c
Merge branch 'master' into carpet-plots
rreusser Jan 11, 2017
e731152
Supply default reorganization for carpet plots
rreusser Jan 16, 2017
bf203a0
Merge branch 'master' into carpet-plots
rreusser Jan 16, 2017
fb002c8
Major refactor of carpet axes
rreusser Jan 16, 2017
714db5a
Large lint-fixing pass
rreusser Jan 17, 2017
2e5fbe6
Fix bad attribute defaults
rreusser Jan 17, 2017
502f89a
Choose better defaults
rreusser Jan 17, 2017
98a660f
Remove unused require
rreusser Jan 17, 2017
656a8db
CLean up the carpet plot function
rreusser Jan 17, 2017
56f9662
Carpet clip path
rreusser Jan 17, 2017
7fd160d
Fix header info
rreusser Jan 17, 2017
6651fdf
Correct bad internal API decisions for spline bounds
rreusser Jan 18, 2017
ef82074
Start fixing setconvert
rreusser Jan 18, 2017
dbf269f
scattercarpet extrapolation and visibility culling
rreusser Jan 19, 2017
17a6b52
Add calc prioritization
rreusser Jan 20, 2017
dc2d76e
Prioritize module.calc + module.transform and make ordering stable
rreusser Jan 20, 2017
136f43c
Basic contourcarpet
rreusser Jan 24, 2017
36e2100
Make a big input transpose fix
rreusser Jan 27, 2017
3c1ca75
Style contourcarpet plots
rreusser Jan 27, 2017
82e86f3
Carpet contour adjustments
rreusser Jan 30, 2017
c80a5e9
Merge branch 'master' into carpet-plots
rreusser Jan 30, 2017
9ccdcfe
Add missing `visible` attribute to gl3d
rreusser Jan 30, 2017
71efcf9
Fix contourcarpet bg path rendering
rreusser Jan 30, 2017
946c751
A giant transpose of most of carpet plots
rreusser Jan 31, 2017
ec7ab18
Extract axsi-aligned carpet lines
rreusser Jan 31, 2017
eed5406
Fix the carpet axis derivatives
rreusser Jan 31, 2017
7304043
Restore badly merged cheater axis hiding logic
rreusser Feb 1, 2017
e4dc03c
Sorta account for missing a/b on contourcarpet
rreusser Feb 2, 2017
490039c
Add a detailed note about mutating user input
rreusser Feb 2, 2017
8f8ea25
Contourcarpet inequalities
rreusser Feb 6, 2017
65eaf4c
Merge branch 'master' into carpet-plots
rreusser Feb 6, 2017
acff100
Fix convertColumnData to default to original behavior
rreusser Feb 6, 2017
4088ee8
Fix bad plot schema attrs
rreusser Feb 6, 2017
223d120
Comment out bad tests
rreusser Feb 6, 2017
5a11a85
Fix incosistent linter result?
rreusser Feb 6, 2017
263d5dc
Fix header dates
rreusser Feb 6, 2017
646255f
Tweak cheater hiding logic
rreusser Feb 6, 2017
ae0e3c8
Add mising visibility attr to ternary axis duck-typing
rreusser Feb 6, 2017
01b0803
Get rid of constraints subattr
rreusser Feb 8, 2017
b708e32
Split everything into lots more files
rreusser Feb 8, 2017
9d99328
A/B axis titles
rreusser Feb 8, 2017
e09b97a
Add cheater baseline
rreusser Feb 9, 2017
b17e7e5
Fix incorrect argument ordering in contourcarpet bg
rreusser Feb 9, 2017
05cd928
Add cheater mock without smoothing
rreusser Feb 9, 2017
dfb9f3e
Dump editable carpet title + default
rreusser Feb 10, 2017
ac0945a
Add carpet constraint mock
rreusser Feb 10, 2017
d54ae59
Fix clip path
rreusser Mar 16, 2017
a2b89b0
Add carpet axis baseline
rreusser Mar 16, 2017
e9865c0
Merge branch 'master' into carpet-plots
rreusser Mar 20, 2017
8a9cbea
Carpet legend
rreusser Mar 21, 2017
f65a109
Update mocks and baselines and carpet defaults
rreusser Mar 22, 2017
52c0e04
Update cheater contour mock
rreusser Mar 22, 2017
4da8426
Merge branch 'master' into carpet-plots
rreusser Mar 22, 2017
34c41cc
Revert unnneded legend style change
rreusser Mar 22, 2017
d15a450
Partial carpet axis fix
rreusser Mar 22, 2017
af0bcea
Break most of carpet plots
rreusser Mar 23, 2017
7eefde2
Add all the files
rreusser Mar 23, 2017
cabeb06
Disable legend isolate for carpet axes
rreusser Mar 23, 2017
564cf8d
Don't coerce cheaterslope if not cheater
rreusser Mar 24, 2017
df3b354
Add scattercarpet mock
rreusser Mar 24, 2017
309d360
Fix lint errors
rreusser Mar 24, 2017
5e5a2ab
Properly pass fullLayout to the new axis
rreusser Mar 24, 2017
e43d716
:hocho: ugly _gd reference
etpinard Mar 24, 2017
310d61e
call carpet setConvert in defaults
etpinard Mar 24, 2017
966e31e
call conversion mehtod on full trace object instead of calcdata item
etpinard Mar 24, 2017
cca3562
Merge branch 'carpet-plots-etienne' into carpet-plots
rreusser Mar 24, 2017
aa6c8a7
Add scattercarpet mock
rreusser Mar 24, 2017
2f4b38b
Carpet baselines
rreusser Mar 24, 2017
a7521ae
Expand carpet_axis mock
rreusser Mar 24, 2017
047a93d
Tweak baseline to make it meaningful
rreusser Mar 24, 2017
3ccce1a
Skew x coords more
rreusser Mar 24, 2017
8a34a20
Rename baselines
rreusser Mar 24, 2017
41e35b4
Tweak scattercarpet baseline
rreusser Mar 24, 2017
1f79e08
Tweak carpet fill mock
rreusser Mar 24, 2017
6846186
setConvert *after* data is categorized
rreusser Mar 24, 2017
dcfcd98
Make unsmooth cheater more unsmooth
rreusser Mar 24, 2017
3f3b879
add a carpet recalc / replot attributes
etpinard Mar 24, 2017
cdba832
Remove broken test
rreusser Mar 24, 2017
d729673
Fix multiple fill baseline
rreusser Mar 24, 2017
06948e3
Extensive mocks for carpet boundaries
rreusser Mar 28, 2017
b466a02
Mocks srsly
rreusser Mar 29, 2017
291b5de
Mock cleanup
rreusser Mar 29, 2017
f053aa0
Test carpet plots
rreusser Mar 30, 2017
86345de
Fill 1D array + tests
rreusser Apr 3, 2017
58261ef
Add carpetlayer that receives carpetaxis
rreusser Apr 3, 2017
fd32c25
Lots of carpet contour fixes
rreusser Apr 6, 2017
992d97a
Airfoil baseline
rreusser Apr 6, 2017
1046dd3
Merge branch 'master' into carpet-plots
rreusser Apr 6, 2017
f98ae64
Airfoil!
rreusser Apr 6, 2017
ea7a71f
Update cheater baseline
rreusser Apr 6, 2017
977021a
Delete fancy contourcarpet code now handled elsewhere
rreusser Apr 6, 2017
4af500a
Fix carpet legend line styling
rreusser Apr 6, 2017
ca49a5a
Axis toolpanel fixes
rreusser Apr 6, 2017
9b4f2b4
Fix carpet visibility changes
rreusser Apr 7, 2017
7ac5f42
Add missing trace class to carpet traces
rreusser Apr 7, 2017
e577ad1
Merge branch 'master' into carpet-plots
rreusser Apr 7, 2017
7e5e5ef
Fix and test cheater axis visibility test
rreusser Apr 7, 2017
688516a
Fix carpet/legendonly interaction and isolate mode
rreusser Apr 7, 2017
cd246e9
Move legendonly restriction to supplyTraceDefaults
rreusser Apr 7, 2017
19a960b
Normalize cheater range for better consistency
rreusser Apr 7, 2017
30b0280
Fix contourcarpet showlegend
rreusser Apr 10, 2017
0136aa3
Fix carpet mocks
rreusser Apr 10, 2017
3f18627
Fix carpet indexing bug
rreusser Apr 10, 2017
1f69fef
Start fixing contour setup
rreusser Apr 10, 2017
ec6e519
Fix colorbar override
rreusser Apr 10, 2017
d693fe5
Fix contourcarpet colorscale setup
rreusser Apr 10, 2017
e202957
Re-run cheater baselines
rreusser Apr 10, 2017
30c9063
Fix contourcarpet line color defaults
rreusser Apr 10, 2017
7d4b482
Change carpetid to carpet
rreusser Apr 10, 2017
800971f
Minor cleanup for PR review
rreusser Apr 10, 2017
d94009e
Add missing file :|
rreusser Apr 10, 2017
11fafef
Fix messy carpet mock
rreusser Apr 10, 2017
bcde707
Fix carpet mocks
rreusser Apr 10, 2017
172ea34
Update scattercarpet baseline
rreusser Apr 10, 2017
6c627d4
Clean up mock/baseline listing
rreusser Apr 12, 2017
1eafd94
Fix scattercarpet on empty axis
rreusser Apr 12, 2017
8f17dd6
Remove redundant keys in cheater mock
rreusser Apr 12, 2017
3764da3
Minor cleanup and remove calcPriority
rreusser Apr 12, 2017
8307c9e
Move ensure_array to lib
rreusser Apr 12, 2017
e3b6d2a
Minor cleanup from PR review
rreusser Apr 12, 2017
906220d
Add carpet meta
rreusser Apr 12, 2017
aedb473
Remove carpet from main plotly bundle
rreusser Apr 12, 2017
8c7d00c
Recycle code
rreusser Apr 12, 2017
b4d0848
Restore carpet to main bundle
rreusser Apr 12, 2017
c88fae1
Remove unused
rreusser Apr 12, 2017
3f90a0b
Merge branch 'master' into carpet-plots
rreusser Apr 12, 2017
c2af4c0
Remove newlines
rreusser Apr 13, 2017
69b4d8b
Remove circular dependency
rreusser Apr 13, 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'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe carpet traces should be part of the cartesian bundle?

If scatterternary wasn't already in there I'd vote for no. But now that I realise scatteternary is part of the cartesian bundle, I'm not so sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. I'm not sure exactly what's best for a default. Easiest for working was just to bundle it. But it's quite a bit of code, generally speaking, so that I feel like it will require some more nuanced per-bundle decisions.

Copy link
Contributor

@etpinard etpinard Apr 12, 2017

Choose a reason for hiding this comment

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

OK. Let's leave carpet traces out of the cartesian bundle to start. We can always add then down the road in a future minor release if we choose to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a bundle which should include it by default?


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;
};
8 changes: 7 additions & 1 deletion src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,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 @@ -540,7 +542,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;

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
35 changes: 32 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,15 @@ 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,
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