@lgv/heatmap 0.0.3 → 0.0.5
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 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lgv/heatmap",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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.4",
|
|
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
|
/**
|
|
@@ -85,7 +64,7 @@ class Heatmap extends VisualizationMap {
|
|
|
85
64
|
|
|
86
65
|
// generate vega specification
|
|
87
66
|
let spec = this.generateSpecification();
|
|
88
|
-
|
|
67
|
+
|
|
89
68
|
// render vega with deck.gl
|
|
90
69
|
let view = new VegaDeckGl.ViewGl(vega.parse(spec))
|
|
91
70
|
.renderer("deck.gl")
|
|
@@ -135,7 +114,7 @@ class Heatmap extends VisualizationMap {
|
|
|
135
114
|
scales: [
|
|
136
115
|
{
|
|
137
116
|
name: "color",
|
|
138
|
-
type: "
|
|
117
|
+
type: "quantize",
|
|
139
118
|
domain: { data: this.name, field: "count" },
|
|
140
119
|
range: { scheme: this.name, count: this.color.length }
|
|
141
120
|
}
|
|
@@ -149,7 +128,7 @@ class Heatmap extends VisualizationMap {
|
|
|
149
128
|
shape: { value: "square" },
|
|
150
129
|
x: { field: "x" },
|
|
151
130
|
y: { field: "y" },
|
|
152
|
-
size: { value: this.mark },
|
|
131
|
+
size: { value: this.mark(this.map.getZoom()) },
|
|
153
132
|
fill: { scale: "color", field: "count" },
|
|
154
133
|
opacity: { value: 1 }
|
|
155
134
|
},
|
|
@@ -158,7 +137,7 @@ class Heatmap extends VisualizationMap {
|
|
|
158
137
|
]
|
|
159
138
|
}
|
|
160
139
|
|
|
161
|
-
}
|
|
140
|
+
}
|
|
162
141
|
|
|
163
142
|
}
|
|
164
143
|
|