@cdc/map 4.25.1 → 4.25.2-25

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.
@@ -2,29 +2,39 @@ import React from 'react'
2
2
 
3
3
  type TerritoriesSectionProps = {
4
4
  territories: JSX.Element[]
5
+ // Keys of the territories to display
6
+ territoresData: string[]
5
7
  logo: string
6
8
  config: any
7
9
  }
8
10
 
9
- const TerritoriesSection: React.FC<TerritoriesSectionProps> = ({ territories, logo, config }) => {
11
+ const TerritoriesSection: React.FC<TerritoriesSectionProps> = ({ territories, logo, config, territoriesData }) => {
12
+ // filter territioriesData into the two groups below
13
+ const freelyAssociatedKeys = territoriesData.filter(territory => {
14
+ return ['US-FM', 'US-MH', 'US-PW'].includes(territory)
15
+ })
16
+ const usTerritoriesKeys = territoriesData.filter(territory => {
17
+ return ['US-AS', 'US-GU', 'US-MP', 'US-PR', 'US-VI'].includes(territory)
18
+ })
19
+
10
20
  const usTerritories = territories
11
21
  .filter(territory => {
12
- return ['US-AS', 'US-GU', 'US-MP', 'US-PR', 'US-VI'].includes(territory?.props?.territory)
22
+ return usTerritoriesKeys.includes(`US-${territory?.props?.label}`)
13
23
  })
14
24
  .sort((a, b) => {
15
- return a.props.territory.localeCompare(b.props.territory)
25
+ return a.props.label.localeCompare(b.props.label)
16
26
  })
17
27
 
18
28
  const freelyAssociatedStates = territories
19
29
  .filter(territory => {
20
- return ['US-FM', 'US-MH', 'US-PW'].includes(territory?.props?.territory)
30
+ return freelyAssociatedKeys.includes(`US-${territory?.props?.label}`)
21
31
  })
22
32
  .sort((a, b) => {
23
- return a.props.territory.localeCompare(b.props.territory)
33
+ return a.props.label.localeCompare(b.props.label)
24
34
  })
25
35
 
26
36
  return (
27
- territories.length > 0 && (
37
+ territoriesData.length > 0 && (
28
38
  <>
29
39
  {/* Temporarily make the max width fit the image width */}
30
40
  <div>
@@ -34,13 +44,13 @@ const TerritoriesSection: React.FC<TerritoriesSectionProps> = ({ territories, lo
34
44
  )}
35
45
  </div>
36
46
  <div>
37
- {usTerritories.length > 0 && (
47
+ {(usTerritories.length > 0 || config.general.territoriesAlwaysShow) && (
38
48
  <>
39
49
  <h5 className='territories-label'>U.S. Territories</h5>
40
50
  <span className='mt-1 mb-2 d-flex flex-wrap territories'>{usTerritories}</span>
41
51
  </>
42
52
  )}
43
- {freelyAssociatedStates.length > 0 && (
53
+ {(freelyAssociatedStates.length > 0 || config.general.territoriesAlwaysShow) && (
44
54
  <>
45
55
  <h5 className='territories-label'>Freely Associated States</h5>
46
56
  <span className='mt-1 mb-2 d-flex flex-wrap territories'>{freelyAssociatedStates}</span>
@@ -52,7 +52,7 @@ const TerritoryHexagon = ({
52
52
  const hexagonLabel = (geo, bgColor = '#FFFFFF', projection) => {
53
53
  let centroid = projection ? projection(geoCentroid(geo)) : [22, 17.5]
54
54
 
55
- let abbr = geo?.properties?.iso ? geo.properties.iso : geo.uid
55
+ let abbr = geo?.properties?.iso ? geo.properties.iso : geo?.uid ? geo.uid : `US-${label}`
56
56
 
57
57
  const getArrowDirection = (geoData, geo, isTerritory = false) => {
58
58
  if (!isTerritory) {
@@ -63,19 +63,20 @@ const TerritoryHexagon = ({
63
63
  <>
64
64
  {state.hexMap.shapeGroups.map((group, groupIndex) => {
65
65
  return group.items.map((item, itemIndex) => {
66
+ if (!geoData) return
66
67
  switch (item.operator) {
67
68
  case '=':
68
- if (geoData[item.key] === item.value || Number(geoData[item.key]) === Number(item.value)) {
69
+ if (geoData?.[item.key] === item.value || Number(geoData[item.key]) === Number(item.value)) {
69
70
  return <HexIcon item={item} index={itemIndex} centroid={centroid} isTerritory />
70
71
  }
71
72
  break
72
73
  case '≠':
73
- if (geoData[item.key] !== item.value && Number(geoData[item.key]) !== Number(item.value)) {
74
+ if (geoData?.[item.key] !== item.value && Number(geoData[item.key]) !== Number(item.value)) {
74
75
  return <HexIcon item={item} index={itemIndex} centroid={centroid} isTerritory />
75
76
  }
76
77
  break
77
78
  case '<':
78
- if (Number(geoData[item.key]) < Number(item.value)) {
79
+ if (Number(geoData?.[item.key]) < Number(item.value)) {
79
80
  return <HexIcon item={item} index={itemIndex} centroid={centroid} isTerritory />
80
81
  }
81
82
  break
@@ -175,18 +176,16 @@ const TerritoryHexagon = ({
175
176
  }
176
177
 
177
178
  return (
178
- territoryData && (
179
- <svg viewBox='-1 -1 46 53' className='territory-wrapper--hex'>
180
- <g {...props} data-tooltip-html={dataTooltipHtml} data-tooltip-id={dataTooltipId} onClick={handleShapeClick}>
181
- <polygon
182
- stroke={stroke}
183
- strokeWidth={strokeWidth}
184
- points='22 0 44 12.702 44 38.105 22 50.807 0 38.105 0 12.702'
185
- />
186
- {state.general.displayAsHex && hexagonLabel(territoryData, stroke, false)}
187
- </g>
188
- </svg>
189
- )
179
+ <svg viewBox='-1 -1 46 53' className='territory-wrapper--hex'>
180
+ <g {...props} data-tooltip-html={dataTooltipHtml} data-tooltip-id={dataTooltipId} onClick={handleShapeClick}>
181
+ <polygon
182
+ stroke={stroke}
183
+ strokeWidth={strokeWidth}
184
+ points='22 0 44 12.702 44 38.105 22 50.807 0 38.105 0 12.702'
185
+ />
186
+ {state.general.displayAsHex && hexagonLabel(territoryData, stroke, false)}
187
+ </g>
188
+ </svg>
190
189
  )
191
190
  }
192
191
 
@@ -597,7 +597,7 @@ const UsaMap = () => {
597
597
  {annotations.length > 0 && <Annotation.Draggable onDragStateChange={handleDragStateChange} />}
598
598
  </svg>
599
599
 
600
- <TerritoriesSection territories={territories} logo={logo} config={state} />
600
+ <TerritoriesSection territories={territories} logo={logo} config={state} territoriesData={territoriesData} />
601
601
  </ErrorBoundary>
602
602
  )
603
603
  }