Skip to content

Commit b1308c6

Browse files
committed
Merge branch 'master' into ortho-zoom
2 parents 6eaa594 + cff31df commit b1308c6

File tree

15 files changed

+618
-194
lines changed

15 files changed

+618
-194
lines changed

src/components/modebar/buttons.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,14 @@ function handleCamera3d(gd, ev) {
347347
var key = sceneId + '.camera';
348348
var scene = fullLayout[sceneId]._scene;
349349

350-
if(attr === 'resetDefault') {
351-
aobj[key] = Lib.extendDeep({}, scene.cameraInitial);
352-
aobj[key].up = null;
353-
aobj[key].eye = null;
354-
aobj[key].center = null;
355-
}
356-
else if(attr === 'resetLastSave') {
357-
aobj[key] = Lib.extendDeep({}, scene.cameraInitial);
350+
if(attr === 'resetLastSave') {
351+
aobj[key + '.up'] = scene.viewInitial.up;
352+
aobj[key + '.eye'] = scene.viewInitial.eye;
353+
aobj[key + '.center'] = scene.viewInitial.center;
354+
} else if(attr === 'resetDefault') {
355+
aobj[key + '.up'] = null;
356+
aobj[key + '.eye'] = null;
357+
aobj[key + '.center'] = null;
358358
}
359359
}
360360

src/plot_api/plot_api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ function _restyle(gd, aobj, traces) {
15891589
// and figure out what kind of graphics update we need to do
15901590
for(var ai in aobj) {
15911591
if(helpers.hasParent(aobj, ai)) {
1592-
throw new Error('cannot set ' + ai + 'and a parent attribute simultaneously');
1592+
throw new Error('cannot set ' + ai + ' and a parent attribute simultaneously');
15931593
}
15941594

15951595
var vi = aobj[ai];
@@ -2095,7 +2095,7 @@ function _relayout(gd, aobj) {
20952095
// alter gd.layout
20962096
for(var ai in aobj) {
20972097
if(helpers.hasParent(aobj, ai)) {
2098-
throw new Error('cannot set ' + ai + 'and a parent attribute simultaneously');
2098+
throw new Error('cannot set ' + ai + ' and a parent attribute simultaneously');
20992099
}
21002100

21012101
var p = layoutNP(layout, ai);

src/plots/cartesian/axes.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,30 @@ axes.drawOne = function(gd, ax, opts) {
19841984
if(ax.title.text !== fullLayout._dfltTitle[axLetter]) {
19851985
push[s] += ax.title.font.size;
19861986
}
1987+
1988+
if(axLetter === 'x' && bbox.width > 0) {
1989+
var rExtra = bbox.right - (ax._offset + ax._length);
1990+
if(rExtra > 0) {
1991+
push.x = 1;
1992+
push.r = rExtra;
1993+
}
1994+
var lExtra = ax._offset - bbox.left;
1995+
if(lExtra > 0) {
1996+
push.x = 0;
1997+
push.l = lExtra;
1998+
}
1999+
} else if(axLetter === 'y' && bbox.height > 0) {
2000+
var bExtra = bbox.bottom - (ax._offset + ax._length);
2001+
if(bExtra > 0) {
2002+
push.y = 0;
2003+
push.b = bExtra;
2004+
}
2005+
var tExtra = ax._offset - bbox.top;
2006+
if(tExtra > 0) {
2007+
push.y = 1;
2008+
push.t = tExtra;
2009+
}
2010+
}
19872011
}
19882012

19892013
Plots.autoMargin(gd, axAutoMarginID(ax), push);

src/plots/cartesian/set_convert.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,14 @@ module.exports = function setConvert(ax, fullLayout) {
484484
ax._length = gs.h * (ax.domain[1] - ax.domain[0]);
485485
ax._m = ax._length / (rl0 - rl1);
486486
ax._b = -ax._m * rl1;
487-
}
488-
else {
487+
} else {
489488
ax._offset = gs.l + ax.domain[0] * gs.w;
490489
ax._length = gs.w * (ax.domain[1] - ax.domain[0]);
491490
ax._m = ax._length / (rl1 - rl0);
492491
ax._b = -ax._m * rl0;
493492
}
494493

495-
if(!isFinite(ax._m) || !isFinite(ax._b)) {
494+
if(!isFinite(ax._m) || !isFinite(ax._b) || ax._length < 0) {
496495
fullLayout._replotting = false;
497496
throw new Error('Something went wrong with axis scaling');
498497
}

src/plots/gl3d/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,25 @@ exports.plot = function plotGl3d(gd) {
6767
sceneLayout._scene = scene;
6868
}
6969

70-
// save 'initial' camera settings for modebar button
71-
if(!scene.cameraInitial) {
72-
scene.cameraInitial = Lib.extendDeep({}, sceneLayout.camera);
70+
// save 'initial' camera view settings for modebar button
71+
if(!scene.viewInitial) {
72+
scene.viewInitial = {
73+
up: {
74+
x: camera.up.x,
75+
y: camera.up.y,
76+
z: camera.up.z
77+
},
78+
eye: {
79+
x: camera.eye.x,
80+
y: camera.eye.y,
81+
z: camera.eye.z
82+
},
83+
center: {
84+
x: camera.center.x,
85+
y: camera.center.y,
86+
z: camera.center.z
87+
}
88+
};
7389
}
7490

7591
scene.plot(fullSceneData, fullLayout, gd.layout);

src/plots/gl3d/scene.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function initializeGLPlot(scene, camera, pixelRatio, canvas, gl) {
255255
if(scene.fullSceneLayout.dragmode === false) return;
256256

257257
var update = {};
258-
update[scene.id + '.camera'] = getLayoutCamera(scene.camera, scene.camera._ortho);
258+
update[scene.id + '.camera'] = getLayoutCamera(scene.camera);
259259
scene.saveCamera(gd.layout);
260260
scene.graphDiv.emit('plotly_relayout', update);
261261
};
@@ -758,19 +758,19 @@ function getOrbitCamera(camera) {
758758

759759
// getLayoutCamera :: orbit_camera_coords -> plotly_coords
760760
// inverse of getOrbitCamera
761-
function getLayoutCamera(camera, isOrtho) {
761+
function getLayoutCamera(camera) {
762762
return {
763763
up: {x: camera.up[0], y: camera.up[1], z: camera.up[2]},
764764
center: {x: camera.center[0], y: camera.center[1], z: camera.center[2]},
765765
eye: {x: camera.eye[0], y: camera.eye[1], z: camera.eye[2]},
766-
projection: {type: (isOrtho === true) ? 'orthographic' : 'perspective'}
766+
projection: {type: (camera._ortho === true) ? 'orthographic' : 'perspective'}
767767
};
768768
}
769769

770770
// get camera position in plotly coords from 'orbit-camera' coords
771771
proto.getCamera = function getCamera() {
772772
this.glplot.camera.view.recalcMatrix(this.camera.view.lastT());
773-
return getLayoutCamera(this.glplot.camera, this.glplot.camera._ortho);
773+
return getLayoutCamera(this.glplot.camera);
774774
};
775775

776776
// set camera position with a set of plotly coords

src/plots/plots.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,8 @@ plots.doAutoMargin = function(gd) {
18411841
var mr = margin.r;
18421842
var mt = margin.t;
18431843
var mb = margin.b;
1844+
var width = fullLayout.width;
1845+
var height = fullLayout.height;
18441846
var pushMargin = fullLayout._pushmargin;
18451847
var pushMarginIds = fullLayout._pushmarginIds;
18461848

@@ -1876,13 +1878,11 @@ plots.doAutoMargin = function(gd) {
18761878
var pr = pushMargin[k2].r.size;
18771879

18781880
if(fr > fl) {
1879-
var newl = (pl * fr +
1880-
(pr - fullLayout.width) * fl) / (fr - fl);
1881-
var newr = (pr * (1 - fl) +
1882-
(pl - fullLayout.width) * (1 - fr)) / (fr - fl);
1883-
if(newl >= 0 && newr >= 0 && newl + newr > ml + mr) {
1884-
ml = newl;
1885-
mr = newr;
1881+
var newL = (pl * fr + (pr - width) * fl) / (fr - fl);
1882+
var newR = (pr * (1 - fl) + (pl - width) * (1 - fr)) / (fr - fl);
1883+
if(newL >= 0 && newR >= 0 && width - (newL + newR) > 0 && newL + newR > ml + mr) {
1884+
ml = newL;
1885+
mr = newR;
18861886
}
18871887
}
18881888
}
@@ -1892,13 +1892,11 @@ plots.doAutoMargin = function(gd) {
18921892
var pt = pushMargin[k2].t.size;
18931893

18941894
if(ft > fb) {
1895-
var newb = (pb * ft +
1896-
(pt - fullLayout.height) * fb) / (ft - fb);
1897-
var newt = (pt * (1 - fb) +
1898-
(pb - fullLayout.height) * (1 - ft)) / (ft - fb);
1899-
if(newb >= 0 && newt >= 0 && newb + newt > mb + mt) {
1900-
mb = newb;
1901-
mt = newt;
1895+
var newB = (pb * ft + (pt - height) * fb) / (ft - fb);
1896+
var newT = (pt * (1 - fb) + (pb - height) * (1 - ft)) / (ft - fb);
1897+
if(newB >= 0 && newT >= 0 && height - (newT + newB) > 0 && newB + newT > mb + mt) {
1898+
mb = newB;
1899+
mt = newT;
19021900
}
19031901
}
19041902
}
@@ -1911,8 +1909,8 @@ plots.doAutoMargin = function(gd) {
19111909
gs.t = Math.round(mt);
19121910
gs.b = Math.round(mb);
19131911
gs.p = Math.round(margin.pad);
1914-
gs.w = Math.round(fullLayout.width) - gs.l - gs.r;
1915-
gs.h = Math.round(fullLayout.height) - gs.t - gs.b;
1912+
gs.w = Math.round(width) - gs.l - gs.r;
1913+
gs.h = Math.round(height) - gs.t - gs.b;
19161914

19171915
// if things changed and we're not already redrawing, trigger a redraw
19181916
if(!fullLayout._replotting &&

src/traces/parcoords/calc.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ var Lib = require('../../lib');
1414
var wrap = require('../../lib/gup').wrap;
1515

1616
module.exports = function calc(gd, trace) {
17-
var cs = !!trace.line.colorscale && Lib.isArrayOrTypedArray(trace.line.color);
17+
18+
for(var i = 0; i < trace.dimensions.length; i++) {
19+
trace.dimensions[i].values = convertTypedArray(trace.dimensions[i].values);
20+
}
21+
trace.line.color = convertTypedArray(trace.line.color);
22+
23+
var cs = !!trace.line.colorscale && Array.isArray(trace.line.color);
1824
var color = cs ? trace.line.color : constHalf(trace._length);
1925
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];
2026

@@ -39,3 +45,7 @@ function constHalf(len) {
3945
}
4046
return out;
4147
}
48+
49+
function convertTypedArray(a) {
50+
return (Lib.isTypedArray(a)) ? Array.prototype.slice.call(a) : a;
51+
}
46.7 KB
Loading
Loading
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
"12 AM diagonal",
6+
"1 AM diagonal",
7+
"2 AM diagonal",
8+
"3 AM diagonal",
9+
"4 AM diagonal",
10+
"5 AM diagonal",
11+
"6 AM diagonal",
12+
"7 AM diagonal",
13+
"8 AM diagonal",
14+
"9 AM diagonal",
15+
"10 AM diagonal",
16+
"11 AM diagonal"
17+
],
18+
"y": [
19+
59.44,
20+
68.75,
21+
87.5,
22+
100.5,
23+
95.56,
24+
92.8,
25+
85.25,
26+
77.4,
27+
76.4,
28+
73.94,
29+
74.56,
30+
81.06
31+
]
32+
},
33+
{
34+
"x": [
35+
"12 AM diagonal",
36+
"1 AM diagonal",
37+
"2 AM diagonal",
38+
"3 AM diagonal",
39+
"4 AM diagonal",
40+
"5 AM diagonal",
41+
"6 AM diagonal",
42+
"7 AM diagonal",
43+
"8 AM diagonal",
44+
"9 AM diagonal",
45+
"10 AM diagonal",
46+
"11 AM diagonal"
47+
],
48+
"y": [
49+
59.44,
50+
68.75,
51+
87.5,
52+
100.5,
53+
95.56,
54+
92.8,
55+
85.25,
56+
77.4,
57+
76.4,
58+
73.94,
59+
74.56,
60+
81.06
61+
],
62+
"xaxis": "x2",
63+
"yaxis": "y2"
64+
}
65+
],
66+
"layout": {
67+
"grid": {
68+
"columns": 2,
69+
"rows": 1,
70+
"pattern": "independent"
71+
},
72+
"margin": {
73+
"l": 0,
74+
"r": 0,
75+
"t": 0,
76+
"b": 0
77+
},
78+
"xaxis": {
79+
"showgrid": false,
80+
"showline": true,
81+
"zeroline": true,
82+
"automargin": true,
83+
"side": "top",
84+
"tickangle": 45
85+
},
86+
"yaxis": {
87+
"side": "right",
88+
"showgrid": false,
89+
"showline": true,
90+
"zeroline": true,
91+
"automargin": true
92+
},
93+
"xaxis2": {
94+
"showgrid": false,
95+
"showline": true,
96+
"zeroline": true,
97+
"automargin": true,
98+
"tickangle": 45
99+
},
100+
"yaxis2": {
101+
"side": "left",
102+
"showgrid": false,
103+
"showline": true,
104+
"zeroline": true,
105+
"automargin": true
106+
},
107+
"showlegend": false
108+
}
109+
}

0 commit comments

Comments
 (0)