Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76d8a11

Browse filesBrowse files
committed
add formatLabels module method for scatter{polar,geo,ternary,carpet}
... in an effort to bring texttemplate and hover coordinates formatting to the same place.
1 parent ac978e5 commit 76d8a11
Copy full SHA for 76d8a11

File tree

15 files changed

+163
-30
lines changed
Filter options

15 files changed

+163
-30
lines changed

‎src/traces/barpolar/index.js

Copy file name to clipboardExpand all lines: src/traces/barpolar/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424

2525
plot: require('./plot'),
2626
colorbar: require('../scatter/marker_colorbar'),
27+
formatLabels: require('../scatterpolar/format_labels'),
2728

2829
style: require('../bar/style').style,
2930
styleOnSelect: require('../bar/style').styleOnSelect,

‎src/traces/scatter/format_labels.js

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Axes = require('../../plots/cartesian/axes');
12+
13+
module.exports = function formatLabels(cdi, trace, fullLayout) {
14+
var labels = {};
15+
16+
var mockGd = {_fullLayout: fullLayout};
17+
var xa = Axes.getFromTrace(mockGd, trace, 'x');
18+
var ya = Axes.getFromTrace(mockGd, trace, 'y');
19+
20+
labels.xLabel = Axes.tickText(xa, cdi.x, true).text;
21+
labels.yLabel = Axes.tickText(ya, cdi.y, true).text;
22+
23+
return labels;
24+
};

‎src/traces/scatter/index.js

Copy file name to clipboardExpand all lines: src/traces/scatter/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
arraysToCalcdata: require('./arrays_to_calcdata'),
2525
plot: require('./plot'),
2626
colorbar: require('./marker_colorbar'),
27+
formatLabels: require('./format_labels'),
2728
style: require('./style').style,
2829
styleOnSelect: require('./style').styleOnSelect,
2930
hoverPoints: require('./hover'),
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function formatLabels(cdi, trace) {
12+
var labels = {};
13+
14+
var carpet = trace._carpet;
15+
var ij = carpet.ab2ij([cdi.a, cdi.b]);
16+
var i0 = Math.floor(ij[0]);
17+
var ti = ij[0] - i0;
18+
var j0 = Math.floor(ij[1]);
19+
var tj = ij[1] - j0;
20+
var xy = carpet.evalxy([], i0, j0, ti, tj);
21+
22+
labels.yLabel = xy[1].toFixed(3);
23+
24+
return labels;
25+
};

‎src/traces/scattercarpet/hover.js

Copy file name to clipboardExpand all lines: src/traces/scattercarpet/hover.js
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
4949
var trace = newPointData.trace;
5050
var carpet = trace._carpet;
5151

52-
var ij = carpet.ab2ij([cdi.a, cdi.b]);
53-
var i0 = Math.floor(ij[0]);
54-
var ti = ij[0] - i0;
55-
var j0 = Math.floor(ij[1]);
56-
var tj = ij[1] - j0;
57-
var xy = carpet.evalxy([], i0, j0, ti, tj);
58-
newPointData.yLabel = xy[1].toFixed(3);
52+
var labels = trace._module.formatLabels(cdi, trace);
53+
newPointData.yLabel = labels.yLabel;
5954

6055
delete newPointData.text;
6156
var text = [];

‎src/traces/scattercarpet/index.js

Copy file name to clipboardExpand all lines: src/traces/scattercarpet/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
attributes: require('./attributes'),
1313
supplyDefaults: require('./defaults'),
1414
colorbar: require('../scatter/marker_colorbar'),
15+
formatLabels: require('./format_labels'),
1516
calc: require('./calc'),
1617
plot: require('./plot'),
1718
style: require('../scatter/style').style,
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Axes = require('../../plots/cartesian/axes');
12+
13+
module.exports = function formatLabels(cdi, trace, fullLayout) {
14+
var labels = {};
15+
16+
var geo = fullLayout[trace.geo]._subplot;
17+
var ax = geo.mockAxis;
18+
var lonlat = cdi.lonlat;
19+
labels.lonLabel = Axes.tickText(ax, ax.c2l(lonlat[0]), true).text;
20+
labels.latLabel = Axes.tickText(ax, ax.c2l(lonlat[1]), true).text;
21+
22+
return labels;
23+
};

‎src/traces/scattergeo/hover.js

Copy file name to clipboardExpand all lines: src/traces/scattergeo/hover.js
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
'use strict';
1010

1111
var Fx = require('../../components/fx');
12-
var Axes = require('../../plots/cartesian/axes');
1312
var BADNUM = require('../../constants/numerical').BADNUM;
1413

1514
var getTraceColor = require('../scatter/get_trace_color');
@@ -63,9 +62,11 @@ module.exports = function hoverPoints(pointData, xval, yval) {
6362
pointData.lon = lonlat[0];
6463
pointData.lat = lonlat[1];
6564

66-
var ax = geo.mockAxis;
67-
pointData.lonLabel = Axes.tickText(ax, ax.c2l(pointData.lon), 'hover').text;
68-
pointData.latLabel = Axes.tickText(ax, ax.c2l(pointData.lat), 'hover').text;
65+
var fullLayout = {};
66+
fullLayout[trace.geo] = {_subplot: geo};
67+
var labels = trace._module.formatLabels(di, trace, fullLayout);
68+
pointData.lonLabel = labels.lonLabel;
69+
pointData.latLabel = labels.latLabel;
6970

7071
pointData.color = getTraceColor(trace, di);
7172
pointData.extraText = getExtraText(trace, di, pointData, cd[0].t.labels);

‎src/traces/scattergeo/index.js

Copy file name to clipboardExpand all lines: src/traces/scattergeo/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
attributes: require('./attributes'),
1313
supplyDefaults: require('./defaults'),
1414
colorbar: require('../scatter/marker_colorbar'),
15+
formatLabels: require('./format_labels'),
1516
calc: require('./calc'),
1617
plot: require('./plot'),
1718
style: require('./style'),
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
var Axes = require('../../plots/cartesian/axes');
13+
14+
module.exports = function formatLabels(cdi, trace, fullLayout) {
15+
var labels = {};
16+
17+
var subplot = fullLayout[trace.subplot]._subplot;
18+
var radialAxis;
19+
var angularAxis;
20+
21+
// for scatterpolargl texttemplate, _subplot is NOT defined, this takes part during the convert step
22+
// TODO we should consider moving the texttemplate formatting logic to the plot step
23+
if(!subplot) {
24+
subplot = fullLayout[trace.subplot];
25+
radialAxis = subplot.radialaxis;
26+
angularAxis = subplot.angularaxis;
27+
} else {
28+
radialAxis = subplot.radialAxis;
29+
angularAxis = subplot.angularAxis;
30+
}
31+
32+
var rVal = radialAxis.c2l(cdi.r);
33+
labels.rLabel = Axes.tickText(radialAxis, rVal, true).text;
34+
35+
// N.B here the ° sign is part of the formatted value for thetaunit:'degrees'
36+
var thetaVal = angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(cdi.theta) : cdi.theta;
37+
labels.thetaLabel = Axes.tickText(angularAxis, thetaVal, true).text;
38+
39+
return labels;
40+
};

‎src/traces/scatterpolar/hover.js

Copy file name to clipboardExpand all lines: src/traces/scatterpolar/hover.js
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
'use strict';
1010

1111
var scatterHover = require('../scatter/hover');
12-
var Axes = require('../../plots/cartesian/axes');
13-
var Lib = require('../../lib');
1412

1513
function hoverPoints(pointData, xval, yval, hovermode) {
1614
var scatterPointData = scatterHover(pointData, xval, yval, hovermode);
@@ -42,12 +40,11 @@ function makeHoverPointText(cdi, trace, subplot, pointData) {
4240
radialAxis._hovertitle = 'r';
4341
angularAxis._hovertitle = 'θ';
4442

45-
var rVal = radialAxis.c2l(cdi.r);
46-
pointData.rLabel = Axes.tickText(radialAxis, rVal, 'hover').text;
47-
48-
// N.B here the ° sign is part of the formatted value for thetaunit:'degrees'
49-
var thetaVal = angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(cdi.theta) : cdi.theta;
50-
pointData.thetaLabel = Axes.tickText(angularAxis, thetaVal, 'hover').text;
43+
var fullLayout = {};
44+
fullLayout[trace.subplot] = {_subplot: subplot};
45+
var labels = trace._module.formatLabels(cdi, trace, fullLayout);
46+
pointData.rLabel = labels.rLabel;
47+
pointData.thetaLabel = labels.thetaLabel;
5148

5249
var hoverinfo = cdi.hi || trace.hoverinfo;
5350
var text = [];

‎src/traces/scatterpolar/index.js

Copy file name to clipboardExpand all lines: src/traces/scatterpolar/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
attributes: require('./attributes'),
1818
supplyDefaults: require('./defaults').supplyDefaults,
1919
colorbar: require('../scatter/marker_colorbar'),
20+
formatLabels: require('./format_labels'),
2021
calc: require('./calc'),
2122
plot: require('./plot'),
2223
style: require('../scatter/style').style,
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Axes = require('../../plots/cartesian/axes');
12+
13+
module.exports = function formatLabels(cdi, trace, fullLayout) {
14+
var labels = {};
15+
16+
var subplot = fullLayout[trace.subplot]._subplot;
17+
labels.aLabel = Axes.tickText(subplot.aaxis, cdi.a, true).text;
18+
labels.bLabel = Axes.tickText(subplot.baxis, cdi.b, true).text;
19+
labels.cLabel = Axes.tickText(subplot.caxis, cdi.c, true).text;
20+
21+
return labels;
22+
};

‎src/traces/scatterternary/hover.js

Copy file name to clipboardExpand all lines: src/traces/scatterternary/hover.js
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var scatterHover = require('../scatter/hover');
13-
var Axes = require('../../plots/cartesian/axes');
14-
1512

1613
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
1714
var scatterPointData = scatterHover(pointData, xval, yval, hovermode);
@@ -40,6 +37,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
4037
}
4138

4239
var cdi = newPointData.cd[newPointData.index];
40+
var trace = newPointData.trace;
41+
var subplot = newPointData.subplot;
4342

4443
newPointData.a = cdi.a;
4544
newPointData.b = cdi.b;
@@ -48,12 +47,13 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
4847
newPointData.xLabelVal = undefined;
4948
newPointData.yLabelVal = undefined;
5049

51-
var ternary = newPointData.subplot;
52-
newPointData.aLabel = Axes.tickText(ternary.aaxis, cdi.a, 'hover').text;
53-
newPointData.bLabel = Axes.tickText(ternary.baxis, cdi.b, 'hover').text;
54-
newPointData.cLabel = Axes.tickText(ternary.caxis, cdi.c, 'hover').text;
50+
var fullLayout = {};
51+
fullLayout[trace.subplot] = {_subplot: subplot};
52+
var labels = trace._module.formatLabels(cdi, trace, fullLayout);
53+
newPointData.aLabel = labels.aLabel;
54+
newPointData.bLabel = labels.bLabel;
55+
newPointData.cLabel = labels.cLabel;
5556

56-
var trace = newPointData.trace;
5757
var hoverinfo = cdi.hi || trace.hoverinfo;
5858
var text = [];
5959
function textPart(ax, val) {
@@ -62,9 +62,9 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
6262
if(!trace.hovertemplate) {
6363
var parts = hoverinfo.split('+');
6464
if(parts.indexOf('all') !== -1) parts = ['a', 'b', 'c'];
65-
if(parts.indexOf('a') !== -1) textPart(ternary.aaxis, newPointData.aLabel);
66-
if(parts.indexOf('b') !== -1) textPart(ternary.baxis, newPointData.bLabel);
67-
if(parts.indexOf('c') !== -1) textPart(ternary.caxis, newPointData.cLabel);
65+
if(parts.indexOf('a') !== -1) textPart(subplot.aaxis, newPointData.aLabel);
66+
if(parts.indexOf('b') !== -1) textPart(subplot.baxis, newPointData.bLabel);
67+
if(parts.indexOf('c') !== -1) textPart(subplot.caxis, newPointData.cLabel);
6868
}
6969
newPointData.extraText = text.join('<br>');
7070
newPointData.hovertemplate = trace.hovertemplate;

‎src/traces/scatterternary/index.js

Copy file name to clipboardExpand all lines: src/traces/scatterternary/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
attributes: require('./attributes'),
1313
supplyDefaults: require('./defaults'),
1414
colorbar: require('../scatter/marker_colorbar'),
15+
formatLabels: require('./format_labels'),
1516
calc: require('./calc'),
1617
plot: require('./plot'),
1718
style: require('../scatter/style').style,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.