@cdc/waffle-chart 4.22.10 → 4.22.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/README.md +4 -4
- package/dist/cdcwafflechart.js +1 -1
- package/examples/example-data.json +90 -90
- package/examples/gallery/avg-to-max.json +3161 -3161
- package/examples/gallery/count.json +3161 -3161
- package/package.json +3 -3
- package/src/CdcWaffleChart.tsx +130 -198
- package/src/ConfigContext.js +3 -3
- package/src/components/EditorPanel.js +149 -310
- package/src/data/initial-state.js +31 -31
- package/src/index.html +24 -26
- package/src/index.js +7 -7
- package/src/scss/main.scss +3 -4
- package/src/scss/waffle-chart.scss +21 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/waffle-chart",
|
|
3
|
-
"version": "4.22.
|
|
3
|
+
"version": "4.22.11",
|
|
4
4
|
"description": "React component for displaying a single piece of data in a card module",
|
|
5
5
|
"main": "dist/cdcwafflechart",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@cdc/core": "^4.22.
|
|
23
|
+
"@cdc/core": "^4.22.11",
|
|
24
24
|
"@visx/shape": "^2.1.1",
|
|
25
25
|
"chroma": "0.0.1",
|
|
26
26
|
"chroma-js": "^2.1.0",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"resolutions": {
|
|
38
38
|
"@types/react": "17.x"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "9768d1ea0e2383044977d988e33531bcdfe33ea6"
|
|
41
41
|
}
|
package/src/CdcWaffleChart.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState,FC } from 'react'
|
|
1
|
+
import React, { useCallback, useEffect, useState, FC } from 'react'
|
|
2
2
|
import parse from 'html-react-parser'
|
|
3
3
|
import { Group } from '@visx/group'
|
|
4
4
|
import { Circle, Bar } from '@visx/shape'
|
|
@@ -13,9 +13,9 @@ import ConfigContext from './ConfigContext'
|
|
|
13
13
|
import EditorPanel from './components/EditorPanel'
|
|
14
14
|
import defaults from './data/initial-state'
|
|
15
15
|
|
|
16
|
-
import { publish } from '@cdc/core/helpers/events'
|
|
16
|
+
import { publish } from '@cdc/core/helpers/events'
|
|
17
17
|
|
|
18
|
-
import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
|
|
18
|
+
import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
|
|
19
19
|
|
|
20
20
|
import './scss/main.scss'
|
|
21
21
|
|
|
@@ -30,57 +30,36 @@ const themeColor = {
|
|
|
30
30
|
'theme-indigo': '#26418f',
|
|
31
31
|
'theme-cyan': '#006778',
|
|
32
32
|
'theme-green': '#4b830d',
|
|
33
|
-
'theme-amber': '#fbab18'
|
|
33
|
+
'theme-amber': '#fbab18'
|
|
34
34
|
}
|
|
35
|
-
interface Props{
|
|
36
|
-
config?:
|
|
35
|
+
interface Props {
|
|
36
|
+
config?: any
|
|
37
|
+
isEditor?: any
|
|
38
|
+
link?: any
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
const WaffleChart:FC<Props>
|
|
40
|
-
let {
|
|
41
|
-
title,
|
|
42
|
-
theme,
|
|
43
|
-
shape,
|
|
44
|
-
nodeWidth,
|
|
45
|
-
nodeSpacer,
|
|
46
|
-
prefix,
|
|
47
|
-
suffix,
|
|
48
|
-
subtext,
|
|
49
|
-
content,
|
|
50
|
-
orientation,
|
|
51
|
-
filters,
|
|
52
|
-
dataColumn,
|
|
53
|
-
dataFunction,
|
|
54
|
-
dataConditionalColumn,
|
|
55
|
-
dataConditionalOperator,
|
|
56
|
-
dataConditionalComparate,
|
|
57
|
-
customDenom,
|
|
58
|
-
dataDenom,
|
|
59
|
-
dataDenomColumn,
|
|
60
|
-
dataDenomFunction,
|
|
61
|
-
roundToPlace
|
|
62
|
-
} = config
|
|
41
|
+
const WaffleChart: FC<Props> = ({ config, isEditor, link }) => {
|
|
42
|
+
let { title, theme, shape, nodeWidth, nodeSpacer, prefix, suffix, subtext, content, orientation, filters, dataColumn, dataFunction, dataConditionalColumn, dataConditionalOperator, dataConditionalComparate, customDenom, dataDenom, dataDenomColumn, dataDenomFunction, roundToPlace } = config
|
|
63
43
|
|
|
64
44
|
const calculateData = useCallback(() => {
|
|
65
|
-
|
|
66
45
|
//If either the column or function aren't set, do not calculate
|
|
67
46
|
if (!dataColumn || !dataFunction) {
|
|
68
47
|
return ''
|
|
69
48
|
}
|
|
70
49
|
|
|
71
|
-
const getColumnSum =
|
|
50
|
+
const getColumnSum = arr => {
|
|
72
51
|
if (Array.isArray(arr) && arr.length > 0) {
|
|
73
52
|
const sum = arr.reduce((sum, x) => sum + x)
|
|
74
53
|
return applyPrecision(sum)
|
|
75
54
|
}
|
|
76
55
|
}
|
|
77
56
|
|
|
78
|
-
const getColumnMean =
|
|
57
|
+
const getColumnMean = arr => {
|
|
79
58
|
const mean = arr.length > 1 ? arr.reduce((a, b) => a + b) / arr.length : arr[0]
|
|
80
59
|
return applyPrecision(mean)
|
|
81
60
|
}
|
|
82
61
|
|
|
83
|
-
const getMode =
|
|
62
|
+
const getMode = arr => {
|
|
84
63
|
let freq = {}
|
|
85
64
|
let max = -Infinity
|
|
86
65
|
|
|
@@ -107,12 +86,12 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
107
86
|
|
|
108
87
|
const getMedian = arr => {
|
|
109
88
|
const mid = Math.floor(arr.length / 2),
|
|
110
|
-
nums = [
|
|
89
|
+
nums = [...arr].sort((a, b) => a - b)
|
|
111
90
|
const value = arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2
|
|
112
91
|
return applyPrecision(value)
|
|
113
92
|
}
|
|
114
93
|
|
|
115
|
-
const applyPrecision =
|
|
94
|
+
const applyPrecision = value => {
|
|
116
95
|
if ('' !== roundToPlace && !isNaN(roundToPlace) && Number(roundToPlace) > -1) {
|
|
117
96
|
value = Number(value).toFixed(Number(roundToPlace))
|
|
118
97
|
}
|
|
@@ -122,7 +101,7 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
122
101
|
//Optionally filter the data based on the user's filter
|
|
123
102
|
let filteredData = config.data
|
|
124
103
|
|
|
125
|
-
filters.map(
|
|
104
|
+
filters.map(filter => {
|
|
126
105
|
if (filter.columnName && filter.columnValue) {
|
|
127
106
|
filteredData = filteredData.filter(function (e) {
|
|
128
107
|
return e[filter.columnName] === filter.columnValue
|
|
@@ -136,26 +115,26 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
136
115
|
|
|
137
116
|
if (dataConditionalColumn !== '' && dataConditionalOperator !== '' && dataConditionalComparate !== '') {
|
|
138
117
|
switch (dataConditionalOperator) {
|
|
139
|
-
case
|
|
118
|
+
case '<':
|
|
140
119
|
conditionalData = filteredData.filter(e => e[dataConditionalColumn] < dataConditionalComparate)
|
|
141
120
|
break
|
|
142
|
-
case
|
|
121
|
+
case '>':
|
|
143
122
|
conditionalData = filteredData.filter(e => e[dataConditionalColumn] > dataConditionalComparate)
|
|
144
123
|
break
|
|
145
|
-
case
|
|
124
|
+
case '<=':
|
|
146
125
|
conditionalData = filteredData.filter(e => e[dataConditionalColumn] <= dataConditionalComparate)
|
|
147
126
|
break
|
|
148
|
-
case
|
|
127
|
+
case '>=':
|
|
149
128
|
conditionalData = filteredData.filter(e => e[dataConditionalColumn] >= dataConditionalComparate)
|
|
150
129
|
break
|
|
151
|
-
case
|
|
130
|
+
case '=':
|
|
152
131
|
if (isNaN(Number(dataConditionalComparate))) {
|
|
153
132
|
conditionalData = filteredData.filter(e => String(e[dataConditionalColumn]) === dataConditionalComparate)
|
|
154
133
|
} else {
|
|
155
134
|
conditionalData = filteredData.filter(e => e[dataConditionalColumn] === dataConditionalComparate)
|
|
156
135
|
}
|
|
157
136
|
break
|
|
158
|
-
case
|
|
137
|
+
case '≠':
|
|
159
138
|
if (isNaN(Number(dataConditionalComparate))) {
|
|
160
139
|
conditionalData = filteredData.filter(e => String(e[dataConditionalColumn]) !== dataConditionalComparate)
|
|
161
140
|
} else {
|
|
@@ -172,21 +151,25 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
172
151
|
const denomColumnData = filteredData.map(a => a[dataDenomColumn])
|
|
173
152
|
|
|
174
153
|
//Filter the column's data for numerical values only
|
|
175
|
-
let numericalData = columnData
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
154
|
+
let numericalData = columnData
|
|
155
|
+
.filter(value => {
|
|
156
|
+
let include = false
|
|
157
|
+
if (Number(value) || Number.isFinite(Number(value))) {
|
|
158
|
+
include = true
|
|
159
|
+
}
|
|
160
|
+
return include
|
|
161
|
+
})
|
|
162
|
+
.map(Number)
|
|
163
|
+
|
|
164
|
+
let numericalDenomData = denomColumnData
|
|
165
|
+
.filter(value => {
|
|
166
|
+
let include = false
|
|
167
|
+
if (Number(value) || Number.isFinite(Number(value))) {
|
|
168
|
+
include = true
|
|
169
|
+
}
|
|
170
|
+
return include
|
|
171
|
+
})
|
|
172
|
+
.map(Number)
|
|
190
173
|
|
|
191
174
|
// Calculate numerator ------------------
|
|
192
175
|
let waffleNumerator = ''
|
|
@@ -213,7 +196,7 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
213
196
|
[DATA_FUNCTION_MEDIAN]: getMedian(numericalDenomData).toString(),
|
|
214
197
|
[DATA_FUNCTION_MAX]: Math.max(...numericalDenomData).toString(),
|
|
215
198
|
[DATA_FUNCTION_MIN]: Math.min(...numericalDenomData).toString(),
|
|
216
|
-
[DATA_FUNCTION_MODE]: getMode(numericalDenomData).join(', ')
|
|
199
|
+
[DATA_FUNCTION_MODE]: getMode(numericalDenomData).join(', ')
|
|
217
200
|
}
|
|
218
201
|
|
|
219
202
|
if (customDenom && dataDenomColumn && dataDenomFunction) {
|
|
@@ -224,20 +207,7 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
224
207
|
|
|
225
208
|
// @ts-ignore
|
|
226
209
|
return applyPrecision((waffleNumerator / waffleDenominator) * 100)
|
|
227
|
-
}, [
|
|
228
|
-
dataColumn,
|
|
229
|
-
dataFunction,
|
|
230
|
-
config.data,
|
|
231
|
-
filters,
|
|
232
|
-
dataConditionalColumn,
|
|
233
|
-
dataConditionalOperator,
|
|
234
|
-
dataConditionalComparate,
|
|
235
|
-
customDenom,
|
|
236
|
-
dataDenomColumn,
|
|
237
|
-
dataDenomFunction,
|
|
238
|
-
roundToPlace,
|
|
239
|
-
dataDenom
|
|
240
|
-
])
|
|
210
|
+
}, [dataColumn, dataFunction, config.data, filters, dataConditionalColumn, dataConditionalOperator, dataConditionalComparate, customDenom, dataDenomColumn, dataDenomFunction, roundToPlace, dataDenom])
|
|
241
211
|
|
|
242
212
|
const dataPercentage = calculateData()
|
|
243
213
|
|
|
@@ -248,7 +218,7 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
248
218
|
|
|
249
219
|
const calculatePos = (shape, axis, index, width, spacer) => {
|
|
250
220
|
let mod = axis === 'x' ? index % 10 : axis === 'y' ? Math.floor(index / 10) : null
|
|
251
|
-
return shape === 'circle' ?
|
|
221
|
+
return shape === 'circle' ? mod * (width + spacer) + width / 2 : mod * (width + spacer)
|
|
252
222
|
}
|
|
253
223
|
|
|
254
224
|
for (let i = 0; i < 100; i++) {
|
|
@@ -257,114 +227,101 @@ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
|
|
|
257
227
|
x: calculatePos(shape, 'x', i, nodeWidthNum, nodeSpacerNum),
|
|
258
228
|
y: calculatePos(shape, 'y', i, nodeWidthNum, nodeSpacerNum),
|
|
259
229
|
color: themeColor[theme],
|
|
260
|
-
opacity: i + 1 >
|
|
230
|
+
opacity: i + 1 > 100 - Math.round(dataPercentage) ? 1 : 0.35
|
|
261
231
|
}
|
|
262
232
|
waffleData.push(newNode)
|
|
263
233
|
}
|
|
264
234
|
|
|
265
|
-
return waffleData.map((node, key) =>
|
|
266
|
-
node.shape === 'square'
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
: node.shape === 'person' ?
|
|
235
|
+
return waffleData.map((node, key) =>
|
|
236
|
+
node.shape === 'square' ? (
|
|
237
|
+
<Bar className='cdc-waffle-chart__node' style={{ transitionDelay: `${0.1 * key}ms` }} x={node.x} y={node.y} width={nodeWidthNum} height={nodeWidthNum} fill={node.color} fillOpacity={node.opacity} key={key} />
|
|
238
|
+
) : node.shape === 'person' ? (
|
|
270
239
|
<path
|
|
271
240
|
style={{ transform: `translateX(${node.x + nodeWidthNum / 4}px) translateY(${node.y}px) scale(${nodeWidthNum / 20})` }}
|
|
272
|
-
fill={node.color}
|
|
273
|
-
|
|
241
|
+
fill={node.color}
|
|
242
|
+
fillOpacity={node.opacity}
|
|
243
|
+
key={key}
|
|
244
|
+
d='M3.75,0a2.5,2.5,0,1,1-2.5,2.5A2.5,2.5,0,0,1,3.75,0M5.625,5.625H5.18125a3.433,3.433,0,0,1-2.8625,0H1.875A1.875,1.875,
|
|
274
245
|
0,0,0,0,7.5v5.3125a.9375.9375,0,0,0,.9375.9375h.625v5.3125A.9375.9375,0,0,0,2.5,20H5a.9375.9375,0,0,0,
|
|
275
|
-
.9375-.9375V13.75h.625A.9375.9375,0,0,0,7.5,12.8125V7.5A1.875,1.875,0,0,0,5.625,5.625Z
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
<Circle className=
|
|
279
|
-
|
|
280
|
-
)
|
|
281
|
-
}, [
|
|
246
|
+
.9375-.9375V13.75h.625A.9375.9375,0,0,0,7.5,12.8125V7.5A1.875,1.875,0,0,0,5.625,5.625Z'
|
|
247
|
+
></path>
|
|
248
|
+
) : (
|
|
249
|
+
<Circle className='cdc-waffle-chart__node' style={{ transitionDelay: `${0.1 * key}ms` }} cx={node.x} cy={node.y} r={nodeWidthNum / 2} fill={node.color} fillOpacity={node.opacity} key={key} />
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
}, [theme, dataPercentage, shape, nodeWidth, nodeSpacer])
|
|
282
253
|
|
|
283
254
|
const setRatio = useCallback(() => {
|
|
284
|
-
return
|
|
285
|
-
}, [
|
|
255
|
+
return nodeWidth * 10 + nodeSpacer * 9
|
|
256
|
+
}, [nodeWidth, nodeSpacer])
|
|
286
257
|
|
|
287
258
|
let dataFontSize = config.fontSize ? { fontSize: config.fontSize + 'px' } : null
|
|
288
259
|
|
|
289
260
|
const { innerContainerClasses, contentClasses } = useDataVizClasses(config)
|
|
290
261
|
|
|
291
262
|
const handleWaffleChartAriaLabel = (state, testing = false) => {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
263
|
+
if (testing) console.log(`handleWaffleChartAriaLabels Testing On:`, state)
|
|
264
|
+
try {
|
|
265
|
+
let ariaLabel = 'Waffle chart'
|
|
266
|
+
if (state.title) {
|
|
267
|
+
ariaLabel += ` with the title: ${state.title}`
|
|
268
|
+
}
|
|
269
|
+
return ariaLabel
|
|
270
|
+
} catch (e) {
|
|
271
|
+
console.error(e.message)
|
|
272
|
+
}
|
|
302
273
|
}
|
|
303
274
|
|
|
304
275
|
return (
|
|
305
276
|
<div className={innerContainerClasses.join(' ')}>
|
|
306
277
|
<>
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
{buildWaffle()}
|
|
320
|
-
</Group>
|
|
321
|
-
</svg>
|
|
322
|
-
</div>
|
|
323
|
-
{(dataPercentage || content) &&
|
|
324
|
-
<div className="cove-waffle-chart__data">
|
|
325
|
-
{dataPercentage &&
|
|
326
|
-
<div className="cove-waffle-chart__data--primary" style={dataFontSize}>
|
|
327
|
-
{prefix ? prefix : null}{dataPercentage}{suffix ? suffix : null}
|
|
278
|
+
{title && (
|
|
279
|
+
<header className={`cove-component__header chart-title ${config.theme}`} aria-hidden='true'>
|
|
280
|
+
{parse(title)}
|
|
281
|
+
</header>
|
|
282
|
+
)}
|
|
283
|
+
<div className={contentClasses.join(' ')}>
|
|
284
|
+
<div className='cove-component__content-wrap'>
|
|
285
|
+
<div className={`cove-waffle-chart${orientation === 'vertical' ? ' cove-waffle-chart--verical' : ''}${config.overallFontSize ? ' font-' + config.overallFontSize : ''}`}>
|
|
286
|
+
<div className='cove-waffle-chart__chart' style={{ width: setRatio() }}>
|
|
287
|
+
<svg width={setRatio()} height={setRatio()} role='img' aria-label={handleWaffleChartAriaLabel(config)} tabIndex={0}>
|
|
288
|
+
<Group>{buildWaffle()}</Group>
|
|
289
|
+
</svg>
|
|
328
290
|
</div>
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
291
|
+
{(dataPercentage || content) && (
|
|
292
|
+
<div className='cove-waffle-chart__data'>
|
|
293
|
+
{dataPercentage && (
|
|
294
|
+
<div className='cove-waffle-chart__data--primary' style={dataFontSize}>
|
|
295
|
+
{prefix ? prefix : null}
|
|
296
|
+
{dataPercentage}
|
|
297
|
+
{suffix ? suffix : null}
|
|
298
|
+
</div>
|
|
299
|
+
)}
|
|
300
|
+
<div className='cove-waffle-chart__data--text'>{parse(content)}</div>
|
|
301
|
+
|
|
302
|
+
{subtext && <div className='cove-waffle-chart__subtext'>{parse(subtext)}</div>}
|
|
335
303
|
</div>
|
|
336
|
-
}
|
|
304
|
+
)}
|
|
337
305
|
</div>
|
|
338
|
-
}
|
|
339
306
|
</div>
|
|
340
307
|
</div>
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
</div>
|
|
308
|
+
{link && link}
|
|
309
|
+
</>
|
|
310
|
+
</div>
|
|
345
311
|
)
|
|
346
312
|
}
|
|
347
313
|
|
|
348
|
-
const CdcWaffleChart = (
|
|
349
|
-
{
|
|
350
|
-
configUrl,
|
|
351
|
-
config: configObj,
|
|
352
|
-
isDashboard = false,
|
|
353
|
-
isEditor = false,
|
|
354
|
-
setConfig: setParentConfig
|
|
355
|
-
}
|
|
356
|
-
) => {
|
|
357
|
-
|
|
314
|
+
const CdcWaffleChart = ({ configUrl, config: configObj, isDashboard = false, isEditor = false, setConfig: setParentConfig }) => {
|
|
358
315
|
// Default States
|
|
359
|
-
const [
|
|
360
|
-
const [
|
|
316
|
+
const [config, setConfig] = useState({ ...defaults })
|
|
317
|
+
const [loading, setLoading] = useState(true)
|
|
361
318
|
|
|
362
|
-
const [
|
|
363
|
-
const [
|
|
364
|
-
const [
|
|
319
|
+
const [currentViewport, setCurrentViewport] = useState<String>('lg')
|
|
320
|
+
const [coveLoadedHasRan, setCoveLoadedHasRan] = useState(false)
|
|
321
|
+
const [container, setContainer] = useState()
|
|
365
322
|
|
|
366
323
|
// Default Functions
|
|
367
|
-
const updateConfig =
|
|
324
|
+
const updateConfig = newConfig => {
|
|
368
325
|
Object.keys(defaults).forEach(key => {
|
|
369
326
|
if (newConfig[key] && 'object' === typeof newConfig[key] && !Array.isArray(newConfig[key])) {
|
|
370
327
|
newConfig[key] = { ...defaults[key], ...newConfig[key] }
|
|
@@ -379,7 +336,7 @@ const CdcWaffleChart = (
|
|
|
379
336
|
}
|
|
380
337
|
|
|
381
338
|
const loadConfig = useCallback(async () => {
|
|
382
|
-
let response = configObj || await (await fetch(configUrl)).json()
|
|
339
|
+
let response = configObj || (await (await fetch(configUrl)).json())
|
|
383
340
|
let responseData = response.data ?? {}
|
|
384
341
|
|
|
385
342
|
if (response.dataUrl) {
|
|
@@ -413,38 +370,35 @@ const CdcWaffleChart = (
|
|
|
413
370
|
|
|
414
371
|
//Load initial config
|
|
415
372
|
useEffect(() => {
|
|
416
|
-
loadConfig().catch(
|
|
373
|
+
loadConfig().catch(err => console.log(err))
|
|
417
374
|
}, [])
|
|
418
375
|
|
|
419
376
|
useEffect(() => {
|
|
420
377
|
if (config && !coveLoadedHasRan && container) {
|
|
421
|
-
|
|
422
|
-
|
|
378
|
+
publish('cove_loaded', { config: config })
|
|
379
|
+
setCoveLoadedHasRan(true)
|
|
423
380
|
}
|
|
424
|
-
}, [config, container])
|
|
381
|
+
}, [config, container])
|
|
425
382
|
|
|
426
383
|
//Reload config if config object provided/updated
|
|
427
384
|
useEffect(() => {
|
|
428
|
-
loadConfig().catch(
|
|
385
|
+
loadConfig().catch(err => console.log(err))
|
|
429
386
|
}, [])
|
|
430
387
|
|
|
431
388
|
//Reload config if parent passes different config
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
389
|
+
if (configObj) {
|
|
390
|
+
useEffect(() => {
|
|
391
|
+
console.log('changing')
|
|
392
|
+
if (!configObj.dataUrl) {
|
|
393
|
+
updateConfig({ ...defaults, ...configObj })
|
|
394
|
+
}
|
|
395
|
+
}, [configObj.data])
|
|
396
|
+
}
|
|
437
397
|
|
|
438
|
-
let content =
|
|
398
|
+
let content = <Loading />
|
|
439
399
|
|
|
440
400
|
if (loading === false) {
|
|
441
|
-
let classNames = [
|
|
442
|
-
'cove',
|
|
443
|
-
'type-waffle-chart',
|
|
444
|
-
currentViewport,
|
|
445
|
-
config.theme,
|
|
446
|
-
'font-' + config.overallFontSize
|
|
447
|
-
]
|
|
401
|
+
let classNames = ['cove', 'type-waffle-chart', currentViewport, config.theme, 'font-' + config.overallFontSize]
|
|
448
402
|
|
|
449
403
|
if (isEditor) {
|
|
450
404
|
classNames.push('is-editor')
|
|
@@ -454,28 +408,21 @@ const CdcWaffleChart = (
|
|
|
454
408
|
|
|
455
409
|
let body = (
|
|
456
410
|
<div className={`${bodyClasses.join(' ')}`} ref={outerContainerRef}>
|
|
457
|
-
<WaffleChart config={config} isEditor={isEditor}/>
|
|
411
|
+
<WaffleChart config={config} isEditor={isEditor} />
|
|
458
412
|
</div>
|
|
459
|
-
)
|
|
413
|
+
)
|
|
460
414
|
|
|
461
415
|
content = (
|
|
462
416
|
<div className={classNames.join(' ')}>
|
|
463
|
-
{isEditor &&
|
|
464
|
-
<EditorPanel>
|
|
465
|
-
{body}
|
|
466
|
-
</EditorPanel>
|
|
467
|
-
}
|
|
417
|
+
{isEditor && <EditorPanel>{body}</EditorPanel>}
|
|
468
418
|
{!isEditor && body}
|
|
469
419
|
</div>
|
|
470
420
|
)
|
|
471
421
|
}
|
|
472
422
|
|
|
473
423
|
return (
|
|
474
|
-
<ErrorBoundary component=
|
|
475
|
-
<ConfigContext.Provider
|
|
476
|
-
value={{ config, updateConfig, loading, data: config.data, setParentConfig, isDashboard, outerContainerRef }}>
|
|
477
|
-
{content}
|
|
478
|
-
</ConfigContext.Provider>
|
|
424
|
+
<ErrorBoundary component='WaffleChart'>
|
|
425
|
+
<ConfigContext.Provider value={{ config, updateConfig, loading, data: config.data, setParentConfig, isDashboard, outerContainerRef }}>{content}</ConfigContext.Provider>
|
|
479
426
|
</ErrorBoundary>
|
|
480
427
|
)
|
|
481
428
|
}
|
|
@@ -490,15 +437,7 @@ export const DATA_FUNCTION_MIN = 'Min'
|
|
|
490
437
|
export const DATA_FUNCTION_MODE = 'Mode'
|
|
491
438
|
export const DATA_FUNCTION_SUM = 'Sum'
|
|
492
439
|
|
|
493
|
-
export const DATA_FUNCTIONS = [
|
|
494
|
-
DATA_FUNCTION_COUNT,
|
|
495
|
-
DATA_FUNCTION_MAX,
|
|
496
|
-
DATA_FUNCTION_MEAN,
|
|
497
|
-
DATA_FUNCTION_MEDIAN,
|
|
498
|
-
DATA_FUNCTION_MIN,
|
|
499
|
-
DATA_FUNCTION_MODE,
|
|
500
|
-
DATA_FUNCTION_SUM
|
|
501
|
-
]
|
|
440
|
+
export const DATA_FUNCTIONS = [DATA_FUNCTION_COUNT, DATA_FUNCTION_MAX, DATA_FUNCTION_MEAN, DATA_FUNCTION_MEDIAN, DATA_FUNCTION_MIN, DATA_FUNCTION_MODE, DATA_FUNCTION_SUM]
|
|
502
441
|
|
|
503
442
|
export const DATA_OPERATOR_LESS = '<'
|
|
504
443
|
export const DATA_OPERATOR_GREATER = '>'
|
|
@@ -507,11 +446,4 @@ export const DATA_OPERATOR_GREATEREQUAL = '>='
|
|
|
507
446
|
export const DATA_OPERATOR_EQUAL = '='
|
|
508
447
|
export const DATA_OPERATOR_NOTEQUAL = '≠'
|
|
509
448
|
|
|
510
|
-
export const DATA_OPERATORS = [
|
|
511
|
-
DATA_OPERATOR_LESS,
|
|
512
|
-
DATA_OPERATOR_GREATER,
|
|
513
|
-
DATA_OPERATOR_LESSEQUAL,
|
|
514
|
-
DATA_OPERATOR_GREATEREQUAL,
|
|
515
|
-
DATA_OPERATOR_EQUAL,
|
|
516
|
-
DATA_OPERATOR_NOTEQUAL
|
|
517
|
-
]
|
|
449
|
+
export const DATA_OPERATORS = [DATA_OPERATOR_LESS, DATA_OPERATOR_GREATER, DATA_OPERATOR_LESSEQUAL, DATA_OPERATOR_GREATEREQUAL, DATA_OPERATOR_EQUAL, DATA_OPERATOR_NOTEQUAL]
|
package/src/ConfigContext.js
CHANGED