Skip to content

Commit 09a40af

Browse files
committed
Merge branch 'master' into fix3576-no-rotate-camera-before-modebar
2 parents a200e78 + cff31df commit 09a40af

38 files changed

+704
-225
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"es6-promise": "^3.0.2",
7373
"fast-isnumeric": "^1.1.2",
7474
"font-atlas-sdf": "^1.3.3",
75-
"gl-cone3d": "^1.2.3",
75+
"gl-cone3d": "^1.3.0",
7676
"gl-contour2d": "^1.1.5",
7777
"gl-error3d": "^1.0.14",
7878
"gl-heatmap2d": "^1.0.5",
@@ -85,7 +85,7 @@
8585
"gl-scatter3d": "^1.2.0",
8686
"gl-select-box": "^1.0.3",
8787
"gl-spikes2d": "^1.0.2",
88-
"gl-streamtube3d": "^1.1.3",
88+
"gl-streamtube3d": "^1.2.0",
8989
"gl-surface3d": "^1.4.2",
9090
"gl-text": "^1.1.6",
9191
"glslify": "^7.0.0",

src/components/fx/hover.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,13 +971,15 @@ function createHoverText(hoverData, opts, gd) {
971971
}
972972

973973
// hovertemplate
974+
var d3locale = gd._fullLayout._d3locale;
974975
var hovertemplate = d.hovertemplate || false;
975976
var hovertemplateLabels = d.hovertemplateLabels || d;
976977
var eventData = d.eventData[0] || {};
977978
if(hovertemplate) {
978979
text = Lib.hovertemplateString(
979980
hovertemplate,
980981
hovertemplateLabels,
982+
d3locale,
981983
eventData,
982984
{meta: fullLayout.meta}
983985
);

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/lib/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,25 +1031,26 @@ var maximumNumberOfHoverTemplateWarnings = 10;
10311031
* or fallback to associated labels.
10321032
*
10331033
* Examples:
1034-
* Lib.templateString('name: %{trace}', {trace: 'asdf'}) --> 'name: asdf'
1035-
* Lib.templateString('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'
1036-
* Lib.templateString('price: %{y:$.2f}', {y: 1}) --> 'price: $1.00'
1034+
* Lib.hovertemplateString('name: %{trace}', {trace: 'asdf'}) --> 'name: asdf'
1035+
* Lib.hovertemplateString('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'
1036+
* Lib.hovertemplateString('price: %{y:$.2f}', {y: 1}) --> 'price: $1.00'
10371037
*
1038+
* @param {obj} d3 locale
10381039
* @param {string} input string containing %{...:...} template strings
10391040
* @param {obj} data object containing fallback text when no formatting is specified, ex.: {yLabel: 'formattedYValue'}
10401041
* @param {obj} data objects containing substitution values
10411042
*
10421043
* @return {string} templated string
10431044
*/
1044-
lib.hovertemplateString = function(string, labels) {
1045+
lib.hovertemplateString = function(string, labels, d3locale) {
10451046
var args = arguments;
10461047
// Not all that useful, but cache nestedProperty instantiation
10471048
// just in case it speeds things up *slightly*:
10481049
var getterCache = {};
10491050

10501051
return string.replace(lib.TEMPLATE_STRING_REGEX, function(match, key, format) {
10511052
var obj, value, i;
1052-
for(i = 2; i < args.length; i++) {
1053+
for(i = 3; i < args.length; i++) {
10531054
obj = args[i];
10541055
if(obj.hasOwnProperty(key)) {
10551056
value = obj[key];
@@ -1076,7 +1077,13 @@ lib.hovertemplateString = function(string, labels) {
10761077
}
10771078

10781079
if(format) {
1079-
value = d3.format(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
1080+
var fmt;
1081+
if(d3locale) {
1082+
fmt = d3locale.numberFormat;
1083+
} else {
1084+
fmt = d3.format;
1085+
}
1086+
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
10801087
} else {
10811088
if(labels.hasOwnProperty(key + 'Label')) value = labels[key + 'Label'];
10821089
}

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
@@ -257,7 +257,7 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
257257
if(scene.fullSceneLayout.dragmode === false) return;
258258

259259
var update = {};
260-
update[scene.id + '.camera'] = getLayoutCamera(scene.camera, scene.camera._ortho);
260+
update[scene.id + '.camera'] = getLayoutCamera(scene.camera);
261261
scene.saveCamera(gd.layout);
262262
scene.graphDiv.emit('plotly_relayout', update);
263263
};
@@ -756,19 +756,19 @@ function getOrbitCamera(camera) {
756756

757757
// getLayoutCamera :: orbit_camera_coords -> plotly_coords
758758
// inverse of getOrbitCamera
759-
function getLayoutCamera(camera, isOrtho) {
759+
function getLayoutCamera(camera) {
760760
return {
761761
up: {x: camera.up[0], y: camera.up[1], z: camera.up[2]},
762762
center: {x: camera.center[0], y: camera.center[1], z: camera.center[2]},
763763
eye: {x: camera.eye[0], y: camera.eye[1], z: camera.eye[2]},
764-
projection: {type: (isOrtho === true) ? 'orthographic' : 'perspective'}
764+
projection: {type: (camera._ortho === true) ? 'orthographic' : 'perspective'}
765765
};
766766
}
767767

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

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

0 commit comments

Comments
 (0)