@cdc/data-bite 4.22.11 → 4.23.2
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/cdcdatabite.js +8153 -8
- package/{src/index.html → index.html} +1 -1
- package/package.json +12 -14
- package/src/{CdcDataBite.tsx → CdcDataBite.jsx} +21 -30
- package/src/index.jsx +14 -0
- package/src/scss/main.scss +3 -3
- package/vite.config.js +4 -0
- package/examples/private/WCMSRD-12345.json +0 -1027
- package/examples/private/double.json +0 -0
- package/examples/private/totals.json +0 -67
- package/src/index.tsx +0 -16
- /package/src/components/{CircleCallout.js → CircleCallout.jsx} +0 -0
- /package/src/components/{EditorPanel.js → EditorPanel.jsx} +0 -0
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
<!-- <div class="react-container" data-config="/examples/gallery/max-value.json"></div> -->
|
|
20
20
|
<!-- <div class="react-container" data-config="/examples/gallery/sum-of-data.json"></div> -->
|
|
21
21
|
|
|
22
|
-
<
|
|
22
|
+
<script type="module" src="./src/index.jsx"></script>
|
|
23
23
|
</body>
|
|
24
24
|
</html>
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/data-bite",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.23.2",
|
|
4
4
|
"description": "React component for displaying a single piece of data in a card module",
|
|
5
|
+
"moduleName": "CdcDataBite",
|
|
5
6
|
"main": "dist/cdcdatabite",
|
|
7
|
+
"type": "module",
|
|
6
8
|
"scripts": {
|
|
7
|
-
"start": "
|
|
8
|
-
"build": "
|
|
9
|
+
"start": "vite --open",
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"graph": "nx graph",
|
|
9
13
|
"prepublishOnly": "lerna run --scope @cdc/data-bite build"
|
|
10
14
|
},
|
|
11
15
|
"repository": {
|
|
@@ -20,24 +24,18 @@
|
|
|
20
24
|
"license": "Apache-2.0",
|
|
21
25
|
"homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"@cdc/core": "^4.
|
|
27
|
+
"@cdc/core": "^4.23.2",
|
|
24
28
|
"chroma": "0.0.1",
|
|
25
29
|
"chroma-js": "^2.1.0",
|
|
26
|
-
"html-react-parser": "
|
|
30
|
+
"html-react-parser": "^3.0.8",
|
|
27
31
|
"papaparse": "^5.3.0",
|
|
28
32
|
"react-accessible-accordion": "^3.3.4",
|
|
29
33
|
"react-beautiful-dnd": "^13.0.0",
|
|
30
|
-
"react-select": "^3.0.8",
|
|
31
|
-
"react-tooltip": "4.2.8",
|
|
32
|
-
"use-debounce": "^6.0.1",
|
|
33
34
|
"whatwg-fetch": "^3.6.2"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
|
-
"react": "^
|
|
37
|
-
"react-dom": "
|
|
37
|
+
"react": "^18.2.0",
|
|
38
|
+
"react-dom": "^18.2.0"
|
|
38
39
|
},
|
|
39
|
-
"
|
|
40
|
-
"@types/react": "17.x"
|
|
41
|
-
},
|
|
42
|
-
"gitHead": "9768d1ea0e2383044977d988e33531bcdfe33ea6"
|
|
40
|
+
"gitHead": "cd4216f47b1c41bfbc1de3b704f70c52cc7293c2"
|
|
43
41
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState, useCallback
|
|
1
|
+
import React, { useEffect, useState, useCallback } from 'react'
|
|
2
2
|
import EditorPanel from './components/EditorPanel'
|
|
3
3
|
import defaults from './data/initial-state'
|
|
4
4
|
import Loading from '@cdc/core/components/Loading'
|
|
@@ -18,21 +18,11 @@ import { publish } from '@cdc/core/helpers/events'
|
|
|
18
18
|
import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
|
|
19
19
|
import cacheBustingString from '@cdc/core/helpers/cacheBustingString'
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
interface Props {
|
|
23
|
-
configUrl?: string
|
|
24
|
-
config?: any
|
|
25
|
-
isDashboard?: boolean
|
|
26
|
-
isEditor?: boolean
|
|
27
|
-
setConfig?: any
|
|
28
|
-
link?: any
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const CdcDataBite: FC<Props> = props => {
|
|
21
|
+
const CdcDataBite = props => {
|
|
32
22
|
const { configUrl, config: configObj, isDashboard = false, isEditor = false, setConfig: setParentConfig, link } = props
|
|
33
23
|
|
|
34
|
-
const [config, setConfig] = useState
|
|
35
|
-
const [loading, setLoading] = useState
|
|
24
|
+
const [config, setConfig] = useState({ ...defaults })
|
|
25
|
+
const [loading, setLoading] = useState(true)
|
|
36
26
|
|
|
37
27
|
const {
|
|
38
28
|
title,
|
|
@@ -52,7 +42,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
52
42
|
|
|
53
43
|
const transform = new DataTransform()
|
|
54
44
|
|
|
55
|
-
const [currentViewport, setCurrentViewport] = useState
|
|
45
|
+
const [currentViewport, setCurrentViewport] = useState('lg')
|
|
56
46
|
|
|
57
47
|
const [coveLoadedHasRan, setCoveLoadedHasRan] = useState(false)
|
|
58
48
|
|
|
@@ -83,6 +73,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
83
73
|
setConfig(newConfig)
|
|
84
74
|
}
|
|
85
75
|
|
|
76
|
+
//@ts-ignore
|
|
86
77
|
const loadConfig = async () => {
|
|
87
78
|
let response = configObj || (await (await fetch(configUrl)).json())
|
|
88
79
|
|
|
@@ -110,13 +101,13 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
110
101
|
setLoading(false)
|
|
111
102
|
}
|
|
112
103
|
|
|
113
|
-
const calculateDataBite = (includePrefixSuffix
|
|
104
|
+
const calculateDataBite = (includePrefixSuffix= true) => {
|
|
114
105
|
//If either the column or function aren't set, do not calculate
|
|
115
106
|
if (!dataColumn || !dataFunction) {
|
|
116
107
|
return ''
|
|
117
108
|
}
|
|
118
109
|
|
|
119
|
-
const applyPrecision = (value
|
|
110
|
+
const applyPrecision = (value) => {
|
|
120
111
|
// first validation
|
|
121
112
|
if (value === undefined || value === null) {
|
|
122
113
|
console.error('Enter correct value to "applyPrecision()" function ')
|
|
@@ -127,7 +118,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
127
118
|
console.error(' Argunment isNaN, "applyPrecision()" function ')
|
|
128
119
|
return
|
|
129
120
|
}
|
|
130
|
-
let result
|
|
121
|
+
let result = value
|
|
131
122
|
let roundToPlace = Number(config.dataFormat.roundToPlace) // default equals to 0
|
|
132
123
|
// ROUND FIELD going -1,-2,-3 numbers
|
|
133
124
|
if (roundToPlace < 0) {
|
|
@@ -141,7 +132,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
141
132
|
}
|
|
142
133
|
|
|
143
134
|
// filter null and 0 out from count data
|
|
144
|
-
const getColumnCount = (arr
|
|
135
|
+
const getColumnCount = (arr) => {
|
|
145
136
|
if (config.dataFormat.ignoreZeros) {
|
|
146
137
|
numericalData = numericalData.filter(item => item && item)
|
|
147
138
|
return numericalData.length
|
|
@@ -150,7 +141,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
150
141
|
}
|
|
151
142
|
}
|
|
152
143
|
|
|
153
|
-
const getColumnSum = (arr
|
|
144
|
+
const getColumnSum = (arr) => {
|
|
154
145
|
// first validation
|
|
155
146
|
if (arr === undefined || arr === null) {
|
|
156
147
|
console.error('Enter valid value for getColumnSum function ')
|
|
@@ -162,17 +153,17 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
162
153
|
console.error('Arguments are not valid getColumnSum function ')
|
|
163
154
|
return
|
|
164
155
|
}
|
|
165
|
-
let sum
|
|
156
|
+
let sum = 0
|
|
166
157
|
if (arr.length > 1) {
|
|
167
158
|
/// first convert each element to number then add using reduce method to escape string concatination.
|
|
168
|
-
sum = arr.map(el => Number(el)).reduce((sum
|
|
159
|
+
sum = arr.map(el => Number(el)).reduce((sum, x) => sum + x)
|
|
169
160
|
} else {
|
|
170
161
|
sum = Number(arr[0])
|
|
171
162
|
}
|
|
172
163
|
return applyPrecision(sum)
|
|
173
164
|
}
|
|
174
165
|
|
|
175
|
-
const getColumnMean = (arr
|
|
166
|
+
const getColumnMean = (arr) => {
|
|
176
167
|
// add default params to escape errors on runtime
|
|
177
168
|
// first validation
|
|
178
169
|
if (arr === undefined || arr === null || !Array.isArray(arr)) {
|
|
@@ -184,7 +175,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
184
175
|
arr = arr.filter(num => num !== 0)
|
|
185
176
|
}
|
|
186
177
|
|
|
187
|
-
let mean
|
|
178
|
+
let mean = 0
|
|
188
179
|
if (arr.length > 1) {
|
|
189
180
|
/// first convert each element to number then add using reduce method to escape string concatination.
|
|
190
181
|
mean = arr.map(el => Number(el)).reduce((a, b) => a + b) / arr.length
|
|
@@ -194,7 +185,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
194
185
|
return applyPrecision(mean)
|
|
195
186
|
}
|
|
196
187
|
|
|
197
|
-
const getMode = (arr
|
|
188
|
+
const getMode = (arr = []) => {
|
|
198
189
|
// add default params to escape errors on runtime
|
|
199
190
|
// this function accepts any array and returns array of strings
|
|
200
191
|
let freq = {}
|
|
@@ -229,7 +220,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
229
220
|
return applyPrecision(value)
|
|
230
221
|
}
|
|
231
222
|
|
|
232
|
-
const applyLocaleString = (value
|
|
223
|
+
const applyLocaleString = (value) => {
|
|
233
224
|
if (value === undefined || value === null) return
|
|
234
225
|
if (Number.isNaN(value) || typeof value === 'number') {
|
|
235
226
|
value = String(value)
|
|
@@ -248,7 +239,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
248
239
|
return formattedValue
|
|
249
240
|
}
|
|
250
241
|
|
|
251
|
-
let dataBite
|
|
242
|
+
let dataBite = ''
|
|
252
243
|
|
|
253
244
|
//Optionally filter the data based on the user's filter
|
|
254
245
|
let filteredData = config.data
|
|
@@ -263,7 +254,7 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
263
254
|
}
|
|
264
255
|
})
|
|
265
256
|
|
|
266
|
-
let numericalData
|
|
257
|
+
let numericalData = []
|
|
267
258
|
// Get the column's data
|
|
268
259
|
if (filteredData.length) {
|
|
269
260
|
filteredData.forEach(row => {
|
|
@@ -297,8 +288,8 @@ const CdcDataBite: FC<Props> = props => {
|
|
|
297
288
|
dataBite = getMode(numericalData).join('')
|
|
298
289
|
break
|
|
299
290
|
case DATA_FUNCTION_RANGE:
|
|
300
|
-
let rangeMin
|
|
301
|
-
let rangeMax
|
|
291
|
+
let rangeMin = Math.min(...numericalData)
|
|
292
|
+
let rangeMax = Math.max(...numericalData)
|
|
302
293
|
rangeMin = applyPrecision(rangeMin)
|
|
303
294
|
rangeMax = applyPrecision(rangeMax)
|
|
304
295
|
if (config.dataFormat.commas) {
|
package/src/index.jsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import ReactDOM from 'react-dom/client'
|
|
3
|
+
|
|
4
|
+
import CdcDataBite from './CdcDataBite'
|
|
5
|
+
|
|
6
|
+
let isEditor = window.location.href.includes('editor=true')
|
|
7
|
+
|
|
8
|
+
let domContainer = document.getElementsByClassName('react-container')[0]
|
|
9
|
+
|
|
10
|
+
ReactDOM.createRoot(domContainer).render(
|
|
11
|
+
<React.StrictMode>
|
|
12
|
+
<CdcDataBite configUrl={domContainer.attributes['data-config']?.value} isEditor={isEditor} />
|
|
13
|
+
</React.StrictMode>,
|
|
14
|
+
)
|
package/src/scss/main.scss
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
@import '
|
|
2
|
-
@import '
|
|
3
|
-
@import '
|
|
1
|
+
@import '@cdc/core/styles/base';
|
|
2
|
+
@import '@cdc/core/styles/heading-colors';
|
|
3
|
+
@import '@cdc/core/styles/v2/themes/color-definitions';
|
|
4
4
|
@import 'variables';
|
|
5
5
|
|
|
6
6
|
.cdc-open-viz-module.type-data-bite {
|
package/vite.config.js
ADDED