@vtx/cs-map 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/feature-layer/FeatureLayer.js +19 -2
- package/lib/feature-layer/FeatureLayer.js.map +1 -1
- package/lib/feature-layer/index.js.map +1 -1
- package/lib/heatmap-layer/heatmap.js +612 -0
- package/lib/heatmap-layer/heatmap.js.map +1 -0
- package/lib/heatmap-layer/index.js +41 -8
- package/lib/heatmap-layer/index.js.map +1 -1
- package/lib/image-layer/ImageLayer.js.map +1 -1
- package/lib/image-layer/index.js.map +1 -1
- package/lib/legend/index.js +84 -60
- package/lib/legend/index.js.map +1 -1
- package/lib/map/Layers.js +4 -4
- package/lib/map/Layers.js.map +1 -1
- package/lib/map/index.js +3 -1
- package/lib/map/index.js.map +1 -1
- package/lib/tools/layer/index.js +25 -6
- package/lib/tools/layer/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/heatmap-layer/CesiumHeatmap.js +0 -345
- package/lib/heatmap-layer/CesiumHeatmap.js.map +0 -1
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* heatmap.js v2.0.0 | JavaScript Heatmap Library
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2008-2014 Patrick Wied <heatmapjs@patrick-wied.at> - All rights reserved.
|
|
11
|
+
* Dual licensed under MIT and Beerware license
|
|
12
|
+
*
|
|
13
|
+
* :: 2015-07-19 15:42
|
|
14
|
+
*/
|
|
15
|
+
// Heatmap Config stores default values and will be merged with instance config
|
|
16
|
+
var HeatmapConfig = {
|
|
17
|
+
defaultRadius: 40,
|
|
18
|
+
defaultRenderer: "canvas2d",
|
|
19
|
+
defaultGradient: {
|
|
20
|
+
0.25: "rgb(0,0,255)",
|
|
21
|
+
0.55: "rgb(0,255,0)",
|
|
22
|
+
0.85: "yellow",
|
|
23
|
+
1.0: "rgb(255,0,0)"
|
|
24
|
+
},
|
|
25
|
+
defaultMaxOpacity: 1,
|
|
26
|
+
defaultMinOpacity: 0,
|
|
27
|
+
defaultBlur: 0.85,
|
|
28
|
+
defaultXField: "x",
|
|
29
|
+
defaultYField: "y",
|
|
30
|
+
defaultValueField: "value",
|
|
31
|
+
plugins: {}
|
|
32
|
+
};
|
|
33
|
+
var Store = function StoreClosure() {
|
|
34
|
+
var Store = function Store(config) {
|
|
35
|
+
this._coordinator = {};
|
|
36
|
+
this._data = [];
|
|
37
|
+
this._radi = [];
|
|
38
|
+
this._min = 0;
|
|
39
|
+
this._max = 1;
|
|
40
|
+
this._xField = config["xField"] || config.defaultXField;
|
|
41
|
+
this._yField = config["yField"] || config.defaultYField;
|
|
42
|
+
this._valueField = config["valueField"] || config.defaultValueField;
|
|
43
|
+
if (config["radius"]) {
|
|
44
|
+
this._cfgRadius = config["radius"];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var defaultRadius = HeatmapConfig.defaultRadius;
|
|
48
|
+
Store.prototype = {
|
|
49
|
+
// when forceRender = false -> called from setData, omits renderall event
|
|
50
|
+
_organiseData: function _organiseData(dataPoint, forceRender) {
|
|
51
|
+
var x = dataPoint[this._xField];
|
|
52
|
+
var y = dataPoint[this._yField];
|
|
53
|
+
var radi = this._radi;
|
|
54
|
+
var store = this._data;
|
|
55
|
+
var max = this._max;
|
|
56
|
+
var min = this._min;
|
|
57
|
+
var value = dataPoint[this._valueField] || 1;
|
|
58
|
+
var radius = dataPoint.radius || this._cfgRadius || defaultRadius;
|
|
59
|
+
if (!store[x]) {
|
|
60
|
+
store[x] = [];
|
|
61
|
+
radi[x] = [];
|
|
62
|
+
}
|
|
63
|
+
if (!store[x][y]) {
|
|
64
|
+
store[x][y] = value;
|
|
65
|
+
radi[x][y] = radius;
|
|
66
|
+
} else {
|
|
67
|
+
store[x][y] += value;
|
|
68
|
+
}
|
|
69
|
+
if (store[x][y] > max) {
|
|
70
|
+
if (!forceRender) {
|
|
71
|
+
this._max = store[x][y];
|
|
72
|
+
} else {
|
|
73
|
+
this.setDataMax(store[x][y]);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
} else {
|
|
77
|
+
return {
|
|
78
|
+
x: x,
|
|
79
|
+
y: y,
|
|
80
|
+
value: value,
|
|
81
|
+
radius: radius,
|
|
82
|
+
min: min,
|
|
83
|
+
max: max
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
_unOrganizeData: function _unOrganizeData() {
|
|
88
|
+
var unorganizedData = [];
|
|
89
|
+
var data = this._data;
|
|
90
|
+
var radi = this._radi;
|
|
91
|
+
for (var x in data) {
|
|
92
|
+
for (var y in data[x]) {
|
|
93
|
+
unorganizedData.push({
|
|
94
|
+
x: x,
|
|
95
|
+
y: y,
|
|
96
|
+
radius: radi[x][y],
|
|
97
|
+
value: data[x][y]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
min: this._min,
|
|
103
|
+
max: this._max,
|
|
104
|
+
data: unorganizedData
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
_onExtremaChange: function _onExtremaChange() {
|
|
108
|
+
this._coordinator.emit("extremachange", {
|
|
109
|
+
min: this._min,
|
|
110
|
+
max: this._max
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
addData: function addData() {
|
|
114
|
+
if (arguments[0].length > 0) {
|
|
115
|
+
var dataArr = arguments[0];
|
|
116
|
+
var dataLen = dataArr.length;
|
|
117
|
+
while (dataLen--) {
|
|
118
|
+
this.addData.call(this, dataArr[dataLen]);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
// add to store
|
|
122
|
+
var organisedEntry = this._organiseData(arguments[0], true);
|
|
123
|
+
if (organisedEntry) {
|
|
124
|
+
this._coordinator.emit("renderpartial", {
|
|
125
|
+
min: this._min,
|
|
126
|
+
max: this._max,
|
|
127
|
+
data: [organisedEntry]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return this;
|
|
132
|
+
},
|
|
133
|
+
setData: function setData(data) {
|
|
134
|
+
var dataPoints = data.data;
|
|
135
|
+
var pointsLen = dataPoints.length;
|
|
136
|
+
|
|
137
|
+
// reset data arrays
|
|
138
|
+
this._data = [];
|
|
139
|
+
this._radi = [];
|
|
140
|
+
for (var i = 0; i < pointsLen; i++) {
|
|
141
|
+
this._organiseData(dataPoints[i], false);
|
|
142
|
+
}
|
|
143
|
+
this._max = data.max;
|
|
144
|
+
this._min = data.min || 0;
|
|
145
|
+
this._onExtremaChange();
|
|
146
|
+
this._coordinator.emit("renderall", this._getInternalData());
|
|
147
|
+
return this;
|
|
148
|
+
},
|
|
149
|
+
removeData: function removeData() {
|
|
150
|
+
// TODO: implement
|
|
151
|
+
},
|
|
152
|
+
setDataMax: function setDataMax(max) {
|
|
153
|
+
this._max = max;
|
|
154
|
+
this._onExtremaChange();
|
|
155
|
+
this._coordinator.emit("renderall", this._getInternalData());
|
|
156
|
+
return this;
|
|
157
|
+
},
|
|
158
|
+
setDataMin: function setDataMin(min) {
|
|
159
|
+
this._min = min;
|
|
160
|
+
this._onExtremaChange();
|
|
161
|
+
this._coordinator.emit("renderall", this._getInternalData());
|
|
162
|
+
return this;
|
|
163
|
+
},
|
|
164
|
+
setCoordinator: function setCoordinator(coordinator) {
|
|
165
|
+
this._coordinator = coordinator;
|
|
166
|
+
},
|
|
167
|
+
_getInternalData: function _getInternalData() {
|
|
168
|
+
return {
|
|
169
|
+
max: this._max,
|
|
170
|
+
min: this._min,
|
|
171
|
+
data: this._data,
|
|
172
|
+
radi: this._radi
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
getData: function getData() {
|
|
176
|
+
return this._unOrganizeData();
|
|
177
|
+
} /*,
|
|
178
|
+
TODO: rethink.
|
|
179
|
+
getValueAt: function(point) {
|
|
180
|
+
var value;
|
|
181
|
+
var radius = 100;
|
|
182
|
+
var x = point.x;
|
|
183
|
+
var y = point.y;
|
|
184
|
+
var data = this._data;
|
|
185
|
+
if (data[x] && data[x][y]) {
|
|
186
|
+
return data[x][y];
|
|
187
|
+
} else {
|
|
188
|
+
var values = [];
|
|
189
|
+
// radial search for datapoints based on default radius
|
|
190
|
+
for(var distance = 1; distance < radius; distance++) {
|
|
191
|
+
var neighbors = distance * 2 +1;
|
|
192
|
+
var startX = x - distance;
|
|
193
|
+
var startY = y - distance;
|
|
194
|
+
for(var i = 0; i < neighbors; i++) {
|
|
195
|
+
for (var o = 0; o < neighbors; o++) {
|
|
196
|
+
if ((i == 0 || i == neighbors-1) || (o == 0 || o == neighbors-1)) {
|
|
197
|
+
if (data[startY+i] && data[startY+i][startX+o]) {
|
|
198
|
+
values.push(data[startY+i][startX+o]);
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (values.length > 0) {
|
|
207
|
+
return Math.max.apply(Math, values);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}*/
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
return Store;
|
|
215
|
+
}();
|
|
216
|
+
var Canvas2dRenderer = function Canvas2dRendererClosure() {
|
|
217
|
+
var _getColorPalette = function _getColorPalette(config) {
|
|
218
|
+
var gradientConfig = config.gradient || config.defaultGradient;
|
|
219
|
+
var paletteCanvas = document.createElement("canvas");
|
|
220
|
+
var paletteCtx = paletteCanvas.getContext("2d");
|
|
221
|
+
paletteCanvas.width = 256;
|
|
222
|
+
paletteCanvas.height = 1;
|
|
223
|
+
var gradient = paletteCtx.createLinearGradient(0, 0, 256, 1);
|
|
224
|
+
for (var key in gradientConfig) {
|
|
225
|
+
gradient.addColorStop(key, gradientConfig[key]);
|
|
226
|
+
}
|
|
227
|
+
paletteCtx.fillStyle = gradient;
|
|
228
|
+
paletteCtx.fillRect(0, 0, 256, 1);
|
|
229
|
+
return paletteCtx.getImageData(0, 0, 256, 1).data;
|
|
230
|
+
};
|
|
231
|
+
var _getPointTemplate = function _getPointTemplate(radius, blurFactor) {
|
|
232
|
+
var tplCanvas = document.createElement("canvas");
|
|
233
|
+
var tplCtx = tplCanvas.getContext("2d");
|
|
234
|
+
var x = radius;
|
|
235
|
+
var y = radius;
|
|
236
|
+
tplCanvas.width = tplCanvas.height = radius * 2;
|
|
237
|
+
if (blurFactor == 1) {
|
|
238
|
+
tplCtx.beginPath();
|
|
239
|
+
tplCtx.arc(x, y, radius, 0, 2 * Math.PI, false);
|
|
240
|
+
tplCtx.fillStyle = "rgba(0,0,0,1)";
|
|
241
|
+
tplCtx.fill();
|
|
242
|
+
} else {
|
|
243
|
+
var gradient = tplCtx.createRadialGradient(x, y, radius * blurFactor, x, y, radius);
|
|
244
|
+
gradient.addColorStop(0, "rgba(0,0,0,1)");
|
|
245
|
+
gradient.addColorStop(1, "rgba(0,0,0,0)");
|
|
246
|
+
tplCtx.fillStyle = gradient;
|
|
247
|
+
tplCtx.fillRect(0, 0, 2 * radius, 2 * radius);
|
|
248
|
+
}
|
|
249
|
+
return tplCanvas;
|
|
250
|
+
};
|
|
251
|
+
var _prepareData = function _prepareData(data) {
|
|
252
|
+
var renderData = [];
|
|
253
|
+
var min = data.min;
|
|
254
|
+
var max = data.max;
|
|
255
|
+
var radi = data.radi;
|
|
256
|
+
var data = data.data;
|
|
257
|
+
var xValues = Object.keys(data);
|
|
258
|
+
var xValuesLen = xValues.length;
|
|
259
|
+
while (xValuesLen--) {
|
|
260
|
+
var xValue = xValues[xValuesLen];
|
|
261
|
+
var yValues = Object.keys(data[xValue]);
|
|
262
|
+
var yValuesLen = yValues.length;
|
|
263
|
+
while (yValuesLen--) {
|
|
264
|
+
var yValue = yValues[yValuesLen];
|
|
265
|
+
var value = data[xValue][yValue];
|
|
266
|
+
var radius = radi[xValue][yValue];
|
|
267
|
+
renderData.push({
|
|
268
|
+
x: xValue,
|
|
269
|
+
y: yValue,
|
|
270
|
+
value: value,
|
|
271
|
+
radius: radius
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
min: min,
|
|
277
|
+
max: max,
|
|
278
|
+
data: renderData
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
function Canvas2dRenderer(config) {
|
|
282
|
+
var container = config.container;
|
|
283
|
+
var shadowCanvas = this.shadowCanvas = document.createElement("canvas");
|
|
284
|
+
var canvas = this.canvas = config.canvas || document.createElement("canvas");
|
|
285
|
+
var renderBoundaries = this._renderBoundaries = [10000, 10000, 0, 0];
|
|
286
|
+
var computed = getComputedStyle(config.container) || {};
|
|
287
|
+
canvas.className = "heatmap-canvas";
|
|
288
|
+
this._width = canvas.width = shadowCanvas.width = +computed.width.replace(/px/, "");
|
|
289
|
+
this._height = canvas.height = shadowCanvas.height = +computed.height.replace(/px/, "");
|
|
290
|
+
this.shadowCtx = shadowCanvas.getContext("2d");
|
|
291
|
+
this.ctx = canvas.getContext("2d");
|
|
292
|
+
|
|
293
|
+
// @TODO:
|
|
294
|
+
// conditional wrapper
|
|
295
|
+
|
|
296
|
+
canvas.style.cssText = shadowCanvas.style.cssText = "position:absolute;left:0;top:0;";
|
|
297
|
+
container.style.position = "relative";
|
|
298
|
+
container.appendChild(canvas);
|
|
299
|
+
this._palette = _getColorPalette(config);
|
|
300
|
+
this._templates = {};
|
|
301
|
+
this._setStyles(config);
|
|
302
|
+
}
|
|
303
|
+
Canvas2dRenderer.prototype = {
|
|
304
|
+
renderPartial: function renderPartial(data) {
|
|
305
|
+
this._drawAlpha(data);
|
|
306
|
+
this._colorize();
|
|
307
|
+
},
|
|
308
|
+
renderAll: function renderAll(data) {
|
|
309
|
+
// reset render boundaries
|
|
310
|
+
this._clear();
|
|
311
|
+
this._drawAlpha(_prepareData(data));
|
|
312
|
+
this._colorize();
|
|
313
|
+
},
|
|
314
|
+
_updateGradient: function _updateGradient(config) {
|
|
315
|
+
this._palette = _getColorPalette(config);
|
|
316
|
+
},
|
|
317
|
+
updateConfig: function updateConfig(config) {
|
|
318
|
+
if (config["gradient"]) {
|
|
319
|
+
this._updateGradient(config);
|
|
320
|
+
}
|
|
321
|
+
this._setStyles(config);
|
|
322
|
+
},
|
|
323
|
+
setDimensions: function setDimensions(width, height) {
|
|
324
|
+
this._width = width;
|
|
325
|
+
this._height = height;
|
|
326
|
+
this.canvas.width = this.shadowCanvas.width = width;
|
|
327
|
+
this.canvas.height = this.shadowCanvas.height = height;
|
|
328
|
+
},
|
|
329
|
+
_clear: function _clear() {
|
|
330
|
+
this.shadowCtx.clearRect(0, 0, this._width, this._height);
|
|
331
|
+
this.ctx.clearRect(0, 0, this._width, this._height);
|
|
332
|
+
},
|
|
333
|
+
_setStyles: function _setStyles(config) {
|
|
334
|
+
this._blur = config.blur == 0 ? 0 : config.blur || config.defaultBlur;
|
|
335
|
+
if (config.backgroundColor) {
|
|
336
|
+
this.canvas.style.backgroundColor = config.backgroundColor;
|
|
337
|
+
}
|
|
338
|
+
this._opacity = (config.opacity || 0) * 255;
|
|
339
|
+
this._maxOpacity = (config.maxOpacity || config.defaultMaxOpacity) * 255;
|
|
340
|
+
this._minOpacity = (config.minOpacity || config.defaultMinOpacity) * 255;
|
|
341
|
+
this._useGradientOpacity = !!config.useGradientOpacity;
|
|
342
|
+
},
|
|
343
|
+
_drawAlpha: function _drawAlpha(data) {
|
|
344
|
+
var min = this._min = data.min;
|
|
345
|
+
var max = this._max = data.max;
|
|
346
|
+
var data = data.data || [];
|
|
347
|
+
var dataLen = data.length;
|
|
348
|
+
// on a point basis?
|
|
349
|
+
var blur = 1 - this._blur;
|
|
350
|
+
while (dataLen--) {
|
|
351
|
+
var point = data[dataLen];
|
|
352
|
+
var x = point.x;
|
|
353
|
+
var y = point.y;
|
|
354
|
+
var radius = point.radius;
|
|
355
|
+
// if value is bigger than max
|
|
356
|
+
// use max as value
|
|
357
|
+
var value = Math.min(point.value, max);
|
|
358
|
+
var rectX = x - radius;
|
|
359
|
+
var rectY = y - radius;
|
|
360
|
+
var shadowCtx = this.shadowCtx;
|
|
361
|
+
var tpl;
|
|
362
|
+
if (!this._templates[radius]) {
|
|
363
|
+
this._templates[radius] = tpl = _getPointTemplate(radius, blur);
|
|
364
|
+
} else {
|
|
365
|
+
tpl = this._templates[radius];
|
|
366
|
+
}
|
|
367
|
+
// value from minimum / value range
|
|
368
|
+
// => [0, 1]
|
|
369
|
+
shadowCtx.globalAlpha = (value - min) / (max - min);
|
|
370
|
+
shadowCtx.drawImage(tpl, rectX, rectY);
|
|
371
|
+
|
|
372
|
+
// update renderBoundaries
|
|
373
|
+
if (rectX < this._renderBoundaries[0]) {
|
|
374
|
+
this._renderBoundaries[0] = rectX;
|
|
375
|
+
}
|
|
376
|
+
if (rectY < this._renderBoundaries[1]) {
|
|
377
|
+
this._renderBoundaries[1] = rectY;
|
|
378
|
+
}
|
|
379
|
+
if (rectX + 2 * radius > this._renderBoundaries[2]) {
|
|
380
|
+
this._renderBoundaries[2] = rectX + 2 * radius;
|
|
381
|
+
}
|
|
382
|
+
if (rectY + 2 * radius > this._renderBoundaries[3]) {
|
|
383
|
+
this._renderBoundaries[3] = rectY + 2 * radius;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
_colorize: function _colorize() {
|
|
388
|
+
var x = this._renderBoundaries[0];
|
|
389
|
+
var y = this._renderBoundaries[1];
|
|
390
|
+
var width = this._renderBoundaries[2] - x;
|
|
391
|
+
var height = this._renderBoundaries[3] - y;
|
|
392
|
+
var maxWidth = this._width;
|
|
393
|
+
var maxHeight = this._height;
|
|
394
|
+
var opacity = this._opacity;
|
|
395
|
+
var maxOpacity = this._maxOpacity;
|
|
396
|
+
var minOpacity = this._minOpacity;
|
|
397
|
+
var useGradientOpacity = this._useGradientOpacity;
|
|
398
|
+
if (x < 0) {
|
|
399
|
+
x = 0;
|
|
400
|
+
}
|
|
401
|
+
if (y < 0) {
|
|
402
|
+
y = 0;
|
|
403
|
+
}
|
|
404
|
+
if (x + width > maxWidth) {
|
|
405
|
+
width = maxWidth - x;
|
|
406
|
+
}
|
|
407
|
+
if (y + height > maxHeight) {
|
|
408
|
+
height = maxHeight - y;
|
|
409
|
+
}
|
|
410
|
+
var img = this.shadowCtx.getImageData(x, y, width, height);
|
|
411
|
+
var imgData = img.data;
|
|
412
|
+
var len = imgData.length;
|
|
413
|
+
var palette = this._palette;
|
|
414
|
+
for (var i = 3; i < len; i += 4) {
|
|
415
|
+
var alpha = imgData[i];
|
|
416
|
+
var offset = alpha * 4;
|
|
417
|
+
if (!offset) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
var finalAlpha;
|
|
421
|
+
if (opacity > 0) {
|
|
422
|
+
finalAlpha = opacity;
|
|
423
|
+
} else {
|
|
424
|
+
if (alpha < maxOpacity) {
|
|
425
|
+
if (alpha < minOpacity) {
|
|
426
|
+
finalAlpha = minOpacity;
|
|
427
|
+
} else {
|
|
428
|
+
finalAlpha = alpha;
|
|
429
|
+
}
|
|
430
|
+
} else {
|
|
431
|
+
finalAlpha = maxOpacity;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
imgData[i - 3] = palette[offset];
|
|
435
|
+
imgData[i - 2] = palette[offset + 1];
|
|
436
|
+
imgData[i - 1] = palette[offset + 2];
|
|
437
|
+
imgData[i] = useGradientOpacity ? palette[offset + 3] : finalAlpha;
|
|
438
|
+
}
|
|
439
|
+
Object.defineProperty(img, "data", {
|
|
440
|
+
value: imgData,
|
|
441
|
+
writable: true,
|
|
442
|
+
configurable: true,
|
|
443
|
+
enumerable: true
|
|
444
|
+
});
|
|
445
|
+
// img.data = imgData;
|
|
446
|
+
this.ctx.putImageData(img, x, y);
|
|
447
|
+
this._renderBoundaries = [1000, 1000, 0, 0];
|
|
448
|
+
},
|
|
449
|
+
getValueAt: function getValueAt(point) {
|
|
450
|
+
var value;
|
|
451
|
+
var shadowCtx = this.shadowCtx;
|
|
452
|
+
var img = shadowCtx.getImageData(point.x, point.y, 1, 1);
|
|
453
|
+
var data = img.data[3];
|
|
454
|
+
var max = this._max;
|
|
455
|
+
var min = this._min;
|
|
456
|
+
value = Math.abs(max - min) * (data / 255) >> 0;
|
|
457
|
+
return value;
|
|
458
|
+
},
|
|
459
|
+
getDataURL: function getDataURL() {
|
|
460
|
+
return this.canvas.toDataURL();
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
return Canvas2dRenderer;
|
|
464
|
+
}();
|
|
465
|
+
var Renderer = function RendererClosure() {
|
|
466
|
+
var rendererFn = false;
|
|
467
|
+
if (HeatmapConfig["defaultRenderer"] === "canvas2d") {
|
|
468
|
+
rendererFn = Canvas2dRenderer;
|
|
469
|
+
}
|
|
470
|
+
return rendererFn;
|
|
471
|
+
}();
|
|
472
|
+
var Util = {
|
|
473
|
+
merge: function merge() {
|
|
474
|
+
var merged = {};
|
|
475
|
+
var argsLen = arguments.length;
|
|
476
|
+
for (var i = 0; i < argsLen; i++) {
|
|
477
|
+
var obj = arguments[i];
|
|
478
|
+
for (var key in obj) {
|
|
479
|
+
merged[key] = obj[key];
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return merged;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
// Heatmap Constructor
|
|
486
|
+
var Heatmap = function HeatmapClosure() {
|
|
487
|
+
var Coordinator = function CoordinatorClosure() {
|
|
488
|
+
function Coordinator() {
|
|
489
|
+
this.cStore = {};
|
|
490
|
+
}
|
|
491
|
+
Coordinator.prototype = {
|
|
492
|
+
on: function on(evtName, callback, scope) {
|
|
493
|
+
var cStore = this.cStore;
|
|
494
|
+
if (!cStore[evtName]) {
|
|
495
|
+
cStore[evtName] = [];
|
|
496
|
+
}
|
|
497
|
+
cStore[evtName].push(function (data) {
|
|
498
|
+
return callback.call(scope, data);
|
|
499
|
+
});
|
|
500
|
+
},
|
|
501
|
+
emit: function emit(evtName, data) {
|
|
502
|
+
var cStore = this.cStore;
|
|
503
|
+
if (cStore[evtName]) {
|
|
504
|
+
var len = cStore[evtName].length;
|
|
505
|
+
for (var i = 0; i < len; i++) {
|
|
506
|
+
var callback = cStore[evtName][i];
|
|
507
|
+
callback(data);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
return Coordinator;
|
|
513
|
+
}();
|
|
514
|
+
var _connect = function _connect(scope) {
|
|
515
|
+
var renderer = scope._renderer;
|
|
516
|
+
var coordinator = scope._coordinator;
|
|
517
|
+
var store = scope._store;
|
|
518
|
+
coordinator.on("renderpartial", renderer.renderPartial, renderer);
|
|
519
|
+
coordinator.on("renderall", renderer.renderAll, renderer);
|
|
520
|
+
coordinator.on("extremachange", function (data) {
|
|
521
|
+
scope._config.onExtremaChange && scope._config.onExtremaChange({
|
|
522
|
+
min: data.min,
|
|
523
|
+
max: data.max,
|
|
524
|
+
gradient: scope._config["gradient"] || scope._config["defaultGradient"]
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
store.setCoordinator(coordinator);
|
|
528
|
+
};
|
|
529
|
+
function Heatmap() {
|
|
530
|
+
var config = this._config = Util.merge(HeatmapConfig, arguments[0] || {});
|
|
531
|
+
this._coordinator = new Coordinator();
|
|
532
|
+
if (config["plugin"]) {
|
|
533
|
+
var pluginToLoad = config["plugin"];
|
|
534
|
+
if (!HeatmapConfig.plugins[pluginToLoad]) {
|
|
535
|
+
throw new Error("Plugin '" + pluginToLoad + "' not found. Maybe it was not registered.");
|
|
536
|
+
} else {
|
|
537
|
+
var plugin = HeatmapConfig.plugins[pluginToLoad];
|
|
538
|
+
// set plugin renderer and store
|
|
539
|
+
this._renderer = new plugin.renderer(config);
|
|
540
|
+
this._store = new plugin.store(config);
|
|
541
|
+
}
|
|
542
|
+
} else {
|
|
543
|
+
this._renderer = new Renderer(config);
|
|
544
|
+
this._store = new Store(config);
|
|
545
|
+
}
|
|
546
|
+
_connect(this);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// @TODO:
|
|
550
|
+
// add API documentation
|
|
551
|
+
Heatmap.prototype = {
|
|
552
|
+
addData: function addData() {
|
|
553
|
+
this._store.addData.apply(this._store, arguments);
|
|
554
|
+
return this;
|
|
555
|
+
},
|
|
556
|
+
removeData: function removeData() {
|
|
557
|
+
this._store.removeData && this._store.removeData.apply(this._store, arguments);
|
|
558
|
+
return this;
|
|
559
|
+
},
|
|
560
|
+
setData: function setData() {
|
|
561
|
+
this._store.setData.apply(this._store, arguments);
|
|
562
|
+
return this;
|
|
563
|
+
},
|
|
564
|
+
setDataMax: function setDataMax() {
|
|
565
|
+
this._store.setDataMax.apply(this._store, arguments);
|
|
566
|
+
return this;
|
|
567
|
+
},
|
|
568
|
+
setDataMin: function setDataMin() {
|
|
569
|
+
this._store.setDataMin.apply(this._store, arguments);
|
|
570
|
+
return this;
|
|
571
|
+
},
|
|
572
|
+
configure: function configure(config) {
|
|
573
|
+
this._config = Util.merge(this._config, config);
|
|
574
|
+
this._renderer.updateConfig(this._config);
|
|
575
|
+
this._coordinator.emit("renderall", this._store._getInternalData());
|
|
576
|
+
return this;
|
|
577
|
+
},
|
|
578
|
+
repaint: function repaint() {
|
|
579
|
+
this._coordinator.emit("renderall", this._store._getInternalData());
|
|
580
|
+
return this;
|
|
581
|
+
},
|
|
582
|
+
getData: function getData() {
|
|
583
|
+
return this._store.getData();
|
|
584
|
+
},
|
|
585
|
+
getDataURL: function getDataURL() {
|
|
586
|
+
return this._renderer.getDataURL();
|
|
587
|
+
},
|
|
588
|
+
getValueAt: function getValueAt(point) {
|
|
589
|
+
if (this._store.getValueAt) {
|
|
590
|
+
return this._store.getValueAt(point);
|
|
591
|
+
} else if (this._renderer.getValueAt) {
|
|
592
|
+
return this._renderer.getValueAt(point);
|
|
593
|
+
} else {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
return Heatmap;
|
|
599
|
+
}();
|
|
600
|
+
|
|
601
|
+
// core
|
|
602
|
+
var heatmapFactory = {
|
|
603
|
+
create: function create(config) {
|
|
604
|
+
return new Heatmap(config);
|
|
605
|
+
},
|
|
606
|
+
register: function register(pluginKey, plugin) {
|
|
607
|
+
HeatmapConfig.plugins[pluginKey] = plugin;
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
var _default = heatmapFactory;
|
|
611
|
+
exports["default"] = _default;
|
|
612
|
+
//# sourceMappingURL=heatmap.js.map
|