Skip to content

Commit

Permalink
Merge pull request #2227 from plotly/clean-subplots
Browse files Browse the repository at this point in the history
Clean subplots
  • Loading branch information
alexcjohnson committed Jan 3, 2018
2 parents 363180b + 44060db commit 3a4788b
Show file tree
Hide file tree
Showing 76 changed files with 1,544 additions and 1,231 deletions.
28 changes: 14 additions & 14 deletions dist/translation-keys.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Autoscale // components/modebar/buttons.js:139
Box Select // components/modebar/buttons.js:103
Click to enter Colorscale title // plots/plots.js:437
Click to enter Component A title // plots/ternary/ternary.js:386
Click to enter Component B title // plots/ternary/ternary.js:400
Click to enter Component C title // plots/ternary/ternary.js:411
Click to enter Colorscale title // plots/plots.js:303
Click to enter Component A title // plots/ternary/ternary.js:392
Click to enter Component B title // plots/ternary/ternary.js:406
Click to enter Component C title // plots/ternary/ternary.js:417
Click to enter Plot title // plot_api/plot_api.js:579
Click to enter X axis title // plots/plots.js:435
Click to enter Y axis title // plots/plots.js:436
Click to enter X axis title // plots/plots.js:301
Click to enter Y axis title // plots/plots.js:302
Compare data on hover // components/modebar/buttons.js:167
Double-click on legend to isolate one trace // components/legend/handle_click.js:90
Double-click to zoom back out // plots/cartesian/dragbox.js:299
Expand All @@ -17,18 +17,18 @@ Lasso Select // components/modebar/but
Orbital rotation // components/modebar/buttons.js:279
Pan // components/modebar/buttons.js:94
Produced with Plotly // components/modebar/modebar.js:256
Reset // components/modebar/buttons.js:432
Reset // components/modebar/buttons.js:431
Reset axes // components/modebar/buttons.js:148
Reset camera to default // components/modebar/buttons.js:314
Reset camera to last save // components/modebar/buttons.js:322
Reset view // components/modebar/buttons.js:583
Reset views // components/modebar/buttons.js:529
Reset camera to default // components/modebar/buttons.js:313
Reset camera to last save // components/modebar/buttons.js:321
Reset view // components/modebar/buttons.js:582
Reset views // components/modebar/buttons.js:528
Show closest data on hover // components/modebar/buttons.js:157
Snapshot succeeded // components/modebar/buttons.js:66
Sorry, there was a problem downloading your snapshot! // components/modebar/buttons.js:69
Taking snapshot - this may take a few seconds // components/modebar/buttons.js:57
Toggle Spike Lines // components/modebar/buttons.js:548
Toggle show closest data on hover // components/modebar/buttons.js:353
Toggle Spike Lines // components/modebar/buttons.js:547
Toggle show closest data on hover // components/modebar/buttons.js:352
Turntable rotation // components/modebar/buttons.js:288
Zoom // components/modebar/buttons.js:85
Zoom in // components/modebar/buttons.js:121
Expand All @@ -52,5 +52,5 @@ q1: // traces/box/calc.js:130
q3: // traces/box/calc.js:131
source: // traces/sankey/plot.js:140
target: // traces/sankey/plot.js:141
trace // plots/plots.js:439
trace // plots/plots.js:305
upper fence: // traces/box/calc.js:135
22 changes: 11 additions & 11 deletions src/components/annotations/calc_autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ module.exports = function calcAutorange(gd) {

var annotationAxes = {};
annotationList.forEach(function(ann) {
annotationAxes[ann.xref] = true;
annotationAxes[ann.yref] = true;
annotationAxes[ann.xref] = 1;
annotationAxes[ann.yref] = 1;
});

var autorangedAnnos = Axes.list(gd).filter(function(ax) {
return ax.autorange && annotationAxes[ax._id];
});
if(!autorangedAnnos.length) return;

return Lib.syncOrAsync([
draw,
annAutorange
], gd);
for(var axId in annotationAxes) {
var ax = Axes.getFromId(gd, axId);
if(ax && ax.autorange) {
return Lib.syncOrAsync([
draw,
annAutorange
], gd);
}
}
};

function annAutorange(gd) {
Expand Down
1 change: 1 addition & 0 deletions src/components/annotations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {

layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),
includeBasePlot: require('../../plots/cartesian/include_components')('annotations'),

calcAutorange: require('./calc_autorange'),
draw: drawModule.draw,
Expand Down
20 changes: 20 additions & 0 deletions src/components/annotations3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

'use strict';

var Registry = require('../../registry');
var Lib = require('../../lib');

module.exports = {
moduleType: 'component',
name: 'annotations3d',
Expand All @@ -20,7 +23,24 @@ module.exports = {

layoutAttributes: require('./attributes'),
handleDefaults: require('./defaults'),
includeBasePlot: includeGL3D,

convert: require('./convert'),
draw: require('./draw')
};

function includeGL3D(layoutIn, layoutOut) {
var GL3D = Registry.subplotsRegistry.gl3d;
if(!GL3D) return;

var attrRegex = GL3D.attrRegex;

var keys = Object.keys(layoutIn);
for(var i = 0; i < keys.length; i++) {
var k = keys[i];
if(attrRegex.test(k) && (layoutIn[k].annotations || []).length) {
Lib.pushUnique(layoutOut._basePlotModules, GL3D);
Lib.pushUnique(layoutOut._subplots.gl3d, k);
}
}
}
7 changes: 5 additions & 2 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,13 @@ module.exports = function draw(gd, id) {
}
}

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

cbAxisOut._axislayer.attr('transform', 'translate(0,' +
Math.round(-gs.t) + ')');

var fills = container.select('.cbfills')
.selectAll('rect.cbfill')
.data(filllevels);
Expand Down Expand Up @@ -433,7 +436,7 @@ module.exports = function draw(gd, id) {
selection: d3.select(gd).selectAll('g.' + cbAxisOut._id + 'tick'),
side: opts.titleside,
offsetLeft: gs.l,
offsetTop: gs.t,
offsetTop: 0,
maxShift: fullLayout.width
},
attributes: {x: x, y: y, 'text-anchor': 'middle'},
Expand Down
1 change: 1 addition & 0 deletions src/components/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {

layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),
includeBasePlot: require('../../plots/cartesian/include_components')('images'),

draw: require('./draw'),

Expand Down
75 changes: 37 additions & 38 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Axes = require('../../plots/cartesian/axes');
var axisIds = require('../../plots/cartesian/axis_ids');
var Lib = require('../../lib');
var downloadImage = require('../../snapshot/download');
var Icons = require('../../../build/ploticon');
Expand Down Expand Up @@ -175,15 +175,15 @@ modeBarButtons.hoverCompareCartesian = {
};

function handleCartesian(gd, ev) {
var button = ev.currentTarget,
astr = button.getAttribute('data-attr'),
val = button.getAttribute('data-val') || true,
fullLayout = gd._fullLayout,
aobj = {},
axList = Axes.list(gd, null, true),
ax,
allEnabled = 'on',
i;
var button = ev.currentTarget;
var astr = button.getAttribute('data-attr');
var val = button.getAttribute('data-val') || true;
var fullLayout = gd._fullLayout;
var aobj = {};
var axList = axisIds.list(gd, null, true);
var allEnabled = 'on';

var ax, i;

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

function handleDrag3d(gd, ev) {
var button = ev.currentTarget,
attr = button.getAttribute('data-attr'),
val = button.getAttribute('data-val') || true,
fullLayout = gd._fullLayout,
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d'),
layoutUpdate = {};
var button = ev.currentTarget;
var attr = button.getAttribute('data-attr');
var val = button.getAttribute('data-val') || true;
var sceneIds = gd._fullLayout._subplots.gl3d;
var layoutUpdate = {};

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

Expand Down Expand Up @@ -326,11 +325,11 @@ modeBarButtons.resetCameraLastSave3d = {
};

function handleCamera3d(gd, ev) {
var button = ev.currentTarget,
attr = button.getAttribute('data-attr'),
fullLayout = gd._fullLayout,
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d'),
aobj = {};
var button = ev.currentTarget;
var attr = button.getAttribute('data-attr');
var fullLayout = gd._fullLayout;
var sceneIds = fullLayout._subplots.gl3d;
var aobj = {};

for(var i = 0; i < sceneIds.length; i++) {
var sceneId = sceneIds[i],
Expand Down Expand Up @@ -360,19 +359,19 @@ modeBarButtons.hoverClosest3d = {
};

function handleHover3d(gd, ev) {
var button = ev.currentTarget,
val = button._previousVal || false,
layout = gd.layout,
fullLayout = gd._fullLayout,
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d');
var button = ev.currentTarget;
var val = button._previousVal || false;
var layout = gd.layout;
var fullLayout = gd._fullLayout;
var sceneIds = fullLayout._subplots.gl3d;

var axes = ['xaxis', 'yaxis', 'zaxis'],
spikeAttrs = ['showspikes', 'spikesides', 'spikethickness', 'spikecolor'];
var axes = ['xaxis', 'yaxis', 'zaxis'];
var spikeAttrs = ['showspikes', 'spikesides', 'spikethickness', 'spikecolor'];

// initialize 'current spike' object to be stored in the DOM
var currentSpikes = {},
axisSpikes = {},
layoutUpdate = {};
var currentSpikes = {};
var axisSpikes = {};
var layoutUpdate = {};

if(val) {
layoutUpdate = Lib.extendDeep(layout, val);
Expand Down Expand Up @@ -452,7 +451,7 @@ function handleGeo(gd, ev) {
var attr = button.getAttribute('data-attr');
var val = button.getAttribute('data-val') || true;
var fullLayout = gd._fullLayout;
var geoIds = Plots.getSubplotIds(fullLayout, 'geo');
var geoIds = fullLayout._subplots.geo;

for(var i = 0; i < geoIds.length; i++) {
var id = geoIds[i];
Expand Down Expand Up @@ -563,11 +562,11 @@ modeBarButtons.toggleSpikelines = {
};

function setSpikelineVisibility(gd) {
var fullLayout = gd._fullLayout,
axList = Axes.list(gd, null, true),
ax,
axName,
aobj = {};
var fullLayout = gd._fullLayout;
var axList = axisIds.list(gd, null, true);
var aobj = {};

var ax, axName;

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

function resetView(gd, subplotType) {
var fullLayout = gd._fullLayout;
var subplotIds = Plots.getSubplotIds(fullLayout, subplotType);
var subplotIds = fullLayout._subplots[subplotType];
var aObj = {};

for(var i = 0; i < subplotIds.length; i++) {
Expand Down
10 changes: 4 additions & 6 deletions src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

var Axes = require('../../plots/cartesian/axes');
var axisIds = require('../../plots/cartesian/axis_ids');
var scatterSubTypes = require('../../traces/scatter/subtypes');
var Registry = require('../../registry');

Expand Down Expand Up @@ -150,17 +150,15 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
}

function areAllAxesFixed(fullLayout) {
var axList = Axes.list({_fullLayout: fullLayout}, null, true);
var allFixed = true;
var axList = axisIds.list({_fullLayout: fullLayout}, null, true);

for(var i = 0; i < axList.length; i++) {
if(!axList[i].fixedrange) {
allFixed = false;
break;
return false;
}
}

return allFixed;
return true;
}

// look for traces that support selection
Expand Down
1 change: 1 addition & 0 deletions src/components/shapes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {

layoutAttributes: require('./attributes'),
supplyLayoutDefaults: require('./defaults'),
includeBasePlot: require('../../plots/cartesian/include_components')('shapes'),

calcAutorange: require('./calc_autorange'),
draw: drawModule.draw,
Expand Down
9 changes: 8 additions & 1 deletion src/constants/alignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ module.exports = {
// of the font, and according to wikipedia:
// an "average" font might have a cap height of 70% of the em
// https://en.wikipedia.org/wiki/Em_(typography)#History
MID_SHIFT: 0.35
MID_SHIFT: 0.35,

OPPOSITE_SIDE: {
left: 'right',
right: 'left',
top: 'bottom',
bottom: 'top'
}
};
26 changes: 26 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,29 @@ lib.templateString = function(string, obj) {
return getterCache[key]() || '';
});
};

/*
* alphanumeric string sort, tailored for subplot IDs like scene2, scene10, x10y13 etc
*/
var char0 = 48;
var char9 = 57;
lib.subplotSort = function(a, b) {
var l = Math.min(a.length, b.length) + 1;
var numA = 0;
var numB = 0;
for(var i = 0; i < l; i++) {
var charA = a.charCodeAt(i) || 0;
var charB = b.charCodeAt(i) || 0;
var isNumA = charA >= char0 && charA <= char9;
var isNumB = charB >= char0 && charB <= char9;

if(isNumA) numA = 10 * numA + charA - char0;
if(isNumB) numB = 10 * numB + charB - char0;

if(!isNumA || !isNumB) {
if(numA !== numB) return numA - numB;
if(charA !== charB) return charA - charB;
}
}
return numB - numA;
};
Loading

0 comments on commit 3a4788b

Please sign in to comment.