@cdc/waffle-chart 4.23.1 → 4.23.3

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.
@@ -25,6 +25,6 @@
25
25
  <!-- <div class="react-container" data-config="/examples/gallery/avg-to-max.json"></div> -->
26
26
  <!-- <div class="react-container" data-config="/examples/gallery/count.json"></div> -->
27
27
 
28
- <noscript>You need to enable JavaScript to run this app.</noscript>
28
+ <script type="module" src="./src/index.jsx"></script>
29
29
  </body>
30
30
  </html>
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "@cdc/waffle-chart",
3
- "version": "4.23.1",
3
+ "version": "4.23.3",
4
4
  "description": "React component for displaying a single piece of data in a card module",
5
+ "moduleName": "CdcWaffleChart",
5
6
  "main": "dist/cdcwafflechart",
7
+ "type": "module",
6
8
  "scripts": {
7
- "start": "npx webpack serve --mode development -c ../../webpack.config.js",
8
- "build": "npx webpack --mode production --env packageName=CdcWaffleChart --env folderName=waffle-chart -c ../../webpack.config.js",
9
- "prepublishOnly": "lerna run --scope @cdc/waffle-chart build"
9
+ "start": "vite --open",
10
+ "build": "vite build",
11
+ "preview": "vite preview",
12
+ "graph": "nx graph",
13
+ "prepublishOnly": "lerna run --scope @cdc/waffle-chart build",
14
+ "test": "vitest watch --reporter verbose",
15
+ "test:ui": "vitest --ui"
10
16
  },
11
17
  "repository": {
12
18
  "type": "git",
@@ -20,22 +26,17 @@
20
26
  "license": "Apache-2.0",
21
27
  "homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
22
28
  "dependencies": {
23
- "@cdc/core": "^4.23.1",
24
- "@visx/shape": "^2.1.1",
29
+ "@cdc/core": "^4.23.3",
30
+ "@visx/shape": "^3.0.0",
25
31
  "chroma": "0.0.1",
26
32
  "chroma-js": "^2.1.0",
27
- "html-react-parser": "1.4.9",
33
+ "html-react-parser": "^3.0.8",
28
34
  "react-accessible-accordion": "^3.3.4",
29
- "react-tooltip": "4.2.8",
30
- "use-debounce": "^6.0.1",
31
35
  "whatwg-fetch": "^3.6.2"
32
36
  },
33
37
  "peerDependencies": {
34
- "react": "^17.0.2",
35
- "react-dom": ">=16"
38
+ "react": "^18.2.0",
39
+ "react-dom": "^18.2.0"
36
40
  },
37
- "resolutions": {
38
- "@types/react": "17.x"
39
- },
40
- "gitHead": "58163844cc9ce2c379235413b19f49679eab4bef"
41
+ "gitHead": "6fa3b11db159d38538f18023fe70b67a29e7d327"
41
42
  }
@@ -1,10 +1,11 @@
1
- import React, { useCallback, useEffect, useState, FC } from 'react'
1
+ import React, { useCallback, useEffect, useState } 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'
5
5
 
6
6
  import ResizeObserver from 'resize-observer-polyfill'
7
7
  import getViewport from '@cdc/core/helpers/getViewport'
8
+ import fetchRemoteData from '@cdc/core/helpers/fetchRemoteData'
8
9
 
9
10
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
10
11
  import Loading from '@cdc/core/components/Loading'
@@ -32,13 +33,8 @@ const themeColor = {
32
33
  'theme-green': '#4b830d',
33
34
  'theme-amber': '#fbab18'
34
35
  }
35
- interface Props {
36
- config?: any
37
- isEditor?: any
38
- link?: any
39
- }
40
36
 
41
- const WaffleChart: FC<Props> = ({ config, isEditor, link }) => {
37
+ const WaffleChart = ({ config, isEditor, link }) => {
42
38
  let { title, theme, shape, nodeWidth, nodeSpacer, prefix, suffix, subtext, content, orientation, filters, dataColumn, dataFunction, dataConditionalColumn, dataConditionalOperator, dataConditionalComparate, customDenom, dataDenom, dataDenomColumn, dataDenomFunction, roundToPlace } = config
43
39
 
44
40
  const calculateData = useCallback(() => {
@@ -316,7 +312,7 @@ const CdcWaffleChart = ({ configUrl, config: configObj, isDashboard = false, isE
316
312
  const [config, setConfig] = useState({ ...defaults })
317
313
  const [loading, setLoading] = useState(true)
318
314
 
319
- const [currentViewport, setCurrentViewport] = useState<String>('lg')
315
+ const [currentViewport, setCurrentViewport] = useState('lg')
320
316
  const [coveLoadedHasRan, setCoveLoadedHasRan] = useState(false)
321
317
  const [container, setContainer] = useState()
322
318
 
@@ -340,8 +336,7 @@ const CdcWaffleChart = ({ configUrl, config: configObj, isDashboard = false, isE
340
336
  let responseData = response.data ?? {}
341
337
 
342
338
  if (response.dataUrl) {
343
- const dataString = await fetch(response.dataUrl)
344
- responseData = await dataString.json()
339
+ responseData = await fetchRemoteData(response.dataUrl)
345
340
  }
346
341
 
347
342
  response.data = responseData
@@ -387,8 +382,8 @@ const CdcWaffleChart = ({ configUrl, config: configObj, isDashboard = false, isE
387
382
 
388
383
  //Reload config if parent passes different config
389
384
  if (configObj) {
385
+ // eslint-disable-next-line react-hooks/rules-of-hooks
390
386
  useEffect(() => {
391
- console.log('changing')
392
387
  if (!configObj.dataUrl) {
393
388
  updateConfig({ ...defaults, ...configObj })
394
389
  }
package/src/index.jsx ADDED
@@ -0,0 +1,14 @@
1
+ import React from 'react'
2
+ import ReactDOM from 'react-dom/client'
3
+
4
+ import CdcWaffleChart from './CdcWaffleChart'
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
+ <CdcWaffleChart configUrl={domContainer.attributes['data-config'].value} isEditor={isEditor} />
13
+ </React.StrictMode>,
14
+ )
@@ -1,4 +1,4 @@
1
- @import '~@cdc/core/styles/v2/main';
1
+ @import '@cdc/core/styles/v2/main';
2
2
  @import 'waffle-chart';
3
3
 
4
4
  .cdc-open-viz-module.type-waffle-chart {
@@ -0,0 +1,6 @@
1
+ // Placeholder test until we add them in.
2
+ describe('Waffle Chart', () => {
3
+ it('has a test.', async () => {
4
+ return true
5
+ })
6
+ })
package/vite.config.js ADDED
@@ -0,0 +1,4 @@
1
+ import GenerateViteConfig from '../../generateViteConfig.js'
2
+ import { moduleName } from './package.json'
3
+
4
+ export default GenerateViteConfig(moduleName)
package/src/index.js DELETED
@@ -1,16 +0,0 @@
1
- import React from 'react'
2
- import { render } from 'react-dom'
3
- import CdcWaffleChart from './CdcWaffleChart'
4
-
5
- const domContainers = document.querySelectorAll('.react-container')
6
-
7
- let isEditor = window.location.href.includes('editor=true')
8
-
9
- domContainers.forEach(domContainer => {
10
- render(
11
- <React.StrictMode>
12
- <CdcWaffleChart configUrl={domContainer.attributes['data-config'].value} isEditor={isEditor} />
13
- </React.StrictMode>,
14
- domContainer
15
- )
16
- })
File without changes