@defra/interactive-map 0.0.52-alpha → 0.0.54-alpha
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.
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/context.md +30 -12
- package/docs/api/marker-config.md +16 -8
- package/docs/api/symbol-config.md +24 -9
- package/docs/api/symbol-registry.md +49 -14
- package/docs/api.md +11 -3
- package/docs/plugins/datasets.md +6 -10
- package/docs/plugins/draw.md +2 -1
- package/docs/plugins/map-key.md +47 -4
- package/package.json +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
- package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +10 -10
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +22 -6
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +20 -27
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +16 -70
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +30 -115
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +101 -13
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +27 -28
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +51 -32
- package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
- package/plugins/datasets/src/initialise/defaults.js +16 -27
- package/plugins/datasets/src/initialise/defaults.test.js +25 -57
- package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
- package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
- package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
- package/plugins/datasets/src/registry/dataset.js +23 -17
- package/plugins/datasets/src/registry/dataset.test.js +114 -11
- package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
- package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +7 -5
- package/plugins/draw/src/DrawInit.test.jsx +18 -2
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
- package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
- package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
- package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
- package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
- package/plugins/draw/src/defaults.js +2 -6
- package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
- package/plugins/draw/src/utils/symbolKeys.js +3 -4
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/map-key/dist/css/index.css +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/map-key/src/components/Key/Key.jsx +8 -4
- package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
- package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +36 -3
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
- package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +19 -18
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +25 -18
- package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
- package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
- package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
- package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
- package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
- package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
- package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
- package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
- package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
- package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
- package/plugins/map-key/src/index.js +34 -0
- package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
- package/plugins/map-key/src/registry/index.js +0 -2
- package/plugins/map-key/src/registry/index.test.js +1 -9
- package/plugins/map-key/src/utils/groupStyles.js +5 -2
- package/plugins/menu/src/registry/index.js +0 -2
- package/plugins/menu/src/registry/index.test.js +1 -9
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/plugins/search/src/Search.jsx +0 -1
- package/plugins/search/src/components/Form/Form.jsx +3 -3
- package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
- package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
- package/plugins/search/src/defaults.js +3 -0
- package/plugins/search/src/events/formHandlers.js +3 -9
- package/plugins/search/src/events/formHandlers.test.js +6 -9
- package/plugins/search/src/events/inputHandlers.js +8 -2
- package/plugins/search/src/events/inputHandlers.test.js +20 -0
- package/plugins/search/src/events/suggestionHandlers.js +3 -5
- package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
- package/plugins/search/src/utils/showResult.js +9 -0
- package/plugins/search/src/utils/showResult.test.js +16 -0
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
- package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
- package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
- package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
- package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
- package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
- package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
- package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
- package/providers/mapProvider.js +53 -1
- package/providers/mapProvider.test.js +6 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +50 -17
- package/providers/maplibre/src/maplibreProvider.test.js +74 -20
- package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
- package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
- package/providers/maplibre/src/utils/patternImages.js +46 -29
- package/providers/maplibre/src/utils/patternImages.test.js +52 -4
- package/providers/maplibre/src/utils/symbolImages.js +80 -39
- package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
- package/src/App/components/Hints/Hints.module.scss +1 -1
- package/src/App/components/Markers/Markers.jsx +16 -25
- package/src/App/components/Markers/Markers.test.jsx +34 -48
- package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
- package/src/App/components/Markers/SymbolMarker.jsx +1 -1
- package/src/App/components/Viewport/Viewport.jsx +6 -4
- package/src/App/components/Viewport/Viewport.test.jsx +18 -1
- package/src/App/hooks/useMapAnnouncements.js +7 -2
- package/src/App/hooks/useMapAnnouncements.test.js +13 -2
- package/src/App/hooks/useModalPanelBehaviour.js +3 -1
- package/src/App/initialiseApp.js +1 -1
- package/src/App/store/ServiceProvider.jsx +12 -3
- package/src/App/store/ServiceProvider.test.jsx +39 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -3
- package/src/config/appConfig.js +1 -5
- package/src/config/mapSizeScales.js +8 -0
- package/src/config/symbolConfig.js +101 -25
- package/src/services/mapFocus.js +64 -0
- package/src/services/mapFocus.test.js +76 -0
- package/src/services/patternRegistry.js +97 -76
- package/src/services/patternRegistry.test.js +19 -1
- package/src/services/symbolComposer.js +184 -0
- package/src/services/symbolComposer.test.js +132 -0
- package/src/services/symbolRegistry.js +326 -155
- package/src/services/symbolRegistry.test.js +334 -32
- package/src/types.js +11 -5
- package/src/utils/detectInterfaceType.js +16 -5
- package/src/utils/detectInterfaceType.test.js +32 -0
- package/src/utils/hashString.js +23 -0
- package/src/utils/hashString.test.js +29 -0
- package/src/utils/imageDataCache.js +43 -0
- package/src/utils/imageDataCache.test.js +38 -0
- package/src/utils/pathBounds.js +330 -0
- package/src/utils/pathBounds.test.js +145 -0
- package/src/utils/patternUtils.js +0 -8
- package/src/utils/patternUtils.test.js +0 -25
- package/src/utils/recentImageSets.js +35 -0
- package/src/utils/recentImageSets.test.js +46 -0
- package/src/utils/symbolUtils.js +26 -29
- package/src/utils/symbolUtils.test.js +27 -41
- package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
|
@@ -1,16 +1,49 @@
|
|
|
1
|
+
import { useRef } from 'react'
|
|
2
|
+
import { getValueForStyle } from '../../../../../src/utils/getValueForStyle.js'
|
|
3
|
+
import { hasSymbol } from '../../../../../src/utils/symbolUtils.js'
|
|
1
4
|
import { KeyItem } from './KeyItem.jsx'
|
|
5
|
+
import { RAMP } from '../../utils/groupStyles.js'
|
|
6
|
+
import { useRampOrientation } from './useRampOrientation.js'
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
8
|
+
const getListClassName = (groupStyle, orientation, hasStroke) => {
|
|
9
|
+
if (!groupStyle) {
|
|
10
|
+
return 'im-c-map-key-list'
|
|
11
|
+
}
|
|
12
|
+
const className = `im-c-map-key-list im-c-map-key-list--${groupStyle}`
|
|
13
|
+
if (groupStyle !== RAMP) {
|
|
14
|
+
return className
|
|
15
|
+
}
|
|
16
|
+
// Stroked ramp bands are separated by a gap; unstroked bands butt up to each other
|
|
17
|
+
const rampClassName = `${className} im-c-map-key-list--ramp-${orientation}`
|
|
18
|
+
return hasStroke ? `${rampClassName} im-c-map-key-list--has-stroke` : rampClassName
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// A ramp's bands stretch to fill their row or column, which point symbols can't, so a ramp
|
|
22
|
+
// group with any symbol entries is shown as a standard group
|
|
23
|
+
const getGroupStyle = (groupStyle, keyDefinitions) =>
|
|
24
|
+
groupStyle === RAMP && keyDefinitions.some(keyDefinition => hasSymbol(keyDefinition.style))
|
|
25
|
+
? undefined
|
|
26
|
+
: groupStyle
|
|
27
|
+
|
|
28
|
+
export const KeyGroupItem = ({ headingId, label, groupStyle: configuredGroupStyle, keyDefinitions, mapStyle, symbolRegistry, patternRegistry }) => {
|
|
29
|
+
const listRef = useRef(null)
|
|
30
|
+
const groupStyle = getGroupStyle(configuredGroupStyle, keyDefinitions)
|
|
31
|
+
const isRamp = groupStyle === RAMP
|
|
32
|
+
const hasStroke = isRamp &&
|
|
33
|
+
keyDefinitions.some(keyDefinition => getValueForStyle(keyDefinition.style?.stroke, mapStyle.id))
|
|
34
|
+
const orientation = useRampOrientation(listRef, keyDefinitions.map(keyDefinition => keyDefinition.label ?? ''), isRamp, hasStroke)
|
|
35
|
+
const className = getListClassName(groupStyle, orientation, hasStroke)
|
|
5
36
|
return (
|
|
6
37
|
<section className='im-c-map-key__group' aria-labelledby={headingId}>
|
|
7
38
|
<h3 id={headingId} className='im-c-map-key__group-heading'>{label}</h3>
|
|
8
|
-
<dl className={className}>
|
|
39
|
+
<dl ref={listRef} className={className}>
|
|
9
40
|
{keyDefinitions.map(keyDefinition =>
|
|
10
41
|
<KeyItem
|
|
11
42
|
key={`${keyDefinition.id}`}
|
|
12
43
|
keyDefinition={keyDefinition}
|
|
13
44
|
mapStyle={mapStyle}
|
|
45
|
+
symbolRegistry={symbolRegistry}
|
|
46
|
+
patternRegistry={patternRegistry}
|
|
14
47
|
groupStyle={groupStyle}
|
|
15
48
|
/>
|
|
16
49
|
)}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { render, screen } from '@testing-library/react'
|
|
2
2
|
import { KeyGroupItem } from './KeyGroupItem'
|
|
3
|
+
import { useRampOrientation } from './useRampOrientation.js'
|
|
4
|
+
|
|
5
|
+
jest.mock('./useRampOrientation.js', () => ({
|
|
6
|
+
useRampOrientation: jest.fn(() => 'horizontal')
|
|
7
|
+
}))
|
|
3
8
|
|
|
4
9
|
jest.mock('./KeyItem.jsx', () => ({
|
|
5
10
|
KeyItem: ({ keyDefinition }) => <div data-testid='key-item'>{keyDefinition.id}</div>
|
|
@@ -52,8 +57,45 @@ describe('KeyGroupItem', () => {
|
|
|
52
57
|
})
|
|
53
58
|
|
|
54
59
|
it('appends the groupStyle modifier class to the dl when groupStyle is provided', () => {
|
|
55
|
-
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='
|
|
56
|
-
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list
|
|
60
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='other' />)
|
|
61
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--other')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('adds the measured orientation to a ramp', () => {
|
|
65
|
+
const keyDefinitions = [{ id: 'a', label: 'Low', style: {} }, { id: 'b', label: 'High', style: {} }]
|
|
66
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
67
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-horizontal')
|
|
68
|
+
expect(useRampOrientation).toHaveBeenLastCalledWith(expect.anything(), ['Low', 'High'], true, false)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('renders a vertical ramp when the labels do not fit', () => {
|
|
72
|
+
useRampOrientation.mockReturnValueOnce('vertical')
|
|
73
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' />)
|
|
74
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-vertical')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('shows a ramp with any symbol entries as a standard group', () => {
|
|
78
|
+
const keyDefinitions = [{ id: 'a', label: 'Low', style: { fill: '#000' } }, { id: 'b', label: 'High', style: { symbol: 'pin' } }]
|
|
79
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
80
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list')
|
|
81
|
+
expect(useRampOrientation).toHaveBeenLastCalledWith(expect.anything(), ['Low', 'High'], false, false)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('does not measure groups that are not ramps', () => {
|
|
85
|
+
render(<KeyGroupItem {...baseProps} />)
|
|
86
|
+
expect(useRampOrientation).toHaveBeenLastCalledWith(expect.anything(), [], false, false)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('adds the has-stroke modifier to a ramp when any item has a stroke', () => {
|
|
90
|
+
const keyDefinitions = [{ id: 'a', style: { fill: '#000' } }, { id: 'b', style: { stroke: { default: '#123' } } }]
|
|
91
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
92
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-horizontal im-c-map-key-list--has-stroke')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('omits the has-stroke modifier when no ramp item has a stroke', () => {
|
|
96
|
+
const keyDefinitions = [{ id: 'a', style: { fill: '#000' } }, { id: 'b', style: { fillPattern: 'dot' } }]
|
|
97
|
+
const { container } = render(<KeyGroupItem {...baseProps} groupStyle='ramp' keyDefinitions={keyDefinitions} />)
|
|
98
|
+
expect(container.querySelector('dl').className).toBe('im-c-map-key-list im-c-map-key-list--ramp im-c-map-key-list--ramp-horizontal')
|
|
57
99
|
})
|
|
58
100
|
|
|
59
101
|
it('uses the base dl class when groupStyle is not provided', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getValueForStyle } from '../../../../../src/utils/getValueForStyle.js'
|
|
2
2
|
import { KeySvg } from './KeySvg.jsx'
|
|
3
3
|
|
|
4
|
-
export const KeyItem = ({ keyDefinition, groupStyle, mapStyle }) => {
|
|
4
|
+
export const KeyItem = ({ keyDefinition, groupStyle, mapStyle, symbolRegistry, patternRegistry }) => {
|
|
5
5
|
// Pure derivations of props — computed directly on every render rather than staged through
|
|
6
6
|
// useState/useEffect, so there's no post-mount frame where the label/description are blank
|
|
7
7
|
// (every panel reopen mounts this fresh, so that frame was visible as a flicker).
|
|
@@ -11,7 +11,7 @@ export const KeyItem = ({ keyDefinition, groupStyle, mapStyle }) => {
|
|
|
11
11
|
return (
|
|
12
12
|
<div className='im-c-map-key-list__item'>
|
|
13
13
|
<dt className='im-c-map-key-list__item-symbol'>
|
|
14
|
-
<KeySvg keyDefinition={keyDefinition} groupStyle={groupStyle} mapStyle={mapStyle} />
|
|
14
|
+
<KeySvg keyDefinition={keyDefinition} groupStyle={groupStyle} mapStyle={mapStyle} symbolRegistry={symbolRegistry} patternRegistry={patternRegistry} />
|
|
15
15
|
</dt>
|
|
16
16
|
<dd className='im-c-map-key-list__item-label'>
|
|
17
17
|
{label}
|
|
@@ -3,46 +3,47 @@ import { KeySvgSymbol } from './KeySvgSymbol.jsx'
|
|
|
3
3
|
import { KeySvgLine } from './KeySvgLine.jsx'
|
|
4
4
|
import { KeySvgRect } from './KeySvgRect.jsx'
|
|
5
5
|
import { KeySvgRamp } from './KeySvgRamp.jsx'
|
|
6
|
-
import {
|
|
7
|
-
import { HORIZONTAL_RAMP } from '../../utils/groupStyles.js'
|
|
6
|
+
import { RAMP } from '../../utils/groupStyles.js'
|
|
8
7
|
|
|
9
8
|
// Pure derivation of keyDefinition — computed directly during render (see KeyItem.jsx for why:
|
|
10
9
|
// staging this through useState/useEffect meant every fresh mount painted a blank symbol first).
|
|
11
10
|
|
|
12
|
-
const getSymbolShape = (keyDefinition, groupStyle) => {
|
|
11
|
+
const getSymbolShape = (keyDefinition, groupStyle, mapStyle, symbolRegistry) => {
|
|
13
12
|
if (!keyDefinition) {
|
|
14
|
-
return { symbolShape: null,
|
|
13
|
+
return { symbolShape: null, keySymbol: null }
|
|
15
14
|
}
|
|
16
15
|
const { hasSymbol, hasPattern, style } = keyDefinition
|
|
17
|
-
if (groupStyle ===
|
|
18
|
-
return { symbolShape:
|
|
16
|
+
if (groupStyle === RAMP) {
|
|
17
|
+
return { symbolShape: RAMP, keySymbol: null }
|
|
19
18
|
}
|
|
20
19
|
if (hasSymbol) {
|
|
21
|
-
const
|
|
22
|
-
return { symbolShape:
|
|
20
|
+
const keySymbol = symbolRegistry.getKeySymbol(style, mapStyle)
|
|
21
|
+
return { symbolShape: keySymbol ? 'symbol' : 'rect', keySymbol }
|
|
23
22
|
}
|
|
24
23
|
if (hasPattern) {
|
|
25
|
-
return { symbolShape: 'pattern',
|
|
24
|
+
return { symbolShape: 'pattern', keySymbol: null }
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// Inferred from the style: a stroke with no fill at all is a line; any fill — including
|
|
27
|
+
// 'transparent' or 'none', for an outline-only shape — is a shape.
|
|
28
|
+
if (style.fill == null && style.stroke) {
|
|
29
|
+
return { symbolShape: 'line', keySymbol: null }
|
|
29
30
|
}
|
|
30
|
-
return { symbolShape: 'rect',
|
|
31
|
+
return { symbolShape: 'rect', keySymbol: null }
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export const KeySvg = ({ keyDefinition, groupStyle, mapStyle }) => {
|
|
34
|
-
const { symbolShape,
|
|
34
|
+
export const KeySvg = ({ keyDefinition, groupStyle, mapStyle, symbolRegistry, patternRegistry }) => {
|
|
35
|
+
const { symbolShape, keySymbol } = getSymbolShape(keyDefinition, groupStyle, mapStyle, symbolRegistry)
|
|
35
36
|
|
|
36
37
|
if (!symbolShape) {
|
|
37
38
|
return null
|
|
38
39
|
} else if (symbolShape === 'symbol') {
|
|
39
|
-
return <KeySvgSymbol
|
|
40
|
+
return <KeySvgSymbol keySymbol={keySymbol} />
|
|
40
41
|
} else if (symbolShape === 'pattern') {
|
|
41
|
-
return <KeySvgPattern mapStyle={mapStyle} keyDefinition={keyDefinition} />
|
|
42
|
+
return <KeySvgPattern mapStyle={mapStyle} keyDefinition={keyDefinition} patternRegistry={patternRegistry} />
|
|
42
43
|
} else if (symbolShape === 'line') {
|
|
43
44
|
return <KeySvgLine mapStyle={mapStyle} keyDefinition={keyDefinition} />
|
|
44
|
-
} else if (symbolShape ===
|
|
45
|
-
return <KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} />
|
|
45
|
+
} else if (symbolShape === RAMP) {
|
|
46
|
+
return <KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} patternRegistry={patternRegistry} />
|
|
46
47
|
} else {
|
|
47
48
|
return <KeySvgRect mapStyle={mapStyle} keyDefinition={keyDefinition} />
|
|
48
49
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { render } from '@testing-library/react'
|
|
2
2
|
import { KeySvg } from './KeySvg'
|
|
3
|
+
import { createSymbolRegistry } from '../../../../../src/services/symbolRegistry.js'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
const symbolRegistry = createSymbolRegistry()
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const getKeySymbol = jest.spyOn(symbolRegistry, 'getKeySymbol')
|
|
7
8
|
|
|
8
9
|
jest.mock('./KeySvgPattern.jsx', () => ({
|
|
9
10
|
KeySvgPattern: () => <svg data-testid='key-svg-pattern' />
|
|
@@ -22,7 +23,7 @@ jest.mock('./KeySvgRect.jsx', () => ({
|
|
|
22
23
|
}))
|
|
23
24
|
|
|
24
25
|
jest.mock('./KeySvgRamp.jsx', () => ({
|
|
25
|
-
KeySvgRamp: () => <svg data-testid='key-svg-
|
|
26
|
+
KeySvgRamp: () => <svg data-testid='key-svg-ramp' />
|
|
26
27
|
}))
|
|
27
28
|
|
|
28
29
|
const baseKeyDefinition = {
|
|
@@ -33,16 +34,17 @@ const baseKeyDefinition = {
|
|
|
33
34
|
|
|
34
35
|
const baseProps = {
|
|
35
36
|
mapStyle: { id: 'default' },
|
|
36
|
-
keyDefinition: baseKeyDefinition
|
|
37
|
+
keyDefinition: baseKeyDefinition,
|
|
38
|
+
symbolRegistry
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
beforeEach(() => {
|
|
40
|
-
|
|
42
|
+
getKeySymbol.mockReturnValue(null)
|
|
41
43
|
})
|
|
42
44
|
|
|
43
45
|
describe('KeySvg', () => {
|
|
44
|
-
it('renders KeySvgSymbol when a
|
|
45
|
-
|
|
46
|
+
it('renders KeySvgSymbol when the style resolves to a key symbol', () => {
|
|
47
|
+
getKeySymbol.mockReturnValue({ svg: '<path/>', viewBox: '0 0 44 44' })
|
|
46
48
|
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, hasSymbol: true }} />)
|
|
47
49
|
expect(getByTestId('key-svg-symbol')).toBeTruthy()
|
|
48
50
|
})
|
|
@@ -52,36 +54,41 @@ describe('KeySvg', () => {
|
|
|
52
54
|
expect(getByTestId('key-svg-pattern')).toBeTruthy()
|
|
53
55
|
})
|
|
54
56
|
|
|
55
|
-
it('renders KeySvgLine
|
|
56
|
-
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, style: {
|
|
57
|
+
it('renders KeySvgLine for a stroke with no fill, and no symbol or pattern', () => {
|
|
58
|
+
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, style: { stroke: '#b58840' } }} />)
|
|
57
59
|
expect(getByTestId('key-svg-line')).toBeTruthy()
|
|
58
60
|
})
|
|
59
61
|
|
|
62
|
+
it.each(['transparent', 'none', '#ff0000'])('renders KeySvgRect for a stroke with fill %s', (fill) => {
|
|
63
|
+
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, style: { stroke: '#b58840', fill } }} />)
|
|
64
|
+
expect(getByTestId('key-svg-rect')).toBeTruthy()
|
|
65
|
+
})
|
|
66
|
+
|
|
60
67
|
it('renders KeySvgRect as the default fallback', () => {
|
|
61
68
|
const { getByTestId } = render(<KeySvg {...baseProps} />)
|
|
62
69
|
expect(getByTestId('key-svg-rect')).toBeTruthy()
|
|
63
70
|
})
|
|
64
71
|
|
|
65
72
|
it('prefers symbol over pattern when both are present', () => {
|
|
66
|
-
|
|
73
|
+
getKeySymbol.mockReturnValue({ svg: '<path/>', viewBox: '0 0 44 44' })
|
|
67
74
|
const { getByTestId, queryByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, hasSymbol: true, hasPattern: true }} />)
|
|
68
75
|
expect(getByTestId('key-svg-symbol')).toBeTruthy()
|
|
69
76
|
expect(queryByTestId('key-svg-pattern')).toBeNull()
|
|
70
77
|
})
|
|
71
78
|
|
|
72
79
|
it('prefers pattern over line when both conditions are met', () => {
|
|
73
|
-
const { getByTestId, queryByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, hasPattern: true, style: {
|
|
80
|
+
const { getByTestId, queryByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, hasPattern: true, style: { stroke: '#b58840' } }} />)
|
|
74
81
|
expect(getByTestId('key-svg-pattern')).toBeTruthy()
|
|
75
82
|
expect(queryByTestId('key-svg-line')).toBeNull()
|
|
76
83
|
})
|
|
77
84
|
|
|
78
|
-
it('renders KeySvgRect
|
|
79
|
-
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, style: {
|
|
85
|
+
it('renders KeySvgRect for a fill with no stroke', () => {
|
|
86
|
+
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, style: { fill: '#ff0000' } }} />)
|
|
80
87
|
expect(getByTestId('key-svg-rect')).toBeTruthy()
|
|
81
88
|
})
|
|
82
89
|
|
|
83
|
-
it('does not render KeySvgSymbol when hasSymbol is true but
|
|
84
|
-
|
|
90
|
+
it('does not render KeySvgSymbol when hasSymbol is true but there is no key symbol', () => {
|
|
91
|
+
getKeySymbol.mockReturnValue(null)
|
|
85
92
|
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition, hasSymbol: true }} />)
|
|
86
93
|
expect(getByTestId('key-svg-rect')).toBeTruthy()
|
|
87
94
|
})
|
|
@@ -91,8 +98,8 @@ describe('KeySvg', () => {
|
|
|
91
98
|
expect(container.firstChild).toBeNull()
|
|
92
99
|
})
|
|
93
100
|
|
|
94
|
-
it('renders KeySvgRamp when groupStyle is
|
|
95
|
-
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition }} groupStyle='
|
|
96
|
-
expect(getByTestId('key-svg-
|
|
101
|
+
it('renders KeySvgRamp when groupStyle is ramp', () => {
|
|
102
|
+
const { getByTestId } = render(<KeySvg {...baseProps} keyDefinition={{ ...baseKeyDefinition }} groupStyle='ramp' />)
|
|
103
|
+
expect(getByTestId('key-svg-ramp')).toBeTruthy()
|
|
97
104
|
})
|
|
98
105
|
})
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { svgProps } from './svgProperties.js'
|
|
2
|
-
import { patternRegistry } from '../../registry/index.js'
|
|
3
2
|
const PATTERN_INSET = 2
|
|
4
3
|
|
|
5
|
-
export const KeySvgPattern = ({ keyDefinition, mapStyle }) => {
|
|
4
|
+
export const KeySvgPattern = ({ keyDefinition, mapStyle, patternRegistry }) => {
|
|
6
5
|
const { style } = keyDefinition
|
|
7
6
|
const paths = patternRegistry.getKeyPatternPaths(style, mapStyle.id)
|
|
8
7
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { render } from '@testing-library/react'
|
|
2
2
|
import { KeySvgPattern } from './KeySvgPattern'
|
|
3
|
-
import {
|
|
3
|
+
import { createPatternRegistry } from '../../../../../src/services/patternRegistry.js'
|
|
4
|
+
|
|
5
|
+
const patternRegistry = createPatternRegistry()
|
|
4
6
|
|
|
5
7
|
const getKeyPatternPaths = jest.spyOn(patternRegistry, 'getKeyPatternPaths')
|
|
6
8
|
const defaultProps = {
|
|
@@ -1,13 +1,42 @@
|
|
|
1
|
+
import { useId } from 'react'
|
|
1
2
|
import { getValueForStyle } from '../../../../../src/utils/getValueForStyle.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// Matches the 2px border and 16×16 tile inset of the standard pattern key symbol.
|
|
5
|
+
const BORDER_WIDTH = 2
|
|
6
|
+
const PATTERN_TILE_SIZE = 16
|
|
7
|
+
|
|
8
|
+
// No viewBox: the band stretches to its column's width, and a viewBox would scale the
|
|
9
|
+
// pattern tile and stroke with it. Shapes and userSpaceOnUse tiles resolve in real pixels.
|
|
10
|
+
export const KeySvgRamp = ({ mapStyle, keyDefinition, patternRegistry }) => {
|
|
11
|
+
const { style, hasPattern } = keyDefinition
|
|
12
|
+
const patternId = 'im-c-map-key-ramp-' + useId().replace(/[^\w-]/g, '')
|
|
13
|
+
const paths = hasPattern ? patternRegistry.getKeyPatternPaths(style, mapStyle.id) : null
|
|
14
|
+
const stroke = getValueForStyle(style.stroke, mapStyle.id)
|
|
15
|
+
const fill = paths ? `url(#${patternId})` : getValueForStyle(style.fill, mapStyle.id)
|
|
7
16
|
|
|
8
17
|
return (
|
|
9
|
-
<svg
|
|
10
|
-
|
|
18
|
+
<svg xmlns='http://www.w3.org/2000/svg' className='im-c-map-key-symbol' aria-hidden='true' focusable='false'>
|
|
19
|
+
{paths && (
|
|
20
|
+
<defs>
|
|
21
|
+
<pattern
|
|
22
|
+
id={patternId}
|
|
23
|
+
patternUnits='userSpaceOnUse'
|
|
24
|
+
x={BORDER_WIDTH}
|
|
25
|
+
y={BORDER_WIDTH}
|
|
26
|
+
width={PATTERN_TILE_SIZE}
|
|
27
|
+
height={PATTERN_TILE_SIZE}
|
|
28
|
+
dangerouslySetInnerHTML={{ __html: paths.content }}
|
|
29
|
+
/>
|
|
30
|
+
</defs>
|
|
31
|
+
)}
|
|
32
|
+
{/* The stroke is drawn at double width on a flush rect; the svg clips the outer half */}
|
|
33
|
+
<rect
|
|
34
|
+
width='100%'
|
|
35
|
+
height='100%'
|
|
36
|
+
fill={fill || 'none'}
|
|
37
|
+
stroke={stroke}
|
|
38
|
+
strokeWidth={stroke ? BORDER_WIDTH * 2 : undefined}
|
|
39
|
+
/>
|
|
11
40
|
</svg>
|
|
12
41
|
)
|
|
13
42
|
}
|
|
@@ -7,37 +7,77 @@ jest.mock('../../../../../src/utils/getValueForStyle.js', () => ({
|
|
|
7
7
|
}))
|
|
8
8
|
|
|
9
9
|
const mapStyle = { id: 'outdoor' }
|
|
10
|
-
const
|
|
10
|
+
const fillKeyDefinition = { style: { fill: { outdoor: '#3d9', dark: '#1a5' }, stroke: '#123' } }
|
|
11
|
+
const patternKeyDefinition = {
|
|
12
|
+
hasPattern: true,
|
|
13
|
+
style: { fillPattern: 'dot', fillPatternForegroundColor: '#2E7D32' }
|
|
14
|
+
}
|
|
15
|
+
const patternRegistry = {
|
|
16
|
+
getKeyPatternPaths: jest.fn(() => ({ border: '<path/>', content: '<path d="M0 0h1v1H0z" fill="#2E7D32"/>' }))
|
|
17
|
+
}
|
|
11
18
|
|
|
12
19
|
beforeEach(() => {
|
|
20
|
+
jest.clearAllMocks()
|
|
13
21
|
getValueForStyle.mockImplementation((value) =>
|
|
14
22
|
typeof value === 'object' ? value.outdoor : value
|
|
15
23
|
)
|
|
16
24
|
})
|
|
17
25
|
|
|
26
|
+
const renderRamp = (keyDefinition) =>
|
|
27
|
+
render(<KeySvgRamp mapStyle={mapStyle} keyDefinition={keyDefinition} patternRegistry={patternRegistry} />)
|
|
28
|
+
|
|
18
29
|
describe('KeySvgRamp', () => {
|
|
19
|
-
it('renders an svg
|
|
20
|
-
const { container } =
|
|
21
|
-
|
|
30
|
+
it('renders an svg without a viewBox, so the band stretches without distortion', () => {
|
|
31
|
+
const { container } = renderRamp(fillKeyDefinition)
|
|
32
|
+
const svg = container.querySelector('svg')
|
|
33
|
+
expect(svg.getAttribute('viewBox')).toBeNull()
|
|
34
|
+
expect(svg.getAttribute('class')).toBe('im-c-map-key-symbol')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('fills the rect with the resolved fill and strokes it with the resolved stroke', () => {
|
|
38
|
+
const { container } = renderRamp(fillKeyDefinition)
|
|
39
|
+
const rect = container.querySelector('rect')
|
|
40
|
+
expect(rect.getAttribute('fill')).toBe('#3d9')
|
|
41
|
+
expect(rect.getAttribute('stroke')).toBe('#123')
|
|
42
|
+
expect(rect.getAttribute('stroke-width')).toBe('4')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('omits the stroke when none is resolved', () => {
|
|
46
|
+
const { container } = renderRamp({ style: { fill: '#3d9' } })
|
|
47
|
+
const rect = container.querySelector('rect')
|
|
48
|
+
expect(rect.getAttribute('stroke')).toBeNull()
|
|
49
|
+
expect(rect.getAttribute('stroke-width')).toBeNull()
|
|
22
50
|
})
|
|
23
51
|
|
|
24
|
-
it('
|
|
25
|
-
const { container } =
|
|
26
|
-
|
|
52
|
+
it('fills the rect with a userSpaceOnUse pattern tile when the item has a pattern', () => {
|
|
53
|
+
const { container } = renderRamp(patternKeyDefinition)
|
|
54
|
+
const pattern = container.querySelector('pattern')
|
|
55
|
+
const rect = container.querySelector('rect')
|
|
56
|
+
expect(patternRegistry.getKeyPatternPaths).toHaveBeenCalledWith(patternKeyDefinition.style, 'outdoor')
|
|
57
|
+
expect(pattern.getAttribute('patternUnits')).toBe('userSpaceOnUse')
|
|
58
|
+
expect(pattern.getAttribute('width')).toBe('16')
|
|
59
|
+
expect(pattern.querySelector('path')).toBeTruthy()
|
|
60
|
+
expect(rect.getAttribute('fill')).toBe(`url(#${pattern.id})`)
|
|
27
61
|
})
|
|
28
62
|
|
|
29
|
-
it('
|
|
30
|
-
const { container } =
|
|
31
|
-
expect(container.querySelector('
|
|
63
|
+
it('draws no stroke on a pattern without a stroke', () => {
|
|
64
|
+
const { container } = renderRamp(patternKeyDefinition)
|
|
65
|
+
expect(container.querySelector('rect').getAttribute('stroke')).toBeNull()
|
|
32
66
|
})
|
|
33
67
|
|
|
34
|
-
it('
|
|
35
|
-
const { container } = render(
|
|
36
|
-
|
|
68
|
+
it('gives each band its own pattern id', () => {
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<>
|
|
71
|
+
<KeySvgRamp mapStyle={mapStyle} keyDefinition={patternKeyDefinition} patternRegistry={patternRegistry} />
|
|
72
|
+
<KeySvgRamp mapStyle={mapStyle} keyDefinition={patternKeyDefinition} patternRegistry={patternRegistry} />
|
|
73
|
+
</>
|
|
74
|
+
)
|
|
75
|
+
const [a, b] = container.querySelectorAll('pattern')
|
|
76
|
+
expect(a.id).not.toBe(b.id)
|
|
37
77
|
})
|
|
38
78
|
|
|
39
|
-
it('
|
|
40
|
-
const { container } =
|
|
41
|
-
expect(container.querySelector('
|
|
79
|
+
it('uses no fill when neither a fill nor a pattern is set', () => {
|
|
80
|
+
const { container } = renderRamp({ style: { stroke: '#123' } })
|
|
81
|
+
expect(container.querySelector('rect').getAttribute('fill')).toBe('none')
|
|
42
82
|
})
|
|
43
83
|
})
|
|
@@ -1,21 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { svgSymbolProps } from './svgProperties.js'
|
|
3
|
-
import { symbolRegistry } from '../../registry/index.js'
|
|
1
|
+
import { svgSymbolProps, SVG_SYMBOL_SIZE, KEY_SYMBOL_MAX_SIZE } from './svgProperties.js'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
const { style } = keyDefinition
|
|
7
|
-
const mapColorScheme = mapStyle?.appColorScheme ?? 'light'
|
|
8
|
-
const keyMapStyle = { ...mapStyle, mapColorScheme }
|
|
9
|
-
const resolvedSvg = symbolRegistry.resolve(symbolDef, getSymbolStyleColors(style), keyMapStyle)
|
|
10
|
-
const viewBox = getSymbolViewBox(style, symbolDef)
|
|
3
|
+
const HALF = 0.5
|
|
11
4
|
|
|
12
|
-
|
|
5
|
+
// keySymbol is symbolRegistry.getKeySymbol's { svg, viewBox }
|
|
6
|
+
export const KeySvgSymbol = ({ keySymbol }) => {
|
|
7
|
+
const { svg, viewBox } = keySymbol ?? {}
|
|
8
|
+
if (!(svg && viewBox)) {
|
|
13
9
|
return null
|
|
14
10
|
}
|
|
15
11
|
|
|
12
|
+
// Drawn 1:1 (one viewBox unit per pixel, as on the map) and centred in the key's fixed square.
|
|
13
|
+
// Symbols vary in size (pin's tail, triangle's width), so the square lets them overflow it
|
|
14
|
+
// rather than shrinking the larger ones; only a symbol bigger than KEY_SYMBOL_MAX_SIZE is
|
|
15
|
+
// scaled down. The nested svg clips to the symbol's own viewBox, the same as on the map.
|
|
16
|
+
const [,, width, height] = viewBox.split(' ').map(Number)
|
|
17
|
+
const scale = Math.min(1, KEY_SYMBOL_MAX_SIZE / Math.max(width, height))
|
|
18
|
+
const drawnWidth = width * scale
|
|
19
|
+
const drawnHeight = height * scale
|
|
20
|
+
|
|
16
21
|
return (
|
|
17
|
-
<svg {...svgSymbolProps}
|
|
18
|
-
<
|
|
22
|
+
<svg {...svgSymbolProps} overflow='visible'>
|
|
23
|
+
<svg
|
|
24
|
+
x={(SVG_SYMBOL_SIZE - drawnWidth) * HALF}
|
|
25
|
+
y={(SVG_SYMBOL_SIZE - drawnHeight) * HALF}
|
|
26
|
+
width={drawnWidth}
|
|
27
|
+
height={drawnHeight}
|
|
28
|
+
viewBox={viewBox}
|
|
29
|
+
overflow='hidden'
|
|
30
|
+
>
|
|
31
|
+
<g dangerouslySetInnerHTML={{ __html: svg }} />
|
|
32
|
+
</svg>
|
|
19
33
|
</svg>
|
|
20
34
|
)
|
|
21
35
|
}
|
|
@@ -1,91 +1,41 @@
|
|
|
1
1
|
import { render } from '@testing-library/react'
|
|
2
2
|
import { KeySvgSymbol } from './KeySvgSymbol'
|
|
3
|
-
import { getSymbolStyleColors, getSymbolViewBox } from '../../../../../src/utils/symbolUtils.js'
|
|
4
|
-
import { symbolRegistry } from '../../registry/index.js'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
getSymbolStyleColors: jest.fn(() => ({ foreground: '#000', background: '#fff' })),
|
|
8
|
-
getSymbolViewBox: jest.fn(() => '0 0 38 38')
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
|
-
const mockResolve = jest.spyOn(symbolRegistry, 'resolve')
|
|
12
|
-
|
|
13
|
-
const defaultProps = {
|
|
14
|
-
symbolDef: { id: 'marker' },
|
|
15
|
-
keyDefinition: {
|
|
16
|
-
style: {
|
|
17
|
-
stroke: '#000000'
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
mapStyle: { id: 'default' }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
mockResolve.mockClear()
|
|
25
|
-
mockResolve.mockReturnValue('<path d="M0 0"/>')
|
|
26
|
-
getSymbolStyleColors.mockReturnValue({ foreground: '#000', background: '#fff' })
|
|
27
|
-
getSymbolViewBox.mockReturnValue('0 0 38 38')
|
|
28
|
-
})
|
|
4
|
+
const keySymbol = (viewBox, svg = '<path d="M0 0"/>') => ({ svg, viewBox })
|
|
29
5
|
|
|
30
6
|
describe('KeySvgSymbol', () => {
|
|
31
|
-
it('
|
|
32
|
-
const { container } = render(<KeySvgSymbol {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(
|
|
39
|
-
|
|
40
|
-
{ foreground: '#000', background: '#fff' },
|
|
41
|
-
expect.objectContaining({ id: 'default' })
|
|
42
|
-
)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('calls getSymbolStyleColors with the dataset props', () => {
|
|
46
|
-
render(<KeySvgSymbol {...defaultProps} />)
|
|
47
|
-
expect(getSymbolStyleColors).toHaveBeenCalledWith(defaultProps.keyDefinition.style)
|
|
7
|
+
it('draws the symbol 1:1, centred in a fixed 44×44 box it may overflow', () => {
|
|
8
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('0 0 42 48')} />)
|
|
9
|
+
const [outer, inner] = container.querySelectorAll('svg')
|
|
10
|
+
expect(outer.getAttribute('width')).toBe('44')
|
|
11
|
+
expect(outer.getAttribute('height')).toBe('44')
|
|
12
|
+
expect(outer.getAttribute('viewBox')).toBe('0 0 44 44')
|
|
13
|
+
expect(outer.getAttribute('overflow')).toBe('visible')
|
|
14
|
+
expect([inner.getAttribute('x'), inner.getAttribute('y')]).toEqual(['1', '-2'])
|
|
15
|
+
expect([inner.getAttribute('width'), inner.getAttribute('height')]).toEqual(['42', '48'])
|
|
48
16
|
})
|
|
49
17
|
|
|
50
|
-
it('
|
|
51
|
-
render(<KeySvgSymbol {
|
|
52
|
-
|
|
18
|
+
it('clips the symbol to its own viewBox, as on the map', () => {
|
|
19
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('10 10 30 30')} />)
|
|
20
|
+
const inner = container.querySelectorAll('svg')[1]
|
|
21
|
+
expect(inner.getAttribute('viewBox')).toBe('10 10 30 30')
|
|
22
|
+
expect(inner.getAttribute('overflow')).toBe('hidden')
|
|
53
23
|
})
|
|
54
24
|
|
|
55
|
-
it('
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
expect(
|
|
25
|
+
it('scales a symbol bigger than the key maximum down to fit it', () => {
|
|
26
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('0 0 112 56')} />)
|
|
27
|
+
const inner = container.querySelectorAll('svg')[1]
|
|
28
|
+
expect([inner.getAttribute('width'), inner.getAttribute('height')]).toEqual(['56', '28'])
|
|
29
|
+
expect([inner.getAttribute('x'), inner.getAttribute('y')]).toEqual(['-6', '8'])
|
|
59
30
|
})
|
|
60
31
|
|
|
61
|
-
it('renders the
|
|
62
|
-
|
|
63
|
-
const { container } = render(<KeySvgSymbol {...defaultProps} />)
|
|
32
|
+
it('renders the symbol\'s svg inside a g element', () => {
|
|
33
|
+
const { container } = render(<KeySvgSymbol keySymbol={keySymbol('0 0 38 38', '<circle id="sym-el"/>')} />)
|
|
64
34
|
expect(container.querySelector('#sym-el')).toBeTruthy()
|
|
65
35
|
})
|
|
66
36
|
|
|
67
|
-
it('
|
|
68
|
-
render(<KeySvgSymbol {
|
|
69
|
-
const callArg = mockResolve.mock.calls[0][2]
|
|
70
|
-
expect(callArg.mapColorScheme).toBe('light')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('uses the mapStyle appColorScheme when provided', () => {
|
|
74
|
-
const props = { ...defaultProps, mapStyle: { id: 'dark', appColorScheme: 'dark' } }
|
|
75
|
-
render(<KeySvgSymbol {...props} />)
|
|
76
|
-
const callArg = mockResolve.mock.calls[0][2]
|
|
77
|
-
expect(callArg.mapColorScheme).toBe('dark')
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('renders nothing when resolve returns falsy', () => {
|
|
81
|
-
mockResolve.mockReturnValue(null)
|
|
82
|
-
const { container } = render(<KeySvgSymbol {...defaultProps} />)
|
|
83
|
-
expect(container.firstChild).toBeNull()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('renders nothing when getSymbolViewBox returns falsy', () => {
|
|
87
|
-
getSymbolViewBox.mockReturnValue(null)
|
|
88
|
-
const { container } = render(<KeySvgSymbol {...defaultProps} />)
|
|
37
|
+
it('renders nothing without a key symbol', () => {
|
|
38
|
+
const { container } = render(<KeySvgSymbol keySymbol={null} />)
|
|
89
39
|
expect(container.firstChild).toBeNull()
|
|
90
40
|
})
|
|
91
41
|
})
|