@cdc/map 2.6.3 → 2.6.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.
Files changed (46) hide show
  1. package/dist/cdcmap.js +26 -18
  2. package/examples/bubble-us.json +363 -0
  3. package/examples/bubble-world.json +427 -0
  4. package/examples/default-hex.json +475 -0
  5. package/examples/default-usa-regions.json +118 -0
  6. package/examples/default-usa.json +1 -1
  7. package/examples/default-world-data.json +1450 -0
  8. package/examples/default-world.json +5 -3
  9. package/examples/example-city-state.json +36 -0
  10. package/examples/private/atsdr.json +439 -0
  11. package/examples/private/atsdr_new.json +436 -0
  12. package/examples/private/bubble.json +285 -0
  13. package/examples/private/default-world-data.json +1444 -0
  14. package/examples/private/default.json +968 -0
  15. package/examples/private/map.csv +60 -0
  16. package/examples/private/mdx.json +210 -0
  17. package/examples/private/regions.json +52 -0
  18. package/examples/private/wcmsrd-13881-data.json +2858 -0
  19. package/examples/private/wcmsrd-13881.json +5823 -0
  20. package/examples/private/wcmsrd-test.json +268 -0
  21. package/examples/private/world.json +1580 -0
  22. package/examples/private/worldmap.json +1490 -0
  23. package/package.json +51 -50
  24. package/src/CdcMap.js +340 -79
  25. package/src/components/BubbleList.js +240 -0
  26. package/src/components/CityList.js +19 -1
  27. package/src/components/CountyMap.js +3 -2
  28. package/src/components/DataTable.js +17 -10
  29. package/src/components/EditorPanel.js +741 -348
  30. package/src/components/Geo.js +1 -1
  31. package/src/components/SingleStateMap.js +1 -1
  32. package/src/components/UsaMap.js +22 -7
  33. package/src/components/UsaRegionMap.js +319 -0
  34. package/src/components/WorldMap.js +112 -35
  35. package/src/data/country-coordinates.js +250 -0
  36. package/src/data/initial-state.js +19 -2
  37. package/src/data/state-coordinates.js +55 -0
  38. package/src/data/supported-geos.js +91 -15
  39. package/src/data/us-regions-topo-2.json +360525 -0
  40. package/src/data/us-regions-topo.json +37894 -0
  41. package/src/hooks/useColorPalette.ts +96 -0
  42. package/src/index.html +10 -2
  43. package/src/scss/editor-panel.scss +76 -55
  44. package/src/scss/map.scss +108 -2
  45. package/src/data/color-palettes.js +0 -200
  46. package/src/images/map-folded.svg +0 -1
@@ -0,0 +1,240 @@
1
+ import React, {memo, useState, useEffect} from 'react'
2
+ import { scaleLinear } from 'd3-scale';
3
+ import { countryCoordinates } from '../data/country-coordinates';
4
+ import stateCoordinates from '../data/state-coordinates';
5
+
6
+ export const BubbleList = (
7
+ {
8
+ data: dataImport,
9
+ state,
10
+ projection,
11
+ applyLegendToRow,
12
+ applyTooltipsToGeo,
13
+ handleCircleClick,
14
+ runtimeData,
15
+ displayGeoName
16
+ }) => {
17
+
18
+
19
+ const maxDataValue = Math.max(...dataImport.map(d => d[state.columns.primary.name]))
20
+ const hasBubblesWithZeroOnMap = state.visual.showBubbleZeros ? 0 : 1;
21
+ // sort runtime data. Smaller bubbles should appear on top.
22
+ const sortedRuntimeData = Object.values(runtimeData).sort((a, b) => a[state.columns.primary.name] < b[state.columns.primary.name] ? 1 : -1 )
23
+ if(!sortedRuntimeData) return;
24
+
25
+ const clickTolerance = 10;
26
+
27
+ // Set bubble sizes
28
+ var size = scaleLinear()
29
+ .domain([hasBubblesWithZeroOnMap, maxDataValue])
30
+ .range([state.visual.minBubbleSize, state.visual.maxBubbleSize])
31
+
32
+ // Start looping through the countries to create the bubbles.
33
+ if(state.general.geoType === 'world') {
34
+ const countries = sortedRuntimeData && sortedRuntimeData.map( (country, index) => {
35
+
36
+ let coordinates = countryCoordinates[country.uid]
37
+
38
+ if(!coordinates) return true;
39
+
40
+ const countryName = displayGeoName(country[state.columns.geo.name]);
41
+ const toolTip = applyTooltipsToGeo(countryName, country);
42
+ const legendColors = applyLegendToRow(country);
43
+
44
+ let primaryKey = state.columns.primary.name
45
+ if ((Math.floor(Number(size(country[primaryKey]))) === 0 || country[primaryKey] === "") && !state.visual.showBubbleZeros) return;
46
+
47
+ let transform = `translate(${projection([coordinates[1], coordinates[0]])})`
48
+
49
+ let pointerX, pointerY;
50
+
51
+ if( !projection(coordinates) ) return true;
52
+
53
+ const circle = (
54
+ <>
55
+ <circle
56
+ key={`circle-${countryName.replace(' ', '')}`}
57
+ data-tip={toolTip}
58
+ data-for="tooltip"
59
+ className="bubble"
60
+ cx={ Number(projection(coordinates[1], coordinates[0])[0]) || 0 } // || 0 handles error on loads where the data isn't ready
61
+ cy={ Number(projection(coordinates[1], coordinates[0])[1]) || 0 }
62
+ r={ Number(size(country[primaryKey])) }
63
+ fill={legendColors[0] }
64
+ stroke={legendColors[0]}
65
+ strokeWidth={1.25}
66
+ fillOpacity={.4}
67
+ onPointerDown={(e) => {
68
+ pointerX = e.clientX;
69
+ pointerY = e.clientY;
70
+ }}
71
+ onPointerUp={(e) => {
72
+ if(pointerX && pointerY &&
73
+ e.clientX > (pointerX - clickTolerance) &&
74
+ e.clientX < (pointerX + clickTolerance) &&
75
+ e.clientY > (pointerY - clickTolerance) &&
76
+ e.clientY < (pointerY + clickTolerance)
77
+ ){
78
+ handleCircleClick(country)
79
+ pointerX = undefined;
80
+ pointerY = undefined;
81
+ }
82
+ }}
83
+ transform={transform}
84
+ style={{ transition: 'all .25s ease-in-out', cursor: "pointer" }}
85
+ />
86
+
87
+ {state.visual.extraBubbleBorder &&
88
+ <circle
89
+ key={`circle-${countryName.replace(' ', '')}`}
90
+ data-tip={toolTip}
91
+ data-for="tooltip"
92
+ className="bubble"
93
+ cx={ Number(projection(coordinates[1], coordinates[0])[0]) || 0 } // || 0 handles error on loads where the data isn't ready
94
+ cy={ Number(projection(coordinates[1], coordinates[0])[1]) || 0 }
95
+ r={ Number(size(country[primaryKey])) + 1 }
96
+ fill={ "transparent" }
97
+ stroke={ "white" }
98
+ strokeWidth={.5}
99
+ onPointerDown={(e) => {
100
+ pointerX = e.clientX;
101
+ pointerY = e.clientY;
102
+ }}
103
+ onPointerUp={(e) => {
104
+ if(pointerX && pointerY &&
105
+ e.clientX > (pointerX - clickTolerance) &&
106
+ e.clientX < (pointerX + clickTolerance) &&
107
+ e.clientY > (pointerY - clickTolerance) &&
108
+ e.clientY < (pointerY + clickTolerance)
109
+ ){
110
+ handleCircleClick(country)
111
+ pointerX = undefined;
112
+ pointerY = undefined;
113
+ }
114
+ }}
115
+ transform={transform}
116
+ style={{ transition: 'all .25s ease-in-out', cursor: "pointer" }}
117
+ />
118
+ }
119
+ </>
120
+ );
121
+
122
+
123
+ return (
124
+ <g key={`group-${countryName.replace(' ', '')}`}>
125
+ {circle}
126
+ </g>
127
+ )
128
+ })
129
+ return countries;
130
+ }
131
+
132
+ if(state.general.geoType === 'us') {
133
+ const bubbles = sortedRuntimeData && sortedRuntimeData.map( (item, index) => {
134
+ let stateData = stateCoordinates[item.uid]
135
+ let primaryKey = state?.columns?.primary?.name
136
+ if ( Number(size(item[primaryKey])) === 0) return;
137
+
138
+ if (item[primaryKey] === null) item[primaryKey] = ""
139
+
140
+ // Return if hiding zeros on the map
141
+ if( (Math.floor(Number(size(item[primaryKey]))) === 0 || item[primaryKey] === "" )&& !state.visual.showBubbleZeros ) return;
142
+
143
+ if(!stateData) return true;
144
+ let longitude = Number( stateData.Longitude);
145
+ let latitude = Number( stateData.Latitude);
146
+ let coordinates = [longitude, latitude]
147
+ //console.log('projection', projection([longitude, latitude]))
148
+ let stateName = stateData.Name;
149
+ if (!coordinates) return true;
150
+
151
+ stateName = displayGeoName(stateName);
152
+ const toolTip = applyTooltipsToGeo(stateName, item);
153
+ const legendColors = applyLegendToRow(item);
154
+
155
+
156
+ let transform = `translate(${projection([coordinates[1], coordinates[0]])})`
157
+
158
+ if ( !projection(coordinates) ) return true;
159
+
160
+ let pointerX, pointerY;
161
+ const circle = (
162
+ <>
163
+ <circle
164
+ key={`circle-${stateName.replace(' ', '')}`}
165
+ data-tip={toolTip}
166
+ data-for="tooltip"
167
+ className="bubble"
168
+ cx={projection(coordinates)[0] || 0} // || 0 handles error on loads where the data isn't ready
169
+ cy={projection(coordinates)[1] || 0}
170
+ r={Number(size(item[primaryKey]))}
171
+ fill={legendColors[0]}
172
+ stroke={legendColors[0]}
173
+ strokeWidth={1.25}
174
+ fillOpacity={.4}
175
+ onPointerDown={(e) => {
176
+ pointerX = e.clientX;
177
+ pointerY = e.clientY;
178
+ }}
179
+ onPointerUp={(e) => {
180
+ if (pointerX && pointerY &&
181
+ e.clientX > (pointerX - clickTolerance) &&
182
+ e.clientX < (pointerX + clickTolerance) &&
183
+ e.clientY > (pointerY - clickTolerance) &&
184
+ e.clientY < (pointerY + clickTolerance)
185
+ ) {
186
+ handleCircleClick(state)
187
+ pointerX = undefined;
188
+ pointerY = undefined;
189
+ }
190
+ }}
191
+ transform={transform}
192
+ style={{ transition: 'all .25s ease-in-out', cursor: "pointer" }}
193
+ />
194
+ { state.visual.extraBubbleBorder &&
195
+ <circle
196
+ key={`circle-${stateName.replace(' ', '')}`}
197
+ data-tip={toolTip}
198
+ data-for="tooltip"
199
+ className="bubble"
200
+ cx={projection(coordinates)[0] || 0} // || 0 handles error on loads where the data isn't ready
201
+ cy={projection(coordinates)[1] || 0}
202
+ r={Number(size(item[primaryKey]) + 1)}
203
+ fill={"transparent"}
204
+ stroke={"white"}
205
+ strokeWidth={.5}
206
+ fillOpacity={.4}
207
+ onPointerDown={(e) => {
208
+ pointerX = e.clientX;
209
+ pointerY = e.clientY;
210
+ }}
211
+ onPointerUp={(e) => {
212
+ if (pointerX && pointerY &&
213
+ e.clientX > (pointerX - clickTolerance) &&
214
+ e.clientX < (pointerX + clickTolerance) &&
215
+ e.clientY > (pointerY - clickTolerance) &&
216
+ e.clientY < (pointerY + clickTolerance)
217
+ ) {
218
+ handleCircleClick(state)
219
+ pointerX = undefined;
220
+ pointerY = undefined;
221
+ }
222
+ }}
223
+ transform={transform}
224
+ style={{ transition: 'all .25s ease-in-out', cursor: "pointer" }}
225
+ />
226
+ }
227
+ </>
228
+ );
229
+
230
+
231
+ return (
232
+ <g key={`group-${stateName.replace(' ', '')}`}>
233
+ {circle}
234
+ </g>
235
+ )
236
+ })
237
+ return bubbles;
238
+ }
239
+ }
240
+ export default memo(BubbleList)
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useContext } from 'react';
2
2
  /** @jsx jsx */
3
3
  import { jsx } from '@emotion/react'
4
4
  import { supportedCities } from '../data/supported-geos';
5
+ import { scaleLinear } from 'd3-scale';
5
6
 
6
7
  const CityList = (({
7
8
  data,
@@ -25,6 +26,18 @@ const CityList = (({
25
26
  setCitiesData(citiesDictionary);
26
27
  }, [data]);
27
28
 
29
+ if (state.general.type === 'bubble') {
30
+ const maxDataValue = Math.max(...state.data.map(d => d[state.columns.primary.name]))
31
+ const sortedRuntimeData = Object.values(data).sort((a, b) => a[state.columns.primary.name] < b[state.columns.primary.name] ? 1 : -1)
32
+ if (!sortedRuntimeData) return;
33
+
34
+ // Set bubble sizes
35
+ var size = scaleLinear()
36
+ .domain([1, maxDataValue])
37
+ .range([state.visual.minBubbleSize, state.visual.maxBubbleSize])
38
+
39
+ }
40
+
28
41
  const cityList = Object.keys(citiesData).filter((c) => undefined !== data[c]);
29
42
 
30
43
  const cities = cityList.map((city, i) => {
@@ -61,15 +74,20 @@ const CityList = (({
61
74
 
62
75
  const radius = state.general.geoType === 'us' ? 8 : 4;
63
76
 
77
+ const additionalProps = {
78
+ fillOpacity: state.general.type === 'bubble' ? .4 : 1
79
+ }
80
+
64
81
  const circle = (
65
82
  <circle
66
83
  data-tip={toolTip}
67
84
  data-for="tooltip"
68
85
  cx={0}
69
86
  cy={0}
70
- r={radius}
87
+ r={ state.general.type === 'bubble' ? size(geoData[state.columns.primary.name]) : radius}
71
88
  title="Click for more information"
72
89
  onClick={() => geoClickHandler(cityDisplayName, geoData)}
90
+ {...additionalProps}
73
91
  />
74
92
  );
75
93
 
@@ -1,11 +1,12 @@
1
1
  import React, { useState, useEffect, memo, useRef } from 'react';
2
+ import Loading from '@cdc/core/components/Loading';
2
3
  /** @jsx jsx */
3
4
  import { jsx } from '@emotion/react';
4
5
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary';
5
6
  import { geoCentroid, geoPath } from 'd3-geo';
6
7
  import { feature, mesh } from 'topojson-client';
7
8
  import { CustomProjection } from '@visx/geo';
8
- import colorPalettes from '../data/color-palettes';
9
+ import colorPalettes from '../../../core/data/colorPalettes'
9
10
  import { geoAlbersUsaTerritories } from 'd3-composite-projections';
10
11
  import testJSON from '../data/dfc-map.json';
11
12
  import { abbrs } from '../data/abbreviations';
@@ -514,7 +515,7 @@ const CountyMap = (props) => {
514
515
  geosJsx.push(<FocusedStateBorder key="focused-border-key" />);
515
516
  return geosJsx;
516
517
  };
517
-
518
+ if(!data) <Loading />
518
519
  return (
519
520
  <ErrorBoundary component='CountyMap'>
520
521
  <svg viewBox={`0 0 ${WIDTH} ${HEIGHT}`} preserveAspectRatio='xMinYMin' className='svg-container' data-scale={scale ? scale : ''} data-translate={translate ? translate : ''}>
@@ -30,7 +30,10 @@ const DataTable = (props) => {
30
30
  applyLegendToRow,
31
31
  displayGeoName,
32
32
  navigationHandler,
33
- viewport
33
+ viewport,
34
+ formatLegendLocation,
35
+ tabbingId,
36
+ setFilteredCountryCode
34
37
  } = props;
35
38
 
36
39
  const [expanded, setExpanded] = useState(expandDataTable);
@@ -39,7 +42,7 @@ const DataTable = (props) => {
39
42
 
40
43
  const [ready, setReady] = useState(false)
41
44
 
42
- const fileName = `${mapTitle}.csv`;
45
+ const fileName = `${mapTitle || 'data-table'}.csv`;
43
46
 
44
47
 
45
48
  // Catch all sorting method used on load by default but also on user click
@@ -164,7 +167,6 @@ const DataTable = (props) => {
164
167
  id={`${skipId}`}
165
168
  data-html2canvas-ignore
166
169
  role="button"
167
- tabIndex="-1"
168
170
  >
169
171
  Download Data (CSV)
170
172
  </a>
@@ -176,9 +178,9 @@ const DataTable = (props) => {
176
178
  const newTableColumns = [];
177
179
 
178
180
  Object.keys(columns).forEach((column) => {
179
- if (columns[column].dataTable === true && '' !== columns[column].name) {
181
+ if (columns[column].dataTable === true && columns[column].name) {
180
182
  const newCol = {
181
- Header: columns[column].label || columns[column].name,
183
+ Header: columns[column].label ? columns[column].label : columns[column].name,
182
184
  id: column,
183
185
  accessor: (row) => {
184
186
  if (runtimeData) {
@@ -204,7 +206,11 @@ const DataTable = (props) => {
204
206
 
205
207
  const legendColor = applyLegendToRow(rowObj);
206
208
 
207
- let labelValue = displayGeoName(row.original);
209
+ if(state.general.geoType !== 'us-county') {
210
+ var labelValue = displayGeoName(row.original);
211
+ } else {
212
+ var labelValue = formatLegendLocation(row.original)
213
+ }
208
214
 
209
215
  labelValue = getCellAnchor(labelValue, rowObj);
210
216
 
@@ -230,11 +236,11 @@ const DataTable = (props) => {
230
236
  });
231
237
 
232
238
  return newTableColumns;
233
- }, [indexTitle, columns, runtimeData, runtimeLegend]);
239
+ }, [indexTitle, columns, runtimeData,getCellAnchor,displayDataAsText,applyLegendToRow,customSort,displayGeoName,state.legend.specialClasses]);
234
240
 
235
241
  const tableData = useMemo(
236
242
  () => Object.keys(runtimeData).filter((key) => applyLegendToRow(runtimeData[key])).sort((a, b) => customSort(a, b)),
237
- [runtimeLegend, runtimeData, applyLegendToRow, customSort]
243
+ [ runtimeData, applyLegendToRow, customSort]
238
244
  );
239
245
 
240
246
  // Change accessibility label depending on expanded status
@@ -311,7 +317,8 @@ const DataTable = (props) => {
311
317
  {headerGroups.map((headerGroup) => (
312
318
  <tr {...headerGroup.getHeaderGroupProps()}>
313
319
  {headerGroup.headers.map((column) => (
314
- <th tabIndex="0"
320
+ <th
321
+ tabIndex="0"
315
322
  title={column.Header}
316
323
  role="columnheader"
317
324
  scope="col"
@@ -338,7 +345,7 @@ const DataTable = (props) => {
338
345
  return (
339
346
  <tr {...row.getRowProps()} role="row">
340
347
  {row.cells.map((cell) => (
341
- <td tabIndex="0" {...cell.getCellProps()} role="gridcell">
348
+ <td tabIndex="0" {...cell.getCellProps()} role="gridcell" onClick={ (e) => (state.general.type === 'bubble' && state.general.allowMapZoom && state.general.geoType === 'world') ? setFilteredCountryCode(cell.row.original) : true }>
342
349
  {cell.render('Cell')}
343
350
  </td>
344
351
  ))}