Skip to content
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

Clean subplots #2227

Merged
merged 17 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
22 changes: 11 additions & 11 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 Colorscale title // plots/plots.js:338
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm, I should have just ignored the changes to this file, since they're only line number changes... I should revisit this so it doesn't get regenerated just because you run test-syntax locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

As a rule, I believe we should only commit changes to files in dist/ when running npm version.

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 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:336
Click to enter Y axis title // plots/plots.js:337
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:340
upper fence: // traces/box/calc.js:135
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this fix #970 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe #1396

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it fixes #970 but yes, it does fix #1396 🎉

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
45 changes: 22 additions & 23 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
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 @@ -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
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

brilliant ✨

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