@cdc/map 4.25.11 → 4.26.1

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 (44) hide show
  1. package/dist/cdcmap.js +29879 -29091
  2. package/examples/private/city_styles_variable.json +877 -0
  3. package/examples/private/map-filter-issue.json +2260 -0
  4. package/examples/private/map-legend.json +5303 -0
  5. package/index.html +27 -37
  6. package/package.json +5 -4
  7. package/src/CdcMapComponent.tsx +42 -6
  8. package/src/_stories/CdcMap.Editor.stories.tsx +92 -37
  9. package/src/_stories/CdcMap.stories.tsx +94 -0
  10. package/src/_stories/_mock/usa-state-gradient.json +1 -0
  11. package/src/components/CityList.tsx +24 -18
  12. package/src/components/EditorPanel/components/EditorPanel.tsx +2320 -2212
  13. package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +0 -19
  14. package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.tsx +14 -17
  15. package/src/components/Legend/components/Legend.tsx +24 -41
  16. package/src/components/Legend/components/LegendGroup/Legend.Group.tsx +1 -1
  17. package/src/components/Legend/components/index.scss +22 -5
  18. package/src/components/UsaMap/components/Territory/Territory.Rectangle.tsx +6 -5
  19. package/src/components/UsaMap/components/Territory/TerritoryShape.ts +1 -0
  20. package/src/components/UsaMap/components/UsaMap.County.tsx +2 -2
  21. package/src/components/UsaMap/components/UsaMap.SingleState.tsx +4 -7
  22. package/src/components/UsaMap/components/UsaMap.State.tsx +4 -2
  23. package/src/data/initial-state.js +1 -0
  24. package/src/helpers/applyLegendToRow.ts +5 -3
  25. package/src/helpers/constants.ts +2 -0
  26. package/src/helpers/displayGeoName.ts +8 -5
  27. package/src/helpers/generateRuntimeFilters.ts +1 -1
  28. package/src/helpers/generateRuntimeLegend.ts +1 -1
  29. package/src/helpers/generateRuntimeLegendHash.ts +1 -1
  30. package/src/helpers/index.ts +9 -3
  31. package/src/helpers/isLegendItemDisabled.ts +2 -2
  32. package/src/helpers/resetLegendToggles.ts +1 -0
  33. package/src/helpers/tests/hashObj.test.ts +1 -1
  34. package/src/helpers/toggleLegendActive.ts +76 -8
  35. package/src/hooks/useResizeObserver.ts +3 -0
  36. package/src/hooks/useStateZoom.tsx +2 -2
  37. package/src/test/CdcMap.test.jsx +1 -1
  38. package/src/types/MapConfig.ts +2 -0
  39. package/src/types/runtimeLegend.ts +1 -0
  40. package/LICENSE +0 -201
  41. package/src/components/MapControls.tsx +0 -44
  42. package/src/helpers/getUniqueValues.ts +0 -19
  43. package/src/helpers/hashObj.ts +0 -25
  44. package/src/hooks/useLegendSeparators.ts +0 -26
@@ -4,8 +4,7 @@ import { GlyphCircle, GlyphDiamond, GlyphSquare, GlyphStar, GlyphTriangle } from
4
4
  import ConfigContext from '../context'
5
5
  import { useLegendMemoContext } from '../context/LegendMemoContext'
6
6
  import { supportedCities } from '../data/supported-geos'
7
- import { getFilterControllingStatesPicked } from './UsaMap/helpers/map'
8
- import { displayGeoName, getGeoStrokeColor, SVG_HEIGHT, SVG_PADDING, SVG_WIDTH, isLegendItemDisabled } from '../helpers'
7
+ import { displayGeoName, getGeoStrokeColor, isLegendItemDisabled } from '../helpers'
9
8
  import useGeoClickHandler from '../hooks/useGeoClickHandler'
10
9
  import useApplyTooltipsToGeo from '../hooks/useApplyTooltipsToGeo'
11
10
  import { applyLegendToRow } from '../helpers/applyLegendToRow'
@@ -19,7 +18,7 @@ type CityListProps = {
19
18
  }
20
19
 
21
20
  const CityList: React.FC<CityListProps> = ({ setSharedFilterValue, isFilterValueSupported, tooltipId, projection }) => {
22
- const { config, topoData, runtimeData, position, runtimeLegend } = useContext(ConfigContext)
21
+ const { config, runtimeData, position, runtimeLegend } = useContext(ConfigContext)
23
22
  const { legendMemo, legendSpecialClassLastMemo } = useLegendMemoContext()
24
23
  const { geoClickHandler } = useGeoClickHandler()
25
24
  const { applyTooltipsToGeo } = useApplyTooltipsToGeo()
@@ -146,20 +145,12 @@ const CityList: React.FC<CityListProps> = ({ setSharedFilterValue, isFilterValue
146
145
  }
147
146
 
148
147
  if (geoData?.[longitudeColumnName] && geoData?.[latitudeColumnName] && config.general.geoType === 'single-state') {
149
- const statesPicked = getFilterControllingStatesPicked(config, runtimeData)
150
- const _statesPickedData = (topoData as any)?.states?.find(s => statesPicked.includes(s.properties.name))
151
-
152
- const newProjection = projection.fitExtent(
153
- [
154
- [SVG_PADDING, SVG_PADDING],
155
- [SVG_WIDTH - SVG_PADDING, SVG_HEIGHT - SVG_PADDING]
156
- ],
157
- _statesPickedData
158
- )
159
- let coords = [Number(geoData?.[longitudeColumnName]), Number(geoData?.[latitudeColumnName])]
160
- transform = `translate(${newProjection(coords)}) scale(${
161
- config.visual.geoCodeCircleSize / ((position as any).zoom > 1 ? (position as any).zoom : 1)
162
- })`
148
+ // For single-state maps, the projection passed in is already fitted from CustomProjection
149
+ // We just need to project the coordinates and apply zoom adjustment
150
+ const coords = [Number(geoData?.[longitudeColumnName]), Number(geoData?.[latitudeColumnName])]
151
+ const projectedCoords = projection(coords)
152
+ const zoomScale = (position as any).zoom > 1 ? 1 / (position as any).zoom : 1
153
+ transform = `translate(${projectedCoords}) scale(${zoomScale})`
163
154
  needsPointer = true
164
155
  }
165
156
 
@@ -216,10 +207,25 @@ const CityList: React.FC<CityListProps> = ({ setSharedFilterValue, isFilterValue
216
207
  triangle: <GlyphTriangle {...shapeProps} />
217
208
  }
218
209
 
210
+ // Check if this city matches any additionalCityStyles
211
+ let shapeToUse = config.visual.cityStyle?.toLowerCase() || 'circle'
212
+ if (config.visual.additionalCityStyles && config.visual.additionalCityStyles.length > 0) {
213
+ for (const style of config.visual.additionalCityStyles) {
214
+ if (style.column && style.value && style.shape) {
215
+ const columnValue = geoData[style.column]
216
+ // Convert both to strings for comparison to handle different data types
217
+ if (String(columnValue) === String(style.value)) {
218
+ shapeToUse = style.shape.toLowerCase()
219
+ break
220
+ }
221
+ }
222
+ }
223
+ }
224
+
219
225
  // Render the city marker
220
226
  return (
221
227
  <g key={i} transform={transform} style={styles} className='geo-point' tabIndex={-1}>
222
- {cityStyleShapes[config.visual.cityStyle?.toLowerCase() || 'circle']}
228
+ {cityStyleShapes[shapeToUse]}
223
229
  </g>
224
230
  )
225
231
  })