@cdc/map 2.6.3 → 9.22.9

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 (73) hide show
  1. package/dist/cdcmap.js +32 -18
  2. package/examples/bubble-us.json +363 -0
  3. package/examples/bubble-world.json +427 -0
  4. package/examples/default-county.json +64 -12
  5. package/examples/default-hex.json +477 -0
  6. package/examples/default-usa-regions.json +118 -0
  7. package/examples/default-usa.json +1 -1
  8. package/examples/default-world-data.json +1450 -0
  9. package/examples/default-world.json +5 -3
  10. package/examples/example-city-state.json +46 -1
  11. package/examples/gallery/categorical-qualitative.json +797 -0
  12. package/examples/gallery/categorical-scale-based.json +739 -0
  13. package/examples/gallery/city-state.json +479 -0
  14. package/examples/gallery/county.json +22731 -0
  15. package/examples/gallery/equal-interval.json +1027 -0
  16. package/examples/gallery/equal-number.json +1027 -0
  17. package/examples/gallery/filterable.json +909 -0
  18. package/examples/gallery/hex-filtered.json +420 -0
  19. package/examples/gallery/hex.json +413 -0
  20. package/examples/gallery/single-state.json +21402 -0
  21. package/examples/gallery/world.json +1592 -0
  22. package/examples/private/atsdr.json +439 -0
  23. package/examples/private/atsdr_new.json +436 -0
  24. package/examples/private/bubble.json +285 -0
  25. package/examples/private/city-state.json +428 -0
  26. package/examples/private/cty-issue.json +42768 -0
  27. package/examples/private/default-usa.json +460 -0
  28. package/examples/private/default-world-data.json +1444 -0
  29. package/examples/private/default.json +968 -0
  30. package/examples/private/legend-issue.json +1 -0
  31. package/examples/private/map-rounding-error.json +42759 -0
  32. package/examples/private/map.csv +60 -0
  33. package/examples/private/mdx.json +210 -0
  34. package/examples/private/monkeypox.json +376 -0
  35. package/examples/private/regions.json +52 -0
  36. package/examples/private/valid-data-map.csv +59 -0
  37. package/examples/private/wcmsrd-13881-data.json +2858 -0
  38. package/examples/private/wcmsrd-13881.json +5823 -0
  39. package/examples/private/wcmsrd-14492-data.json +292 -0
  40. package/examples/private/wcmsrd-14492.json +114 -0
  41. package/examples/private/wcmsrd-test.json +268 -0
  42. package/examples/private/world.json +1580 -0
  43. package/examples/private/worldmap.json +1490 -0
  44. package/package.json +51 -50
  45. package/src/CdcMap.js +496 -158
  46. package/src/components/BubbleList.js +244 -0
  47. package/src/components/CityList.js +41 -5
  48. package/src/components/CountyMap.js +16 -6
  49. package/src/components/DataTable.js +25 -18
  50. package/src/components/EditorPanel.js +915 -404
  51. package/src/components/Geo.js +1 -1
  52. package/src/components/Modal.js +2 -1
  53. package/src/components/NavigationMenu.js +4 -3
  54. package/src/components/Sidebar.js +14 -19
  55. package/src/components/SingleStateMap.js +11 -5
  56. package/src/components/UsaMap.js +103 -36
  57. package/src/components/UsaRegionMap.js +320 -0
  58. package/src/components/WorldMap.js +116 -34
  59. package/src/data/country-coordinates.js +250 -0
  60. package/src/data/{dfc-map.json → county-map.json} +0 -0
  61. package/src/data/initial-state.js +20 -2
  62. package/src/data/state-coordinates.js +55 -0
  63. package/src/data/supported-geos.js +96 -15
  64. package/src/data/us-regions-topo-2.json +360525 -0
  65. package/src/data/us-regions-topo.json +37894 -0
  66. package/src/hooks/useColorPalette.ts +96 -0
  67. package/src/index.html +7 -4
  68. package/src/scss/editor-panel.scss +78 -57
  69. package/src/scss/main.scss +1 -1
  70. package/src/scss/map.scss +112 -2
  71. package/src/scss/sidebar.scss +2 -1
  72. package/src/data/color-palettes.js +0 -200
  73. package/src/images/map-folded.svg +0 -1
@@ -18,4 +18,4 @@ const Geo = ({path, styles, stroke, strokeWidth, ...props}) => {
18
18
  )
19
19
  }
20
20
 
21
- export default memo(Geo)
21
+ export default memo(Geo)
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import closeIcon from '../images/close.svg?inline';
3
3
  import LegendCircle from '@cdc/core/components/LegendCircle';
4
4
 
5
+ //TODO: Where is this being used? Transfer to new Modal component?
5
6
  const Modal = (props) => {
6
7
  const {
7
8
  applyTooltipsToGeo,
@@ -28,4 +29,4 @@ const Modal = (props) => {
28
29
  };
29
30
 
30
31
 
31
- export default Modal;
32
+ export default Modal;
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
 
3
3
  const NavigationMenu = ({
4
- data, navigationHandler, options, columns, displayGeoName
4
+ data, navigationHandler, options, columns, displayGeoName, mapTabbingID
5
5
  }) => {
6
6
  const [activeGeo, setActiveGeo] = useState('');
7
7
 
@@ -15,6 +15,7 @@ const NavigationMenu = ({
15
15
  navigationHandler(urlString);
16
16
  }
17
17
  };
18
+
18
19
  let navSelect; let
19
20
  navGo;
20
21
 
@@ -51,9 +52,9 @@ const NavigationMenu = ({
51
52
  return (
52
53
  <section className="navigation-menu">
53
54
  <form onSubmit={handleSubmit} type="get">
54
- <label htmlFor="dropdown">
55
+ <label htmlFor={mapTabbingID.replace('#', '')}>
55
56
  <div className="select-heading">{navSelect}</div>
56
- <select value={activeGeo} id="dropdown" onChange={(e) => setActiveGeo(e.target.value)}>
57
+ <select value={activeGeo} id={mapTabbingID.replace('#', '')} onChange={(e) => setActiveGeo(e.target.value)}>
57
58
  {Object.keys(dropdownItems).map((key, i) => <option key={key} value={key}>{key}</option>)}
58
59
  </select>
59
60
  </label>
@@ -16,18 +16,10 @@ const Sidebar = (props) => {
16
16
  setRuntimeLegend,
17
17
  prefix,
18
18
  suffix,
19
- viewport
19
+ viewport,
20
+ displayDataAsText
20
21
  } = props;
21
22
 
22
- const addCommas = (value) => {
23
- // If value is a number, apply specific formattings
24
- if (value && columns.primary.hasOwnProperty('useCommas') && columns.primary.useCommas === true) {
25
- return value.toLocaleString('en-US', { style: 'decimal' });
26
- }
27
-
28
- return value;
29
- };
30
-
31
23
  // Toggles if a legend is active and being applied to the map and data table.
32
24
  const toggleLegendActive = (i, legendLabel) => {
33
25
  const newValue = !runtimeLegend[i].disabled;
@@ -48,21 +40,22 @@ const Sidebar = (props) => {
48
40
  };
49
41
 
50
42
  const legendList = runtimeLegend.map((entry, idx) => {
51
- const entryMax = addCommas(entry.max);
52
43
 
53
- const entryMin = addCommas(entry.min);
44
+ const entryMax = displayDataAsText(entry.max, 'primary');
54
45
 
55
- let formattedText = `${prefix + entryMin + suffix}${entryMax !== entryMin ? ` - ${prefix + entryMax + suffix}` : ''}`;
46
+ const entryMin = displayDataAsText(entry.min, 'primary');
47
+
48
+ let formattedText = `${entryMin}${entryMax !== entryMin ? ` - ${entryMax}` : ''}`;
56
49
 
57
50
  // If interval, add some formatting
58
51
  if (legend.type === 'equalinterval' && idx !== runtimeLegend.length - 1) {
59
- formattedText = `${prefix + entryMin + suffix} - < ${prefix + entryMax + suffix}`;
52
+ formattedText = `${entryMin} - < ${entryMax}`;
60
53
  }
61
54
 
62
55
  const { disabled } = entry;
63
56
 
64
57
  if (legend.type === 'category') {
65
- formattedText = prefix + entry.value + suffix;
58
+ formattedText = displayDataAsText(entry.value, 'primary');
66
59
  }
67
60
 
68
61
  if (entry.max === 0 && entry.min === 0) {
@@ -76,12 +69,13 @@ const Sidebar = (props) => {
76
69
  }
77
70
 
78
71
  return (
79
- <li
72
+ <li
73
+ className={disabled ? 'disabled single-legend' : 'single-legend'}
80
74
  key={idx}
81
75
  title={`Legend item ${legendLabel} - Click to disable`}
82
- onClick={() => { toggleLegendActive(idx, legendLabel); }}
83
- className={disabled ? 'disabled single-legend' : 'single-legend'}
84
- ><LegendCircle fill={entry.color} /> <span className="label">{legendLabel}</span>
76
+ onClick={() => { toggleLegendActive(idx, legendLabel); } }
77
+ >
78
+ <LegendCircle fill={entry.color} /> <span className="label">{legendLabel}</span>
85
79
  </li>
86
80
  );
87
81
  });
@@ -105,6 +99,7 @@ const Sidebar = (props) => {
105
99
  <select
106
100
  id={`filter-${idx}`}
107
101
  className="filter-select"
102
+ aria-label="select filter"
108
103
  value={singleFilter.active}
109
104
  onChange={(val) => {
110
105
  changeFilterActive(idx, val.target.value);
@@ -5,9 +5,9 @@ import ErrorBoundary from '@cdc/core/components/ErrorBoundary';
5
5
  import { geoCentroid, geoPath } from "d3-geo";
6
6
  import { feature, mesh } from "topojson-client";
7
7
  import { CustomProjection } from '@visx/geo';
8
- import colorPalettes from '../data/color-palettes';
8
+ import colorPalettes from '../../../core/data/colorPalettes';
9
9
  import { geoAlbersUsaTerritories } from 'd3-composite-projections';
10
- import testJSON from '../data/dfc-map.json';
10
+ import testJSON from '../data/county-map.json';
11
11
 
12
12
  const abbrs = {
13
13
  Alabama: 'AL',
@@ -99,7 +99,8 @@ const SingleStateMap = (props) => {
99
99
  supportedTerritories,
100
100
  rebuildTooltips,
101
101
  runtimeLegend,
102
- generateColorsArray
102
+ generateColorsArray,
103
+ handleMapAriaLabels
103
104
  } = props;
104
105
 
105
106
 
@@ -290,11 +291,16 @@ const SingleStateMap = (props) => {
290
291
  return geosJsx;
291
292
  };
292
293
 
293
-
294
294
  return (
295
295
  <ErrorBoundary component="SingleStateMap">
296
296
  {stateToShow &&
297
- <svg viewBox={`0 0 ${WIDTH} ${HEIGHT}`} preserveAspectRatio="xMinYMin" className="svg-container">
297
+ <svg
298
+ viewBox={`0 0 ${WIDTH} ${HEIGHT}`}
299
+ preserveAspectRatio="xMinYMin"
300
+ className="svg-container"
301
+ role="img"
302
+ aria-label={handleMapAriaLabels(state)}
303
+ >
298
304
  <rect className="background center-container ocean" width={WIDTH} height={HEIGHT} fillOpacity={1} fill="white"></rect>
299
305
  <CustomProjection
300
306
  data={ [{states: stateToShow, counties: countiesToShow }] }
@@ -9,6 +9,8 @@ import hexTopoJSON from '../data/us-hex-topo.json';
9
9
  import { AlbersUsa, Mercator } from '@visx/geo';
10
10
  import chroma from 'chroma-js';
11
11
  import CityList from './CityList';
12
+ import BubbleList from './BubbleList';
13
+ import { supportedCities, supportedStates } from '../data/supported-geos';
12
14
 
13
15
  const { features: unitedStates } = feature(topoJSON, topoJSON.objects.states)
14
16
  const { features: unitedStatesHex } = feature(hexTopoJSON, hexTopoJSON.objects.states)
@@ -68,9 +70,32 @@ const UsaMap = (props) => {
68
70
  displayGeoName,
69
71
  supportedTerritories,
70
72
  rebuildTooltips,
71
- titleCase
73
+ titleCase,
74
+ handleCircleClick,
75
+ setSharedFilterValue,
76
+ handleMapAriaLabels
72
77
  } = props;
73
78
 
79
+ let isFilterValueSupported = false;
80
+
81
+ if(setSharedFilterValue){
82
+ Object.keys(supportedStates).forEach(supportedState => {
83
+ if(supportedStates[supportedState].indexOf(setSharedFilterValue.toUpperCase()) !== -1){
84
+ isFilterValueSupported = true;
85
+ }
86
+ });
87
+ Object.keys(supportedTerritories).forEach(supportedTerritory => {
88
+ if(supportedTerritories[supportedTerritory].indexOf(setSharedFilterValue.toUpperCase()) !== -1){
89
+ isFilterValueSupported = true;
90
+ }
91
+ });
92
+ Object.keys(supportedCities).forEach(supportedCity => {
93
+ if(supportedCity === setSharedFilterValue.toUpperCase()){
94
+ isFilterValueSupported = true;
95
+ }
96
+ });
97
+ }
98
+
74
99
  // "Choose State" options
75
100
  const [extent, setExtent] = useState(null)
76
101
  const [focusedStates, setFocusedStates] = useState(unitedStates)
@@ -123,7 +148,7 @@ const UsaMap = (props) => {
123
148
 
124
149
  if (legendColors) {
125
150
  // Use white text if the background is dark, and dark grey if it's light
126
- if (chroma.contrast(textColor, legendColors[0]) < 4.5) {
151
+ if (chroma.contrast(textColor, legendColors[0]) < 3.5) {
127
152
  textColor = '#202020';
128
153
  }
129
154
 
@@ -137,6 +162,8 @@ const UsaMap = (props) => {
137
162
  styles = {
138
163
  color: textColor,
139
164
  fill: legendColors[0],
165
+ opacity: setSharedFilterValue && isFilterValueSupported && setSharedFilterValue !== territoryData[state.columns.geo.name] ? .5 : 1,
166
+ stroke: setSharedFilterValue && isFilterValueSupported && setSharedFilterValue === territoryData[state.columns.geo.name] ? 'rgba(0, 0, 0, 1)' : geoStrokeColor,
140
167
  cursor: needsPointer ? 'pointer' : 'default',
141
168
  '&:hover': {
142
169
  fill: legendColors[1],
@@ -153,7 +180,6 @@ const UsaMap = (props) => {
153
180
  text={styles.color}
154
181
  data-tip={toolTip}
155
182
  data-for="tooltip"
156
- stroke={geoStrokeColor}
157
183
  strokeWidth={1.5}
158
184
  onClick={() => geoClickHandler(territory, territoryData)}
159
185
  />)
@@ -169,7 +195,7 @@ const UsaMap = (props) => {
169
195
  let textColor = "#FFF"
170
196
 
171
197
  // Dynamic text color
172
- if (chroma.contrast(textColor, bgColor) < 4.5 ) {
198
+ if (chroma.contrast(textColor, bgColor) < 3.5 ) {
173
199
  textColor = '#202020';
174
200
  }
175
201
 
@@ -206,6 +232,25 @@ const UsaMap = (props) => {
206
232
  const constructGeoJsx = (geographies, projection) => {
207
233
  let showLabel = state.general.displayStateLabels
208
234
 
235
+ // Order alphabetically. Important for accessibility if ever read out loud.
236
+ geographies.map ( state => {
237
+ if(!state.feature.properties.iso) return;
238
+ state.feature.properties.name = titleCase(supportedStates[state.feature.properties.iso][0])
239
+ })
240
+
241
+ geographies.sort( (a,b) => {
242
+ const first = a.feature.properties.name.toUpperCase(); // ignore upper and lowercase
243
+ const second = b.feature.properties.name.toUpperCase(); // ignore upper and lowercase
244
+ if (first < second) {
245
+ return -1;
246
+ }
247
+ if (first > second) {
248
+ return 1;
249
+ }
250
+
251
+ // names must be equal
252
+ return 0;
253
+ })
209
254
  const geosJsx = geographies.map(( {feature: geo, path = ''}) => {
210
255
  const key = isHex ? geo.properties.iso + '-hex-group' : geo.properties.iso + '-group'
211
256
 
@@ -216,11 +261,9 @@ const UsaMap = (props) => {
216
261
 
217
262
  // Map the name from the geo data with the appropriate key for the processed data
218
263
  let geoKey = geo.properties.iso;
264
+ let geoName = geo.properties.name;
219
265
 
220
266
  // Manually add Washington D.C. in for Hex maps
221
- if(isHex && geoKey === 'US-DC') {
222
- geoKey = 'District of Columbia'
223
- }
224
267
 
225
268
  if(!geoKey) return
226
269
 
@@ -240,13 +283,15 @@ const UsaMap = (props) => {
240
283
  const tooltip = applyTooltipsToGeo(geoDisplayName, geoData);
241
284
 
242
285
  styles = {
243
- fill: legendColors[0],
286
+ fill: state.general.type !== 'bubble' ? legendColors[0] : '#E6E6E6',
287
+ opacity: setSharedFilterValue && isFilterValueSupported && setSharedFilterValue !== geoData[state.columns.geo.name] ? .5 : 1,
288
+ stroke: setSharedFilterValue && isFilterValueSupported && setSharedFilterValue === geoData[state.columns.geo.name] ? 'rgba(0, 0, 0, 1)' : geoStrokeColor,
244
289
  cursor: 'default',
245
290
  '&:hover': {
246
- fill: legendColors[1],
291
+ fill: state.general.type !== 'bubble' ? legendColors[1] : '#e6e6e6',
247
292
  },
248
293
  '&:active': {
249
- fill: legendColors[2],
294
+ fill: state.general.type !== 'bubble' ? legendColors[2] : '#e6e6e6',
250
295
  },
251
296
  };
252
297
 
@@ -254,43 +299,43 @@ const UsaMap = (props) => {
254
299
  if ((state.columns.navigate && geoData[state.columns.navigate.name]) || state.tooltips.appearanceType === 'click') {
255
300
  styles.cursor = 'pointer'
256
301
  }
257
-
258
302
  return (
303
+ <g data-name={geoName} key={key}>
304
+ <g
305
+ data-for="tooltip"
306
+ data-tip={tooltip}
307
+ className="geo-group"
308
+ css={styles}
309
+ onClick={() => geoClickHandler(geoDisplayName, geoData)}
310
+ >
311
+ <path
312
+ tabIndex={-1}
313
+ className='single-geo'
314
+ strokeWidth={1.3}
315
+ d={path}
316
+ />
317
+ {(isHex || showLabel) && geoLabel(geo, legendColors[0], projection)}
318
+ </g>
319
+ </g>
320
+ )
321
+ }
322
+
323
+ // Default return state, just geo with no additional information
324
+ return (
325
+ <g data-name={geoName} key={key}>
259
326
  <g
260
- data-for="tooltip"
261
- data-tip={tooltip}
262
- key={key}
263
327
  className="geo-group"
264
328
  css={styles}
265
- onClick={() => geoClickHandler(geoDisplayName, geoData)}
266
329
  >
267
330
  <path
268
331
  tabIndex={-1}
269
332
  className='single-geo'
270
333
  stroke={geoStrokeColor}
271
- strokeWidth={1.3}
334
+ strokeWidth={1.3}
272
335
  d={path}
273
336
  />
274
- {(isHex || showLabel) && geoLabel(geo, legendColors[0], projection)}
337
+ {(isHex || showLabel) && geoLabel(geo, styles.fill, projection)}
275
338
  </g>
276
- )
277
- }
278
-
279
- // Default return state, just geo with no additional information
280
- return (
281
- <g
282
- key={key}
283
- className="geo-group"
284
- css={styles}
285
- >
286
- <path
287
- tabIndex={-1}
288
- className='single-geo'
289
- stroke={geoStrokeColor}
290
- strokeWidth={1.3}
291
- d={path}
292
- />
293
- {(isHex || showLabel) && geoLabel(geo, styles.fill, projection)}
294
339
  </g>
295
340
  )
296
341
  });
@@ -308,14 +353,36 @@ const UsaMap = (props) => {
308
353
  displayGeoName={displayGeoName}
309
354
  applyLegendToRow={applyLegendToRow}
310
355
  titleCase={titleCase}
356
+ setSharedFilterValue={setSharedFilterValue}
357
+ isFilterValueSupported={isFilterValueSupported}
311
358
  />)
312
359
 
360
+ // Bubbles
361
+ if (state.general.type === 'bubble') {
362
+ geosJsx.push(
363
+ <BubbleList
364
+ key="bubbles"
365
+ data={state.data}
366
+ runtimeData={data}
367
+ state={state}
368
+ projection={projection}
369
+ applyLegendToRow={applyLegendToRow}
370
+ applyTooltipsToGeo={applyTooltipsToGeo}
371
+ displayGeoName={displayGeoName}
372
+ />
373
+ )
374
+ }
375
+
313
376
  return geosJsx;
314
377
  };
315
378
 
316
379
  return (
317
380
  <ErrorBoundary component="UsaMap">
318
- <svg viewBox="0 0 880 500">
381
+ <svg
382
+ viewBox="0 0 880 500"
383
+ role="img"
384
+ aria-label={handleMapAriaLabels(state)}
385
+ >
319
386
  {state.general.displayAsHex ?
320
387
  (<Mercator data={unitedStatesHex} scale={650} translate={[1600, 775]}>
321
388
  {({ features, projection }) => constructGeoJsx(features, projection)}