@cdc/chart 4.22.10 → 4.23.1

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.
Files changed (80) hide show
  1. package/README.md +5 -5
  2. package/dist/495.js +3 -0
  3. package/dist/703.js +1 -0
  4. package/dist/cdcchart.js +723 -6
  5. package/examples/age-adjusted-rates.json +1486 -1218
  6. package/examples/box-plot-data.json +71 -0
  7. package/examples/box-plot.csv +5 -0
  8. package/examples/{private/yaxis-test.json → box-plot.json} +46 -54
  9. package/examples/case-rate-example-config.json +1 -1
  10. package/examples/covid-confidence-example-config.json +33 -33
  11. package/examples/covid-example-config.json +34 -34
  12. package/examples/covid-example-data-confidence.json +30 -30
  13. package/examples/covid-example-data.json +20 -20
  14. package/examples/cutoff-example-config.json +36 -36
  15. package/examples/cutoff-example-data.json +36 -36
  16. package/examples/date-exclusions-config.json +1 -1
  17. package/examples/dynamic-legends.json +124 -124
  18. package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart-with-numbers-on-bar.json +191 -197
  19. package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart.json +230 -240
  20. package/examples/gallery/bar-chart-horizontal/horizontal-stacked.json +239 -247
  21. package/examples/gallery/bar-chart-vertical/combo-line-chart.json +138 -136
  22. package/examples/gallery/bar-chart-vertical/vertical-bar-chart-categorical.json +79 -79
  23. package/examples/gallery/bar-chart-vertical/vertical-bar-chart-stacked.json +80 -80
  24. package/examples/gallery/bar-chart-vertical/vertical-bar-chart-with-confidence.json +67 -67
  25. package/examples/gallery/bar-chart-vertical/vertical-bar-chart.json +179 -110
  26. package/examples/gallery/lollipop/lollipop-style-horizontal.json +215 -219
  27. package/examples/gallery/paired-bar/paired-bar-chart.json +195 -195
  28. package/examples/horizontal-chart.json +35 -35
  29. package/examples/horizontal-stacked-bar-chart.json +34 -34
  30. package/examples/line-chart.json +75 -75
  31. package/examples/new-data.csv +17 -0
  32. package/examples/newdata.json +90 -0
  33. package/examples/paired-bar-data.json +16 -14
  34. package/examples/paired-bar-example.json +48 -48
  35. package/examples/paired-bar-formatted.json +36 -36
  36. package/examples/planet-chart-horizontal-example-config.json +33 -33
  37. package/examples/planet-combo-example-config.json +34 -31
  38. package/examples/planet-example-config.json +35 -33
  39. package/examples/planet-example-data.json +56 -56
  40. package/examples/planet-pie-example-config.json +28 -28
  41. package/examples/stacked-vertical-bar-example.json +1 -1
  42. package/examples/temp-example-config.json +61 -54
  43. package/examples/temp-example-data.json +1 -1
  44. package/package.json +3 -2
  45. package/src/CdcChart.tsx +449 -434
  46. package/src/components/BarChart.tsx +383 -497
  47. package/src/components/BoxPlot.js +92 -0
  48. package/src/components/DataTable.tsx +182 -197
  49. package/src/components/EditorPanel.js +1068 -722
  50. package/src/components/Filters.js +131 -0
  51. package/src/components/Legend.js +286 -329
  52. package/src/components/LineChart.tsx +143 -81
  53. package/src/components/LinearChart.tsx +432 -451
  54. package/src/components/PairedBarChart.tsx +197 -213
  55. package/src/components/PieChart.tsx +105 -151
  56. package/src/components/SparkLine.js +179 -201
  57. package/src/components/useIntersectionObserver.tsx +19 -20
  58. package/src/context.tsx +3 -3
  59. package/src/data/initial-state.js +44 -17
  60. package/src/hooks/useActiveElement.js +13 -13
  61. package/src/hooks/useChartClasses.js +34 -28
  62. package/src/hooks/useColorPalette.ts +56 -63
  63. package/src/hooks/useLegendClasses.js +18 -10
  64. package/src/hooks/useReduceData.ts +64 -77
  65. package/src/hooks/useRightAxis.js +25 -0
  66. package/src/hooks/useTopAxis.js +6 -0
  67. package/src/index.html +19 -19
  68. package/src/index.tsx +13 -16
  69. package/src/scss/DataTable.scss +6 -5
  70. package/src/scss/editor-panel.scss +71 -69
  71. package/src/scss/main.scss +188 -114
  72. package/src/scss/variables.scss +1 -1
  73. package/examples/private/line-test-data.json +0 -22
  74. package/examples/private/line-test-two.json +0 -216
  75. package/examples/private/line-test.json +0 -102
  76. package/examples/private/newtest.csv +0 -101
  77. package/examples/private/shawn.json +0 -1296
  78. package/examples/private/test.json +0 -10124
  79. package/examples/private/yaxis-testing.csv +0 -27
  80. package/examples/private/yaxis.json +0 -28
@@ -0,0 +1,131 @@
1
+ import React, { useEffect, useState, useContext } from 'react'
2
+ import Context from './../context'
3
+ import Button from '@cdc/core/components/elements/Button'
4
+
5
+ const useFilters = () => {
6
+ const { config, setConfig, filteredData, setFilteredData, excludedData, filterData, runtimeFilters } = useContext(Context)
7
+ const [showApplyButton, setShowApplyButton] = useState(false)
8
+
9
+ const sortAsc = (a, b) => {
10
+ return a.toString().localeCompare(b.toString(), 'en', { numeric: true })
11
+ }
12
+
13
+ const sortDesc = (a, b) => {
14
+ return b.toString().localeCompare(a.toString(), 'en', { numeric: true })
15
+ }
16
+
17
+ const announceChange = text => {}
18
+
19
+ const changeFilterActive = (index, value) => {
20
+ let newFilters = config.filters
21
+ newFilters[index].active = value
22
+ setConfig({
23
+ ...config,
24
+ filters: newFilters
25
+ })
26
+ setShowApplyButton(true)
27
+ }
28
+
29
+ const handleApplyButton = newFilters => {
30
+ setConfig({ ...config, filters: newFilters })
31
+ setFilteredData(filterData(newFilters, excludedData))
32
+ setShowApplyButton(false)
33
+ }
34
+
35
+ const handleReset = () => {
36
+ let newFilters = config.filters
37
+
38
+ // reset to first item in values array.
39
+ newFilters.map(filter => {
40
+ filter.active = filter.values[0]
41
+ })
42
+
43
+ setFilteredData(filterData(newFilters, excludedData))
44
+ setConfig({ ...config, filters: newFilters })
45
+ }
46
+
47
+ return { handleApplyButton, changeFilterActive, announceChange, sortAsc, sortDesc, showApplyButton, handleReset }
48
+ }
49
+
50
+ const Filters = () => {
51
+ const { config } = useContext(Context)
52
+ const { handleApplyButton, changeFilterActive, announceChange, sortAsc, sortDesc, showApplyButton, handleReset } = useFilters()
53
+ const { filters } = config
54
+ const buttonText = 'Apply Filters'
55
+ const resetText = 'Reset All'
56
+
57
+ // A List of Dropdowns
58
+ const FilterList = () => {
59
+ if (config.filters) {
60
+ return config.filters.map((singleFilter, index) => {
61
+ const values = []
62
+
63
+ if (!singleFilter.order || singleFilter.order === '') {
64
+ singleFilter.order = 'asc'
65
+ }
66
+
67
+ if (singleFilter.order === 'desc') {
68
+ singleFilter.values = singleFilter.values.sort(sortDesc)
69
+ }
70
+
71
+ if (singleFilter.order === 'asc') {
72
+ singleFilter.values = singleFilter.values.sort(sortAsc)
73
+ }
74
+
75
+ singleFilter.values.forEach((filterOption, index) => {
76
+ values.push(
77
+ <option key={index} value={filterOption}>
78
+ {filterOption}
79
+ </option>
80
+ )
81
+ })
82
+
83
+ return (
84
+ <div className='single-filter' key={index}>
85
+ <label htmlFor={`filter-${index}`}>{singleFilter.label}</label>
86
+ <select
87
+ id={`filter-${index}`}
88
+ className='filter-select'
89
+ data-index='0'
90
+ value={singleFilter.active}
91
+ onChange={e => {
92
+ changeFilterActive(index, e.target.value)
93
+ announceChange(`Filter ${singleFilter.label} value has been changed to ${e.target.value}, please reference the data table to see updated values.`)
94
+ }}
95
+ >
96
+ {values}
97
+ </select>
98
+ </div>
99
+ )
100
+ })
101
+ } else {
102
+ return null
103
+ }
104
+ }
105
+
106
+ return (
107
+ <section className={`filters-section`} style={{ display: 'block', width: '100%' }}>
108
+ {config.filters.length > 0 && (
109
+ <>
110
+ <h3 className='filters-section__title'>Filters</h3>
111
+ <hr />
112
+ </>
113
+ )}
114
+ <div className='filters-section__wrapper' style={{ flexWrap: 'wrap', display: 'flex', gap: '7px 15px' }}>
115
+ <FilterList />
116
+ {config.filters.length > 0 && (
117
+ <div className='filter-section__buttons' style={{ width: '100%' }}>
118
+ <Button onClick={() => handleApplyButton(filters)} disabled={!showApplyButton} style={{ marginRight: '10px' }}>
119
+ {buttonText}
120
+ </Button>
121
+ <a href='#!' role='button' onClick={handleReset}>
122
+ {resetText}
123
+ </a>
124
+ </div>
125
+ )}
126
+ </div>
127
+ </section>
128
+ )
129
+ }
130
+
131
+ export default Filters