@cdc/waffle-chart 1.0.2 → 9.22.9

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