@cdc/waffle-chart 4.24.10 → 4.24.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdc/waffle-chart",
3
- "version": "4.24.10",
3
+ "version": "4.24.11",
4
4
  "description": "React component for displaying a single piece of data in a card module",
5
5
  "moduleName": "CdcWaffleChart",
6
6
  "main": "dist/cdcwafflechart",
@@ -27,7 +27,7 @@
27
27
  "license": "Apache-2.0",
28
28
  "homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
29
29
  "dependencies": {
30
- "@cdc/core": "^4.24.10",
30
+ "@cdc/core": "^4.24.11",
31
31
  "@visx/group": "^3.0.0",
32
32
  "@visx/scale": "^3.0.0",
33
33
  "@visx/shape": "^3.0.0",
@@ -42,5 +42,5 @@
42
42
  "react": "^18.2.0",
43
43
  "react-dom": "^18.2.0"
44
44
  },
45
- "gitHead": "a4d88d1bc91f596e1b0307d8e25c57ad8c668b75"
45
+ "gitHead": "9ab5ee9b2b0ef7321a66a2104be6ce8899ec3808"
46
46
  }
@@ -39,7 +39,29 @@ type CdcWaffleChartProps = {
39
39
  }
40
40
 
41
41
  const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateConfig }) => {
42
- const { title, theme, shape, nodeWidth, nodeSpacer, prefix, suffix, subtext, content, orientation, filters, dataColumn, dataFunction, dataConditionalColumn, dataConditionalOperator, dataConditionalComparate, customDenom, dataDenom, dataDenomColumn, dataDenomFunction, roundToPlace } = config
42
+ const {
43
+ title,
44
+ theme,
45
+ shape,
46
+ nodeWidth,
47
+ nodeSpacer,
48
+ prefix,
49
+ suffix,
50
+ subtext,
51
+ content,
52
+ orientation,
53
+ filters,
54
+ dataColumn,
55
+ dataFunction,
56
+ dataConditionalColumn,
57
+ dataConditionalOperator,
58
+ dataConditionalComparate,
59
+ customDenom,
60
+ dataDenom,
61
+ dataDenomColumn,
62
+ dataDenomFunction,
63
+ roundToPlace
64
+ } = config
43
65
 
44
66
  const gaugeColor = config.visual.colors[config.theme]
45
67
  let dataFontSize = config.fontSize ? { fontSize: config.fontSize + 'px' } : null
@@ -150,7 +172,8 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
150
172
  }
151
173
 
152
174
  //Get the column's data
153
- const columnData = conditionalData.length > 0 ? conditionalData.map(a => a[dataColumn]) : filteredData.map(a => a[dataColumn])
175
+ const columnData =
176
+ conditionalData.length > 0 ? conditionalData.map(a => a[dataColumn]) : filteredData.map(a => a[dataColumn])
154
177
  const denomColumnData = filteredData.map(a => a[dataDenomColumn])
155
178
 
156
179
  //Filter the column's data for numerical values only
@@ -209,8 +232,25 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
209
232
  }
210
233
 
211
234
  // @ts-ignore
212
- return [applyPrecision((waffleNumerator / waffleDenominator) * 100), waffleDenominator, applyPrecision(waffleNumerator)]
213
- }, [dataColumn, dataFunction, config.data, filters, dataConditionalColumn, dataConditionalOperator, dataConditionalComparate, customDenom, dataDenomColumn, dataDenomFunction, roundToPlace, dataDenom])
235
+ return [
236
+ applyPrecision((waffleNumerator / waffleDenominator) * 100),
237
+ waffleDenominator,
238
+ applyPrecision(waffleNumerator)
239
+ ]
240
+ }, [
241
+ dataColumn,
242
+ dataFunction,
243
+ config.data,
244
+ filters,
245
+ dataConditionalColumn,
246
+ dataConditionalOperator,
247
+ dataConditionalComparate,
248
+ customDenom,
249
+ dataDenomColumn,
250
+ dataDenomFunction,
251
+ roundToPlace,
252
+ dataDenom
253
+ ])
214
254
 
215
255
  const [dataPercentage, waffleDenominator, waffleNumerator] = calculateData()
216
256
 
@@ -237,10 +277,22 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
237
277
 
238
278
  return waffleData.map((node, key) =>
239
279
  node.shape === 'square' ? (
240
- <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} />
280
+ <Bar
281
+ className='cdc-waffle-chart__node'
282
+ style={{ transitionDelay: `${0.1 * key}ms` }}
283
+ x={node.x}
284
+ y={node.y}
285
+ width={nodeWidthNum}
286
+ height={nodeWidthNum}
287
+ fill={node.color}
288
+ fillOpacity={node.opacity}
289
+ key={key}
290
+ />
241
291
  ) : node.shape === 'person' ? (
242
292
  <path
243
- style={{ transform: `translateX(${node.x + nodeWidthNum / 4}px) translateY(${node.y}px) scale(${nodeWidthNum / 20})` }}
293
+ style={{
294
+ transform: `translateX(${node.x + nodeWidthNum / 4}px) translateY(${node.y}px) scale(${nodeWidthNum / 20})`
295
+ }}
244
296
  fill={node.color}
245
297
  fillOpacity={node.opacity}
246
298
  key={key}
@@ -249,7 +301,16 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
249
301
  .9375-.9375V13.75h.625A.9375.9375,0,0,0,7.5,12.8125V7.5A1.875,1.875,0,0,0,5.625,5.625Z'
250
302
  ></path>
251
303
  ) : (
252
- <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} />
304
+ <Circle
305
+ className='cdc-waffle-chart__node'
306
+ style={{ transitionDelay: `${0.1 * key}ms` }}
307
+ cx={node.x}
308
+ cy={node.y}
309
+ r={nodeWidthNum / 2}
310
+ fill={node.color}
311
+ fillOpacity={node.opacity}
312
+ key={key}
313
+ />
253
314
  )
254
315
  )
255
316
  }, [theme, dataPercentage, shape, nodeWidth, nodeSpacer])
@@ -289,7 +350,7 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
289
350
  <section className='waiting-container'>
290
351
  <h3>Finish Configuring</h3>
291
352
  <p>Set all required options to the left and confirm below to display a preview of the chart.</p>
292
- <button className='btn' style={{ margin: '1em auto' }} onClick={confirmDone}>
353
+ <button className='btn btn-primary' style={{ margin: '1em auto' }} onClick={confirmDone}>
293
354
  I'm Done
294
355
  </button>
295
356
  </section>
@@ -301,7 +362,9 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
301
362
  <div className='cove-component__content'>
302
363
  <Title title={title} config={config} classes={['chart-title', `${config.theme}`, 'mb-0']} />
303
364
  <div className={contentClasses.join(' ')}>
304
- {!config.newViz && config.runtime && config.runtime.editorErrorMessage && <Error updateConfig={updateConfig} config={config} />}
365
+ {!config.newViz && config.runtime && config.runtime.editorErrorMessage && (
366
+ <Error updateConfig={updateConfig} config={config} />
367
+ )}
305
368
  {config.newViz && showConfigConfirm && <Confirm updateConfig={updateConfig} config={config} />}
306
369
  <div className='cove-component__content-wrap'>
307
370
  {config.visualizationType === 'Gauge' && (
@@ -310,12 +373,20 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
310
373
  <div className='cove-waffle-chart__data--primary' style={dataFontSize}>
311
374
  {prefix ? prefix : ' '}
312
375
  {config.showPercent ? dataPercentage : waffleNumerator}
313
- {suffix ? suffix + ' ' : ' '} {config.valueDescription} {config.showDenominator && waffleDenominator ? waffleDenominator : ' '}
376
+ {suffix ? suffix + ' ' : ' '} {config.valueDescription}{' '}
377
+ {config.showDenominator && waffleDenominator ? waffleDenominator : ' '}
314
378
  </div>
315
379
  <div className='cove-waffle-chart__data--text'>{parse(content)}</div>
316
380
  <svg height={config.gauge.height} width={'100%'}>
317
381
  <Group>
318
- <foreignObject style={{ border: '1px solid black' }} x={0} y={0} width={config.gauge.width} height={config.gauge.height} fill='#fff' />
382
+ <foreignObject
383
+ style={{ border: '1px solid black' }}
384
+ x={0}
385
+ y={0}
386
+ width={config.gauge.width}
387
+ height={config.gauge.height}
388
+ fill='#fff'
389
+ />
319
390
  <Bar x={0} y={0} width={xScale(waffleNumerator)} height={config.gauge.height} fill={gaugeColor} />
320
391
  </Group>
321
392
  </svg>
@@ -324,7 +395,11 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
324
395
  </div>
325
396
  )}
326
397
  {config.visualizationType !== 'Gauge' && (
327
- <div className={`cove-waffle-chart${orientation === 'vertical' ? ' cove-waffle-chart--verical' : ''}${config.overallFontSize ? ' font-' + config.overallFontSize : ''}`}>
398
+ <div
399
+ className={`cove-waffle-chart${orientation === 'vertical' ? ' cove-waffle-chart--verical' : ''}${
400
+ config.overallFontSize ? ' font-' + config.overallFontSize : ''
401
+ }`}
402
+ >
328
403
  <div className='cove-waffle-chart__chart' style={{ width: setRatio() }}>
329
404
  <svg width={setRatio()} height={setRatio()}>
330
405
  <Group>{buildWaffle()}</Group>
@@ -353,9 +428,22 @@ const WaffleChart = ({ config, isEditor, link = '', showConfigConfirm, updateCon
353
428
  )
354
429
  }
355
430
 
356
- const CdcWaffleChart = ({ configUrl, config: configObj, isDashboard = false, isEditor = false, setConfig: setParentConfig }: CdcWaffleChartProps) => {
431
+ const CdcWaffleChart = ({
432
+ configUrl,
433
+ config: configObj,
434
+ isDashboard = false,
435
+ isEditor = false,
436
+ setConfig: setParentConfig
437
+ }: CdcWaffleChartProps) => {
357
438
  // Default States
358
- const [state, dispatch] = useReducer(chartReducer, { config: configObj ?? defaults, loading: true, preview: false, viewport: 'lg', coveLoadedHasRan: false, container: null })
439
+ const [state, dispatch] = useReducer(chartReducer, {
440
+ config: configObj ?? defaults,
441
+ loading: true,
442
+ preview: false,
443
+ viewport: 'lg',
444
+ coveLoadedHasRan: false,
445
+ container: null
446
+ })
359
447
  const { loading, config, viewport: currentViewport, coveLoadedHasRan, container } = state
360
448
  const [showConfigConfirm, setShowConfigConfirm] = useState(false)
361
449
 
@@ -429,7 +517,12 @@ const CdcWaffleChart = ({ configUrl, config: configObj, isDashboard = false, isE
429
517
  if (loading === false) {
430
518
  let body = (
431
519
  <Layout.Responsive isEditor={isEditor}>
432
- <WaffleChart config={config} isEditor={isEditor} showConfigConfirm={showConfigConfirm} updateConfig={updateConfig} />
520
+ <WaffleChart
521
+ config={config}
522
+ isEditor={isEditor}
523
+ showConfigConfirm={showConfigConfirm}
524
+ updateConfig={updateConfig}
525
+ />
433
526
  </Layout.Responsive>
434
527
  )
435
528
 
@@ -443,8 +536,15 @@ const CdcWaffleChart = ({ configUrl, config: configObj, isDashboard = false, isE
443
536
 
444
537
  return (
445
538
  <ErrorBoundary component='WaffleChart'>
446
- <ConfigContext.Provider value={{ config, updateConfig, loading, data: config.data, setParentConfig, isDashboard, outerContainerRef }}>
447
- <Layout.VisualizationWrapper config={config} isEditor={isEditor} ref={outerContainerRef} showEditorPanel={config?.showEditorPanel}>
539
+ <ConfigContext.Provider
540
+ value={{ config, updateConfig, loading, data: config.data, setParentConfig, isDashboard, outerContainerRef }}
541
+ >
542
+ <Layout.VisualizationWrapper
543
+ config={config}
544
+ isEditor={isEditor}
545
+ ref={outerContainerRef}
546
+ showEditorPanel={config?.showEditorPanel}
547
+ >
448
548
  {content}
449
549
  </Layout.VisualizationWrapper>
450
550
  </ConfigContext.Provider>
@@ -462,7 +562,15 @@ export const DATA_FUNCTION_MIN = 'Min'
462
562
  export const DATA_FUNCTION_MODE = 'Mode'
463
563
  export const DATA_FUNCTION_SUM = 'Sum'
464
564
 
465
- 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]
565
+ export const DATA_FUNCTIONS = [
566
+ DATA_FUNCTION_COUNT,
567
+ DATA_FUNCTION_MAX,
568
+ DATA_FUNCTION_MEAN,
569
+ DATA_FUNCTION_MEDIAN,
570
+ DATA_FUNCTION_MIN,
571
+ DATA_FUNCTION_MODE,
572
+ DATA_FUNCTION_SUM
573
+ ]
466
574
 
467
575
  export const DATA_OPERATOR_LESS = '<'
468
576
  export const DATA_OPERATOR_GREATER = '>'
@@ -471,4 +579,11 @@ export const DATA_OPERATOR_GREATEREQUAL = '>='
471
579
  export const DATA_OPERATOR_EQUAL = '='
472
580
  export const DATA_OPERATOR_NOTEQUAL = '≠'
473
581
 
474
- export const DATA_OPERATORS = [DATA_OPERATOR_LESS, DATA_OPERATOR_GREATER, DATA_OPERATOR_LESSEQUAL, DATA_OPERATOR_GREATEREQUAL, DATA_OPERATOR_EQUAL, DATA_OPERATOR_NOTEQUAL]
582
+ export const DATA_OPERATORS = [
583
+ DATA_OPERATOR_LESS,
584
+ DATA_OPERATOR_GREATER,
585
+ DATA_OPERATOR_LESSEQUAL,
586
+ DATA_OPERATOR_GREATEREQUAL,
587
+ DATA_OPERATOR_EQUAL,
588
+ DATA_OPERATOR_NOTEQUAL
589
+ ]