@cdc/map 4.25.7 → 4.25.10

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 (99) hide show
  1. package/.claude/settings.local.json +30 -0
  2. package/CLAUDE.local.md +0 -0
  3. package/dist/cdcmap.js +54785 -53159
  4. package/examples/private/c.json +290 -0
  5. package/examples/private/canvas-city-hover.json +787 -0
  6. package/examples/private/d.json +345 -0
  7. package/examples/private/filter-map.json +909 -0
  8. package/examples/private/g.json +1 -0
  9. package/examples/private/h.json +105911 -0
  10. package/examples/private/measles-data.json +378 -0
  11. package/examples/private/measles.json +211 -0
  12. package/examples/private/north-dakota.json +1132 -0
  13. package/examples/private/rsv-data.json +532 -0
  14. package/examples/private/state-with-pattern.json +883 -0
  15. package/examples/private/test.json +222 -640
  16. package/index.html +1 -1
  17. package/package.json +26 -5
  18. package/src/CdcMap.tsx +28 -8
  19. package/src/CdcMapComponent.tsx +230 -306
  20. package/src/_stories/CdcMap.Filters.stories.tsx +2 -2
  21. package/src/_stories/CdcMap.Legend.Gradient.stories.tsx +3 -3
  22. package/src/_stories/CdcMap.Legend.stories.tsx +7 -4
  23. package/src/_stories/CdcMap.Patterns.stories.tsx +2 -2
  24. package/src/_stories/CdcMap.Table.stories.tsx +2 -2
  25. package/src/_stories/CdcMap.stories.tsx +18 -11
  26. package/src/_stories/GoogleMap.stories.tsx +2 -2
  27. package/src/_stories/UsaMap.NoData.stories.tsx +2 -2
  28. package/src/_stories/_mock/equal-number.json +1109 -0
  29. package/src/_stories/_mock/multi-state.json +21389 -0
  30. package/src/_stories/_mock/us-bubble-cities.json +306 -0
  31. package/src/components/BubbleList.tsx +16 -12
  32. package/src/components/CityList.tsx +88 -110
  33. package/src/components/DataTable.tsx +44 -12
  34. package/src/components/EditorPanel/components/EditorPanel.tsx +201 -203
  35. package/src/components/EditorPanel/components/HexShapeSettings.tsx +3 -2
  36. package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +7 -5
  37. package/src/components/Geo.tsx +2 -0
  38. package/src/components/Legend/components/Legend.tsx +117 -93
  39. package/src/components/Legend/components/LegendGroup/Legend.Group.tsx +10 -7
  40. package/src/components/MapContainer.tsx +52 -0
  41. package/src/components/MapControls.tsx +44 -0
  42. package/src/components/Modal.tsx +2 -8
  43. package/src/components/NavigationMenu.tsx +13 -1
  44. package/src/components/UsaMap/components/SingleState/SingleState.CountyOutput.tsx +24 -7
  45. package/src/components/UsaMap/components/SingleState/SingleState.StateOutput.tsx +21 -15
  46. package/src/components/UsaMap/components/TerritoriesSection.tsx +2 -2
  47. package/src/components/UsaMap/components/UsaMap.County.tsx +112 -33
  48. package/src/components/UsaMap/components/UsaMap.Region.tsx +23 -5
  49. package/src/components/UsaMap/components/UsaMap.SingleState.tsx +38 -26
  50. package/src/components/UsaMap/components/UsaMap.State.tsx +28 -10
  51. package/src/components/UsaMap/helpers/map.ts +16 -8
  52. package/src/components/WorldMap/WorldMap.tsx +116 -11
  53. package/src/components/ZoomControls.tsx +6 -9
  54. package/src/context/LegendMemoContext.tsx +30 -0
  55. package/src/context.ts +1 -39
  56. package/src/data/initial-state.js +143 -128
  57. package/src/data/supported-geos.js +202 -4
  58. package/src/helpers/addUIDs.ts +8 -8
  59. package/src/helpers/applyColorToLegend.ts +122 -45
  60. package/src/helpers/applyLegendToRow.ts +15 -13
  61. package/src/helpers/componentHelpers.ts +8 -0
  62. package/src/helpers/constants.ts +12 -0
  63. package/src/helpers/dataTableHelpers.ts +6 -0
  64. package/src/helpers/displayGeoName.ts +12 -7
  65. package/src/helpers/formatLegendLocation.ts +1 -3
  66. package/src/helpers/generateRuntimeLegend.ts +192 -340
  67. package/src/helpers/generateRuntimeLegendHash.ts +4 -2
  68. package/src/helpers/getColumnNames.ts +1 -1
  69. package/src/helpers/getPatternForRow.ts +36 -0
  70. package/src/helpers/getStatesPicked.ts +14 -0
  71. package/src/helpers/handleMapAriaLabels.ts +2 -2
  72. package/src/helpers/index.ts +11 -3
  73. package/src/helpers/isLegendItemDisabled.ts +16 -0
  74. package/src/helpers/mapObserverHelpers.ts +40 -0
  75. package/src/helpers/resetLegendToggles.ts +3 -2
  76. package/src/helpers/toggleLegendActive.ts +6 -11
  77. package/src/helpers/urlDataHelpers.ts +70 -0
  78. package/src/hooks/useGeoClickHandler.ts +35 -1
  79. package/src/hooks/useLegendMemo.ts +17 -0
  80. package/src/hooks/useMapLayers.tsx +5 -4
  81. package/src/hooks/useStateZoom.tsx +137 -88
  82. package/src/hooks/useTooltip.ts +1 -2
  83. package/src/index.jsx +6 -3
  84. package/src/scss/main.scss +23 -12
  85. package/src/store/map.actions.ts +2 -2
  86. package/src/store/map.reducer.ts +21 -10
  87. package/src/test/CdcMap.test.jsx +11 -0
  88. package/src/types/MapConfig.ts +25 -17
  89. package/src/types/MapContext.ts +2 -8
  90. package/src/types/runtimeLegend.ts +12 -10
  91. package/vite.config.js +2 -7
  92. package/vitest.config.ts +16 -0
  93. package/src/_stories/_mock/floating-point.json +0 -427
  94. package/src/coreStyles_map.scss +0 -3
  95. package/src/helpers/colorDistributions.ts +0 -12
  96. package/src/helpers/generateColorsArray.ts +0 -14
  97. package/src/helpers/getStatePicked.ts +0 -8
  98. package/src/helpers/tests/generateColorsArray.test.ts +0 -18
  99. package/src/helpers/tests/generateRuntimeLegendHash.test.ts +0 -11
@@ -1,14 +1,16 @@
1
+ export type RuntimeLegendItem = {
2
+ disabled?: boolean
3
+ bin?: number
4
+ color?: string
5
+ special?: boolean
6
+ value?: string | number
7
+ label?: string
8
+ min?: number
9
+ max?: number
10
+ }
11
+
1
12
  export type RuntimeLegend = {
2
- items: {
3
- disabled?: boolean
4
- bin?: number
5
- color?: string
6
- special?: boolean
7
- value?: any
8
- label?: string
9
- min?: number
10
- max?: number
11
- }[]
13
+ items: RuntimeLegendItem[]
12
14
  disabledAmt?: number
13
15
  fromHash?: number
14
16
  runtimeDataHash?: number
package/vite.config.js CHANGED
@@ -1,9 +1,4 @@
1
- import GenerateViteConfig from '../../generateViteConfig.js'
1
+ import GenerateViteConfig from '@cdc/core/generateViteConfig.js'
2
2
  import { moduleName } from './package.json'
3
3
 
4
- export default GenerateViteConfig(moduleName, null, {
5
- jsxImportSource: '@emotion/react',
6
- babel: {
7
- plugins: ['@emotion/babel-plugin']
8
- }
9
- })
4
+ export default GenerateViteConfig(moduleName)
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: 'jsdom',
6
+ globals: true,
7
+ setupFiles: ['../../vitest.setup.ts'],
8
+ exclude: [
9
+ '**/node_modules/**',
10
+ '**/dist/**',
11
+ '**/.storybook/**',
12
+ '**/*.stories.*',
13
+ '**/storybook-static/**'
14
+ ]
15
+ }
16
+ })
@@ -1,427 +0,0 @@
1
- {
2
- "general": {
3
- "geoType": "us",
4
- "geoBorderColor": "darkGray",
5
- "showTitle": false,
6
- "showSidebar": true,
7
- "showDownloadButton": false,
8
- "showDownloadMediaButton": false,
9
- "displayAsHex": true,
10
- "displayStateLabels": false,
11
- "territoriesLabel": "Territories",
12
- "language": "en",
13
- "hasRegions": false,
14
- "expandDataTable": false,
15
- "fullBorder": false,
16
- "type": "data",
17
- "palette": {
18
- "isReversed": true
19
- },
20
- "geoLabelOverride": "",
21
- "convertFipsCodes": true,
22
- "allowMapZoom": true,
23
- "hideGeoColumnInTooltip": false,
24
- "hidePrimaryColumnInTooltip": false,
25
- "superTitle": "",
26
- "equalNumberOptIn": true,
27
- "navigationTarget": "_self",
28
- "noStateFoundMessage": "Map Unavailable",
29
- "annotationDropdownText": "Annotations",
30
- "headerColor": "theme-blue",
31
- "title": "",
32
- "territoriesAlwaysShow": false,
33
- "statePicked": {
34
- "fipsCode": "01",
35
- "stateName": "Alabama"
36
- }
37
- },
38
- "type": "map",
39
- "customColors": [
40
- "gray",
41
- "#edf8fb",
42
- "gray",
43
- "#b3cde3",
44
- "gray",
45
- "#8c96c6",
46
- "#8856a7",
47
- "#810f7c"
48
- ],
49
- "columns": {
50
- "geo": {
51
- "name": "state",
52
- "label": "Location",
53
- "tooltip": false,
54
- "dataTable": true
55
- },
56
- "primary": {
57
- "dataTable": true,
58
- "tooltip": true,
59
- "prefix": "",
60
- "suffix": "%",
61
- "name": "value",
62
- "label": "",
63
- "roundToPlace": 1
64
- },
65
- "navigate": {
66
- "name": ""
67
- },
68
- "latitude": {
69
- "name": ""
70
- },
71
- "longitude": {
72
- "name": ""
73
- }
74
- },
75
- "legend": {
76
- "descriptions": {},
77
- "specialClasses": [
78
- {
79
- "key": "value",
80
- "value": "",
81
- "label": "No data"
82
- }
83
- ],
84
- "unified": false,
85
- "singleColumn": false,
86
- "dynamicDescription": false,
87
- "type": "equalnumber",
88
- "numberOfItems": 5,
89
- "position": "side",
90
- "title": "Legend",
91
- "singleRow": false,
92
- "verticalSorted": false,
93
- "showSpecialClassesLast": true,
94
- "categoryValuesOrder": [
95
- "No",
96
- "Yes"
97
- ]
98
- },
99
- "filters": [],
100
- "table": {
101
- "wrapColumns": false,
102
- "label": "Data Table",
103
- "expanded": false,
104
- "limitHeight": false,
105
- "height": "",
106
- "caption": "",
107
- "showDownloadUrl": false,
108
- "showDataTableLink": false,
109
- "showFullGeoNameInCSV": false,
110
- "forceDisplay": false,
111
- "download": true,
112
- "indexLabel": "",
113
- "showDownloadLinkBelow": true,
114
- "cellMinWidth": "0"
115
- },
116
- "tooltips": {
117
- "appearanceType": "hover",
118
- "linkLabel": "Learn More",
119
- "capitalizeLabels": true,
120
- "opacity": 90
121
- },
122
- "visual": {
123
- "minBubbleSize": 1,
124
- "maxBubbleSize": 20,
125
- "extraBubbleBorder": false,
126
- "cityStyle": "circle",
127
- "cityStyleLabel": "",
128
- "showBubbleZeros": false,
129
- "additionalCityStyles": [],
130
- "geoCodeCircleSize": 8
131
- },
132
- "mapPosition": {
133
- "coordinates": [
134
- 0,
135
- 30
136
- ],
137
- "zoom": 1
138
- },
139
- "map": {
140
- "layers": [],
141
- "patterns": []
142
- },
143
- "filterBehavior": "Filter Change",
144
- "dataTable": {
145
- "title": "Data Table",
146
- "forceDisplay": true,
147
- "caption": "Lorem Ipsum - Text added to Data Table Caption",
148
- "limitHeight": true,
149
- "height": "100"
150
- },
151
- "orientation": null,
152
- "visualizationSubType": null,
153
- "validated": "4.24.3",
154
- "version": "4.24.12",
155
- "data": [
156
- {
157
- "state": "Alaska",
158
- "stratification": "Total",
159
- "value": "33.3"
160
- },
161
- {
162
- "state": "Alabama",
163
- "stratification": "Total",
164
- "value": "32.7"
165
- },
166
- {
167
- "state": "Arkansas",
168
- "stratification": "Total",
169
- "value": "31.8"
170
- },
171
- {
172
- "state": "Arizona",
173
- "stratification": "Total",
174
- "value": "34.5"
175
- },
176
- {
177
- "state": "California",
178
- "stratification": "Total",
179
- "value": "36.4"
180
- },
181
- {
182
- "state": "Colorado",
183
- "stratification": "Total",
184
- "value": "35.0"
185
- },
186
- {
187
- "state": "Connecticut",
188
- "stratification": "Total",
189
- "value": "36.5"
190
- },
191
- {
192
- "state": "District of Columbia",
193
- "stratification": "Total",
194
- "value": "33.5"
195
- },
196
- {
197
- "state": "Delaware",
198
- "stratification": "Total",
199
- "value": "35.6"
200
- },
201
- {
202
- "state": "Florida",
203
- "stratification": "Total",
204
- "value": "35.6"
205
- },
206
- {
207
- "state": "Georgia",
208
- "stratification": "Total",
209
- "value": "33.7"
210
- },
211
- {
212
- "state": "Guam",
213
- "stratification": "Total",
214
- "value": "34.9"
215
- },
216
- {
217
- "state": "Hawaii",
218
- "stratification": "Total",
219
- "value": "34.4"
220
- },
221
- {
222
- "state": "Iowa",
223
- "stratification": "Total",
224
- "value": "34.3"
225
- },
226
- {
227
- "state": "Idaho",
228
- "stratification": "Total",
229
- "value": "35.7"
230
- },
231
- {
232
- "state": "Illinois",
233
- "stratification": "Total",
234
- "value": "35.0"
235
- },
236
- {
237
- "state": "Indiana",
238
- "stratification": "Total",
239
- "value": "33.3"
240
- },
241
- {
242
- "state": "Kansas",
243
- "stratification": "Total",
244
- "value": "33.3"
245
- },
246
- {
247
- "state": "Kentucky",
248
- "stratification": "Total",
249
- "value": ""
250
- },
251
- {
252
- "state": "Louisiana",
253
- "stratification": "Total",
254
- "value": "32.1"
255
- },
256
- {
257
- "state": "Massachusetts",
258
- "stratification": "Total",
259
- "value": "35.2"
260
- },
261
- {
262
- "state": "Maryland",
263
- "stratification": "Total",
264
- "value": "34.7"
265
- },
266
- {
267
- "state": "Maine",
268
- "stratification": "Total",
269
- "value": "35.3"
270
- },
271
- {
272
- "state": "Michigan",
273
- "stratification": "Total",
274
- "value": "33.4"
275
- },
276
- {
277
- "state": "Minnesota",
278
- "stratification": "Total",
279
- "value": "34.2"
280
- },
281
- {
282
- "state": "Missouri",
283
- "stratification": "Total",
284
- "value": "34.3"
285
- },
286
- {
287
- "state": "Mississippi",
288
- "stratification": "Total",
289
- "value": "31.6"
290
- },
291
- {
292
- "state": "Montana",
293
- "stratification": "Total",
294
- "value": "35.2"
295
- },
296
- {
297
- "state": "North Carolina",
298
- "stratification": "Total",
299
- "value": "35.0"
300
- },
301
- {
302
- "state": "North Dakota",
303
- "stratification": "Total",
304
- "value": "35.8"
305
- },
306
- {
307
- "state": "Nebraska",
308
- "stratification": "Total",
309
- "value": "34.8"
310
- },
311
- {
312
- "state": "New Hampshire",
313
- "stratification": "Total",
314
- "value": "35.6"
315
- },
316
- {
317
- "state": "New Jersey",
318
- "stratification": "Total",
319
- "value": "35.9"
320
- },
321
- {
322
- "state": "New Mexico",
323
- "stratification": "Total",
324
- "value": "33.9"
325
- },
326
- {
327
- "state": "Nevada",
328
- "stratification": "Total",
329
- "value": "35.6"
330
- },
331
- {
332
- "state": "New York",
333
- "stratification": "Total",
334
- "value": "36.1"
335
- },
336
- {
337
- "state": "Ohio",
338
- "stratification": "Total",
339
- "value": "33.2"
340
- },
341
- {
342
- "state": "Oklahoma",
343
- "stratification": "Total",
344
- "value": "31.9"
345
- },
346
- {
347
- "state": "Oregon",
348
- "stratification": "Total",
349
- "value": "33.4"
350
- },
351
- {
352
- "state": "Pennsylvania",
353
- "stratification": "Total",
354
- "value": ""
355
- },
356
- {
357
- "state": "Puerto Rico",
358
- "stratification": "Total",
359
- "value": "35.1"
360
- },
361
- {
362
- "state": "Rhode Island",
363
- "stratification": "Total",
364
- "value": "34.8"
365
- },
366
- {
367
- "state": "South Carolina",
368
- "stratification": "Total",
369
- "value": "33.9"
370
- },
371
- {
372
- "state": "South Dakota",
373
- "stratification": "Total",
374
- "value": "34.3"
375
- },
376
- {
377
- "state": "Tennessee",
378
- "stratification": "Total",
379
- "value": "33.1"
380
- },
381
- {
382
- "state": "Texas",
383
- "stratification": "Total",
384
- "value": "35.0"
385
- },
386
- {
387
- "state": "Utah",
388
- "stratification": "Total",
389
- "value": "34.3"
390
- },
391
- {
392
- "state": "Virginia",
393
- "stratification": "Total",
394
- "value": "34.3"
395
- },
396
- {
397
- "state": "Virgin Islands",
398
- "stratification": "Total",
399
- "value": "38.2"
400
- },
401
- {
402
- "state": "Vermont",
403
- "stratification": "Total",
404
- "value": "34.8"
405
- },
406
- {
407
- "state": "Washington",
408
- "stratification": "Total",
409
- "value": "35.2"
410
- },
411
- {
412
- "state": "Wisconsin",
413
- "stratification": "Total",
414
- "value": "34.1"
415
- },
416
- {
417
- "state": "West Virginia",
418
- "stratification": "Total",
419
- "value": "32.0"
420
- },
421
- {
422
- "state": "Wyoming",
423
- "stratification": "Total",
424
- "value": "35.7"
425
- }
426
- ]
427
- }
@@ -1,3 +0,0 @@
1
- @import '@cdc/core/styles/base';
2
- @import '@cdc/core/styles/heading-colors';
3
- @import '@cdc/core/styles/v2/components/ui/tooltip';
@@ -1,12 +0,0 @@
1
- export const colorDistributions = {
2
- 1: [1],
3
- 2: [1, 3],
4
- 3: [1, 3, 5],
5
- 4: [0, 2, 4, 6],
6
- 5: [0, 2, 4, 6, 7],
7
- 6: [0, 2, 3, 4, 5, 7],
8
- 7: [0, 2, 3, 4, 5, 6, 7],
9
- 8: [0, 2, 3, 4, 5, 6, 7, 8],
10
- 9: [0, 1, 2, 3, 4, 5, 6, 7, 8],
11
- 10: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
12
- }
@@ -1,14 +0,0 @@
1
- import chroma from 'chroma-js'
2
- import { DEFAULT_MAP_BACKGROUND } from './constants'
3
-
4
- /**
5
- * Generate an array of colors based on a given color [color, hoverColor, darkColor]
6
- * @param {string} color - The base color to generate the array from
7
- * @param {boolean} special - A flag to determine if the hover color should be brighter or saturated
8
- * @returns {string[]} - An array of colors
9
- */
10
- export const generateColorsArray = (color: string = DEFAULT_MAP_BACKGROUND, special: boolean = false) => {
11
- let colorObj = chroma(color)
12
- let hoverColor = special ? colorObj.brighten(0.5).hex() : colorObj.saturate(1.3).hex()
13
- return [color, hoverColor, colorObj.darken(0.3).hex()]
14
- }
@@ -1,8 +0,0 @@
1
- import { getFilterControllingStatePicked } from '../components/UsaMap/helpers/map'
2
- import { supportedStatesFipsCodes } from '../data/supported-geos'
3
-
4
- export const getStatePicked = (config, runtimeData) => {
5
- const stateName = getFilterControllingStatePicked(config, runtimeData)
6
- const fipsCode = Object.keys(supportedStatesFipsCodes).find(key => supportedStatesFipsCodes[key] === stateName)
7
- return { stateName, fipsCode }
8
- }
@@ -1,18 +0,0 @@
1
- import { generateColorsArray } from '../generateColorsArray'
2
-
3
- describe('generateColorsArray', () => {
4
- it('should return an array of colors', () => {
5
- const colors = generateColorsArray('#fde0dd', false)
6
- expect(colors).toEqual(expect.arrayContaining(['#fde0dd', '#ffd0c9', '#edd1ce']))
7
- })
8
-
9
- it('should return a brighter hover color when special flag is true', () => {
10
- const colors = generateColorsArray('#fde0dd', true)
11
- expect(colors[1]).toEqual('#fffaf7')
12
- })
13
-
14
- it('should return a darker color for the third element in the array', () => {
15
- const colors = generateColorsArray('#fde0dd', false)
16
- expect(colors[2]).toBe('#edd1ce')
17
- })
18
- })
@@ -1,11 +0,0 @@
1
- import { generateRuntimeLegendHash } from '../generateRuntimeLegendHash'
2
- import usaExample from './../../../examples/default-usa.json'
3
-
4
- describe('generateRuntimeLegendHash', () => {
5
- it('should return a hash value for a given state and runtime filters', () => {
6
- const runtimeFilters = []
7
- const expectedHash = 1253406922
8
- const result = generateRuntimeLegendHash(usaExample, runtimeFilters)
9
- expect(result).toBe(expectedHash)
10
- })
11
- })