@cdc/map 2.6.2 → 2.6.3
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 +27 -27
- package/examples/default-county.json +105 -0
- package/examples/default-single-state.json +109 -0
- package/examples/default-usa.json +744 -603
- package/examples/example-city-state.json +474 -0
- package/examples/example-world-map.json +1596 -0
- package/examples/gender-rate-map.json +1 -0
- package/package.json +50 -47
- package/src/CdcMap.js +422 -159
- package/src/components/CityList.js +3 -2
- package/src/components/CountyMap.js +556 -0
- package/src/components/DataTable.js +73 -19
- package/src/components/EditorPanel.js +2088 -1230
- package/src/components/Sidebar.js +5 -5
- package/src/components/SingleStateMap.js +326 -0
- package/src/components/UsaMap.js +20 -3
- package/src/data/abbreviations.js +57 -0
- package/src/data/color-palettes.js +10 -1
- package/src/data/county-map-halfquality.json +58453 -0
- package/src/data/county-map-quarterquality.json +1 -0
- package/src/data/county-topo.json +1 -0
- package/src/data/dfc-map.json +1 -0
- package/src/data/initial-state.js +2 -2
- package/src/data/newtest.json +1 -0
- package/src/data/state-abbreviations.js +60 -0
- package/src/data/supported-geos.js +3504 -151
- package/src/data/test.json +1 -0
- package/src/hooks/useActiveElement.js +19 -0
- package/src/index.html +27 -20
- package/src/index.js +8 -4
- package/src/scss/datatable.scss +2 -1
- package/src/scss/main.scss +10 -1
- package/src/scss/map.scss +153 -123
- package/src/scss/sidebar.scss +0 -1
- package/uploads/upload-example-city-state.json +392 -0
- package/uploads/upload-example-world-data.json +1490 -0
- package/LICENSE +0 -201
|
@@ -10,8 +10,12 @@ import ExternalIcon from '../images/external-link.svg';
|
|
|
10
10
|
import ErrorBoundary from '@cdc/core/components/ErrorBoundary';
|
|
11
11
|
import LegendCircle from '@cdc/core/components/LegendCircle';
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
import Loading from '@cdc/core/components/Loading';
|
|
15
|
+
|
|
13
16
|
const DataTable = (props) => {
|
|
14
17
|
const {
|
|
18
|
+
state,
|
|
15
19
|
tableTitle,
|
|
16
20
|
indexTitle,
|
|
17
21
|
mapTitle,
|
|
@@ -26,13 +30,18 @@ const DataTable = (props) => {
|
|
|
26
30
|
applyLegendToRow,
|
|
27
31
|
displayGeoName,
|
|
28
32
|
navigationHandler,
|
|
29
|
-
viewport
|
|
33
|
+
viewport
|
|
30
34
|
} = props;
|
|
31
35
|
|
|
32
36
|
const [expanded, setExpanded] = useState(expandDataTable);
|
|
33
37
|
|
|
34
38
|
const [accessibilityLabel, setAccessibilityLabel] = useState('');
|
|
35
39
|
|
|
40
|
+
const [ready, setReady] = useState(false)
|
|
41
|
+
|
|
42
|
+
const fileName = `${mapTitle}.csv`;
|
|
43
|
+
|
|
44
|
+
|
|
36
45
|
// Catch all sorting method used on load by default but also on user click
|
|
37
46
|
// Having a custom method means we can add in any business logic we want going forward
|
|
38
47
|
const customSort = useCallback((a, b) => {
|
|
@@ -132,28 +141,33 @@ const DataTable = (props) => {
|
|
|
132
141
|
}, [columns.navigate, navigationHandler]);
|
|
133
142
|
|
|
134
143
|
const DownloadButton = memo(() => {
|
|
135
|
-
const fileName = `${mapTitle}.csv`;
|
|
136
144
|
const csvData = Papa.unparse(rawData);
|
|
137
145
|
|
|
138
146
|
const blob = new Blob([csvData], {type: "text/csv;charset=utf-8;"});
|
|
139
147
|
|
|
140
148
|
const saveBlob = () => {
|
|
141
|
-
|
|
149
|
+
//@ts-ignore
|
|
150
|
+
if (typeof window.navigator.msSaveBlob === 'function') {
|
|
151
|
+
//@ts-ignore
|
|
142
152
|
navigator.msSaveBlob(blob, fileName);
|
|
143
153
|
}
|
|
144
154
|
}
|
|
145
155
|
|
|
146
156
|
return (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
+
<a
|
|
158
|
+
download={fileName}
|
|
159
|
+
type="button"
|
|
160
|
+
onClick={saveBlob}
|
|
161
|
+
href={URL.createObjectURL(blob)}
|
|
162
|
+
aria-label="Download this data in a CSV file format."
|
|
163
|
+
className={`${headerColor} btn btn-download no-border`}
|
|
164
|
+
id={`${skipId}`}
|
|
165
|
+
data-html2canvas-ignore
|
|
166
|
+
role="button"
|
|
167
|
+
tabIndex="-1"
|
|
168
|
+
>
|
|
169
|
+
Download Data (CSV)
|
|
170
|
+
</a>
|
|
157
171
|
)
|
|
158
172
|
}, [rawData]);
|
|
159
173
|
|
|
@@ -168,6 +182,13 @@ const DataTable = (props) => {
|
|
|
168
182
|
id: column,
|
|
169
183
|
accessor: (row) => {
|
|
170
184
|
if (runtimeData) {
|
|
185
|
+
if(state.legend.specialClasses && state.legend.specialClasses.length && typeof state.legend.specialClasses[0] === 'object'){
|
|
186
|
+
for(let i = 0; i < state.legend.specialClasses.length; i++){
|
|
187
|
+
if(String(runtimeData[row][state.legend.specialClasses[i].key]) === state.legend.specialClasses[i].value){
|
|
188
|
+
return state.legend.specialClasses[i].label;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
171
192
|
return runtimeData[row][columns[column].name] ?? null;
|
|
172
193
|
}
|
|
173
194
|
|
|
@@ -240,6 +261,13 @@ const DataTable = (props) => {
|
|
|
240
261
|
[]
|
|
241
262
|
);
|
|
242
263
|
|
|
264
|
+
const mapLookup = {
|
|
265
|
+
'us-county': 'United States County Map',
|
|
266
|
+
'single-state': 'State Map',
|
|
267
|
+
'us': 'United States Map',
|
|
268
|
+
'world': 'World Map'
|
|
269
|
+
}
|
|
270
|
+
|
|
243
271
|
const {
|
|
244
272
|
getTableProps,
|
|
245
273
|
getTableBodyProps,
|
|
@@ -248,30 +276,56 @@ const DataTable = (props) => {
|
|
|
248
276
|
prepareRow,
|
|
249
277
|
} = useTable({ columns: tableColumns, data: tableData, defaultColumn }, useSortBy, useBlockLayout, useResizeColumns);
|
|
250
278
|
|
|
279
|
+
const rand = Math.random().toString(16).substr(2, 8);
|
|
280
|
+
const skipId = `btn__${rand}`
|
|
281
|
+
|
|
282
|
+
if(!state.data) return <Loading />
|
|
251
283
|
return (
|
|
252
284
|
<ErrorBoundary component="DataTable">
|
|
253
|
-
<section className={`data-table-container ${viewport}`} aria-label={accessibilityLabel}>
|
|
285
|
+
<section id={state.general.title ? `dataTableSection__${state.general.title.replace(/\s/g, '')}` : `dataTableSection`} className={`data-table-container ${viewport}`} aria-label={accessibilityLabel}>
|
|
286
|
+
<a id='skip-nav' className='cdcdataviz-sr-only-focusable' href={`#${skipId}`}>
|
|
287
|
+
Skip Navigation or Skip to Content
|
|
288
|
+
</a>
|
|
254
289
|
<div
|
|
255
290
|
className={expanded ? 'data-table-heading' : 'collapsed data-table-heading'}
|
|
256
291
|
onClick={() => { setExpanded(!expanded); }}
|
|
257
292
|
tabIndex="0"
|
|
258
293
|
onKeyDown={(e) => { if (e.keyCode === 13) { setExpanded(!expanded); } }}
|
|
259
294
|
>
|
|
295
|
+
|
|
260
296
|
{tableTitle}
|
|
261
297
|
</div>
|
|
262
|
-
<div
|
|
263
|
-
|
|
264
|
-
|
|
298
|
+
<div
|
|
299
|
+
className="table-container"
|
|
300
|
+
style={ { maxHeight: state.dataTable.limitHeight && `${state.dataTable.height}px`, overflowY: 'scroll' } }
|
|
301
|
+
>
|
|
302
|
+
<table
|
|
303
|
+
height={expanded ? null : 0} {...getTableProps()}
|
|
304
|
+
aria-live="assertive"
|
|
305
|
+
className={expanded ? 'data-table' : 'data-table cdcdataviz-sr-only'}
|
|
306
|
+
hidden={!expanded}
|
|
307
|
+
aria-rowcount={state?.data.length ? state.data.length : '-1' }
|
|
308
|
+
>
|
|
309
|
+
<caption className='cdcdataviz-sr-only'>{state.dataTable.caption ? state.dataTable.caption : `Datatable showing data for the ${mapLookup[state.general.geoType]} figure.`}</caption>
|
|
310
|
+
<thead style={{position: 'sticky', top: 0, zIndex: 999}}>
|
|
265
311
|
{headerGroups.map((headerGroup) => (
|
|
266
312
|
<tr {...headerGroup.getHeaderGroupProps()}>
|
|
267
313
|
{headerGroup.headers.map((column) => (
|
|
268
314
|
<th tabIndex="0"
|
|
269
315
|
title={column.Header}
|
|
316
|
+
role="columnheader"
|
|
317
|
+
scope="col"
|
|
270
318
|
{...column.getHeaderProps(column.getSortByToggleProps())}
|
|
271
319
|
className={column.isSorted ? column.isSortedDesc ? 'sort sort-desc' : 'sort sort-asc' : 'sort'}
|
|
272
320
|
onKeyDown={(e) => { if (e.keyCode === 13) { column.toggleSortBy(); } }}
|
|
321
|
+
//aria-sort={column.isSorted ? column.isSortedDesc ? 'descending' : 'ascending' : 'none' }
|
|
322
|
+
{...(column.isSorted ? column.isSortedDesc ? { 'aria-sort': 'descending' } : { 'aria-sort': 'ascending' } : null)}
|
|
323
|
+
|
|
273
324
|
>
|
|
274
325
|
{column.render('Header')}
|
|
326
|
+
<button>
|
|
327
|
+
<span className="cdcdataviz-sr-only">{`Sort by ${(column.render('Header')).toLowerCase() } in ${ column.isSorted ? column.isSortedDesc ? 'descending' : 'ascending' : 'no'} `} order</span>
|
|
328
|
+
</button>
|
|
275
329
|
<div {...column.getResizerProps()} className="resizer" />
|
|
276
330
|
</th>
|
|
277
331
|
))}
|
|
@@ -282,9 +336,9 @@ const DataTable = (props) => {
|
|
|
282
336
|
{rows.map((row) => {
|
|
283
337
|
prepareRow(row);
|
|
284
338
|
return (
|
|
285
|
-
<tr {...row.getRowProps()}>
|
|
339
|
+
<tr {...row.getRowProps()} role="row">
|
|
286
340
|
{row.cells.map((cell) => (
|
|
287
|
-
<td tabIndex="0" {...cell.getCellProps()}>
|
|
341
|
+
<td tabIndex="0" {...cell.getCellProps()} role="gridcell">
|
|
288
342
|
{cell.render('Cell')}
|
|
289
343
|
</td>
|
|
290
344
|
))}
|