@cdc/map 4.24.5 → 4.24.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.
- package/dist/cdcmap.js +71853 -64936
- package/examples/annotation/index.json +552 -0
- package/examples/annotation/usa-map.json +900 -0
- package/examples/county-year.csv +10 -0
- package/examples/default-geocode.json +44 -10
- package/examples/default-patterns.json +0 -2
- package/examples/default-single-state.json +279 -108
- package/examples/map-issue-3.json +646 -0
- package/examples/single-state-filter.json +153 -0
- package/index.html +10 -6
- package/package.json +6 -5
- package/src/CdcMap.tsx +367 -199
- package/src/_stories/CdcMap.stories.tsx +14 -0
- package/src/_stories/_mock/DEV-7286.json +165 -0
- package/src/_stories/_mock/DEV-8942.json +270 -0
- package/src/components/Annotation/Annotation.Draggable.styles.css +18 -0
- package/src/components/Annotation/Annotation.Draggable.tsx +152 -0
- package/src/components/Annotation/AnnotationDropdown.styles.css +14 -0
- package/src/components/Annotation/AnnotationDropdown.tsx +70 -0
- package/src/components/Annotation/AnnotationList.styles.css +45 -0
- package/src/components/Annotation/AnnotationList.tsx +42 -0
- package/src/components/Annotation/index.tsx +11 -0
- package/src/components/{BubbleList.jsx → BubbleList.tsx} +1 -1
- package/src/components/{CityList.jsx → CityList.tsx} +28 -2
- package/src/components/{DataTable.jsx → DataTable.tsx} +2 -2
- package/src/components/EditorPanel/components/EditorPanel.tsx +650 -129
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +336 -0
- package/src/components/EditorPanel/components/{Panel.PatternSettings.tsx → Panels/Panel.PatternSettings.tsx} +63 -13
- package/src/components/EditorPanel/components/{Panels.tsx → Panels/index.tsx} +3 -0
- package/src/components/Legend/components/Legend.tsx +125 -42
- package/src/components/Legend/components/index.scss +42 -42
- package/src/components/Modal.tsx +25 -0
- package/src/components/UsaMap/components/SingleState/SingleState.CountyOutput.tsx +74 -0
- package/src/components/UsaMap/components/SingleState/SingleState.StateOutput.tsx +29 -0
- package/src/components/UsaMap/components/SingleState/index.tsx +9 -0
- package/src/components/UsaMap/components/Territory/Territory.Rectangle.tsx +4 -3
- package/src/components/UsaMap/components/UsaMap.County.tsx +114 -36
- package/src/components/UsaMap/components/UsaMap.Region.tsx +2 -0
- package/src/components/UsaMap/components/UsaMap.SingleState.tsx +175 -206
- package/src/components/UsaMap/components/UsaMap.State.tsx +188 -44
- package/src/components/UsaMap/data/us-extended-geography.json +1 -0
- package/src/components/UsaMap/helpers/map.ts +111 -0
- package/src/components/WorldMap/WorldMap.tsx +17 -32
- package/src/components/ZoomControls.tsx +41 -0
- package/src/data/initial-state.js +11 -2
- package/src/data/supported-geos.js +15 -4
- package/src/helpers/generateColorsArray.ts +13 -0
- package/src/helpers/generateRuntimeLegendHash.ts +23 -0
- package/src/helpers/getUniqueValues.ts +19 -0
- package/src/helpers/hashObj.ts +25 -0
- package/src/helpers/tests/generateColorsArray.test.ts +18 -0
- package/src/helpers/tests/generateRuntimeLegendHash.test.ts +11 -0
- package/src/helpers/tests/hashObj.test.ts +10 -0
- package/src/hooks/useStateZoom.tsx +157 -0
- package/src/hooks/{useZoomPan.js → useZoomPan.ts} +6 -5
- package/src/scss/editor-panel.scss +0 -4
- package/src/scss/main.scss +23 -1
- package/src/scss/map.scss +14 -3
- package/src/types/MapConfig.ts +9 -1
- package/src/types/MapContext.ts +16 -2
- package/LICENSE +0 -201
- package/src/components/Modal.jsx +0 -22
- package/src/test/CdcMap.test.jsx +0 -19
- /package/src/components/EditorPanel/components/{Panel.PatternSettings-style.css → Panels/Panel.PatternSettings-style.css} +0 -0
- /package/src/components/{Geo.jsx → Geo.tsx} +0 -0
- /package/src/components/{NavigationMenu.jsx → NavigationMenu.tsx} +0 -0
- /package/src/components/{ZoomableGroup.jsx → ZoomableGroup.tsx} +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react'
|
|
2
2
|
import CdcMap from '../CdcMap'
|
|
3
|
+
import EqualNumberOptInExample from './_mock/DEV-7286.json'
|
|
4
|
+
import SingleStateWithFilters from './_mock/DEV-8942.json'
|
|
3
5
|
|
|
4
6
|
const meta: Meta<typeof CdcMap> = {
|
|
5
7
|
title: 'Components/Templates/Map',
|
|
@@ -14,6 +16,12 @@ export const Equal_Interval_Map: Story = {
|
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
export const Equal_Number_Opt_In: Story = {
|
|
20
|
+
args: {
|
|
21
|
+
config: EqualNumberOptInExample
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
export const Equal_Number_Map: Story = {
|
|
18
26
|
args: {
|
|
19
27
|
configUrl: 'https://www.cdc.gov/wcms/4.0/cdc-wp/data-presentation/page-elements/equal-number-map.json'
|
|
@@ -84,4 +92,10 @@ export const Geocode: Story = {
|
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
export const Single_State_With_Filters: Story = {
|
|
96
|
+
args: {
|
|
97
|
+
config: SingleStateWithFilters
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
export default meta
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
{
|
|
2
|
+
"annotations": [],
|
|
3
|
+
"general": {
|
|
4
|
+
"geoType": "us-county",
|
|
5
|
+
"type": "data",
|
|
6
|
+
"geoBorderColor": "darkGray",
|
|
7
|
+
"headerColor": "theme-blue",
|
|
8
|
+
"title": "",
|
|
9
|
+
"showTitle": true,
|
|
10
|
+
"showSidebar": true,
|
|
11
|
+
"showDownloadButton": true,
|
|
12
|
+
"showDownloadMediaButton": false,
|
|
13
|
+
"displayAsHex": false,
|
|
14
|
+
"displayStateLabels": false,
|
|
15
|
+
"territoriesLabel": "Territories",
|
|
16
|
+
"territoriesAlwaysShow": false,
|
|
17
|
+
"language": "en",
|
|
18
|
+
"geoLabelOverride": "",
|
|
19
|
+
"hasRegions": false,
|
|
20
|
+
"fullBorder": false,
|
|
21
|
+
"convertFipsCodes": true,
|
|
22
|
+
"palette": {
|
|
23
|
+
"isReversed": false
|
|
24
|
+
},
|
|
25
|
+
"allowMapZoom": true,
|
|
26
|
+
"hideGeoColumnInTooltip": false,
|
|
27
|
+
"hidePrimaryColumnInTooltip": false,
|
|
28
|
+
"statePicked": {
|
|
29
|
+
"fipsCode": "01",
|
|
30
|
+
"stateName": "Alabama"
|
|
31
|
+
},
|
|
32
|
+
"expandDataTable": false,
|
|
33
|
+
"equalNumberOptIn": true
|
|
34
|
+
},
|
|
35
|
+
"type": "map",
|
|
36
|
+
"color": "pinkpurple",
|
|
37
|
+
"columns": {
|
|
38
|
+
"geo": {
|
|
39
|
+
"name": "FIPS Codes",
|
|
40
|
+
"label": "Location",
|
|
41
|
+
"tooltip": false,
|
|
42
|
+
"dataTable": true
|
|
43
|
+
},
|
|
44
|
+
"primary": {
|
|
45
|
+
"dataTable": true,
|
|
46
|
+
"tooltip": true,
|
|
47
|
+
"prefix": "",
|
|
48
|
+
"suffix": "",
|
|
49
|
+
"name": "Percent Vaccinated",
|
|
50
|
+
"label": "",
|
|
51
|
+
"roundToPlace": 2
|
|
52
|
+
},
|
|
53
|
+
"navigate": {
|
|
54
|
+
"name": ""
|
|
55
|
+
},
|
|
56
|
+
"latitude": {
|
|
57
|
+
"name": ""
|
|
58
|
+
},
|
|
59
|
+
"longitude": {
|
|
60
|
+
"name": ""
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"legend": {
|
|
64
|
+
"descriptions": {},
|
|
65
|
+
"specialClasses": [],
|
|
66
|
+
"unified": false,
|
|
67
|
+
"singleColumn": false,
|
|
68
|
+
"singleRow": false,
|
|
69
|
+
"verticalSorted": false,
|
|
70
|
+
"showSpecialClassesLast": false,
|
|
71
|
+
"dynamicDescription": false,
|
|
72
|
+
"type": "equalnumber",
|
|
73
|
+
"numberOfItems": 3,
|
|
74
|
+
"position": "side",
|
|
75
|
+
"title": "Legend"
|
|
76
|
+
},
|
|
77
|
+
"filters": [],
|
|
78
|
+
"table": {
|
|
79
|
+
"wrapColumns": false,
|
|
80
|
+
"label": "Data Table",
|
|
81
|
+
"expanded": false,
|
|
82
|
+
"limitHeight": false,
|
|
83
|
+
"height": "",
|
|
84
|
+
"caption": "",
|
|
85
|
+
"showDownloadUrl": false,
|
|
86
|
+
"showDataTableLink": true,
|
|
87
|
+
"showFullGeoNameInCSV": false,
|
|
88
|
+
"forceDisplay": true,
|
|
89
|
+
"download": true,
|
|
90
|
+
"indexLabel": ""
|
|
91
|
+
},
|
|
92
|
+
"tooltips": {
|
|
93
|
+
"appearanceType": "hover",
|
|
94
|
+
"linkLabel": "Learn More",
|
|
95
|
+
"capitalizeLabels": true,
|
|
96
|
+
"opacity": 90
|
|
97
|
+
},
|
|
98
|
+
"runtime": {
|
|
99
|
+
"editorErrorMessage": []
|
|
100
|
+
},
|
|
101
|
+
"visual": {
|
|
102
|
+
"minBubbleSize": 1,
|
|
103
|
+
"maxBubbleSize": 20,
|
|
104
|
+
"extraBubbleBorder": false,
|
|
105
|
+
"cityStyle": "circle",
|
|
106
|
+
"cityStyleLabel": "",
|
|
107
|
+
"showBubbleZeros": false,
|
|
108
|
+
"additionalCityStyles": [],
|
|
109
|
+
"geoCodeCircleSize": 8
|
|
110
|
+
},
|
|
111
|
+
"mapPosition": {
|
|
112
|
+
"coordinates": [
|
|
113
|
+
0,
|
|
114
|
+
30
|
|
115
|
+
],
|
|
116
|
+
"zoom": 1
|
|
117
|
+
},
|
|
118
|
+
"map": {
|
|
119
|
+
"layers": [],
|
|
120
|
+
"patterns": []
|
|
121
|
+
},
|
|
122
|
+
"hexMap": {
|
|
123
|
+
"type": "",
|
|
124
|
+
"shapeGroups": [
|
|
125
|
+
{
|
|
126
|
+
"legendTitle": "",
|
|
127
|
+
"legendDescription": "",
|
|
128
|
+
"items": [
|
|
129
|
+
{
|
|
130
|
+
"key": "",
|
|
131
|
+
"shape": "Arrow Up",
|
|
132
|
+
"column": "",
|
|
133
|
+
"operator": "=",
|
|
134
|
+
"value": ""
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
"filterBehavior": "Filter Change",
|
|
141
|
+
"datasets": {},
|
|
142
|
+
"data": [
|
|
143
|
+
{
|
|
144
|
+
"FIPS Codes": "02013",
|
|
145
|
+
"County": "Aleutians East Borough",
|
|
146
|
+
"Public Health Jurisdiction": "AK",
|
|
147
|
+
"Percent Vaccinated": 99.99,
|
|
148
|
+
"Vaccination Coverage Group": "70% or More"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"FIPS Codes": "02016",
|
|
152
|
+
"County": "Aleutians West Census Area",
|
|
153
|
+
"Public Health Jurisdiction": "AK",
|
|
154
|
+
"Percent Vaccinated": 89.74,
|
|
155
|
+
"Vaccination Coverage Group": "70% or More"
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"dataFileName": "02-map-valid-county-special-values.csv",
|
|
159
|
+
"dataFileSourceType": "file",
|
|
160
|
+
"dataDescription": {
|
|
161
|
+
"horizontal": false,
|
|
162
|
+
"series": false
|
|
163
|
+
},
|
|
164
|
+
"version": "4.24.4"
|
|
165
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
{
|
|
2
|
+
"annotations": [],
|
|
3
|
+
"general": {
|
|
4
|
+
"title": "Default County Map",
|
|
5
|
+
"subtext": "",
|
|
6
|
+
"territoriesLabel": "Territories",
|
|
7
|
+
"type": "map",
|
|
8
|
+
"geoType": "single-state",
|
|
9
|
+
"headerColor": "theme-blue",
|
|
10
|
+
"showSidebar": true,
|
|
11
|
+
"showTitle": true,
|
|
12
|
+
"geoBorderColor": "darkGray",
|
|
13
|
+
"showDownloadButton": true,
|
|
14
|
+
"expandDataTable": false,
|
|
15
|
+
"statePicked": {
|
|
16
|
+
"fipsCode": "06",
|
|
17
|
+
"stateName": "California"
|
|
18
|
+
},
|
|
19
|
+
"annotationDropdownText": "Annotations",
|
|
20
|
+
"showDownloadMediaButton": false,
|
|
21
|
+
"displayAsHex": false,
|
|
22
|
+
"displayStateLabels": false,
|
|
23
|
+
"territoriesAlwaysShow": false,
|
|
24
|
+
"language": "en",
|
|
25
|
+
"geoLabelOverride": "Location",
|
|
26
|
+
"hasRegions": false,
|
|
27
|
+
"fullBorder": false,
|
|
28
|
+
"convertFipsCodes": true,
|
|
29
|
+
"palette": {
|
|
30
|
+
"isReversed": false
|
|
31
|
+
},
|
|
32
|
+
"allowMapZoom": true,
|
|
33
|
+
"hideGeoColumnInTooltip": false,
|
|
34
|
+
"hidePrimaryColumnInTooltip": false
|
|
35
|
+
},
|
|
36
|
+
"type": "map",
|
|
37
|
+
"color": "pinkpurple",
|
|
38
|
+
"columns": {
|
|
39
|
+
"geo": {
|
|
40
|
+
"name": "FIPS Codes",
|
|
41
|
+
"label": "Location",
|
|
42
|
+
"tooltip": false,
|
|
43
|
+
"dataTable": true
|
|
44
|
+
},
|
|
45
|
+
"primary": {
|
|
46
|
+
"name": "Insured Rate",
|
|
47
|
+
"label": "Data Label",
|
|
48
|
+
"prefix": "",
|
|
49
|
+
"suffix": "%",
|
|
50
|
+
"dataTable": true,
|
|
51
|
+
"tooltip": true,
|
|
52
|
+
"roundToPlace": 0
|
|
53
|
+
},
|
|
54
|
+
"navigate": {
|
|
55
|
+
"name": "link",
|
|
56
|
+
"tooltip": false,
|
|
57
|
+
"dataTable": false
|
|
58
|
+
},
|
|
59
|
+
"latitude": {
|
|
60
|
+
"name": "Latitude"
|
|
61
|
+
},
|
|
62
|
+
"longitude": {
|
|
63
|
+
"name": "Longitude"
|
|
64
|
+
},
|
|
65
|
+
"additionalColumn1": {
|
|
66
|
+
"label": "New Column",
|
|
67
|
+
"dataTable": true,
|
|
68
|
+
"tooltips": false,
|
|
69
|
+
"prefix": "",
|
|
70
|
+
"suffix": "",
|
|
71
|
+
"name": "State"
|
|
72
|
+
},
|
|
73
|
+
"additionalColumn2": {
|
|
74
|
+
"label": "New Column",
|
|
75
|
+
"dataTable": true,
|
|
76
|
+
"tooltips": false,
|
|
77
|
+
"prefix": "",
|
|
78
|
+
"suffix": "",
|
|
79
|
+
"name": "Latitude"
|
|
80
|
+
},
|
|
81
|
+
"additionalColumn3": {
|
|
82
|
+
"label": "New Column",
|
|
83
|
+
"dataTable": true,
|
|
84
|
+
"tooltips": false,
|
|
85
|
+
"prefix": "",
|
|
86
|
+
"suffix": "",
|
|
87
|
+
"name": "Longitude"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"legend": {
|
|
91
|
+
"numberOfItems": 3,
|
|
92
|
+
"position": "side",
|
|
93
|
+
"title": "Legend Title",
|
|
94
|
+
"description": "Legend Text",
|
|
95
|
+
"type": "equalnumber",
|
|
96
|
+
"specialClasses": [
|
|
97
|
+
{
|
|
98
|
+
"key": "Insured Rate",
|
|
99
|
+
"value": "N/A",
|
|
100
|
+
"label": "N/A"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"descriptions": {},
|
|
104
|
+
"unified": false,
|
|
105
|
+
"singleColumn": false,
|
|
106
|
+
"singleRow": false,
|
|
107
|
+
"verticalSorted": false,
|
|
108
|
+
"showSpecialClassesLast": false,
|
|
109
|
+
"dynamicDescription": false
|
|
110
|
+
},
|
|
111
|
+
"filters": [
|
|
112
|
+
{
|
|
113
|
+
"order": "asc",
|
|
114
|
+
"label": "",
|
|
115
|
+
"columnName": "State",
|
|
116
|
+
"values": [
|
|
117
|
+
"California",
|
|
118
|
+
"Florida"
|
|
119
|
+
],
|
|
120
|
+
"active": "California",
|
|
121
|
+
"filterStyle": "dropdown"
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"table": {
|
|
125
|
+
"wrapColumns": false,
|
|
126
|
+
"label": "Data Table",
|
|
127
|
+
"expanded": false,
|
|
128
|
+
"limitHeight": false,
|
|
129
|
+
"height": "",
|
|
130
|
+
"caption": "",
|
|
131
|
+
"showDownloadUrl": false,
|
|
132
|
+
"showDataTableLink": true,
|
|
133
|
+
"showFullGeoNameInCSV": false,
|
|
134
|
+
"forceDisplay": true,
|
|
135
|
+
"download": true,
|
|
136
|
+
"indexLabel": ""
|
|
137
|
+
},
|
|
138
|
+
"tooltips": {
|
|
139
|
+
"appearanceType": "hover",
|
|
140
|
+
"linkLabel": "Learn More",
|
|
141
|
+
"capitalizeLabels": true,
|
|
142
|
+
"opacity": 90
|
|
143
|
+
},
|
|
144
|
+
"runtime": {
|
|
145
|
+
"editorErrorMessage": []
|
|
146
|
+
},
|
|
147
|
+
"visual": {
|
|
148
|
+
"minBubbleSize": 1,
|
|
149
|
+
"maxBubbleSize": 20,
|
|
150
|
+
"extraBubbleBorder": false,
|
|
151
|
+
"cityStyle": "circle",
|
|
152
|
+
"cityStyleLabel": "",
|
|
153
|
+
"showBubbleZeros": false,
|
|
154
|
+
"additionalCityStyles": [],
|
|
155
|
+
"geoCodeCircleSize": "7"
|
|
156
|
+
},
|
|
157
|
+
"mapPosition": {
|
|
158
|
+
"coordinates": [
|
|
159
|
+
0,
|
|
160
|
+
0
|
|
161
|
+
],
|
|
162
|
+
"zoom": 1
|
|
163
|
+
},
|
|
164
|
+
"map": {
|
|
165
|
+
"layers": [],
|
|
166
|
+
"patterns": []
|
|
167
|
+
},
|
|
168
|
+
"hexMap": {
|
|
169
|
+
"type": "",
|
|
170
|
+
"shapeGroups": [
|
|
171
|
+
{
|
|
172
|
+
"legendTitle": "",
|
|
173
|
+
"legendDescription": "",
|
|
174
|
+
"items": [
|
|
175
|
+
{
|
|
176
|
+
"key": "",
|
|
177
|
+
"shape": "Arrow Up",
|
|
178
|
+
"column": "",
|
|
179
|
+
"operator": "=",
|
|
180
|
+
"value": ""
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
},
|
|
186
|
+
"filterBehavior": "Filter Change",
|
|
187
|
+
"data": [
|
|
188
|
+
{
|
|
189
|
+
"Insured Rate": 8,
|
|
190
|
+
"Coverage Status": "Insured",
|
|
191
|
+
"FIPS Codes": "06071",
|
|
192
|
+
"Year (Good filter option)": "2010",
|
|
193
|
+
"link": "",
|
|
194
|
+
"Latitude": "",
|
|
195
|
+
"Longitude": "",
|
|
196
|
+
"State": "California"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"Insured Rate": 25,
|
|
200
|
+
"Coverage Status": "Insured",
|
|
201
|
+
"FIPS Codes": "55005",
|
|
202
|
+
"Year (Good filter option)": "2010",
|
|
203
|
+
"link": "",
|
|
204
|
+
"Latitude": "",
|
|
205
|
+
"Longitude": "",
|
|
206
|
+
"State": "California"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"Insured Rate": 25,
|
|
210
|
+
"Coverage Status": "Insured",
|
|
211
|
+
"FIPS Codes": "12103",
|
|
212
|
+
"Year (Good filter option)": "2010",
|
|
213
|
+
"link": "",
|
|
214
|
+
"Latitude": "",
|
|
215
|
+
"Longitude": "",
|
|
216
|
+
"State": "Florida"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"Insured Rate": 25,
|
|
220
|
+
"Coverage Status": "Insured",
|
|
221
|
+
"FIPS Codes": "32005",
|
|
222
|
+
"Year (Good filter option)": "2010",
|
|
223
|
+
"link": "",
|
|
224
|
+
"Latitude": "",
|
|
225
|
+
"State": "California",
|
|
226
|
+
"Longitude": ""
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"Insured Rate": 18,
|
|
230
|
+
"Coverage Status": "Insured",
|
|
231
|
+
"FIPS Codes": "06075",
|
|
232
|
+
"Year (Good filter option)": "2010",
|
|
233
|
+
"link": "",
|
|
234
|
+
"Latitude": "",
|
|
235
|
+
"Longitude": "",
|
|
236
|
+
"State": "California"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"Insured Rate": 3,
|
|
240
|
+
"Coverage Status": "Insured",
|
|
241
|
+
"FIPS Codes": "06027",
|
|
242
|
+
"Year (Good filter option)": "2010",
|
|
243
|
+
"link": "",
|
|
244
|
+
"Latitude": "",
|
|
245
|
+
"Longitude": "",
|
|
246
|
+
"State": "California"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"Insured Rate": 25,
|
|
250
|
+
"Coverage Status": "Insured",
|
|
251
|
+
"FIPS Codes": "06029",
|
|
252
|
+
"Year (Good filter option)": "2010",
|
|
253
|
+
"link": "",
|
|
254
|
+
"Latitude": "",
|
|
255
|
+
"Longitude": "",
|
|
256
|
+
"State": "California"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"Insured Rate": 60,
|
|
260
|
+
"Coverage Status": "Insured",
|
|
261
|
+
"FIPS Codes": "Yosemite is great!",
|
|
262
|
+
"Year (Good filter option)": "2010",
|
|
263
|
+
"link": "",
|
|
264
|
+
"Latitude": "37.865101",
|
|
265
|
+
"Longitude": "-119.538330",
|
|
266
|
+
"State": "California"
|
|
267
|
+
}
|
|
268
|
+
],
|
|
269
|
+
"version": "4.24.9"
|
|
270
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.cdc-open-viz-module .annotation__desktop-label {
|
|
2
|
+
display: none;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.cdc-open-viz-module {
|
|
6
|
+
.annotation__mobile-label-circle {
|
|
7
|
+
stroke-width: 2;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@container content (min-width: 700px) {
|
|
12
|
+
.cdc-open-viz-module .annotation__mobile-label {
|
|
13
|
+
display: none;
|
|
14
|
+
}
|
|
15
|
+
.cdc-open-viz-module .annotation__desktop-label {
|
|
16
|
+
display: block;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { useContext, useState, useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
// helpers
|
|
4
|
+
import { applyBandScaleOffset, handleConnectionHorizontalType, handleConnectionVerticalType, createPoints } from '@cdc/chart/src/components/Annotations/components/helpers'
|
|
5
|
+
|
|
6
|
+
// visx
|
|
7
|
+
import { HtmlLabel, CircleSubject, LineSubject, EditableAnnotation, Connector, Annotation as VisxAnnotation } from '@visx/annotation'
|
|
8
|
+
import { Drag, raise } from '@visx/drag'
|
|
9
|
+
import { MarkerArrow } from '@visx/marker'
|
|
10
|
+
import { LinePath } from '@visx/shape'
|
|
11
|
+
import * as allCurves from '@visx/curve'
|
|
12
|
+
import { Annotation } from '@cdc/core/types/Annotation'
|
|
13
|
+
|
|
14
|
+
// styles
|
|
15
|
+
import './Annotation.Draggable.styles.css'
|
|
16
|
+
import ConfigContext from '../../context'
|
|
17
|
+
import { MapContext } from '../../types/MapContext'
|
|
18
|
+
|
|
19
|
+
const Annotations = ({ xScale, yScale, xMax, svgRef, onDragStateChange }) => {
|
|
20
|
+
const [draggingItems, setDraggingItems] = useState([])
|
|
21
|
+
const { state: config, dimensions, setState: updateConfig, isEditor, isDraggingAnnotation } = useContext<MapContext>(ConfigContext)
|
|
22
|
+
const [width, height] = dimensions
|
|
23
|
+
const { annotations } = config
|
|
24
|
+
// const { colorScale } = useColorScale()
|
|
25
|
+
const prevDimensions = useRef(dimensions)
|
|
26
|
+
const AnnotationComponent = isEditor ? EditableAnnotation : VisxAnnotation
|
|
27
|
+
|
|
28
|
+
const handleMobileXPosition = annotation => {
|
|
29
|
+
if (annotation.snapToNearestPoint) {
|
|
30
|
+
return Number(annotation.dx) + xScale(annotation.xKey) + (config.xAxis.type !== 'date-time' ? xScale.bandwidth() / 2 : 0) + Number(config.yAxis.size)
|
|
31
|
+
}
|
|
32
|
+
return Number(annotation.x) + Number(annotation.dx)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const handleMobileYPosition = annotation => {
|
|
36
|
+
if (annotation.snapToNearestPoint) {
|
|
37
|
+
return yScale(annotation.yKey) + Number(annotation.dy)
|
|
38
|
+
}
|
|
39
|
+
return Number(annotation.dy) + Number(annotation.y)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const handleTextX = annotation => {
|
|
43
|
+
if (annotation.snapToNearestPoint) {
|
|
44
|
+
return Number(annotation.dx) + Number(xScale(annotation.xKey)) + (config.xAxis.type !== 'date-time' ? xScale.bandwidth() / 2 : 0) + Number(config.yAxis.size) - 16 / 3
|
|
45
|
+
}
|
|
46
|
+
return Number(annotation.dx) + Number(annotation.x) - 16 / 3
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const handleTextY = annotation => {
|
|
50
|
+
if (annotation.snapToNearestPoint) {
|
|
51
|
+
return yScale(annotation.yKey) + Number(annotation.dy) + 5
|
|
52
|
+
}
|
|
53
|
+
return Number(annotation.y) + Number(annotation.dy) + 16 / 3
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
annotations &&
|
|
58
|
+
annotations.map((annotation, index) => {
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<Drag
|
|
62
|
+
key={`annotation--${index}`}
|
|
63
|
+
width={width}
|
|
64
|
+
height={height}
|
|
65
|
+
x={annotation.x} // subject x
|
|
66
|
+
y={annotation.y} // subject y
|
|
67
|
+
onDragStart={() => {
|
|
68
|
+
setDraggingItems(raise(annotations, index))
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
{({ dragStart, dragEnd, dragMove, isDragging, x, y, dx, dy }) => {
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
<AnnotationComponent
|
|
75
|
+
dx={annotation.dx} // label position
|
|
76
|
+
dy={annotation.dy} // label postion
|
|
77
|
+
x={annotation.x}
|
|
78
|
+
y={annotation.y}
|
|
79
|
+
canEditLabel={annotation.edit.label || false}
|
|
80
|
+
canEditSubject={annotation.edit.subject || false}
|
|
81
|
+
labelDragHandleProps={{ r: 15, stroke: isDraggingAnnotation ? 'red' : 'var(--primary)' }}
|
|
82
|
+
subjectDragHandleProps={{ r: 15, stroke: isDraggingAnnotation ? 'red' : 'var(--primary)' }}
|
|
83
|
+
onDragEnd={props => {
|
|
84
|
+
onDragStateChange(false)
|
|
85
|
+
const updatedAnnotations = annotations.map((annotation, idx) => {
|
|
86
|
+
if (idx === index) {
|
|
87
|
+
const nearestDatum = annotation
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
...annotation,
|
|
91
|
+
x: props.x,
|
|
92
|
+
y: props.y,
|
|
93
|
+
dx: props.dx,
|
|
94
|
+
dy: props.dy
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return annotation
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
updateConfig({
|
|
101
|
+
...config,
|
|
102
|
+
annotations: updatedAnnotations
|
|
103
|
+
})
|
|
104
|
+
}}
|
|
105
|
+
onMouseMove={dragMove}
|
|
106
|
+
onMouseUp={dragEnd}
|
|
107
|
+
onMouseDown={dragStart}
|
|
108
|
+
onTouchStart={dragStart}
|
|
109
|
+
onTouchMove={dragMove}
|
|
110
|
+
onTouchEnd={dragEnd}
|
|
111
|
+
anchorPosition={'auto'}
|
|
112
|
+
onDragStart={() => {
|
|
113
|
+
onDragStateChange(true)
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
<HtmlLabel className='' showAnchorLine={false}>
|
|
117
|
+
<div
|
|
118
|
+
style={{
|
|
119
|
+
padding: '10px',
|
|
120
|
+
borderRadius: 5, // Optional: set border radius
|
|
121
|
+
backgroundColor: `rgba(255, 255, 255, ${annotation?.opacity ? Number(annotation?.opacity) / 100 : 1})`
|
|
122
|
+
}}
|
|
123
|
+
role='presentation'
|
|
124
|
+
// ! IMPORTANT: Workaround for 508
|
|
125
|
+
// - HTML needs to be set from the editor and we need a wrapper with the tabIndex
|
|
126
|
+
// - TabIndex is only supposed to be used on interactive elements. This is a workaround.
|
|
127
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
128
|
+
tabIndex={0}
|
|
129
|
+
aria-label={`Annotation text that reads: ${annotation.text}`}
|
|
130
|
+
dangerouslySetInnerHTML={{ __html: annotation.text }}
|
|
131
|
+
/>
|
|
132
|
+
</HtmlLabel>
|
|
133
|
+
|
|
134
|
+
{annotation.connectionType === 'line' && <Connector type='line' pathProps={{ markerStart: 'url(#marker-start)' }} />}
|
|
135
|
+
|
|
136
|
+
{annotation.connectionType === 'elbow' && <Connector type='elbow' pathProps={{ markerStart: 'url(#marker-start)' }} />}
|
|
137
|
+
|
|
138
|
+
{/* MARKERS */}
|
|
139
|
+
{annotation.marker === 'circle' && <CircleSubject className='circle-subject' stroke={'black'} radius={8} />}
|
|
140
|
+
{annotation.marker === 'arrow' && <MarkerArrow fill='black' id='marker-start' x={annotation.x} y={annotation.dy} stroke='#333' markerWidth={10} size={10} strokeWidth={1} orient='auto-start-reverse' />}
|
|
141
|
+
</AnnotationComponent>
|
|
142
|
+
</>
|
|
143
|
+
)
|
|
144
|
+
}}
|
|
145
|
+
</Drag>
|
|
146
|
+
</>
|
|
147
|
+
)
|
|
148
|
+
})
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export default Annotations
|