Skip to content

Commit 3625be4

Browse files
committed
rework subplot logic - create subplots from traces and components only
not from axes and scenes. So if you make axes or scenes and then change the trace types, the old ones will not appear.
1 parent 2c9d90f commit 3625be4

Some content is hidden

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

58 files changed

+1366
-1046
lines changed

dist/translation-keys.txt

+11-11
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
3+
Click to enter Colorscale title // plots/plots.js:338
44
Click to enter Component A title // plots/ternary/ternary.js:386
55
Click to enter Component B title // plots/ternary/ternary.js:400
66
Click to enter Component C title // plots/ternary/ternary.js:411
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:336
9+
Click to enter Y axis title // plots/plots.js:337
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:340
5656
upper fence: // traces/box/calc.js:135

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

+22-23
Original file line numberDiff line numberDiff line change
@@ -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];
@@ -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/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)