@cdc/core 4.23.10 → 4.23.11
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/LICENSE +201 -0
- package/assets/icon-deviation-bar.svg +1 -0
- package/components/DataTable/DataTable.tsx +205 -0
- package/components/DataTable/components/BoxplotHeader.tsx +16 -0
- package/components/DataTable/components/CellAnchor.tsx +44 -0
- package/components/DataTable/components/ChartHeader.tsx +91 -0
- package/components/DataTable/components/ExpandCollapse.tsx +21 -0
- package/components/DataTable/components/Icons.tsx +10 -0
- package/components/DataTable/components/MapHeader.tsx +56 -0
- package/components/DataTable/components/SkipNav.tsx +7 -0
- package/components/DataTable/helpers/boxplotCellMatrix.tsx +64 -0
- package/components/DataTable/helpers/chartCellMatrix.tsx +78 -0
- package/components/DataTable/helpers/customSort.ts +55 -0
- package/components/DataTable/helpers/getChartCellValue.ts +55 -0
- package/components/DataTable/helpers/getDataSeriesColumns.ts +28 -0
- package/components/DataTable/helpers/getSeriesName.ts +26 -0
- package/components/DataTable/helpers/mapCellMatrix.tsx +56 -0
- package/components/DataTable/helpers/regionCellMatrix.tsx +13 -0
- package/components/DataTable/helpers/standardizeState.js +76 -0
- package/components/DataTable/index.ts +1 -0
- package/components/DataTable/types/TableConfig.ts +57 -0
- package/components/DownloadButton.tsx +29 -0
- package/components/LegendCircle.jsx +2 -2
- package/components/Table/Table.tsx +49 -0
- package/components/Table/components/Cell.tsx +9 -0
- package/components/Table/components/GroupRow.tsx +16 -0
- package/components/Table/components/Row.tsx +19 -0
- package/components/Table/index.ts +1 -0
- package/components/Table/types/CellMatrix.ts +4 -0
- package/components/_stories/DataTable.stories.tsx +62 -0
- package/components/_stories/Table.stories.tsx +53 -0
- package/components/_stories/_mocks/dashboard_no_filter.json +121 -0
- package/components/_stories/_mocks/example-city-state.json +808 -0
- package/components/_stories/styles.scss +9 -0
- package/components/managers/{DataDesigner.jsx → DataDesigner.tsx} +96 -87
- package/components/ui/Title/Title.scss +95 -0
- package/components/ui/Title/index.tsx +34 -0
- package/components/ui/_stories/Title.stories.tsx +21 -0
- package/helpers/DataTransform.ts +45 -18
- package/helpers/cove/string.ts +11 -0
- package/helpers/fetchRemoteData.js +1 -1
- package/package.json +2 -2
- package/styles/_data-table.scss +1 -0
- package/styles/heading-colors.scss +0 -3
- package/styles/v2/layout/_component.scss +0 -11
- package/types/Axis.ts +6 -0
- package/types/Color.ts +5 -0
- package/types/ComponentStyles.ts +7 -0
- package/types/ComponentThemes.ts +13 -0
- package/types/EditorColumnProperties.ts +8 -0
- package/types/Runtime.ts +9 -0
- package/types/Series.ts +1 -0
- package/types/Visualization.ts +21 -0
- package/components/DataTable.jsx +0 -754
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 99.1 79.69"><defs><style>.cls-1{fill:#231f20;}</style></defs><rect class="cls-1" x="46.87" y="5.79" width="8.32" height="67.79" rx="1"/><rect class="cls-1" x="23.98" y="17.65" width="8.32" height="23.31" rx="1" transform="translate(57.44 1.16) rotate(90)"/><rect class="cls-1" x="19.53" y="25.99" width="8.32" height="32.21" rx="1" transform="translate(65.79 18.41) rotate(90)"/><rect class="cls-1" x="27.33" y="60.4" width="8.32" height="14.6" rx="1" transform="translate(99.19 36.2) rotate(90)"/><path class="cls-1" d="M81,52.74v4.32H64.55V52.74H81m1-2H63.55a1,1,0,0,0-1,1v6.32a1,1,0,0,0,1,1H82a1,1,0,0,0,1-1V51.74a1,1,0,0,0-1-1Z"/><path class="cls-1" d="M90,14.41v4.33H64.55V14.41H90m1-2H63.55a1,1,0,0,0-1,1v6.33a1,1,0,0,0,1,1H91a1,1,0,0,0,1-1V13.41a1,1,0,0,0-1-1Z"/></svg>
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { useEffect, useState, useMemo } from 'react'
|
|
2
|
+
|
|
3
|
+
import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
4
|
+
import MediaControls from '@cdc/core/components/MediaControls'
|
|
5
|
+
import Loading from '@cdc/core/components/Loading'
|
|
6
|
+
import DownloadButton from '../DownloadButton'
|
|
7
|
+
import { customSort } from './helpers/customSort'
|
|
8
|
+
import ChartHeader from './components/ChartHeader'
|
|
9
|
+
import BoxplotHeader from './components/BoxplotHeader'
|
|
10
|
+
import MapHeader from './components/MapHeader'
|
|
11
|
+
import SkipNav from './components/SkipNav'
|
|
12
|
+
import ExpandCollapse from './components/ExpandCollapse'
|
|
13
|
+
import mapCellMatrix from './helpers/mapCellMatrix'
|
|
14
|
+
import Table from '../Table'
|
|
15
|
+
import chartCellMatrix from './helpers/chartCellMatrix'
|
|
16
|
+
import regionCellMatrix from './helpers/regionCellMatrix'
|
|
17
|
+
import boxplotCellMatrix from './helpers/boxplotCellMatrix'
|
|
18
|
+
import { TableConfig } from './types/TableConfig'
|
|
19
|
+
|
|
20
|
+
export type DataTableProps = {
|
|
21
|
+
applyLegendToRow?: Function
|
|
22
|
+
colorScale?: Function
|
|
23
|
+
columns?: { navigate: { name: string } }
|
|
24
|
+
config: TableConfig
|
|
25
|
+
dataConfig?: Object
|
|
26
|
+
displayDataAsText?: Function
|
|
27
|
+
displayGeoName?: Function
|
|
28
|
+
expandDataTable: boolean
|
|
29
|
+
formatLegendLocation?: Function
|
|
30
|
+
groupBy?: string
|
|
31
|
+
headerColor?: string
|
|
32
|
+
indexTitle?: string
|
|
33
|
+
navigationHandler?: Function
|
|
34
|
+
rawData: Object[]
|
|
35
|
+
runtimeData: Object[] | Record<string, Object> // UNSAFE
|
|
36
|
+
setFilteredCountryCode?: Function // used for Maps only
|
|
37
|
+
tabbingId: string
|
|
38
|
+
tableTitle: string
|
|
39
|
+
viewport: string
|
|
40
|
+
vizTitle?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* eslint-disable jsx-a11y/no-noninteractive-tabindex, jsx-a11y/no-static-element-interactions */
|
|
44
|
+
const DataTable = (props: DataTableProps) => {
|
|
45
|
+
const { config, dataConfig, tableTitle, vizTitle, rawData, runtimeData, headerColor, expandDataTable, columns, viewport, formatLegendLocation, tabbingId } = props
|
|
46
|
+
|
|
47
|
+
const [expanded, setExpanded] = useState(expandDataTable)
|
|
48
|
+
|
|
49
|
+
const [sortBy, setSortBy] = useState<any>({ column: config.type === 'map' ? 'geo' : 'date', asc: false, colIndex: null })
|
|
50
|
+
|
|
51
|
+
const [accessibilityLabel, setAccessibilityLabel] = useState('')
|
|
52
|
+
|
|
53
|
+
const isVertical = !(config.type === 'chart' && !config.table?.showVertical)
|
|
54
|
+
|
|
55
|
+
const rand = Math.random().toString(16).substr(2, 8)
|
|
56
|
+
const skipId = `btn__${rand}`
|
|
57
|
+
|
|
58
|
+
const mapLookup = {
|
|
59
|
+
'us-county': 'United States County Map',
|
|
60
|
+
'single-state': 'State Map',
|
|
61
|
+
us: 'United States Map',
|
|
62
|
+
world: 'World Map'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Change accessibility label depending on expanded status
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const expandedLabel = 'Accessible data table.'
|
|
68
|
+
const collapsedLabel = 'Accessible data table. This table is currently collapsed visually but can still be read using a screen reader.'
|
|
69
|
+
|
|
70
|
+
if (expanded === true && accessibilityLabel !== expandedLabel) {
|
|
71
|
+
setAccessibilityLabel(expandedLabel)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (expanded === false && accessibilityLabel !== collapsedLabel) {
|
|
75
|
+
setAccessibilityLabel(collapsedLabel)
|
|
76
|
+
}
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
}, [expanded])
|
|
79
|
+
|
|
80
|
+
switch (config.visualizationType) {
|
|
81
|
+
case 'Box Plot':
|
|
82
|
+
if (!config.boxplot) return <Loading />
|
|
83
|
+
break
|
|
84
|
+
case 'Line' || 'Bar' || 'Combo' || 'Pie' || 'Deviation Bar' || 'Paired Bar':
|
|
85
|
+
if (!runtimeData) return <Loading />
|
|
86
|
+
break
|
|
87
|
+
default:
|
|
88
|
+
if (!runtimeData) return <Loading />
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const rawRows = Object.keys(runtimeData)
|
|
93
|
+
const rows = isVertical
|
|
94
|
+
? rawRows.sort((a, b) => {
|
|
95
|
+
let dataA
|
|
96
|
+
let dataB
|
|
97
|
+
if (config.type === 'map' && config.columns) {
|
|
98
|
+
const sortByColName = config.columns[sortBy.column].name
|
|
99
|
+
dataA = runtimeData[a][sortByColName]
|
|
100
|
+
dataB = runtimeData[b][sortByColName]
|
|
101
|
+
}
|
|
102
|
+
if (config.type === 'chart' || config.type === 'dashboard') {
|
|
103
|
+
dataA = runtimeData[a][sortBy.column]
|
|
104
|
+
dataB = runtimeData[b][sortBy.column]
|
|
105
|
+
}
|
|
106
|
+
return dataA && dataB ? customSort(dataA, dataB, sortBy, config) : 0
|
|
107
|
+
})
|
|
108
|
+
: rawRows
|
|
109
|
+
|
|
110
|
+
const limitHeight = {
|
|
111
|
+
maxHeight: config.table.limitHeight && `${config.table.height}px`,
|
|
112
|
+
OverflowY: 'scroll'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const caption = useMemo(() => {
|
|
116
|
+
if (config.type === 'map') {
|
|
117
|
+
return config.table.caption ? config.table.caption : `Data table showing data for the ${mapLookup[config.general.geoType]} figure.`
|
|
118
|
+
} else {
|
|
119
|
+
return config.table.caption ? config.table.caption : `Data table showing data for the ${config.type} figure.`
|
|
120
|
+
}
|
|
121
|
+
}, [config.table.caption])
|
|
122
|
+
|
|
123
|
+
// prettier-ignore
|
|
124
|
+
const tableData = useMemo(() => (
|
|
125
|
+
config.visualizationType === 'Pie'
|
|
126
|
+
? [config.yAxis.dataKey]
|
|
127
|
+
: config.visualizationType === 'Box Plot'
|
|
128
|
+
? Object.entries(config.boxplot.tableData[0])
|
|
129
|
+
: config.runtime?.seriesKeys),
|
|
130
|
+
[config.runtime?.seriesKeys]) // eslint-disable-line
|
|
131
|
+
|
|
132
|
+
if (config.visualizationType !== 'Box Plot') {
|
|
133
|
+
const getDownloadData = () => {
|
|
134
|
+
// only use fullGeoName on County maps and no other
|
|
135
|
+
if (config.general?.geoType === 'us-county') {
|
|
136
|
+
// Add column for full Geo name along with State
|
|
137
|
+
return rawData.map(row => ({ FullGeoName: formatLegendLocation(row[config.columns.geo.name]), ...row }))
|
|
138
|
+
} else {
|
|
139
|
+
return rawData
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<ErrorBoundary component='DataTable'>
|
|
145
|
+
<MediaControls.Section classes={['download-links']}>
|
|
146
|
+
<MediaControls.Link config={config} dashboardDataConfig={dataConfig} />
|
|
147
|
+
{(config.table.download || config.general?.showDownloadButton) && <DownloadButton rawData={getDownloadData()} fileName={`${vizTitle || 'data-table'}.csv`} headerColor={headerColor} skipId={skipId} />}
|
|
148
|
+
</MediaControls.Section>
|
|
149
|
+
<section id={tabbingId.replace('#', '')} className={`data-table-container ${viewport}`} aria-label={accessibilityLabel}>
|
|
150
|
+
<SkipNav skipId={skipId} />
|
|
151
|
+
<ExpandCollapse expanded={expanded} setExpanded={setExpanded} tableTitle={tableTitle} />
|
|
152
|
+
<div className='table-container' style={limitHeight}>
|
|
153
|
+
<Table
|
|
154
|
+
childrenMatrix={config.type === 'map' ? mapCellMatrix({ rows, ...props }) : chartCellMatrix({ rows, ...props, isVertical, sortBy })}
|
|
155
|
+
tableName={config.type}
|
|
156
|
+
caption={caption}
|
|
157
|
+
stickyHeader
|
|
158
|
+
headContent={config.type === 'map' ? <MapHeader columns={columns} {...props} sortBy={sortBy} setSortBy={setSortBy} /> : <ChartHeader data={runtimeData} {...props} isVertical={isVertical} sortBy={sortBy} setSortBy={setSortBy} />}
|
|
159
|
+
tableOptions={{ className: `${expanded ? 'data-table' : 'data-table cdcdataviz-sr-only'}${isVertical ? '' : ' horizontal'}`, 'aria-live': 'assertive', 'aria-rowcount': config?.data?.length ? config.data.length : -1, hidden: !expanded }}
|
|
160
|
+
/>
|
|
161
|
+
|
|
162
|
+
{/* REGION Data Table */}
|
|
163
|
+
{config.regions && config.regions.length > 0 && config.visualizationType !== 'Box Plot' && (
|
|
164
|
+
<Table
|
|
165
|
+
childrenMatrix={regionCellMatrix({ config })}
|
|
166
|
+
tableName={config.visualizationType}
|
|
167
|
+
caption='Table of the highlighted regions in the visualization'
|
|
168
|
+
headContent={
|
|
169
|
+
<tr>
|
|
170
|
+
<th>Region Name</th>
|
|
171
|
+
<th>Start Date</th>
|
|
172
|
+
<th>End Date</th>
|
|
173
|
+
</tr>
|
|
174
|
+
}
|
|
175
|
+
tableOptions={{ className: 'region-table data-table' }}
|
|
176
|
+
/>
|
|
177
|
+
)}
|
|
178
|
+
</div>
|
|
179
|
+
</section>
|
|
180
|
+
</ErrorBoundary>
|
|
181
|
+
)
|
|
182
|
+
} else {
|
|
183
|
+
// Render Data Table for Box Plots
|
|
184
|
+
return (
|
|
185
|
+
<ErrorBoundary component='DataTable'>
|
|
186
|
+
<section id={tabbingId.replace('#', '')} className={`data-table-container ${viewport}`} aria-label={accessibilityLabel}>
|
|
187
|
+
<SkipNav skipId={skipId} />
|
|
188
|
+
<ExpandCollapse expanded={expanded} setExpanded={setExpanded} tableTitle={tableTitle} />
|
|
189
|
+
<div className='table-container' style={limitHeight}>
|
|
190
|
+
<Table
|
|
191
|
+
childrenMatrix={boxplotCellMatrix({ rows: tableData, config })}
|
|
192
|
+
tableName={config.visualizationType}
|
|
193
|
+
caption={caption}
|
|
194
|
+
stickyHeader
|
|
195
|
+
headContent={<BoxplotHeader categories={config.boxplot.categories} />}
|
|
196
|
+
tableOptions={{ className: `${expanded ? 'data-table' : 'data-table cdcdataviz-sr-only'}`, 'aria-live': 'assertive', 'aria-rowcount': 11, hidden: !expanded }}
|
|
197
|
+
/>
|
|
198
|
+
</div>
|
|
199
|
+
</section>
|
|
200
|
+
</ErrorBoundary>
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export default DataTable
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const BoxplotHeader = ({ categories }) => {
|
|
2
|
+
let columns = ['Measures', ...categories]
|
|
3
|
+
return (
|
|
4
|
+
<tr>
|
|
5
|
+
{columns.map(column => {
|
|
6
|
+
return (
|
|
7
|
+
<th key={`col-header-${column}`} tabIndex={0} title={column} role='columnheader' scope='col'>
|
|
8
|
+
{column}
|
|
9
|
+
</th>
|
|
10
|
+
)
|
|
11
|
+
})}
|
|
12
|
+
</tr>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default BoxplotHeader
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ExternalIcon from '@cdc/core/assets/external-link.svg'
|
|
2
|
+
// Optionally wrap cell with anchor if config defines a navigation url
|
|
3
|
+
const CellAnchor = ({ markup, row, columns, navigationHandler, mapZoomHandler }) => {
|
|
4
|
+
if (columns.navigate && row[columns.navigate.name]) {
|
|
5
|
+
return (
|
|
6
|
+
<span
|
|
7
|
+
onClick={() => navigationHandler(row[columns.navigate.name])}
|
|
8
|
+
className='table-link'
|
|
9
|
+
title='Click for more information (Opens in a new window)'
|
|
10
|
+
role='link'
|
|
11
|
+
tabIndex={0}
|
|
12
|
+
onKeyDown={e => {
|
|
13
|
+
if (e.keyCode === 13) {
|
|
14
|
+
navigationHandler(row[columns.navigate.name])
|
|
15
|
+
}
|
|
16
|
+
}}
|
|
17
|
+
>
|
|
18
|
+
{markup}
|
|
19
|
+
<ExternalIcon className='inline-icon' />
|
|
20
|
+
</span>
|
|
21
|
+
)
|
|
22
|
+
} else if (mapZoomHandler) {
|
|
23
|
+
return (
|
|
24
|
+
<span
|
|
25
|
+
onClick={mapZoomHandler}
|
|
26
|
+
className='table-link'
|
|
27
|
+
title='Click to view on map'
|
|
28
|
+
role='link'
|
|
29
|
+
tabIndex={0}
|
|
30
|
+
onKeyDown={e => {
|
|
31
|
+
if (e.keyCode === 13) {
|
|
32
|
+
mapZoomHandler()
|
|
33
|
+
}
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
{markup}
|
|
37
|
+
</span>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return <>{markup}</>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default CellAnchor
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { getChartCellValue } from '../helpers/getChartCellValue'
|
|
2
|
+
import { getSeriesName } from '../helpers/getSeriesName'
|
|
3
|
+
import { getDataSeriesColumns } from '../helpers/getDataSeriesColumns'
|
|
4
|
+
import { DownIcon, UpIcon } from './Icons'
|
|
5
|
+
|
|
6
|
+
type ChartHeaderProps = { data; isVertical; config; runtimeData; setSortBy; sortBy; groupBy? }
|
|
7
|
+
|
|
8
|
+
const ChartHeader = ({ data, isVertical, config, runtimeData, setSortBy, sortBy, groupBy }: ChartHeaderProps) => {
|
|
9
|
+
if (!data) return
|
|
10
|
+
let dataSeriesColumns = getDataSeriesColumns(config, isVertical, runtimeData)
|
|
11
|
+
if (groupBy) {
|
|
12
|
+
let groupHeaderRemoved = dataSeriesColumns.filter(col => col !== groupBy)
|
|
13
|
+
if (groupHeaderRemoved.length != dataSeriesColumns.length) {
|
|
14
|
+
// match was found
|
|
15
|
+
// assign headers with groupHeaderRemoved
|
|
16
|
+
dataSeriesColumns = groupHeaderRemoved
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (isVertical) {
|
|
20
|
+
return (
|
|
21
|
+
<tr>
|
|
22
|
+
{dataSeriesColumns.map((column, index) => {
|
|
23
|
+
const text = getSeriesName(column, config)
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<th
|
|
27
|
+
key={`col-header-${column}__${index}`}
|
|
28
|
+
tabIndex={0}
|
|
29
|
+
title={text}
|
|
30
|
+
role='columnheader'
|
|
31
|
+
scope='col'
|
|
32
|
+
onClick={() => {
|
|
33
|
+
setSortBy({ column, asc: sortBy.column === column ? !sortBy.asc : false, colIndex: index })
|
|
34
|
+
}}
|
|
35
|
+
onKeyDown={e => {
|
|
36
|
+
if (e.keyCode === 13) {
|
|
37
|
+
setSortBy({ column, asc: sortBy.column === column ? !sortBy.asc : false, colIndex: index })
|
|
38
|
+
}
|
|
39
|
+
}}
|
|
40
|
+
className={sortBy.column === column ? (sortBy.asc ? 'sort sort-asc' : 'sort sort-desc') : 'sort'}
|
|
41
|
+
{...(sortBy.column === column ? (sortBy.asc ? { 'aria-sort': 'ascending' } : { 'aria-sort': 'descending' }) : null)}
|
|
42
|
+
>
|
|
43
|
+
{text}
|
|
44
|
+
{column === sortBy.column && <span className={'sort-icon'}>{!sortBy.asc ? <UpIcon /> : <DownIcon />}</span>}
|
|
45
|
+
<button>
|
|
46
|
+
<span className='cdcdataviz-sr-only'>{`Sort by ${text} in ${sortBy.column === column ? (!sortBy.asc ? 'descending' : 'ascending') : 'descending'} `} order</span>
|
|
47
|
+
</button>
|
|
48
|
+
</th>
|
|
49
|
+
)
|
|
50
|
+
})}
|
|
51
|
+
</tr>
|
|
52
|
+
)
|
|
53
|
+
} else {
|
|
54
|
+
const sliceVal = config.visualizationType === 'Pie' ? 1 : 0
|
|
55
|
+
return (
|
|
56
|
+
<tr>
|
|
57
|
+
{['__series__', ...Object.keys(runtimeData)].slice(sliceVal).map((row, index) => {
|
|
58
|
+
let column = config.xAxis?.dataKey
|
|
59
|
+
let text = row !== '__series__' ? getChartCellValue(row, column, config, runtimeData) : '__series__'
|
|
60
|
+
return (
|
|
61
|
+
<th
|
|
62
|
+
key={`col-header-${text}__${index}`}
|
|
63
|
+
tabIndex={0}
|
|
64
|
+
title={text}
|
|
65
|
+
role='columnheader'
|
|
66
|
+
scope='col'
|
|
67
|
+
onClick={() => {
|
|
68
|
+
setSortBy({ column: text, asc: sortBy.column === text ? !sortBy.asc : false, colIndex: index })
|
|
69
|
+
}}
|
|
70
|
+
onKeyDown={e => {
|
|
71
|
+
if (e.keyCode === 13) {
|
|
72
|
+
setSortBy({ column: text, asc: sortBy.column === text ? !sortBy.asc : false, colIndex: index })
|
|
73
|
+
}
|
|
74
|
+
}}
|
|
75
|
+
className={sortBy.column === text ? (sortBy.asc ? 'sort sort-asc' : 'sort sort-desc') : 'sort'}
|
|
76
|
+
{...(sortBy.column === text ? (sortBy.asc ? { 'aria-sort': 'ascending' } : { 'aria-sort': 'descending' }) : null)}
|
|
77
|
+
>
|
|
78
|
+
{text === '__series__' ? '' : text}
|
|
79
|
+
{index === sortBy.colIndex && <span className={'sort-icon'}>{!sortBy.asc ? <UpIcon /> : <DownIcon />}</span>}
|
|
80
|
+
<button>
|
|
81
|
+
<span className='cdcdataviz-sr-only'>{`Sort by ${text} in ${sortBy.column === text ? (!sortBy.asc ? 'descending' : 'ascending') : 'descending'} `} order</span>
|
|
82
|
+
</button>
|
|
83
|
+
</th>
|
|
84
|
+
)
|
|
85
|
+
})}
|
|
86
|
+
</tr>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default ChartHeader
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Icon from '@cdc/core/components/ui/Icon'
|
|
2
|
+
|
|
3
|
+
const ExpandCollapse = ({ expanded, setExpanded, tableTitle }) => (
|
|
4
|
+
<div
|
|
5
|
+
className={expanded ? 'data-table-heading' : 'collapsed data-table-heading'}
|
|
6
|
+
onClick={() => {
|
|
7
|
+
setExpanded(!expanded)
|
|
8
|
+
}}
|
|
9
|
+
tabIndex={0}
|
|
10
|
+
onKeyDown={e => {
|
|
11
|
+
if (e.keyCode === 13) {
|
|
12
|
+
setExpanded(!expanded)
|
|
13
|
+
}
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
<Icon display={expanded ? 'minus' : 'plus'} base />
|
|
17
|
+
{tableTitle}
|
|
18
|
+
</div>
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
export default ExpandCollapse
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const UpIcon = () => (
|
|
2
|
+
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 5'>
|
|
3
|
+
<path d='M0 5l5-5 5 5z' />
|
|
4
|
+
</svg>
|
|
5
|
+
)
|
|
6
|
+
export const DownIcon = () => (
|
|
7
|
+
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 5'>
|
|
8
|
+
<path d='M0 0l5 5 5-5z' />
|
|
9
|
+
</svg>
|
|
10
|
+
)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DataTableProps } from '../DataTable'
|
|
2
|
+
import { DownIcon, UpIcon } from './Icons'
|
|
3
|
+
|
|
4
|
+
type MapHeaderProps = DataTableProps & {
|
|
5
|
+
sortBy: { column; asc }
|
|
6
|
+
setSortBy: Function
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const MapHeader = ({ columns, config, indexTitle, sortBy, setSortBy }: MapHeaderProps) => {
|
|
10
|
+
return (
|
|
11
|
+
<tr>
|
|
12
|
+
{Object.keys(columns)
|
|
13
|
+
.filter(column => columns[column].dataTable === true && columns[column].name)
|
|
14
|
+
.map((column, index) => {
|
|
15
|
+
let text
|
|
16
|
+
if (column !== 'geo') {
|
|
17
|
+
text = columns[column].label ? columns[column].label : columns[column].name
|
|
18
|
+
} else {
|
|
19
|
+
text = config.type === 'map' ? indexTitle : config.xAxis?.dataKey
|
|
20
|
+
}
|
|
21
|
+
if (config.type === 'map' && (text === undefined || text === '')) {
|
|
22
|
+
text = 'Location'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<th
|
|
27
|
+
key={`col-header-${column}__${index}`}
|
|
28
|
+
id={column}
|
|
29
|
+
tabIndex={0}
|
|
30
|
+
title={text}
|
|
31
|
+
role='columnheader'
|
|
32
|
+
scope='col'
|
|
33
|
+
onClick={() => {
|
|
34
|
+
setSortBy({ column, asc: sortBy.column === column ? !sortBy.asc : false })
|
|
35
|
+
}}
|
|
36
|
+
onKeyDown={e => {
|
|
37
|
+
if (e.keyCode === 13) {
|
|
38
|
+
setSortBy({ column, asc: sortBy.column === column ? !sortBy.asc : false })
|
|
39
|
+
}
|
|
40
|
+
}}
|
|
41
|
+
className={sortBy.column === column ? (sortBy.asc ? 'sort sort-asc' : 'sort sort-desc') : 'sort'}
|
|
42
|
+
{...(sortBy.column === column ? (sortBy.asc ? { 'aria-sort': 'ascending' } : { 'aria-sort': 'descending' }) : null)}
|
|
43
|
+
>
|
|
44
|
+
{text}
|
|
45
|
+
{sortBy.column === column && <span className={'sort-icon'}>{!sortBy.asc ? <UpIcon /> : <DownIcon />}</span>}
|
|
46
|
+
<button>
|
|
47
|
+
<span className='cdcdataviz-sr-only'>{`Sort by ${text} in ${sortBy.column === column ? (!sortBy.asc ? 'descending' : 'ascending') : 'descending'} `} order</span>
|
|
48
|
+
</button>
|
|
49
|
+
</th>
|
|
50
|
+
)
|
|
51
|
+
})}
|
|
52
|
+
</tr>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default MapHeader
|