@cdc/waffle-chart 1.0.2 → 4.22.10

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": "1.0.2",
3
+ "version": "4.22.10",
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": "^1.1.4",
23
+ "@cdc/core": "^4.22.10",
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": "ff89a7aea74c533413c62ef8859cc011e6b3cbfa"
40
+ "gitHead": "a7eb551a98c7363d3be58cb81dfc8bbc00522804"
41
41
  }
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useState } 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'
@@ -15,6 +15,8 @@ import defaults from './data/initial-state'
15
15
 
16
16
  import { publish } from '@cdc/core/helpers/events';
17
17
 
18
+ import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses';
19
+
18
20
  import './scss/main.scss'
19
21
 
20
22
  const themeColor = {
@@ -30,8 +32,11 @@ const themeColor = {
30
32
  'theme-green': '#4b830d',
31
33
  'theme-amber': '#fbab18',
32
34
  }
35
+ interface Props{
36
+ config?:any, isEditor?:any ,link?:any
37
+ }
33
38
 
34
- const WaffleChart = ({ config, isEditor }) => {
39
+ const WaffleChart:FC<Props> = ({ config, isEditor ,link}) => {
35
40
  let {
36
41
  title,
37
42
  theme,
@@ -281,63 +286,62 @@ const WaffleChart = ({ config, isEditor }) => {
281
286
 
282
287
  let dataFontSize = config.fontSize ? { fontSize: config.fontSize + 'px' } : null
283
288
 
289
+ const { innerContainerClasses, contentClasses } = useDataVizClasses(config)
284
290
 
285
- let innerContainerClasses = ['cove-component__inner']
286
- config.title && innerContainerClasses.push('component--has-title')
287
- config.subtext && innerContainerClasses.push('component--has-subtext')
288
- config.biteStyle && innerContainerClasses.push(`bite__style--${config.biteStyle}`)
289
- config.general?.isCompactStyle && innerContainerClasses.push(`component--isCompactStyle`)
290
-
291
- let contentClasses = ['cove-component__content'];
292
- !config.visual?.border && contentClasses.push('no-borders');
293
- config.visual?.borderColorTheme && contentClasses.push('component--has-borderColorTheme');
294
- config.visual?.accent && contentClasses.push('component--has-accent');
295
- config.visual?.background && contentClasses.push('component--has-background');
296
- config.visual?.hideBackgroundColor && contentClasses.push('component--hideBackgroundColor');
297
-
298
- // ! these two will be retired.
299
- config.shadow && innerContainerClasses.push('shadow')
300
- config?.visual?.roundedBorders && innerContainerClasses.push('bite--has-rounded-borders')
291
+ const handleWaffleChartAriaLabel = (state, testing = false) => {
292
+ if(testing) console.log(`handleWaffleChartAriaLabels Testing On:`, state);
293
+ try {
294
+ let ariaLabel = 'Waffle chart';
295
+ if(state.title) {
296
+ ariaLabel += ` with the title: ${state.title}`
297
+ }
298
+ return ariaLabel;
299
+ } catch(e) {
300
+ console.error(e.message)
301
+ }
302
+ }
301
303
 
302
304
  return (
303
305
  <div className={innerContainerClasses.join(' ')}>
304
306
  <>
305
- {title &&
306
- <div className={`cove-component__header chart-title ${config.theme}`} >
307
- {parse(title)}
308
- </div>
309
- }
310
- <div className={contentClasses.join(' ')}>
311
- <div className="cove-component__content-wrap">
312
- <div
313
- className={`cove-waffle-chart${orientation === 'vertical' ? ' cove-waffle-chart--verical' : ''}${config.overallFontSize ? ' font-' + config.overallFontSize : ''}`}>
314
- <div className="cove-waffle-chart__chart" style={{ width: setRatio() }}>
315
- <svg width={setRatio()} height={setRatio()}>
316
- <Group>
317
- {buildWaffle()}
318
- </Group>
319
- </svg>
307
+ {title &&
308
+ <header className={`cove-component__header chart-title ${config.theme}`} aria-hidden="true">
309
+ {parse(title)}
310
+ </header>
311
+ }
312
+ <div className={contentClasses.join(' ')}>
313
+ <div className="cove-component__content-wrap">
314
+ <div
315
+ className={`cove-waffle-chart${orientation === 'vertical' ? ' cove-waffle-chart--verical' : ''}${config.overallFontSize ? ' font-' + config.overallFontSize : ''}`}>
316
+ <div className="cove-waffle-chart__chart" style={{ width: setRatio() }}>
317
+ <svg width={setRatio()} height={setRatio()} role="img" aria-label={handleWaffleChartAriaLabel(config)} tabIndex={0}>
318
+ <Group>
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}
320
328
  </div>
321
- {(dataPercentage || content) &&
322
- <div className="cove-waffle-chart__data">
323
- {dataPercentage &&
324
- <div className="cove-waffle-chart__data--primary" style={dataFontSize}>
325
- {prefix ? prefix : null}{dataPercentage}{suffix ? suffix : null}
329
+ }
330
+ <div className="cove-waffle-chart__data--text">{parse(content)}</div>
331
+
332
+ {subtext &&
333
+ <div className="cove-waffle-chart__subtext">
334
+ {parse(subtext)}
326
335
  </div>
327
- }
328
- <div className="cove-waffle-chart__data--text" >{parse(content)}</div>
329
- </div>
330
336
  }
331
337
  </div>
332
- {subtext &&
333
- <div className="cove-waffle-chart__subtext">
334
- {parse(subtext)}
335
- </div>
336
338
  }
337
339
  </div>
338
340
  </div>
339
- </>
340
- </div>
341
+ </div>
342
+ {link && link}
343
+ </>
344
+ </div>
341
345
  )
342
346
  }
343
347
 
@@ -422,13 +426,20 @@ const CdcWaffleChart = (
422
426
  //Reload config if config object provided/updated
423
427
  useEffect(() => {
424
428
  loadConfig().catch((err) => console.log(err))
425
- }, [ configObj?.data ])
429
+ }, [])
430
+
431
+ //Reload config if parent passes different config
432
+ useEffect(() => {
433
+ if(!configObj.dataUrl){
434
+ updateConfig({ ...defaults, ...configObj});
435
+ }
436
+ }, [configObj.data])
426
437
 
427
438
  let content = (<Loading/>)
428
439
 
429
440
  if (loading === false) {
430
441
  let classNames = [
431
- 'cdc-open-viz-module',
442
+ 'cove',
432
443
  'type-waffle-chart',
433
444
  currentViewport,
434
445
  config.theme,
@@ -441,17 +452,19 @@ const CdcWaffleChart = (
441
452
 
442
453
  let bodyClasses = ['cove-component', 'waffle-chart']
443
454
 
444
-
445
-
446
455
  let body = (
447
456
  <div className={`${bodyClasses.join(' ')}`} ref={outerContainerRef}>
448
457
  <WaffleChart config={config} isEditor={isEditor}/>
449
458
  </div>
450
- )
459
+ );
451
460
 
452
461
  content = (
453
- <div className={`cove ${config.theme}`}>
454
- {isEditor && <EditorPanel>{body}</EditorPanel>}
462
+ <div className={classNames.join(' ')}>
463
+ {isEditor &&
464
+ <EditorPanel>
465
+ {body}
466
+ </EditorPanel>
467
+ }
455
468
  {!isEditor && body}
456
469
  </div>
457
470
  )