@hpcc-js/map 2.79.1 → 2.79.3

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.
Files changed (89) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +88 -88
  3. package/TopoJSON/BR.json +122 -122
  4. package/TopoJSON/GB_idx.json +1 -1
  5. package/TopoJSON/IE_idx.json +1 -1
  6. package/TopoJSON/ND_idx.json +1 -1
  7. package/TopoJSON/countries.json +257 -257
  8. package/TopoJSON/us-counties.json +16550 -16550
  9. package/TopoJSON/us-states.json +458 -458
  10. package/dist/index.es6.js +19949 -19949
  11. package/dist/index.es6.js.map +1 -1
  12. package/dist/index.js +19947 -19947
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.min.js +2 -2
  15. package/dist/index.min.js.map +1 -1
  16. package/package.json +9 -9
  17. package/src/CanvasPinLayer.ts +99 -99
  18. package/src/CanvasPins.ts +396 -396
  19. package/src/Choropleth.css +27 -27
  20. package/src/Choropleth.ts +195 -195
  21. package/src/ChoroplethContinents.ts +13 -13
  22. package/src/ChoroplethCounties.ts +109 -109
  23. package/src/ChoroplethCountries.ts +100 -100
  24. package/src/ChoroplethStates.ts +104 -104
  25. package/src/ChoroplethStatesHeat.ts +8 -8
  26. package/src/GMap.css +16 -16
  27. package/src/GMap.ts +879 -879
  28. package/src/GMapCounties.ts +93 -93
  29. package/src/GMapGraph.ts +61 -61
  30. package/src/GMapHeat.ts +27 -27
  31. package/src/GMapLayered.ts +94 -94
  32. package/src/GMapPin.ts +115 -115
  33. package/src/GMapPinLine.ts +125 -125
  34. package/src/GeoHash.css +15 -15
  35. package/src/GeoHash.ts +125 -125
  36. package/src/Graph.css +10 -10
  37. package/src/Graph.ts +98 -98
  38. package/src/Graticule.css +13 -13
  39. package/src/Graticule.ts +90 -90
  40. package/src/Heat.css +2 -2
  41. package/src/Heat.ts +82 -82
  42. package/src/IChoropleth.ts +8 -8
  43. package/src/Layer.ts +90 -90
  44. package/src/Layered.css +19 -19
  45. package/src/Layered.ts +206 -206
  46. package/src/Lines.css +9 -9
  47. package/src/Lines.ts +75 -75
  48. package/src/OpenStreet.css +15 -15
  49. package/src/OpenStreet.ts +123 -123
  50. package/src/Pins.css +18 -18
  51. package/src/Pins.ts +319 -319
  52. package/src/Projection.ts +42 -42
  53. package/src/TestHeatMap.ts +8 -8
  54. package/src/TopoJSONChoropleth.ts +114 -114
  55. package/src/Utility.ts +482 -482
  56. package/src/__package__.ts +3 -3
  57. package/src/index.ts +34 -34
  58. package/src/leaflet/AlbersPR.ts +48 -48
  59. package/src/leaflet/Blank.ts +9 -9
  60. package/src/leaflet/Circles.ts +139 -139
  61. package/src/leaflet/ClusterCircles.css +26 -26
  62. package/src/leaflet/ClusterCircles.ts +88 -88
  63. package/src/leaflet/Countries.ts +43 -43
  64. package/src/leaflet/DrawLayer.ts +167 -167
  65. package/src/leaflet/FeatureLayer.ts +138 -138
  66. package/src/leaflet/GMap.ts +44 -44
  67. package/src/leaflet/HeatLayer.ts +77 -77
  68. package/src/leaflet/Icons.ts +60 -60
  69. package/src/leaflet/Leaflet.css +3 -3
  70. package/src/leaflet/Leaflet.ts +238 -238
  71. package/src/leaflet/MapBox.ts +35 -35
  72. package/src/leaflet/Markers.ts +109 -109
  73. package/src/leaflet/OpenStreet.ts +27 -27
  74. package/src/leaflet/Path.ts +138 -138
  75. package/src/leaflet/Pins.ts +73 -73
  76. package/src/leaflet/Polygons.ts +113 -113
  77. package/src/leaflet/Region.ts +138 -138
  78. package/src/leaflet/Text.ts +99 -99
  79. package/src/leaflet/TileLayer.ts +81 -81
  80. package/src/leaflet/TopoJSON.ts +146 -146
  81. package/src/leaflet/US.ts +15 -15
  82. package/src/leaflet/USCounties.ts +43 -43
  83. package/src/leaflet/USStates.ts +41 -41
  84. package/src/leaflet/World.css +3 -3
  85. package/src/leaflet/World.ts +171 -171
  86. package/src/leaflet/index.ts +18 -18
  87. package/src/test.ts +114 -114
  88. package/types/__package__.d.ts +2 -2
  89. package/types-3.4/__package__.d.ts +2 -2
@@ -1,109 +1,109 @@
1
- import { InputField } from "@hpcc-js/common";
2
- import { json as d3Json } from "d3-request";
3
- import { select as d3Select } from "d3-selection";
4
- import * as topojson from "topojson-client";
5
- import { Choropleth, topoJsonFolder } from "./Choropleth";
6
-
7
- let usCounties = null;
8
- let features = null;
9
- let rFeatures = null;
10
-
11
- export class ChoroplethCounties extends Choropleth {
12
- static __inputs: InputField[] = [{
13
- id: "fips",
14
- type: "string"
15
- }, {
16
- id: "value",
17
- type: "number"
18
- }];
19
-
20
- _selection;
21
- choroPaths;
22
-
23
- constructor() {
24
- super();
25
-
26
- this.projection("AlbersUsaPr");
27
- }
28
-
29
- layerEnter(base, svgElement, domElement) {
30
- Choropleth.prototype.layerEnter.apply(this, arguments);
31
- this._choroTopology = usCounties.topology;
32
- this._choroTopologyObjects = usCounties.topology.objects.counties;
33
-
34
- this._selection.widgetElement(this._choroplethData);
35
- this.choroPaths = d3Select(null);
36
- const context = this;
37
- this
38
- .tooltipHTML(function (d) {
39
- const code = d[0];
40
- return context.tooltipFormat({ label: usCounties.countyNames[code], value: context._dataMap[code] ? context._dataMap[code][1] : "N/A" });
41
- })
42
- ;
43
- }
44
-
45
- layerUpdate(base) {
46
- Choropleth.prototype.layerUpdate.apply(this, arguments);
47
-
48
- this._choroplethData
49
- .style("stroke", this.meshVisible() ? null : "black")
50
- ;
51
-
52
- this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
53
- const context = this;
54
- this.choroPaths.enter().append("path")
55
- .attr("class", "shape")
56
- .attr("vector-effect", "non-scaling-stroke")
57
- .call(this._selection.enter.bind(this._selection))
58
- .on("click", function (d) {
59
- context.click(context.rowToObj(d), "weight", context._selection.selected(this));
60
- })
61
- .on("dblclick", function (d) {
62
- context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
63
- })
64
- .on("mouseout.tooltip", this.tooltip.hide)
65
- .on("mousemove.tooltip", this.tooltip.show)
66
- .merge(this.choroPaths)
67
- .attr("d", function (d) {
68
- const retVal = base._d3GeoPath(rFeatures[d[0]]);
69
- if (!retVal) {
70
- console.warn("Unknown US County: " + d[0]);
71
- }
72
- return retVal;
73
- })
74
- .style("fill", function (d) {
75
- const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
76
- return retVal;
77
- })
78
- ;
79
- this.choroPaths.exit().remove();
80
- }
81
-
82
- layerPreRender() {
83
- if (!this._topoJsonPromise) {
84
- this._topoJsonPromise = new Promise<void>((resolve, reject) => {
85
- if (usCounties) {
86
- resolve();
87
- }
88
- d3Json(`${topoJsonFolder()}/us-counties.json`, function (_usCounties) {
89
- usCounties = _usCounties;
90
- features = topojson.feature(usCounties.topology, usCounties.topology.objects.counties).features;
91
- rFeatures = {};
92
- for (const key in features) {
93
- if (features[key].id) {
94
- rFeatures[features[key].id] = features[key];
95
- }
96
- }
97
- resolve();
98
- });
99
- });
100
- }
101
- return this._topoJsonPromise;
102
- }
103
-
104
- onClickFormatFIPS: { (): boolean; (_: boolean): ChoroplethCounties };
105
- onClickFormatFIPS_exists: () => boolean;
106
- }
107
- ChoroplethCounties.prototype._class += " map_ChoroplethCounties";
108
-
109
- ChoroplethCounties.prototype.publish("onClickFormatFIPS", false, "boolean", "format FIPS code as a String on Click");
1
+ import { InputField } from "@hpcc-js/common";
2
+ import { json as d3Json } from "d3-request";
3
+ import { select as d3Select } from "d3-selection";
4
+ import * as topojson from "topojson-client";
5
+ import { Choropleth, topoJsonFolder } from "./Choropleth";
6
+
7
+ let usCounties = null;
8
+ let features = null;
9
+ let rFeatures = null;
10
+
11
+ export class ChoroplethCounties extends Choropleth {
12
+ static __inputs: InputField[] = [{
13
+ id: "fips",
14
+ type: "string"
15
+ }, {
16
+ id: "value",
17
+ type: "number"
18
+ }];
19
+
20
+ _selection;
21
+ choroPaths;
22
+
23
+ constructor() {
24
+ super();
25
+
26
+ this.projection("AlbersUsaPr");
27
+ }
28
+
29
+ layerEnter(base, svgElement, domElement) {
30
+ Choropleth.prototype.layerEnter.apply(this, arguments);
31
+ this._choroTopology = usCounties.topology;
32
+ this._choroTopologyObjects = usCounties.topology.objects.counties;
33
+
34
+ this._selection.widgetElement(this._choroplethData);
35
+ this.choroPaths = d3Select(null);
36
+ const context = this;
37
+ this
38
+ .tooltipHTML(function (d) {
39
+ const code = d[0];
40
+ return context.tooltipFormat({ label: usCounties.countyNames[code], value: context._dataMap[code] ? context._dataMap[code][1] : "N/A" });
41
+ })
42
+ ;
43
+ }
44
+
45
+ layerUpdate(base) {
46
+ Choropleth.prototype.layerUpdate.apply(this, arguments);
47
+
48
+ this._choroplethData
49
+ .style("stroke", this.meshVisible() ? null : "black")
50
+ ;
51
+
52
+ this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
53
+ const context = this;
54
+ this.choroPaths.enter().append("path")
55
+ .attr("class", "shape")
56
+ .attr("vector-effect", "non-scaling-stroke")
57
+ .call(this._selection.enter.bind(this._selection))
58
+ .on("click", function (d) {
59
+ context.click(context.rowToObj(d), "weight", context._selection.selected(this));
60
+ })
61
+ .on("dblclick", function (d) {
62
+ context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
63
+ })
64
+ .on("mouseout.tooltip", this.tooltip.hide)
65
+ .on("mousemove.tooltip", this.tooltip.show)
66
+ .merge(this.choroPaths)
67
+ .attr("d", function (d) {
68
+ const retVal = base._d3GeoPath(rFeatures[d[0]]);
69
+ if (!retVal) {
70
+ console.warn("Unknown US County: " + d[0]);
71
+ }
72
+ return retVal;
73
+ })
74
+ .style("fill", function (d) {
75
+ const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
76
+ return retVal;
77
+ })
78
+ ;
79
+ this.choroPaths.exit().remove();
80
+ }
81
+
82
+ layerPreRender() {
83
+ if (!this._topoJsonPromise) {
84
+ this._topoJsonPromise = new Promise<void>((resolve, reject) => {
85
+ if (usCounties) {
86
+ resolve();
87
+ }
88
+ d3Json(`${topoJsonFolder()}/us-counties.json`, function (_usCounties) {
89
+ usCounties = _usCounties;
90
+ features = topojson.feature(usCounties.topology, usCounties.topology.objects.counties).features;
91
+ rFeatures = {};
92
+ for (const key in features) {
93
+ if (features[key].id) {
94
+ rFeatures[features[key].id] = features[key];
95
+ }
96
+ }
97
+ resolve();
98
+ });
99
+ });
100
+ }
101
+ return this._topoJsonPromise;
102
+ }
103
+
104
+ onClickFormatFIPS: { (): boolean; (_: boolean): ChoroplethCounties };
105
+ onClickFormatFIPS_exists: () => boolean;
106
+ }
107
+ ChoroplethCounties.prototype._class += " map_ChoroplethCounties";
108
+
109
+ ChoroplethCounties.prototype.publish("onClickFormatFIPS", false, "boolean", "format FIPS code as a String on Click");
@@ -1,100 +1,100 @@
1
- import { json as d3Json } from "d3-request";
2
- import { select as d3Select } from "d3-selection";
3
- import * as topojson from "topojson-client";
4
- import { Choropleth, topoJsonFolder } from "./Choropleth";
5
-
6
- let countries = null;
7
- let features = null;
8
- let rFeatures = null;
9
-
10
- export class ChoroplethCountries extends Choropleth {
11
- _choroTopologyObjectsCountries;
12
- _choroTopologyObjectsLand;
13
- _selection;
14
- choroPaths;
15
-
16
- constructor() {
17
- super();
18
- }
19
-
20
- layerEnter(base, svgElement, domElement) {
21
- Choropleth.prototype.layerEnter.apply(this, arguments);
22
- this._choroTopology = countries.topology;
23
- this._choroTopologyObjectsCountries = countries.topology.objects.countries;
24
- this._choroTopologyObjectsLand = countries.topology.objects.land;
25
- this._choroTopologyObjects = this._choroTopologyObjectsCountries;
26
-
27
- this._selection.widgetElement(this._choroplethData);
28
- this.choroPaths = d3Select(null);
29
- const context = this;
30
- this
31
- .tooltipHTML(function (d) {
32
- return context.tooltipFormat({ label: d[0], value: d[1] });
33
- })
34
- ;
35
- }
36
-
37
- layerUpdate(base) {
38
- Choropleth.prototype.layerUpdate.apply(this, arguments);
39
-
40
- this._choroplethData
41
- .style("stroke", this.meshVisible() ? null : "black")
42
- ;
43
-
44
- this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
45
- const context = this;
46
- this.choroPaths.enter().append("path")
47
- .attr("class", "shape")
48
- .attr("vector-effect", "non-scaling-stroke")
49
- .call(this._selection.enter.bind(this._selection))
50
- .on("click", function (d) {
51
- if (context._dataMap[d[0]]) {
52
- context.click(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
53
- }
54
- })
55
- .on("dblclick", function (d) {
56
- if (context._dataMap[d[0]]) {
57
- context.dblclick(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
58
- }
59
- })
60
- .on("mouseout.tooltip", this.tooltip.hide)
61
- .on("mousemove.tooltip", this.tooltip.show)
62
- .merge(this.choroPaths)
63
- .attr("d", function (d) {
64
- const retVal = base._d3GeoPath(rFeatures[d[0]]);
65
- if (!retVal) {
66
- console.warn("Unknown Country: " + d);
67
- }
68
- return retVal;
69
- })
70
- .style("fill", function (d) {
71
- const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
72
- return retVal;
73
- })
74
- ;
75
- this.choroPaths.exit().remove();
76
- }
77
-
78
- layerPreRender() {
79
- if (!this._topoJsonPromise) {
80
- this._topoJsonPromise = new Promise<void>((resolve, reject) => {
81
- if (countries) {
82
- resolve();
83
- }
84
- d3Json(`${topoJsonFolder()}/countries.json`, function (_countries) {
85
- countries = _countries;
86
- features = topojson.feature(countries.topology, countries.topology.objects.countries).features;
87
- rFeatures = {};
88
- for (const key in features) {
89
- if (features[key].id && countries.countryNames[features[key].id]) {
90
- rFeatures[countries.countryNames[features[key].id].name] = features[key];
91
- }
92
- }
93
- resolve();
94
- });
95
- });
96
- }
97
- return this._topoJsonPromise;
98
- }
99
- }
100
- ChoroplethCountries.prototype._class += " map_ChoroplethCountries";
1
+ import { json as d3Json } from "d3-request";
2
+ import { select as d3Select } from "d3-selection";
3
+ import * as topojson from "topojson-client";
4
+ import { Choropleth, topoJsonFolder } from "./Choropleth";
5
+
6
+ let countries = null;
7
+ let features = null;
8
+ let rFeatures = null;
9
+
10
+ export class ChoroplethCountries extends Choropleth {
11
+ _choroTopologyObjectsCountries;
12
+ _choroTopologyObjectsLand;
13
+ _selection;
14
+ choroPaths;
15
+
16
+ constructor() {
17
+ super();
18
+ }
19
+
20
+ layerEnter(base, svgElement, domElement) {
21
+ Choropleth.prototype.layerEnter.apply(this, arguments);
22
+ this._choroTopology = countries.topology;
23
+ this._choroTopologyObjectsCountries = countries.topology.objects.countries;
24
+ this._choroTopologyObjectsLand = countries.topology.objects.land;
25
+ this._choroTopologyObjects = this._choroTopologyObjectsCountries;
26
+
27
+ this._selection.widgetElement(this._choroplethData);
28
+ this.choroPaths = d3Select(null);
29
+ const context = this;
30
+ this
31
+ .tooltipHTML(function (d) {
32
+ return context.tooltipFormat({ label: d[0], value: d[1] });
33
+ })
34
+ ;
35
+ }
36
+
37
+ layerUpdate(base) {
38
+ Choropleth.prototype.layerUpdate.apply(this, arguments);
39
+
40
+ this._choroplethData
41
+ .style("stroke", this.meshVisible() ? null : "black")
42
+ ;
43
+
44
+ this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
45
+ const context = this;
46
+ this.choroPaths.enter().append("path")
47
+ .attr("class", "shape")
48
+ .attr("vector-effect", "non-scaling-stroke")
49
+ .call(this._selection.enter.bind(this._selection))
50
+ .on("click", function (d) {
51
+ if (context._dataMap[d[0]]) {
52
+ context.click(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
53
+ }
54
+ })
55
+ .on("dblclick", function (d) {
56
+ if (context._dataMap[d[0]]) {
57
+ context.dblclick(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
58
+ }
59
+ })
60
+ .on("mouseout.tooltip", this.tooltip.hide)
61
+ .on("mousemove.tooltip", this.tooltip.show)
62
+ .merge(this.choroPaths)
63
+ .attr("d", function (d) {
64
+ const retVal = base._d3GeoPath(rFeatures[d[0]]);
65
+ if (!retVal) {
66
+ console.warn("Unknown Country: " + d);
67
+ }
68
+ return retVal;
69
+ })
70
+ .style("fill", function (d) {
71
+ const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
72
+ return retVal;
73
+ })
74
+ ;
75
+ this.choroPaths.exit().remove();
76
+ }
77
+
78
+ layerPreRender() {
79
+ if (!this._topoJsonPromise) {
80
+ this._topoJsonPromise = new Promise<void>((resolve, reject) => {
81
+ if (countries) {
82
+ resolve();
83
+ }
84
+ d3Json(`${topoJsonFolder()}/countries.json`, function (_countries) {
85
+ countries = _countries;
86
+ features = topojson.feature(countries.topology, countries.topology.objects.countries).features;
87
+ rFeatures = {};
88
+ for (const key in features) {
89
+ if (features[key].id && countries.countryNames[features[key].id]) {
90
+ rFeatures[countries.countryNames[features[key].id].name] = features[key];
91
+ }
92
+ }
93
+ resolve();
94
+ });
95
+ });
96
+ }
97
+ return this._topoJsonPromise;
98
+ }
99
+ }
100
+ ChoroplethCountries.prototype._class += " map_ChoroplethCountries";
@@ -1,104 +1,104 @@
1
- import { InputField } from "@hpcc-js/common";
2
- import { json as d3Json } from "d3-request";
3
- import { select as d3Select } from "d3-selection";
4
- import * as topojson from "topojson-client";
5
- import { Choropleth, topoJsonFolder } from "./Choropleth";
6
-
7
- let usStates = null;
8
- let features = null;
9
- let rFeatures = null;
10
-
11
- export class ChoroplethStates extends Choropleth {
12
- static __inputs: InputField[] = [{
13
- id: "state",
14
- type: "string"
15
- }, {
16
- id: "value",
17
- type: "number"
18
- }];
19
-
20
- _selection;
21
- choroPaths;
22
-
23
- constructor() {
24
- super();
25
-
26
- this.projection("AlbersUsaPr");
27
- }
28
-
29
- layerEnter(base, svgElement, domElement) {
30
- Choropleth.prototype.layerEnter.apply(this, arguments);
31
- this._choroTopology = usStates.topology;
32
- this._choroTopologyObjects = usStates.topology.objects.states;
33
-
34
- this._selection.widgetElement(this._choroplethData);
35
- this.choroPaths = d3Select(null);
36
- const context = this;
37
- this
38
- .tooltipHTML(function (d) {
39
- const code = rFeatures[d[0]].id;
40
- return context.tooltipFormat({ label: usStates.stateNames[code].name, value: d[1] });
41
- })
42
- ;
43
- }
44
-
45
- layerUpdate(base) {
46
- Choropleth.prototype.layerUpdate.apply(this, arguments);
47
-
48
- this._choroplethData
49
- .style("stroke", this.meshVisible() ? null : "black")
50
- ;
51
-
52
- this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
53
- const context = this;
54
- this.choroPaths.enter().append("path")
55
- .attr("class", "shape")
56
- .attr("vector-effect", "non-scaling-stroke")
57
- .call(this._selection.enter.bind(this._selection))
58
- .on("click", function (d) {
59
- context.click(context.rowToObj(d), "weight", context._selection.selected(this));
60
- })
61
- .on("dblclick", function (d) {
62
- context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
63
- })
64
- .on("mouseout.tooltip", this.tooltip.hide)
65
- .on("mousemove.tooltip", this.tooltip.show)
66
- .merge(this.choroPaths)
67
- .attr("d", function (d) {
68
- const retVal = base._d3GeoPath(rFeatures[d[0]]);
69
- if (!retVal) {
70
- console.warn("Unknown US State: " + d[0]);
71
- }
72
- return retVal;
73
- })
74
- .style("fill", function (d) {
75
- const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
76
- return retVal;
77
- })
78
- ;
79
- this.choroPaths.exit().remove();
80
- }
81
-
82
- layerPreRender() {
83
- if (!this._topoJsonPromise) {
84
- this._topoJsonPromise = new Promise<void>((resolve, reject) => {
85
- if (usStates) {
86
- resolve();
87
- }
88
- d3Json(`${topoJsonFolder()}/us-states.json`, function (_usStates) {
89
- usStates = _usStates;
90
- features = topojson.feature(usStates.topology, usStates.topology.objects.states).features;
91
- rFeatures = {};
92
- for (const key in features) {
93
- if (features[key].id) {
94
- rFeatures[usStates.stateNames[features[key].id].code] = features[key];
95
- }
96
- }
97
- resolve();
98
- });
99
- });
100
- }
101
- return this._topoJsonPromise;
102
- }
103
- }
104
- ChoroplethStates.prototype._class += " map_ChoroplethStates";
1
+ import { InputField } from "@hpcc-js/common";
2
+ import { json as d3Json } from "d3-request";
3
+ import { select as d3Select } from "d3-selection";
4
+ import * as topojson from "topojson-client";
5
+ import { Choropleth, topoJsonFolder } from "./Choropleth";
6
+
7
+ let usStates = null;
8
+ let features = null;
9
+ let rFeatures = null;
10
+
11
+ export class ChoroplethStates extends Choropleth {
12
+ static __inputs: InputField[] = [{
13
+ id: "state",
14
+ type: "string"
15
+ }, {
16
+ id: "value",
17
+ type: "number"
18
+ }];
19
+
20
+ _selection;
21
+ choroPaths;
22
+
23
+ constructor() {
24
+ super();
25
+
26
+ this.projection("AlbersUsaPr");
27
+ }
28
+
29
+ layerEnter(base, svgElement, domElement) {
30
+ Choropleth.prototype.layerEnter.apply(this, arguments);
31
+ this._choroTopology = usStates.topology;
32
+ this._choroTopologyObjects = usStates.topology.objects.states;
33
+
34
+ this._selection.widgetElement(this._choroplethData);
35
+ this.choroPaths = d3Select(null);
36
+ const context = this;
37
+ this
38
+ .tooltipHTML(function (d) {
39
+ const code = rFeatures[d[0]].id;
40
+ return context.tooltipFormat({ label: usStates.stateNames[code].name, value: d[1] });
41
+ })
42
+ ;
43
+ }
44
+
45
+ layerUpdate(base) {
46
+ Choropleth.prototype.layerUpdate.apply(this, arguments);
47
+
48
+ this._choroplethData
49
+ .style("stroke", this.meshVisible() ? null : "black")
50
+ ;
51
+
52
+ this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
53
+ const context = this;
54
+ this.choroPaths.enter().append("path")
55
+ .attr("class", "shape")
56
+ .attr("vector-effect", "non-scaling-stroke")
57
+ .call(this._selection.enter.bind(this._selection))
58
+ .on("click", function (d) {
59
+ context.click(context.rowToObj(d), "weight", context._selection.selected(this));
60
+ })
61
+ .on("dblclick", function (d) {
62
+ context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
63
+ })
64
+ .on("mouseout.tooltip", this.tooltip.hide)
65
+ .on("mousemove.tooltip", this.tooltip.show)
66
+ .merge(this.choroPaths)
67
+ .attr("d", function (d) {
68
+ const retVal = base._d3GeoPath(rFeatures[d[0]]);
69
+ if (!retVal) {
70
+ console.warn("Unknown US State: " + d[0]);
71
+ }
72
+ return retVal;
73
+ })
74
+ .style("fill", function (d) {
75
+ const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
76
+ return retVal;
77
+ })
78
+ ;
79
+ this.choroPaths.exit().remove();
80
+ }
81
+
82
+ layerPreRender() {
83
+ if (!this._topoJsonPromise) {
84
+ this._topoJsonPromise = new Promise<void>((resolve, reject) => {
85
+ if (usStates) {
86
+ resolve();
87
+ }
88
+ d3Json(`${topoJsonFolder()}/us-states.json`, function (_usStates) {
89
+ usStates = _usStates;
90
+ features = topojson.feature(usStates.topology, usStates.topology.objects.states).features;
91
+ rFeatures = {};
92
+ for (const key in features) {
93
+ if (features[key].id) {
94
+ rFeatures[usStates.stateNames[features[key].id].code] = features[key];
95
+ }
96
+ }
97
+ resolve();
98
+ });
99
+ });
100
+ }
101
+ return this._topoJsonPromise;
102
+ }
103
+ }
104
+ ChoroplethStates.prototype._class += " map_ChoroplethStates";
@@ -1,8 +1,8 @@
1
- import { Layered } from "./Layered";
2
-
3
- export class ChoroplethStatesHeat extends Layered {
4
- constructor() {
5
- super();
6
- }
7
- }
8
- ChoroplethStatesHeat.prototype._class += " map_ChoroplethStatesHeat";
1
+ import { Layered } from "./Layered";
2
+
3
+ export class ChoroplethStatesHeat extends Layered {
4
+ constructor() {
5
+ super();
6
+ }
7
+ }
8
+ ChoroplethStatesHeat.prototype._class += " map_ChoroplethStatesHeat";