Skip to content

Commit dea5317

Browse files
committed
Merge branch 'master' into refactor-parcoords-bug-fixes-labelangle-side
2 parents 97f61b6 + 795220f commit dea5317

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2135
-1723
lines changed

package-lock.json

+13-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,15 @@
132132
"gzip-size": "^5.1.1",
133133
"image-size": "^0.7.4",
134134
"into-stream": "^4.0.0",
135-
"jasmine-core": "^2.99.1",
135+
"jasmine-core": "^3.4.0",
136136
"jsdom": "^11.12.0",
137137
"karma": "^4.1.0",
138138
"karma-browserify": "^6.0.0",
139139
"karma-chrome-launcher": "^2.0.0",
140-
"karma-fail-fast-reporter": "^1.0.5",
141140
"karma-firefox-launcher": "^1.0.1",
142141
"karma-ie-launcher": "^1.0.0",
143-
"karma-jasmine": "^1.1.2",
144-
"karma-jasmine-spec-tags": "^1.0.1",
142+
"karma-jasmine": "^2.0.1",
143+
"karma-jasmine-spec-tags": "^1.1.0",
145144
"karma-spec-reporter": "0.0.32",
146145
"karma-verbose-reporter": "0.0.6",
147146
"karma-viewport": "^1.0.4",

src/components/fx/hover.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,15 @@ function createHoverText(hoverData, opts, gd) {
896896
if(d.zLabel !== undefined) {
897897
if(d.xLabel !== undefined) text += 'x: ' + d.xLabel + '<br>';
898898
if(d.yLabel !== undefined) text += 'y: ' + d.yLabel + '<br>';
899-
text += (text ? 'z: ' : '') + d.zLabel;
899+
if(d.trace.type !== 'choropleth') {
900+
text += (text ? 'z: ' : '') + d.zLabel;
901+
}
900902
} else if(showCommonLabel && d[hovermode + 'Label'] === t0) {
901903
text = d[(hovermode === 'x' ? 'y' : 'x') + 'Label'] || '';
902904
} else if(d.xLabel === undefined) {
903-
if(d.yLabel !== undefined && d.trace.type !== 'scattercarpet') text = d.yLabel;
905+
if(d.yLabel !== undefined && d.trace.type !== 'scattercarpet') {
906+
text = d.yLabel;
907+
}
904908
} else if(d.yLabel === undefined) text = d.xLabel;
905909
else text = '(' + d.xLabel + ', ' + d.yLabel + ')';
906910

src/traces/choropleth/hover.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Axes = require('../../plots/cartesian/axes');
@@ -47,17 +46,16 @@ module.exports = function hoverPoints(pointData, xval, yval) {
4746
pointData.index = pt.index;
4847
pointData.location = pt.loc;
4948
pointData.z = pt.z;
49+
pointData.zLabel = Axes.tickText(geo.mockAxis, geo.mockAxis.c2l(pt.z), 'hover').text;
5050
pointData.hovertemplate = pt.hovertemplate;
5151

5252
makeHoverInfo(pointData, trace, pt, geo.mockAxis);
5353

5454
return [pointData];
5555
};
5656

57-
function makeHoverInfo(pointData, trace, pt, axis) {
58-
if(trace.hovertemplate) {
59-
return;
60-
}
57+
function makeHoverInfo(pointData, trace, pt) {
58+
if(trace.hovertemplate) return;
6159

6260
var hoverinfo = pt.hi || trace.hoverinfo;
6361

@@ -73,18 +71,16 @@ function makeHoverInfo(pointData, trace, pt, axis) {
7371

7472
var text = [];
7573

76-
function formatter(val) {
77-
return Axes.tickText(axis, axis.c2l(val), 'hover').text;
78-
}
79-
8074
if(hasIdAsNameLabel) {
8175
pointData.nameOverride = pt.loc;
8276
} else {
8377
if(hasName) pointData.nameOverride = trace.name;
8478
if(hasLocation) text.push(pt.loc);
8579
}
8680

87-
if(hasZ) text.push(formatter(pt.z));
81+
if(hasZ) {
82+
text.push(pointData.zLabel);
83+
}
8884
if(hasText) {
8985
fillText(pt, trace, text);
9086
}

src/traces/scattergeo/hover.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Fx = require('../../components/fx');
@@ -64,17 +63,19 @@ module.exports = function hoverPoints(pointData, xval, yval) {
6463
pointData.lon = lonlat[0];
6564
pointData.lat = lonlat[1];
6665

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;
69+
6770
pointData.color = getTraceColor(trace, di);
68-
pointData.extraText = getExtraText(trace, di, geo.mockAxis, cd[0].t.labels);
71+
pointData.extraText = getExtraText(trace, di, pointData, cd[0].t.labels);
6972
pointData.hovertemplate = trace.hovertemplate;
7073

7174
return [pointData];
7275
};
7376

74-
function getExtraText(trace, pt, axis, labels) {
75-
if(trace.hovertemplate) {
76-
return;
77-
}
77+
function getExtraText(trace, pt, pointData, labels) {
78+
if(trace.hovertemplate) return;
7879

7980
var hoverinfo = pt.hi || trace.hoverinfo;
8081

@@ -88,18 +89,16 @@ function getExtraText(trace, pt, axis, labels) {
8889
var hasText = (parts.indexOf('text') !== -1);
8990
var text = [];
9091

91-
function format(val) {
92-
return Axes.tickText(axis, axis.c2l(val), 'hover').text + '\u00B0';
93-
}
92+
function format(val) { return val + '\u00B0'; }
9493

9594
if(hasLocation) {
9695
text.push(pt.loc);
9796
} else if(hasLon && hasLat) {
98-
text.push('(' + format(pt.lonlat[0]) + ', ' + format(pt.lonlat[1]) + ')');
97+
text.push('(' + format(pointData.lonLabel) + ', ' + format(pointData.latLabel) + ')');
9998
} else if(hasLon) {
100-
text.push(labels.lon + format(pt.lonlat[0]));
99+
text.push(labels.lon + format(pointData.lonLabel));
101100
} else if(hasLat) {
102-
text.push(labels.lat + format(pt.lonlat[1]));
101+
text.push(labels.lat + format(pointData.latLabel));
103102
}
104103

105104
if(hasText) {

src/traces/scattergl/calc.js

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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 cluster = require('point-cluster');
12+
13+
var Lib = require('../../lib');
14+
var AxisIDs = require('../../plots/cartesian/axis_ids');
15+
var findExtremes = require('../../plots/cartesian/autorange').findExtremes;
16+
17+
var scatterCalc = require('../scatter/calc');
18+
var calcMarkerSize = scatterCalc.calcMarkerSize;
19+
var calcAxisExpansion = scatterCalc.calcAxisExpansion;
20+
var setFirstScatter = scatterCalc.setFirstScatter;
21+
var calcColorscale = require('../scatter/colorscale_calc');
22+
var convert = require('./convert');
23+
var sceneUpdate = require('./scene_update');
24+
25+
var BADNUM = require('../../constants/numerical').BADNUM;
26+
var TOO_MANY_POINTS = require('./constants').TOO_MANY_POINTS;
27+
28+
module.exports = function calc(gd, trace) {
29+
var fullLayout = gd._fullLayout;
30+
var xa = AxisIDs.getFromId(gd, trace.xaxis);
31+
var ya = AxisIDs.getFromId(gd, trace.yaxis);
32+
var subplot = fullLayout._plots[trace.xaxis + trace.yaxis];
33+
var len = trace._length;
34+
var hasTooManyPoints = len >= TOO_MANY_POINTS;
35+
var len2 = len * 2;
36+
var stash = {};
37+
var i, xx, yy;
38+
39+
var x = xa.makeCalcdata(trace, 'x');
40+
var y = ya.makeCalcdata(trace, 'y');
41+
42+
// we need hi-precision for scatter2d,
43+
// regl-scatter2d uses NaNs for bad/missing values
44+
var positions = new Array(len2);
45+
for(i = 0; i < len; i++) {
46+
xx = x[i];
47+
yy = y[i];
48+
positions[i * 2] = xx === BADNUM ? NaN : xx;
49+
positions[i * 2 + 1] = yy === BADNUM ? NaN : yy;
50+
}
51+
52+
if(xa.type === 'log') {
53+
for(i = 0; i < len2; i += 2) {
54+
positions[i] = xa.c2l(positions[i]);
55+
}
56+
}
57+
if(ya.type === 'log') {
58+
for(i = 1; i < len2; i += 2) {
59+
positions[i] = ya.c2l(positions[i]);
60+
}
61+
}
62+
63+
// we don't build a tree for log axes since it takes long to convert log2px
64+
// and it is also
65+
if(hasTooManyPoints && (xa.type !== 'log' && ya.type !== 'log')) {
66+
// FIXME: delegate this to webworker
67+
stash.tree = cluster(positions);
68+
} else {
69+
var ids = stash.ids = new Array(len);
70+
for(i = 0; i < len; i++) {
71+
ids[i] = i;
72+
}
73+
}
74+
75+
// create scene options and scene
76+
calcColorscale(gd, trace);
77+
var opts = sceneOptions(gd, subplot, trace, positions, x, y);
78+
var scene = sceneUpdate(gd, subplot);
79+
80+
// Reuse SVG scatter axis expansion routine.
81+
// For graphs with very large number of points and array marker.size,
82+
// use average marker size instead to speed things up.
83+
setFirstScatter(fullLayout, trace);
84+
var ppad;
85+
if(!hasTooManyPoints) {
86+
ppad = calcMarkerSize(trace, len);
87+
} else if(opts.marker) {
88+
ppad = 2 * (opts.marker.sizeAvg || Math.max(opts.marker.size, 3));
89+
}
90+
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
91+
if(opts.errorX) expandForErrorBars(trace, xa, opts.errorX);
92+
if(opts.errorY) expandForErrorBars(trace, ya, opts.errorY);
93+
94+
// set flags to create scene renderers
95+
if(opts.fill && !scene.fill2d) scene.fill2d = true;
96+
if(opts.marker && !scene.scatter2d) scene.scatter2d = true;
97+
if(opts.line && !scene.line2d) scene.line2d = true;
98+
if((opts.errorX || opts.errorY) && !scene.error2d) scene.error2d = true;
99+
if(opts.text && !scene.glText) scene.glText = true;
100+
101+
// FIXME: organize it in a more appropriate manner, probably in sceneOptions
102+
// put point-cluster instance for optimized regl calc
103+
if(opts.marker) {
104+
opts.marker.snap = stash.tree || TOO_MANY_POINTS;
105+
}
106+
107+
scene.lineOptions.push(opts.line);
108+
scene.errorXOptions.push(opts.errorX);
109+
scene.errorYOptions.push(opts.errorY);
110+
scene.fillOptions.push(opts.fill);
111+
scene.markerOptions.push(opts.marker);
112+
scene.markerSelectedOptions.push(opts.markerSel);
113+
scene.markerUnselectedOptions.push(opts.markerUnsel);
114+
scene.textOptions.push(opts.text);
115+
scene.textSelectedOptions.push(opts.textSel);
116+
scene.textUnselectedOptions.push(opts.textUnsel);
117+
scene.selectBatch.push([]);
118+
scene.unselectBatch.push([]);
119+
120+
stash._scene = scene;
121+
stash.index = scene.count;
122+
stash.x = x;
123+
stash.y = y;
124+
stash.positions = positions;
125+
scene.count++;
126+
127+
return [{x: false, y: false, t: stash, trace: trace}];
128+
};
129+
130+
function expandForErrorBars(trace, ax, opts) {
131+
var extremes = trace._extremes[ax._id];
132+
var errExt = findExtremes(ax, opts._bnds, {padded: true});
133+
extremes.min = extremes.min.concat(errExt.min);
134+
extremes.max = extremes.max.concat(errExt.max);
135+
}
136+
137+
function sceneOptions(gd, subplot, trace, positions, x, y) {
138+
var opts = convert.style(gd, trace);
139+
140+
if(opts.marker) {
141+
opts.marker.positions = positions;
142+
}
143+
144+
if(opts.line && positions.length > 1) {
145+
Lib.extendFlat(
146+
opts.line,
147+
convert.linePositions(gd, trace, positions)
148+
);
149+
}
150+
151+
if(opts.errorX || opts.errorY) {
152+
var errors = convert.errorBarPositions(gd, trace, positions, x, y);
153+
154+
if(opts.errorX) {
155+
Lib.extendFlat(opts.errorX, errors.x);
156+
}
157+
if(opts.errorY) {
158+
Lib.extendFlat(opts.errorY, errors.y);
159+
}
160+
}
161+
162+
if(opts.text) {
163+
Lib.extendFlat(
164+
opts.text,
165+
{positions: positions},
166+
convert.textPosition(gd, trace, opts.text, opts.marker)
167+
);
168+
Lib.extendFlat(
169+
opts.textSel,
170+
{positions: positions},
171+
convert.textPosition(gd, trace, opts.text, opts.markerSel)
172+
);
173+
Lib.extendFlat(
174+
opts.textUnsel,
175+
{positions: positions},
176+
convert.textPosition(gd, trace, opts.text, opts.markerUnsel)
177+
);
178+
}
179+
180+
return opts;
181+
}

0 commit comments

Comments
 (0)