@cdc/chart 4.24.9 → 4.24.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.
Files changed (65) hide show
  1. package/LICENSE +201 -0
  2. package/dist/cdcchart.js +43919 -40370
  3. package/index.html +1 -1
  4. package/package.json +2 -2
  5. package/src/CdcChart.tsx +129 -108
  6. package/src/_stories/Chart.Legend.Gradient.stories.tsx +33 -0
  7. package/src/_stories/Chart.stories.tsx +28 -0
  8. package/src/_stories/ChartAxisLabels.stories.tsx +20 -0
  9. package/src/_stories/ChartAxisTitles.stories.tsx +53 -0
  10. package/src/_stories/ChartPrefixSuffix.stories.tsx +151 -0
  11. package/src/_stories/_mock/horizontal_bar.json +257 -0
  12. package/src/_stories/_mock/large_x_axis_labels.json +261 -0
  13. package/src/_stories/_mock/paired-bar.json +262 -0
  14. package/src/_stories/_mock/pie_with_data.json +255 -0
  15. package/src/_stories/_mock/simplified_line.json +1510 -0
  16. package/src/components/Annotations/components/AnnotationDraggable.tsx +0 -3
  17. package/src/components/Annotations/components/AnnotationDropdown.tsx +1 -1
  18. package/src/components/Axis/Categorical.Axis.tsx +22 -4
  19. package/src/components/BarChart/components/BarChart.Horizontal.tsx +95 -16
  20. package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +41 -17
  21. package/src/components/BarChart/components/BarChart.Vertical.tsx +78 -20
  22. package/src/components/BarChart/helpers/index.ts +23 -4
  23. package/src/components/BrushChart.tsx +3 -2
  24. package/src/components/DeviationBar.jsx +58 -8
  25. package/src/components/EditorPanel/EditorPanel.tsx +63 -40
  26. package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +8 -25
  27. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +21 -4
  28. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +297 -35
  29. package/src/components/EditorPanel/components/panels.scss +4 -6
  30. package/src/components/EditorPanel/editor-panel.scss +0 -8
  31. package/src/components/EditorPanel/helpers/tests/updateFieldRankByValue.test.ts +38 -0
  32. package/src/components/EditorPanel/helpers/updateFieldRankByValue.ts +42 -0
  33. package/src/components/EditorPanel/useEditorPermissions.ts +1 -0
  34. package/src/components/ForestPlot/ForestPlot.tsx +2 -3
  35. package/src/components/ForestPlot/ForestPlotProps.ts +2 -0
  36. package/src/components/Legend/Legend.Component.tsx +16 -16
  37. package/src/components/Legend/Legend.Suppression.tsx +25 -20
  38. package/src/components/Legend/Legend.tsx +0 -2
  39. package/src/components/Legend/helpers/index.ts +16 -19
  40. package/src/components/LegendWrapper.tsx +3 -1
  41. package/src/components/LineChart/components/LineChart.Circle.tsx +10 -0
  42. package/src/components/LinearChart.tsx +740 -562
  43. package/src/components/PairedBarChart.jsx +50 -10
  44. package/src/components/PieChart/PieChart.tsx +1 -6
  45. package/src/components/Regions/components/Regions.tsx +33 -19
  46. package/src/components/ZoomBrush.tsx +25 -6
  47. package/src/coreStyles_chart.scss +3 -0
  48. package/src/data/initial-state.js +6 -2
  49. package/src/helpers/configHelpers.ts +28 -0
  50. package/src/helpers/handleRankByValue.ts +15 -0
  51. package/src/helpers/sizeHelpers.ts +25 -0
  52. package/src/helpers/tests/handleRankByValue.test.ts +37 -0
  53. package/src/helpers/tests/sizeHelpers.test.ts +80 -0
  54. package/src/hooks/useColorPalette.js +10 -2
  55. package/src/hooks/useLegendClasses.ts +4 -0
  56. package/src/hooks/useScales.ts +31 -3
  57. package/src/hooks/useTooltip.tsx +9 -5
  58. package/src/index.jsx +1 -0
  59. package/src/scss/DataTable.scss +5 -4
  60. package/src/scss/main.scss +57 -52
  61. package/src/types/ChartConfig.ts +38 -16
  62. package/src/types/ChartContext.ts +18 -14
  63. package/src/_stories/Chart.Legend.Gradient.tsx +0 -19
  64. package/src/_stories/ChartBrush.stories.tsx +0 -19
  65. package/src/components/LinearChart.jsx +0 -817
@@ -0,0 +1,53 @@
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+ import Chart from '../CdcChart'
3
+ import longXLabelsConfig from './_mock/large_x_axis_labels.json'
4
+ import pairedBarConfig from './_mock/paired-bar.json'
5
+ import { editConfigKeys } from '../helpers/configHelpers'
6
+ import { ChartConfig } from '../types/ChartConfig'
7
+
8
+ const meta: Meta<typeof Chart> = {
9
+ title: 'Components/Templates/Chart/Axis Titles',
10
+ component: Chart
11
+ }
12
+
13
+ export default meta
14
+
15
+ type Story = StoryObj<typeof Chart>
16
+
17
+ export const Dynamic_Labels: Story = {
18
+ args: {
19
+ config: editConfigKeys(longXLabelsConfig, [{ path: ['xAxis', 'label'], value: 'This is the title' }])
20
+ }
21
+ }
22
+
23
+ export const Rotated_Labels: StoryObj<{ config: ChartConfig; tickRotation: number }> = {
24
+ args: {
25
+ tickRotation: 0, // Default value
26
+ config: longXLabelsConfig
27
+ },
28
+ argTypes: {
29
+ tickRotation: {
30
+ control: {
31
+ type: 'range',
32
+ min: 0,
33
+ max: 90,
34
+ step: 5
35
+ }
36
+ }
37
+ },
38
+ render: args => {
39
+ // Create a new config object with the updated tickRotation
40
+ const config = editConfigKeys(longXLabelsConfig, [
41
+ { path: ['xAxis', 'label'], value: 'This is the title This is the title This is the title' },
42
+ { path: ['xAxis', 'tickRotation'], value: args.tickRotation }
43
+ ])
44
+
45
+ return <Chart config={config} />
46
+ }
47
+ }
48
+
49
+ export const Paired_Bar: Story = {
50
+ args: {
51
+ config: pairedBarConfig
52
+ }
53
+ }
@@ -0,0 +1,151 @@
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+ import barConfig from './_mock/line_chart_two_points_new_chart.json'
3
+ import annotationConfig from './_mock/annotation_category_mock.json'
4
+ import areaPrefix from './_mock/annotation_category_mock.json'
5
+ import horizontalBarConfig from './_mock/horizontal_bar.json'
6
+
7
+ import Chart from '../CdcChart'
8
+ import { editConfigKeys } from '../helpers/configHelpers'
9
+
10
+ const meta: Meta<typeof Chart> = {
11
+ title: 'Components/Templates/Chart/Prefix Suffix',
12
+ component: Chart
13
+ }
14
+
15
+ type Story = StoryObj<typeof Chart>
16
+
17
+ export const Top_Suffix: Story = {
18
+ args: {
19
+ config: editConfigKeys(barConfig, [
20
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
21
+ { path: ['dataFormat', 'suffix'], value: ' Somethings per Something' },
22
+ { path: ['yAxis', 'gridLines'], value: true }
23
+ ])
24
+ }
25
+ }
26
+
27
+ export const Top_Suffix_Worst_Case: Story = {
28
+ args: {
29
+ config: editConfigKeys(annotationConfig, [
30
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
31
+ { path: ['dataFormat', 'suffix'], value: ' Somethings per Something' }
32
+ ])
33
+ }
34
+ }
35
+
36
+ export const Top_Suffix_With_Options: Story = {
37
+ args: {
38
+ config: editConfigKeys(annotationConfig, [
39
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
40
+ { path: ['yAxis', 'tickRotation'], value: 45 },
41
+ { path: ['yAxis', 'tickLabelColor'], value: 'red' }
42
+ ])
43
+ }
44
+ }
45
+
46
+ export const Top_Suffix_No_Space: Story = {
47
+ args: {
48
+ config: editConfigKeys(annotationConfig, [
49
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
50
+ { path: ['dataFormat', 'suffix'], value: 'lbs' }
51
+ ])
52
+ }
53
+ }
54
+
55
+ export const Top_Suffix_With_Space: Story = {
56
+ args: {
57
+ config: editConfigKeys(annotationConfig, [
58
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
59
+ { path: ['dataFormat', 'suffix'], value: 'lbs of something' }
60
+ ])
61
+ }
62
+ }
63
+
64
+ export const Suffix: Story = {
65
+ args: {
66
+ config: annotationConfig
67
+ }
68
+ }
69
+ export const Top_Prefix: Story = {
70
+ args: {
71
+ config: editConfigKeys(annotationConfig, [
72
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
73
+ { path: ['dataFormat', 'prefix'], value: '$' },
74
+ { path: ['dataFormat', 'suffix'], value: '' }
75
+ ])
76
+ }
77
+ }
78
+ export const Prefix: Story = {
79
+ args: {
80
+ config: editConfigKeys(areaPrefix, [
81
+ { path: ['dataFormat', 'prefix'], value: '$' },
82
+ { path: ['dataFormat', 'suffix'], value: '' }
83
+ ])
84
+ }
85
+ }
86
+
87
+ export const Top_Prefix_And_Suffix: Story = {
88
+ args: {
89
+ config: editConfigKeys(annotationConfig, [
90
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
91
+ { path: ['dataFormat', 'prefix'], value: '$' }
92
+ ])
93
+ }
94
+ }
95
+ export const Horizontal_Bar: Story = {
96
+ args: {
97
+ config: editConfigKeys(horizontalBarConfig, [
98
+ { path: ['dataFormat', 'suffix'], value: ' suf' },
99
+ { path: ['dataFormat', 'prefix'], value: 'pre' }
100
+ ])
101
+ }
102
+ }
103
+
104
+ export const Top_Suffix_On_Line: Story = {
105
+ args: {
106
+ config: editConfigKeys(barConfig, [
107
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
108
+ { path: ['dataFormat', 'suffix'], value: ' Somethings per Something' },
109
+ { path: ['yAxis', 'gridLines'], value: true },
110
+ { path: ['yAxis', 'labelsAboveGridlines'], value: true },
111
+ { path: ['yAxis', 'hideAxis'], value: true }
112
+ ])
113
+ }
114
+ }
115
+
116
+ export const Values_On_Line_All_Suffix: Story = {
117
+ args: {
118
+ config: editConfigKeys(annotationConfig, [
119
+ { path: ['yAxis', 'labelsAboveGridlines'], value: true },
120
+ { path: ['dataFormat', 'suffix'], value: ' units' },
121
+ { path: ['yAxis', 'gridLines'], value: true },
122
+ { path: ['yAxis', 'hideAxis'], value: true }
123
+ ])
124
+ }
125
+ }
126
+
127
+ export const Values_on_Line_Top_Suffix_Only_Area_Worst_Case: Story = {
128
+ args: {
129
+ config: editConfigKeys(annotationConfig, [
130
+ { path: ['dataFormat', 'onlyShowTopPrefixSuffix'], value: true },
131
+ { path: ['dataFormat', 'prefix'], value: 'pre' },
132
+ { path: ['dataFormat', 'suffix'], value: ' Somethings per Something' },
133
+ { path: ['yAxis', 'labelsAboveGridlines'], value: true },
134
+ { path: ['yAxis', 'gridLines'], value: true }
135
+ ])
136
+ }
137
+ }
138
+
139
+ export const Top_Suffix_Above_Gridlines_With_Options: Story = {
140
+ args: {
141
+ config: editConfigKeys(annotationConfig, [
142
+ { path: ['yAxis', 'tickRotation'], value: 45 },
143
+ { path: ['yAxis', 'tickLabelColor'], value: 'red' },
144
+ { path: ['yAxis', 'labelsAboveGridlines'], value: true },
145
+ { path: ['yAxis', 'gridLines'], value: true },
146
+ { path: ['yAxis', 'hideAxis'], value: true }
147
+ ])
148
+ }
149
+ }
150
+
151
+ export default meta
@@ -0,0 +1,257 @@
1
+ {
2
+ "annotations": [],
3
+ "type": "chart",
4
+ "debugSvg": false,
5
+ "chartMessage": { "noData": "No Data Available" },
6
+ "title": "",
7
+ "showTitle": true,
8
+ "showDownloadMediaButton": false,
9
+ "theme": "theme-blue",
10
+ "animate": false,
11
+ "fontSize": "medium",
12
+ "lineDatapointStyle": "hover",
13
+ "lineDatapointColor": "Same as Line",
14
+ "barHasBorder": "false",
15
+ "isLollipopChart": false,
16
+ "lollipopShape": "circle",
17
+ "lollipopColorStyle": "two-tone",
18
+ "visualizationSubType": "stacked",
19
+ "barStyle": "",
20
+ "roundingStyle": "standard",
21
+ "tipRounding": "top",
22
+ "isResponsiveTicks": false,
23
+ "general": {
24
+ "annotationDropdownText": "Annotations",
25
+ "showDownloadButton": false,
26
+ "showMissingDataLabel": true,
27
+ "showSuppressedSymbol": true,
28
+ "hideNullValue": true
29
+ },
30
+ "padding": { "left": 5, "right": 5 },
31
+ "preliminaryData": [],
32
+ "yAxis": {
33
+ "hideAxis": false,
34
+ "displayNumbersOnBar": false,
35
+ "hideLabel": false,
36
+ "hideTicks": false,
37
+ "size": 50,
38
+ "gridLines": false,
39
+ "enablePadding": false,
40
+ "min": "",
41
+ "max": "",
42
+ "labelColor": "#333",
43
+ "tickLabelColor": "#333",
44
+ "tickColor": "#333",
45
+ "rightHideAxis": true,
46
+ "rightAxisSize": 0,
47
+ "rightLabel": "",
48
+ "rightLabelOffsetSize": 0,
49
+ "rightAxisLabelColor": "#333",
50
+ "rightAxisTickLabelColor": "#333",
51
+ "rightAxisTickColor": "#333",
52
+ "numTicks": "",
53
+ "axisPadding": 0,
54
+ "scalePadding": 10,
55
+ "tickRotation": 0,
56
+ "anchors": [],
57
+ "shoMissingDataLabel": true,
58
+ "showMissingDataLine": true,
59
+ "categories": [],
60
+ "labelPlacement": "Below Bar"
61
+ },
62
+ "boxplot": {
63
+ "plots": [],
64
+ "borders": "true",
65
+ "firstQuartilePercentage": 25,
66
+ "thirdQuartilePercentage": 75,
67
+ "boxWidthPercentage": 40,
68
+ "plotOutlierValues": false,
69
+ "plotNonOutlierValues": true,
70
+ "legend": { "showHowToReadText": false, "howToReadText": "" },
71
+ "labels": {
72
+ "q1": "Lower Quartile",
73
+ "q2": "q2",
74
+ "q3": "Upper Quartile",
75
+ "q4": "q4",
76
+ "minimum": "Minimum",
77
+ "maximum": "Maximum",
78
+ "mean": "Mean",
79
+ "median": "Median",
80
+ "sd": "Standard Deviation",
81
+ "iqr": "Interquartile Range",
82
+ "total": "Total",
83
+ "outliers": "Outliers",
84
+ "values": "Values",
85
+ "lowerBounds": "Lower Bounds",
86
+ "upperBounds": "Upper Bounds"
87
+ }
88
+ },
89
+ "topAxis": { "hasLine": false },
90
+ "isLegendValue": false,
91
+ "barThickness": "0.37",
92
+ "barHeight": 25,
93
+ "barSpace": 15,
94
+ "heights": { "vertical": 300, "horizontal": 308 },
95
+ "xAxis": {
96
+ "sortDates": false,
97
+ "anchors": [],
98
+ "type": "categorical",
99
+ "showTargetLabel": true,
100
+ "targetLabel": "Target",
101
+ "hideAxis": false,
102
+ "hideLabel": false,
103
+ "hideTicks": false,
104
+ "size": 75,
105
+ "tickRotation": 0,
106
+ "min": "",
107
+ "max": "",
108
+ "labelColor": "#333",
109
+ "tickLabelColor": "#333",
110
+ "tickColor": "#333",
111
+ "numTicks": "",
112
+ "labelOffset": 65,
113
+ "axisPadding": 200,
114
+ "target": 0,
115
+ "maxTickRotation": 45,
116
+ "padding": 0,
117
+ "dataKey": "Race",
118
+ "tickWidthMax": 31
119
+ },
120
+ "table": {
121
+ "label": "Data Table",
122
+ "expanded": true,
123
+ "limitHeight": false,
124
+ "height": "",
125
+ "caption": "",
126
+ "showDownloadUrl": false,
127
+ "showDataTableLink": true,
128
+ "showDownloadLinkBelow": true,
129
+ "indexLabel": "",
130
+ "download": true,
131
+ "showVertical": true,
132
+ "dateDisplayFormat": "",
133
+ "showMissingDataLabel": true,
134
+ "showSuppressedSymbol": true,
135
+ "show": true
136
+ },
137
+ "orientation": "horizontal",
138
+ "color": "pinkpurple",
139
+ "columns": {},
140
+ "legend": {
141
+ "hide": false,
142
+ "behavior": "isolate",
143
+ "axisAlign": true,
144
+ "singleRow": true,
145
+ "colorCode": "",
146
+ "reverseLabelOrder": false,
147
+ "description": "",
148
+ "dynamicLegend": false,
149
+ "dynamicLegendDefaultText": "Show All",
150
+ "dynamicLegendItemLimit": 5,
151
+ "dynamicLegendItemLimitMessage": "Dynamic Legend Item Limit Hit.",
152
+ "dynamicLegendChartMessage": "Select Options from the Legend",
153
+ "label": "",
154
+ "lineMode": false,
155
+ "verticalSorted": false,
156
+ "highlightOnHover": false,
157
+ "hideSuppressedLabels": false,
158
+ "hideSuppressionLink": false,
159
+ "seriesHighlight": [],
160
+ "style": "circles",
161
+ "subStyle": "linear blocks",
162
+ "tickRotation": "",
163
+ "hideBorder": { "side": false, "topBottom": true }
164
+ },
165
+ "brush": { "height": 25, "active": false },
166
+ "exclusions": { "active": false, "keys": [] },
167
+ "palette": "qualitative-bold",
168
+ "isPaletteReversed": false,
169
+ "twoColor": { "palette": "monochrome-1", "isPaletteReversed": false },
170
+ "labels": false,
171
+ "dataFormat": {
172
+ "commas": false,
173
+ "prefix": "",
174
+ "suffix": "",
175
+ "abbreviated": false,
176
+ "bottomSuffix": "",
177
+ "bottomPrefix": "",
178
+ "bottomAbbreviated": false
179
+ },
180
+ "confidenceKeys": {},
181
+ "visual": {
182
+ "border": true,
183
+ "accent": true,
184
+ "background": true,
185
+ "verticalHoverLine": false,
186
+ "horizontalHoverLine": false
187
+ },
188
+ "useLogScale": false,
189
+ "filterBehavior": "Filter Change",
190
+ "highlightedBarValues": [],
191
+ "series": [{ "dataKey": "Age-adjusted rate", "type": "Bar", "axis": "Left", "tooltip": true }],
192
+ "tooltips": { "opacity": 90, "singleSeries": false, "dateDisplayFormat": "" },
193
+ "forestPlot": {
194
+ "startAt": 0,
195
+ "colors": { "line": "", "shape": "" },
196
+ "lineOfNoEffect": { "show": true },
197
+ "type": "",
198
+ "pooledResult": { "diamondHeight": 5, "column": "" },
199
+ "estimateField": "",
200
+ "estimateRadius": "",
201
+ "shape": "square",
202
+ "rowHeight": 20,
203
+ "description": { "show": true, "text": "description", "location": 0 },
204
+ "result": { "show": true, "text": "result", "location": 100 },
205
+ "radius": { "min": 2, "max": 10, "scalingColumn": "" },
206
+ "regression": { "lower": 0, "upper": 0, "estimateField": 0 },
207
+ "leftWidthOffset": 0,
208
+ "rightWidthOffset": 0,
209
+ "showZeroLine": false,
210
+ "leftLabel": "",
211
+ "rightLabel": ""
212
+ },
213
+ "area": { "isStacked": false },
214
+ "sankey": {
215
+ "title": { "defaultColor": "black" },
216
+ "iterations": 1,
217
+ "rxValue": 0.9,
218
+ "overallSize": { "width": 900, "height": 700 },
219
+ "margin": { "margin_y": 25, "margin_x": 0 },
220
+ "nodeSize": { "nodeWidth": 26, "nodeHeight": 40 },
221
+ "nodePadding": 55,
222
+ "nodeFontColor": "black",
223
+ "nodeColor": { "default": "#ff8500", "inactive": "#808080" },
224
+ "linkColor": { "default": "#ffc900", "inactive": "#D3D3D3" },
225
+ "opacity": {
226
+ "nodeOpacityDefault": 1,
227
+ "nodeOpacityInactive": 0.1,
228
+ "LinkOpacityDefault": 1,
229
+ "LinkOpacityInactive": 0.1
230
+ },
231
+ "storyNodeFontColor": "#006778",
232
+ "storyNodeText": [],
233
+ "nodeValueStyle": { "textBefore": "(", "textAfter": ")" },
234
+ "data": []
235
+ },
236
+ "datasets": {},
237
+ "visualizationType": "Bar",
238
+ "data": [
239
+ { "Race": "Hispanic or Latino", "Age-adjusted rate": "644.2" },
240
+ { "Race": "Non-Hispanic American Indian", "Age-adjusted rate": "636.1" },
241
+ { "Race": "Non-Hispanic Black", "Age-adjusted rate": "563.7" },
242
+ { "Race": "Non-Hispanic Asian or Pacific Islander", "Age-adjusted rate": "202.5" },
243
+ { "Race": "Non-Hispanic White", "Age-adjusted rate": "183.6" }
244
+ ],
245
+ "dataFileName": "valid-data-chart.csv",
246
+ "dataFileSourceType": "file",
247
+ "formattedData": [
248
+ { "Race": "Hispanic or Latino", "Age-adjusted rate": "644.2" },
249
+ { "Race": "Non-Hispanic American Indian", "Age-adjusted rate": "636.1" },
250
+ { "Race": "Non-Hispanic Black", "Age-adjusted rate": "563.7" },
251
+ { "Race": "Non-Hispanic Asian or Pacific Islander", "Age-adjusted rate": "202.5" },
252
+ { "Race": "Non-Hispanic White", "Age-adjusted rate": "183.6" }
253
+ ],
254
+ "dataDescription": { "horizontal": false, "series": false },
255
+ "version": "4.24.10",
256
+ "dynamicMarginTop": 0
257
+ }