Skip to content

Commit 3a4788b

Browse files
authored
Merge pull request #2227 from plotly/clean-subplots
Clean subplots
2 parents 363180b + 44060db commit 3a4788b

Some content is hidden

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

76 files changed

+1544
-1231
lines changed

dist/translation-keys.txt

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Autoscale // components/modebar/buttons.js:139
22
Box Select // components/modebar/buttons.js:103
3-
Click to enter Colorscale title // plots/plots.js:437
4-
Click to enter Component A title // plots/ternary/ternary.js:386
5-
Click to enter Component B title // plots/ternary/ternary.js:400
6-
Click to enter Component C title // plots/ternary/ternary.js:411
3+
Click to enter Colorscale title // plots/plots.js:303
4+
Click to enter Component A title // plots/ternary/ternary.js:392
5+
Click to enter Component B title // plots/ternary/ternary.js:406
6+
Click to enter Component C title // plots/ternary/ternary.js:417
77
Click to enter Plot title // plot_api/plot_api.js:579
8-
Click to enter X axis title // plots/plots.js:435
9-
Click to enter Y axis title // plots/plots.js:436
8+
Click to enter X axis title // plots/plots.js:301
9+
Click to enter Y axis title // plots/plots.js:302
1010
Compare data on hover // components/modebar/buttons.js:167
1111
Double-click on legend to isolate one trace // components/legend/handle_click.js:90
1212
Double-click to zoom back out // plots/cartesian/dragbox.js:299
@@ -17,18 +17,18 @@ Lasso Select // components/modebar/but
1717
Orbital rotation // components/modebar/buttons.js:279
1818
Pan // components/modebar/buttons.js:94
1919
Produced with Plotly // components/modebar/modebar.js:256
20-
Reset // components/modebar/buttons.js:432
20+
Reset // components/modebar/buttons.js:431
2121
Reset axes // components/modebar/buttons.js:148
22-
Reset camera to default // components/modebar/buttons.js:314
23-
Reset camera to last save // components/modebar/buttons.js:322
24-
Reset view // components/modebar/buttons.js:583
25-
Reset views // components/modebar/buttons.js:529
22+
Reset camera to default // components/modebar/buttons.js:313
23+
Reset camera to last save // components/modebar/buttons.js:321
24+
Reset view // components/modebar/buttons.js:582
25+
Reset views // components/modebar/buttons.js:528
2626
Show closest data on hover // components/modebar/buttons.js:157
2727
Snapshot succeeded // components/modebar/buttons.js:66
2828
Sorry, there was a problem downloading your snapshot! // components/modebar/buttons.js:69
2929
Taking snapshot - this may take a few seconds // components/modebar/buttons.js:57
30-
Toggle Spike Lines // components/modebar/buttons.js:548
31-
Toggle show closest data on hover // components/modebar/buttons.js:353
30+
Toggle Spike Lines // components/modebar/buttons.js:547
31+
Toggle show closest data on hover // components/modebar/buttons.js:352
3232
Turntable rotation // components/modebar/buttons.js:288
3333
Zoom // components/modebar/buttons.js:85
3434
Zoom in // components/modebar/buttons.js:121
@@ -52,5 +52,5 @@ q1: // traces/box/calc.js:130
5252
q3: // traces/box/calc.js:131
5353
source: // traces/sankey/plot.js:140
5454
target: // traces/sankey/plot.js:141
55-
trace // plots/plots.js:439
55+
trace // plots/plots.js:305
5656
upper fence: // traces/box/calc.js:135

src/components/annotations/calc_autorange.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ module.exports = function calcAutorange(gd) {
2323

2424
var annotationAxes = {};
2525
annotationList.forEach(function(ann) {
26-
annotationAxes[ann.xref] = true;
27-
annotationAxes[ann.yref] = true;
26+
annotationAxes[ann.xref] = 1;
27+
annotationAxes[ann.yref] = 1;
2828
});
2929

30-
var autorangedAnnos = Axes.list(gd).filter(function(ax) {
31-
return ax.autorange && annotationAxes[ax._id];
32-
});
33-
if(!autorangedAnnos.length) return;
34-
35-
return Lib.syncOrAsync([
36-
draw,
37-
annAutorange
38-
], gd);
30+
for(var axId in annotationAxes) {
31+
var ax = Axes.getFromId(gd, axId);
32+
if(ax && ax.autorange) {
33+
return Lib.syncOrAsync([
34+
draw,
35+
annAutorange
36+
], gd);
37+
}
38+
}
3939
};
4040

4141
function annAutorange(gd) {

src/components/annotations/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818

1919
layoutAttributes: require('./attributes'),
2020
supplyLayoutDefaults: require('./defaults'),
21+
includeBasePlot: require('../../plots/cartesian/include_components')('annotations'),
2122

2223
calcAutorange: require('./calc_autorange'),
2324
draw: drawModule.draw,

src/components/annotations3d/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
'use strict';
1010

11+
var Registry = require('../../registry');
12+
var Lib = require('../../lib');
13+
1114
module.exports = {
1215
moduleType: 'component',
1316
name: 'annotations3d',
@@ -20,7 +23,24 @@ module.exports = {
2023

2124
layoutAttributes: require('./attributes'),
2225
handleDefaults: require('./defaults'),
26+
includeBasePlot: includeGL3D,
2327

2428
convert: require('./convert'),
2529
draw: require('./draw')
2630
};
31+
32+
function includeGL3D(layoutIn, layoutOut) {
33+
var GL3D = Registry.subplotsRegistry.gl3d;
34+
if(!GL3D) return;
35+
36+
var attrRegex = GL3D.attrRegex;
37+
38+
var keys = Object.keys(layoutIn);
39+
for(var i = 0; i < keys.length; i++) {
40+
var k = keys[i];
41+
if(attrRegex.test(k) && (layoutIn[k].annotations || []).length) {
42+
Lib.pushUnique(layoutOut._basePlotModules, GL3D);
43+
Lib.pushUnique(layoutOut._subplots.gl3d, k);
44+
}
45+
}
46+
}

src/components/colorbar/draw.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,13 @@ module.exports = function draw(gd, id) {
341341
}
342342
}
343343

344-
container.selectAll('.cbfills,.cblines,.cbaxis')
344+
container.selectAll('.cbfills,.cblines')
345345
.attr('transform', 'translate(0,' +
346346
Math.round(gs.h * (1 - cbAxisOut.domain[1])) + ')');
347347

348+
cbAxisOut._axislayer.attr('transform', 'translate(0,' +
349+
Math.round(-gs.t) + ')');
350+
348351
var fills = container.select('.cbfills')
349352
.selectAll('rect.cbfill')
350353
.data(filllevels);
@@ -433,7 +436,7 @@ module.exports = function draw(gd, id) {
433436
selection: d3.select(gd).selectAll('g.' + cbAxisOut._id + 'tick'),
434437
side: opts.titleside,
435438
offsetLeft: gs.l,
436-
offsetTop: gs.t,
439+
offsetTop: 0,
437440
maxShift: fullLayout.width
438441
},
439442
attributes: {x: x, y: y, 'text-anchor': 'middle'},

src/components/images/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414

1515
layoutAttributes: require('./attributes'),
1616
supplyLayoutDefaults: require('./defaults'),
17+
includeBasePlot: require('../../plots/cartesian/include_components')('images'),
1718

1819
draw: require('./draw'),
1920

src/components/modebar/buttons.js

+37-38
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
var Plotly = require('../../plotly');
1313
var Plots = require('../../plots/plots');
14-
var Axes = require('../../plots/cartesian/axes');
14+
var axisIds = require('../../plots/cartesian/axis_ids');
1515
var Lib = require('../../lib');
1616
var downloadImage = require('../../snapshot/download');
1717
var Icons = require('../../../build/ploticon');
@@ -175,15 +175,15 @@ modeBarButtons.hoverCompareCartesian = {
175175
};
176176

177177
function handleCartesian(gd, ev) {
178-
var button = ev.currentTarget,
179-
astr = button.getAttribute('data-attr'),
180-
val = button.getAttribute('data-val') || true,
181-
fullLayout = gd._fullLayout,
182-
aobj = {},
183-
axList = Axes.list(gd, null, true),
184-
ax,
185-
allEnabled = 'on',
186-
i;
178+
var button = ev.currentTarget;
179+
var astr = button.getAttribute('data-attr');
180+
var val = button.getAttribute('data-val') || true;
181+
var fullLayout = gd._fullLayout;
182+
var aobj = {};
183+
var axList = axisIds.list(gd, null, true);
184+
var allEnabled = 'on';
185+
186+
var ax, i;
187187

188188
if(astr === 'zoom') {
189189
var mag = (val === 'in') ? 0.5 : 2,
@@ -293,12 +293,11 @@ modeBarButtons.tableRotation = {
293293
};
294294

295295
function handleDrag3d(gd, ev) {
296-
var button = ev.currentTarget,
297-
attr = button.getAttribute('data-attr'),
298-
val = button.getAttribute('data-val') || true,
299-
fullLayout = gd._fullLayout,
300-
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d'),
301-
layoutUpdate = {};
296+
var button = ev.currentTarget;
297+
var attr = button.getAttribute('data-attr');
298+
var val = button.getAttribute('data-val') || true;
299+
var sceneIds = gd._fullLayout._subplots.gl3d;
300+
var layoutUpdate = {};
302301

303302
var parts = attr.split('.');
304303

@@ -326,11 +325,11 @@ modeBarButtons.resetCameraLastSave3d = {
326325
};
327326

328327
function handleCamera3d(gd, ev) {
329-
var button = ev.currentTarget,
330-
attr = button.getAttribute('data-attr'),
331-
fullLayout = gd._fullLayout,
332-
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d'),
333-
aobj = {};
328+
var button = ev.currentTarget;
329+
var attr = button.getAttribute('data-attr');
330+
var fullLayout = gd._fullLayout;
331+
var sceneIds = fullLayout._subplots.gl3d;
332+
var aobj = {};
334333

335334
for(var i = 0; i < sceneIds.length; i++) {
336335
var sceneId = sceneIds[i],
@@ -360,19 +359,19 @@ modeBarButtons.hoverClosest3d = {
360359
};
361360

362361
function handleHover3d(gd, ev) {
363-
var button = ev.currentTarget,
364-
val = button._previousVal || false,
365-
layout = gd.layout,
366-
fullLayout = gd._fullLayout,
367-
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d');
362+
var button = ev.currentTarget;
363+
var val = button._previousVal || false;
364+
var layout = gd.layout;
365+
var fullLayout = gd._fullLayout;
366+
var sceneIds = fullLayout._subplots.gl3d;
368367

369-
var axes = ['xaxis', 'yaxis', 'zaxis'],
370-
spikeAttrs = ['showspikes', 'spikesides', 'spikethickness', 'spikecolor'];
368+
var axes = ['xaxis', 'yaxis', 'zaxis'];
369+
var spikeAttrs = ['showspikes', 'spikesides', 'spikethickness', 'spikecolor'];
371370

372371
// initialize 'current spike' object to be stored in the DOM
373-
var currentSpikes = {},
374-
axisSpikes = {},
375-
layoutUpdate = {};
372+
var currentSpikes = {};
373+
var axisSpikes = {};
374+
var layoutUpdate = {};
376375

377376
if(val) {
378377
layoutUpdate = Lib.extendDeep(layout, val);
@@ -452,7 +451,7 @@ function handleGeo(gd, ev) {
452451
var attr = button.getAttribute('data-attr');
453452
var val = button.getAttribute('data-val') || true;
454453
var fullLayout = gd._fullLayout;
455-
var geoIds = Plots.getSubplotIds(fullLayout, 'geo');
454+
var geoIds = fullLayout._subplots.geo;
456455

457456
for(var i = 0; i < geoIds.length; i++) {
458457
var id = geoIds[i];
@@ -563,11 +562,11 @@ modeBarButtons.toggleSpikelines = {
563562
};
564563

565564
function setSpikelineVisibility(gd) {
566-
var fullLayout = gd._fullLayout,
567-
axList = Axes.list(gd, null, true),
568-
ax,
569-
axName,
570-
aobj = {};
565+
var fullLayout = gd._fullLayout;
566+
var axList = axisIds.list(gd, null, true);
567+
var aobj = {};
568+
569+
var ax, axName;
571570

572571
for(var i = 0; i < axList.length; i++) {
573572
ax = axList[i];
@@ -590,7 +589,7 @@ modeBarButtons.resetViewMapbox = {
590589

591590
function resetView(gd, subplotType) {
592591
var fullLayout = gd._fullLayout;
593-
var subplotIds = Plots.getSubplotIds(fullLayout, subplotType);
592+
var subplotIds = fullLayout._subplots[subplotType];
594593
var aObj = {};
595594

596595
for(var i = 0; i < subplotIds.length; i++) {

src/components/modebar/manage.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
var Axes = require('../../plots/cartesian/axes');
12+
var axisIds = require('../../plots/cartesian/axis_ids');
1313
var scatterSubTypes = require('../../traces/scatter/subtypes');
1414
var Registry = require('../../registry');
1515

@@ -150,17 +150,15 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
150150
}
151151

152152
function areAllAxesFixed(fullLayout) {
153-
var axList = Axes.list({_fullLayout: fullLayout}, null, true);
154-
var allFixed = true;
153+
var axList = axisIds.list({_fullLayout: fullLayout}, null, true);
155154

156155
for(var i = 0; i < axList.length; i++) {
157156
if(!axList[i].fixedrange) {
158-
allFixed = false;
159-
break;
157+
return false;
160158
}
161159
}
162160

163-
return allFixed;
161+
return true;
164162
}
165163

166164
// look for traces that support selection

src/components/shapes/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717

1818
layoutAttributes: require('./attributes'),
1919
supplyLayoutDefaults: require('./defaults'),
20+
includeBasePlot: require('../../plots/cartesian/include_components')('shapes'),
2021

2122
calcAutorange: require('./calc_autorange'),
2223
draw: drawModule.draw,

src/constants/alignment.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,12 @@ module.exports = {
3838
// of the font, and according to wikipedia:
3939
// an "average" font might have a cap height of 70% of the em
4040
// https://en.wikipedia.org/wiki/Em_(typography)#History
41-
MID_SHIFT: 0.35
41+
MID_SHIFT: 0.35,
42+
43+
OPPOSITE_SIDE: {
44+
left: 'right',
45+
right: 'left',
46+
top: 'bottom',
47+
bottom: 'top'
48+
}
4249
};

src/lib/index.js

+26
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,29 @@ lib.templateString = function(string, obj) {
858858
return getterCache[key]() || '';
859859
});
860860
};
861+
862+
/*
863+
* alphanumeric string sort, tailored for subplot IDs like scene2, scene10, x10y13 etc
864+
*/
865+
var char0 = 48;
866+
var char9 = 57;
867+
lib.subplotSort = function(a, b) {
868+
var l = Math.min(a.length, b.length) + 1;
869+
var numA = 0;
870+
var numB = 0;
871+
for(var i = 0; i < l; i++) {
872+
var charA = a.charCodeAt(i) || 0;
873+
var charB = b.charCodeAt(i) || 0;
874+
var isNumA = charA >= char0 && charA <= char9;
875+
var isNumB = charB >= char0 && charB <= char9;
876+
877+
if(isNumA) numA = 10 * numA + charA - char0;
878+
if(isNumB) numB = 10 * numB + charB - char0;
879+
880+
if(!isNumA || !isNumB) {
881+
if(numA !== numB) return numA - numB;
882+
if(charA !== charB) return charA - charB;
883+
}
884+
}
885+
return numB - numA;
886+
};

0 commit comments

Comments
 (0)