Skip to content

Commit e4971ef

Browse files
committed
Carpet plots
1 parent b8c71e1 commit e4971ef

File tree

125 files changed

+15333
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+15333
-9
lines changed

lib/carpet.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = require('../src/traces/carpet');

lib/contourcarpet.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = require('../src/traces/contourcarpet');

lib/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Plotly.register([
3636

3737
require('./scattermapbox'),
3838

39+
require('./carpet'),
40+
require('./scattercarpet'),
41+
require('./contourcarpet'),
42+
3943
require('./ohlc'),
4044
require('./candlestick')
4145
]);

lib/scattercarpet.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = require('../src/traces/scattercarpet');

src/components/legend/style.js

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ function styleLines(d) {
6565
showFill = trace.visible && trace.fill && trace.fill !== 'none',
6666
showLine = subTypes.hasLines(trace);
6767

68+
if(trace && trace._module && trace._module.name === 'contourcarpet') {
69+
showLine = trace.contours.showlines;
70+
showFill = trace.contours.coloring === 'fill';
71+
}
72+
6873
var fill = d3.select(this).select('.legendfill').selectAll('path')
6974
.data(showFill ? [d] : []);
7075
fill.enter().append('path').classed('js-fill', true);

src/plot_api/plot_api.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@ function _restyle(gd, aobj, _traces) {
12941294
'autobinx', 'nbinsx', 'xbins', 'xbins.start', 'xbins.end', 'xbins.size',
12951295
'autobiny', 'nbinsy', 'ybins', 'ybins.start', 'ybins.end', 'ybins.size',
12961296
'autocontour', 'ncontours', 'contours', 'contours.coloring',
1297+
'contours.operation', 'contours.value', 'contours.type', 'contours.value[0]', 'contours.value[1]',
12971298
'error_y', 'error_y.visible', 'error_y.value', 'error_y.type',
12981299
'error_y.traceref', 'error_y.array', 'error_y.symmetric',
12991300
'error_y.arrayminus', 'error_y.valueminus', 'error_y.tracerefminus',
@@ -1311,9 +1312,31 @@ function _restyle(gd, aobj, _traces) {
13111312
'line.showscale', 'line.cauto', 'line.autocolorscale', 'line.reversescale',
13121313
'marker.line.showscale', 'marker.line.cauto', 'marker.line.autocolorscale', 'marker.line.reversescale',
13131314
'xcalendar', 'ycalendar',
1314-
'cumulative', 'cumulative.enabled', 'cumulative.direction', 'cumulative.currentbin'
1315+
'cumulative', 'cumulative.enabled', 'cumulative.direction', 'cumulative.currentbin',
1316+
'a0', 'da', 'b0', 'db', 'atype', 'btype',
1317+
'cheaterslope', 'carpet', 'sum',
13151318
];
13161319

1320+
var carpetAxisAttributes = [
1321+
'color', 'smoothing', 'title', 'titlefont', 'titlefont.size', 'titlefont.family',
1322+
'titlefont.color', 'titleoffset', 'type', 'autorange', 'rangemode', 'range',
1323+
'fixedrange', 'cheatertype', 'tickmode', 'nticks', 'tickvals', 'ticktext',
1324+
'ticks', 'mirror', 'ticklen', 'tickwidth', 'tickcolor', 'showticklabels',
1325+
'tickfont', 'tickfont.size', 'tickfont.family', 'tickfont.color', 'tickprefix',
1326+
'showtickprefix', 'ticksuffix', 'showticksuffix', 'showexponent', 'exponentformat',
1327+
'separatethousands', 'tickformat', 'categoryorder', 'categoryarray', 'labelpadding',
1328+
'labelprefix', 'labelsuffix', 'labelfont', 'labelfont.family', 'labelfont.size',
1329+
'labelfont.color', 'showline', 'linecolor', 'linewidth', 'gridcolor', 'gridwidth',
1330+
'showgrid', 'minorgridcount', 'minorgridwidth', 'minorgridcolor', 'startline',
1331+
'startlinecolor', 'startlinewidth', 'endline', 'endlinewidth', 'endlinecolor',
1332+
'tick0', 'dtick', 'arraytick0', 'arraydtick', 'hoverformat', 'tickangle'
1333+
];
1334+
1335+
for(i = 0; i < carpetAxisAttributes.length; i++) {
1336+
recalcAttrs.push('aaxis.' + carpetAxisAttributes[i]);
1337+
recalcAttrs.push('baxis.' + carpetAxisAttributes[i]);
1338+
}
1339+
13171340
for(i = 0; i < traces.length; i++) {
13181341
if(Registry.traceIs(fullData[traces[i]], 'box')) {
13191342
recalcAttrs.push('name');
@@ -1657,9 +1680,14 @@ function _restyle(gd, aobj, _traces) {
16571680
doextra(axlist.map(rangeAttr), [0, 1], 0);
16581681
}
16591682
flags.docalc = true;
1683+
1684+
} else if(replotAttrs.indexOf(aiAboveArray) !== -1) {
1685+
flags.doplot = true;
1686+
} else if(aiAboveArray.indexOf('aaxis') === 0 || aiAboveArray.indexOf('baxis') === 0) {
1687+
flags.doplot = true;
1688+
} else if(autorangeAttrs.indexOf(aiAboveArray) !== -1) {
1689+
flags.docalcAutorange = true;
16601690
}
1661-
else if(replotAttrs.indexOf(aiAboveArray) !== -1) flags.doplot = true;
1662-
else if(autorangeAttrs.indexOf(aiAboveArray) !== -1) flags.docalcAutorange = true;
16631691
}
16641692

16651693
// do we need to force a recalc?

src/plots/cartesian/graph_interact.js

+5
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ function hover(gd, evt, subplot) {
467467
if(!cd || !cd[0] || !cd[0].trace || cd[0].trace.visible !== true) continue;
468468

469469
trace = cd[0].trace;
470+
471+
// Explicitly bail out for these two. I don't know how to otherwise prevent
472+
// the rest of this function from running and failing
473+
if(['carpet', 'contourcarpet'].indexOf(trace._module.name) !== -1) continue;
474+
470475
subplotId = getSubplot(trace);
471476
subploti = subplots.indexOf(subplotId);
472477

src/plots/plots.js

+42-6
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayou
578578
var query = (
579579
'.hm' + oldUid +
580580
',.contour' + oldUid +
581+
',.carpet' + oldUid +
581582
',#clip' + oldUid +
582583
',.trace' + oldUid
583584
);
@@ -632,6 +633,7 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
632633
};
633634

634635
plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
636+
var i, fullTrace, trace;
635637
var modules = fullLayout._modules = [],
636638
basePlotModules = fullLayout._basePlotModules = [],
637639
cnt = 0;
@@ -650,9 +652,12 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
650652
cnt++;
651653
}
652654

653-
for(var i = 0; i < dataIn.length; i++) {
654-
var trace = dataIn[i],
655-
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i);
655+
var carpetIndex = {};
656+
var carpetDependents = [];
657+
658+
for(i = 0; i < dataIn.length; i++) {
659+
trace = dataIn[i];
660+
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i);
656661

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

690695
pushModule(fullTrace);
691696
}
697+
698+
if(Registry.traceIs(fullTrace, 'carpetAxis')) {
699+
carpetIndex[fullTrace.carpet] = fullTrace;
700+
}
701+
702+
if(Registry.traceIs(fullTrace, 'carpetDependent')) {
703+
carpetDependents.push(i);
704+
}
705+
}
706+
707+
for(i = 0; i < carpetDependents.length; i++) {
708+
fullTrace = dataOut[carpetDependents[i]];
709+
710+
if(!fullTrace.visible) continue;
711+
712+
var carpetAxis = carpetIndex[fullTrace.carpet];
713+
fullTrace._carpet = carpetAxis;
714+
715+
if(!carpetAxis || !carpetAxis.visible) {
716+
fullTrace.visible = false;
717+
continue;
718+
}
719+
720+
fullTrace.xaxis = carpetAxis.xaxis;
721+
fullTrace.yaxis = carpetAxis.yaxis;
692722
}
693723
};
694724

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

844+
if(plots.traceIs(traceOut, 'showLegend')) {
845+
coerce('showlegend');
846+
coerce('legendgroup');
847+
}
848+
814849
// TODO add per-base-plot-module trace defaults step
815850

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

826-
if(plots.traceIs(traceOut, 'showLegend')) {
827-
coerce('showlegend');
828-
coerce('legendgroup');
861+
if(plots.traceIs(traceOut, 'notLegendIsolatable')) {
862+
// This clears out the legendonly state for traces like carpet that
863+
// cannot be isolated in the legend
864+
traceOut.visible = !!traceOut.visible;
829865
}
830866

831867
plots.supplyTransformDefaults(traceIn, traceOut, layout);

src/traces/carpet/ab_defaults.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var handleAxisDefaults = require('./axis_defaults');
12+
13+
module.exports = function handleABDefaults(traceIn, traceOut, fullLayout, coerce, dfltColor) {
14+
var a = coerce('a');
15+
16+
if(!a) {
17+
coerce('da');
18+
coerce('a0');
19+
}
20+
21+
var b = coerce('b');
22+
23+
if(!b) {
24+
coerce('db');
25+
coerce('b0');
26+
}
27+
28+
mimickAxisDefaults(traceIn, traceOut, fullLayout, dfltColor);
29+
30+
return;
31+
};
32+
33+
function mimickAxisDefaults(traceIn, traceOut, fullLayout, dfltColor) {
34+
var axesList = ['aaxis', 'baxis'];
35+
36+
axesList.forEach(function(axName) {
37+
var axLetter = axName.charAt(0);
38+
var axIn = traceIn[axName] || {};
39+
var axOut = {};
40+
41+
var defaultOptions = {
42+
tickfont: 'x',
43+
id: axLetter + 'axis',
44+
letter: axLetter,
45+
font: traceOut.font,
46+
name: axName,
47+
data: traceIn[axLetter],
48+
calendar: traceOut.calendar,
49+
dfltColor: dfltColor,
50+
bgColor: fullLayout.paper_bgcolor,
51+
fullLayout: fullLayout
52+
};
53+
54+
handleAxisDefaults(axIn, axOut, defaultOptions);
55+
56+
axOut._categories = axOut._categories || [];
57+
58+
traceOut[axName] = axOut;
59+
60+
// so we don't have to repeat autotype unnecessarily,
61+
// copy an autotype back to traceIn
62+
if(!traceIn[axName] && axIn.type !== '-') {
63+
traceIn[axName] = {type: axIn.type};
64+
}
65+
});
66+
}

src/traces/carpet/array_minmax.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(a) {
12+
return minMax(a, 0);
13+
};
14+
15+
function minMax(a, depth) {
16+
// Limit to ten dimensional datasets. This seems *exceedingly* unlikely to
17+
// ever cause problems or even be a concern. It's include strictly so that
18+
// circular arrays could never cause this to loop.
19+
if(!Array.isArray(a) || depth >= 10) {
20+
return null;
21+
}
22+
23+
var min = Infinity;
24+
var max = -Infinity;
25+
var n = a.length;
26+
for(var i = 0; i < n; i++) {
27+
var datum = a[i];
28+
29+
if(Array.isArray(datum)) {
30+
var result = minMax(datum, depth + 1);
31+
32+
if(result) {
33+
min = Math.min(result[0], min);
34+
max = Math.max(result[1], max);
35+
}
36+
} else {
37+
min = Math.min(datum, min);
38+
max = Math.max(datum, max);
39+
}
40+
}
41+
42+
return [min, max];
43+
}

0 commit comments

Comments
 (0)