-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathcalc.js
107 lines (80 loc) · 2.82 KB
/
calc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var isNumeric = require('fast-isnumeric');
var Lib = require('../../lib');
var Colorscale = require('../../components/colorscale');
var subtypes = require('../scatter/subtypes');
var calcMarkerColorscale = require('../scatter/colorscale_calc');
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
module.exports = function calc(gd, trace) {
var len = trace.lon.length,
marker = trace.marker;
var hasMarkers = subtypes.hasMarkers(trace),
hasColorArray = (hasMarkers && Array.isArray(marker.color)),
hasSizeArray = (hasMarkers && Array.isArray(marker.size)),
hasSymbolArray = (hasMarkers && Array.isArray(marker.symbol)),
hasTextArray = Array.isArray(trace.text),
hasHoverTextArray = Array.isArray(trace.hovertext);
calcMarkerColorscale(trace);
var colorFn = Colorscale.hasColorscale(trace, 'marker') ?
Colorscale.makeColorScaleFunc(
Colorscale.extractScale(
marker.colorscale,
marker.cmin,
marker.cmax
)
) :
Lib.identity;
var sizeFn = subtypes.isBubble(trace) ?
makeBubbleSizeFn(trace) :
Lib.identity;
var calcTrace = [],
cnt = 0;
// Different than cartesian calc step
// as skip over non-numeric lon, lat pairs.
// This makes the hover and convert calculations simpler.
for(var i = 0; i < len; i++) {
var lon = trace.lon[i],
lat = trace.lat[i];
if(!isNumeric(lon) || !isNumeric(lat)) {
if(cnt > 0) calcTrace[cnt - 1].gapAfter = true;
continue;
}
var calcPt = {};
cnt++;
// coerce numeric strings into numbers
calcPt.lonlat = [+lon, +lat];
if(hasMarkers) {
if(hasColorArray) {
var mc = marker.color[i];
calcPt.mc = mc;
calcPt.mcc = colorFn(mc);
}
if(hasSizeArray) {
var ms = marker.size[i];
calcPt.ms = ms;
calcPt.mrc = sizeFn(ms);
}
if(hasSymbolArray) {
var mx = marker.symbol[i];
calcPt.mx = (typeof mx === 'string') ? mx : 'circle';
}
}
if(hasTextArray) {
var tx = trace.text[i];
calcPt.tx = (typeof tx === 'string') ? tx : '';
}
if(hasHoverTextArray) {
var htx = trace.hovertext[i];
calcPt.htx = (typeof htx === 'string') ? htx : '';
}
calcTrace.push(calcPt);
}
return calcTrace;
};