@lgv/heatmap 0.0.3 → 0.0.4
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/package.json +3 -2
- package/src/visualization/index.js +12 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lgv/heatmap",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ES6 heatmap visualization for leaflet using vega/d3.js.",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -46,9 +46,10 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@deck.gl/core": "^9.0.34",
|
|
48
48
|
"@deck.gl/layers": "^9.0.34",
|
|
49
|
-
"@lgv/visualization-map": "^1.0.
|
|
49
|
+
"@lgv/visualization-map": "^1.0.3",
|
|
50
50
|
"@luma.gl/core": "^9.0.27",
|
|
51
51
|
"@msrvida/vega-deck.gl": "^3.3.6",
|
|
52
|
+
"d3-scale": "^4.0.2",
|
|
52
53
|
"leaflet": "^1.9.4",
|
|
53
54
|
"vega": "^5.30.0"
|
|
54
55
|
},
|
|
@@ -6,6 +6,8 @@ import * as vega from "vega";
|
|
|
6
6
|
import * as VegaDeckGl from "@msrvida/vega-deck.gl";
|
|
7
7
|
|
|
8
8
|
import { VisualizationMap } from "@lgv/visualization-map";
|
|
9
|
+
import { scaleOrdinal } from "d3-scale";
|
|
10
|
+
|
|
9
11
|
import { HeatLayout as HL } from "../layout/index.js";
|
|
10
12
|
|
|
11
13
|
import { configuration, configurationColor, configurationLayout } from "../configuration.js";
|
|
@@ -33,49 +35,26 @@ class Heatmap extends VisualizationMap {
|
|
|
33
35
|
// update self
|
|
34
36
|
this.color = color;
|
|
35
37
|
this.imageOverlay = null;
|
|
38
|
+
this.zoom = 5;
|
|
36
39
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
43
|
* Determine if data is array of objects with xy precomputed.
|
|
44
|
+
* @returns A boolean if TRUE data is already in xy format vs. geojson features.
|
|
41
45
|
*/
|
|
42
46
|
get isXY() {
|
|
43
47
|
return this.data && this.data.length > 0 && Object.keys(this.data[0]).some(k => ["count","x","y"].includes(k));
|
|
44
48
|
}
|
|
45
|
-
|
|
49
|
+
|
|
46
50
|
/**
|
|
47
51
|
* Generate mark size.
|
|
48
52
|
* @returns An integer representing the render size of a visual mark.
|
|
49
53
|
*/
|
|
50
54
|
get mark() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// set starting size
|
|
55
|
-
let base = isHighDensityDisplay ? this.unit * 1.75 : this.unit * 2;
|
|
56
|
-
let mark = base;
|
|
57
|
-
|
|
58
|
-
// determine mark size
|
|
59
|
-
switch (true) {
|
|
60
|
-
case (this.zoom >= 16):
|
|
61
|
-
mark = base - 1;
|
|
62
|
-
break;
|
|
63
|
-
case (this.zoom >= 14):
|
|
64
|
-
mark = base - 2;
|
|
65
|
-
break;
|
|
66
|
-
case (this.zoom >= 12):
|
|
67
|
-
mark = base - 3;
|
|
68
|
-
break;
|
|
69
|
-
case (this.zoom >= 8):
|
|
70
|
-
mark = base - 4;
|
|
71
|
-
break;
|
|
72
|
-
case (this.zoom >= 0):
|
|
73
|
-
mark = base - 5;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return mark;
|
|
78
|
-
|
|
55
|
+
return scaleOrdinal()
|
|
56
|
+
.domain([...Array(19).keys()])
|
|
57
|
+
.range([0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.6,0.6,0.6,0.6,0.7,0.7,0.8,0.8,1,1,1].map(d => d * this.unit));
|
|
79
58
|
}
|
|
80
59
|
|
|
81
60
|
/**
|
|
@@ -125,6 +104,8 @@ class Heatmap extends VisualizationMap {
|
|
|
125
104
|
*/
|
|
126
105
|
generateSpecification() {
|
|
127
106
|
|
|
107
|
+
let mark = this.mark(this.map.getZoom());
|
|
108
|
+
|
|
128
109
|
// register custom scheme
|
|
129
110
|
vega.scheme(this.name, this.color);
|
|
130
111
|
|
|
@@ -149,7 +130,7 @@ class Heatmap extends VisualizationMap {
|
|
|
149
130
|
shape: { value: "square" },
|
|
150
131
|
x: { field: "x" },
|
|
151
132
|
y: { field: "y" },
|
|
152
|
-
size: { value:
|
|
133
|
+
size: { value: mark },
|
|
153
134
|
fill: { scale: "color", field: "count" },
|
|
154
135
|
opacity: { value: 1 }
|
|
155
136
|
},
|
|
@@ -158,7 +139,7 @@ class Heatmap extends VisualizationMap {
|
|
|
158
139
|
]
|
|
159
140
|
}
|
|
160
141
|
|
|
161
|
-
}
|
|
142
|
+
}
|
|
162
143
|
|
|
163
144
|
}
|
|
164
145
|
|