@cdc/chart 4.26.2 → 4.26.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.
- package/LICENSE +201 -0
- package/dist/cdcchart.js +35674 -32430
- package/examples/data/data-with-metadata.json +10 -0
- package/examples/feature/pie/planet-pie-example-config.json +2 -1
- package/examples/metadata-variables.json +58 -0
- package/package.json +3 -3
- package/src/CdcChart.tsx +8 -4
- package/src/CdcChartComponent.tsx +321 -288
- package/src/_stories/Chart.CustomColors.stories.tsx +74 -0
- package/src/_stories/Chart.Defaults.stories.tsx +95 -0
- package/src/_stories/Chart.SmallestLeftAxisMax.stories.tsx +64 -0
- package/src/_stories/Chart.stories.tsx +36 -2
- package/src/_stories/ChartBar.Editor.stories.tsx +97 -38
- package/src/_stories/ChartBrush.Editor.stories.tsx +11 -25
- package/src/_stories/ChartEditor.Editor.stories.tsx +1 -1
- package/src/_stories/_mock/paired-bar-abbr.json +421 -0
- package/src/_stories/_mock/pie_custom_colors.json +268 -0
- package/src/_stories/_mock/smallest_left_axis_max.json +104 -0
- package/src/components/Annotations/components/AnnotationDraggable.styles.css +10 -10
- package/src/components/Annotations/components/AnnotationDropdown.styles.css +1 -1
- package/src/components/Annotations/components/AnnotationList.styles.css +11 -11
- package/src/components/Axis/BottomAxis.tsx +10 -3
- package/src/components/Axis/PairedBarAxis.tsx +10 -4
- package/src/components/BarChart/components/BarChart.Horizontal.tsx +12 -28
- package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +12 -30
- package/src/components/BarChart/components/BarChart.StackedVertical.tsx +12 -31
- package/src/components/BarChart/components/BarChart.Vertical.tsx +12 -28
- package/src/components/BarChart/helpers/getPatternUrl.ts +94 -0
- package/src/components/BarChart/helpers/tests/getPatternUrl.test.ts +134 -0
- package/src/components/BarChart/helpers/useBarChart.ts +3 -0
- package/src/components/Brush/BrushSelector.tsx +2 -1
- package/src/components/Brush/MiniChartPreview.tsx +21 -26
- package/src/components/EditorPanel/EditorPanel.tsx +56 -43
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +9 -9
- package/src/components/EditorPanel/components/Panels/Panel.ForestPlotSettings.tsx +0 -78
- package/src/components/EditorPanel/components/Panels/Panel.General.tsx +39 -1
- package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +24 -42
- package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +83 -2
- package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +45 -42
- package/src/components/EditorPanel/editor-panel.scss +1 -1
- package/src/components/ForestPlot/ForestPlot.tsx +26 -22
- package/src/components/Legend/LegendGroup/LegendGroup.styles.css +4 -4
- package/src/components/Legend/helpers/createFormatLabels.tsx +3 -2
- package/src/components/LinearChart/tests/LinearChart.test.tsx +77 -0
- package/src/components/LinearChart/tests/mockConfigContext.ts +2 -0
- package/src/components/LinearChart.tsx +26 -6
- package/src/components/PieChart/PieChart.tsx +19 -4
- package/src/components/RadarChart/RadarChart.tsx +1 -1
- package/src/components/Regions/components/Regions.tsx +6 -6
- package/src/components/Sankey/components/Sankey.tsx +3 -3
- package/src/components/Sankey/sankey.scss +1 -1
- package/src/components/SmallMultiples/SmallMultiples.css +5 -5
- package/src/components/Sparkline/index.scss +4 -2
- package/src/components/WarmingStripes/WarmingStripesGradientLegend.css +8 -8
- package/src/data/initial-state.js +23 -14
- package/src/data/legacy-defaults.ts +18 -0
- package/src/helpers/abbreviateNumber.ts +24 -17
- package/src/helpers/getChartPatternId.ts +17 -0
- package/src/helpers/getMinMax.ts +16 -2
- package/src/helpers/seriesColumnSettings.ts +114 -0
- package/src/helpers/tests/countNumOfTicks.test.ts +77 -0
- package/src/helpers/tests/seriesColumnSettings.test.ts +84 -0
- package/src/hooks/useRightAxis.ts +14 -0
- package/src/hooks/useScales.ts +92 -56
- package/src/hooks/useTooltip.tsx +20 -3
- package/src/scss/main.scss +152 -79
- package/src/test/CdcChart.test.jsx +2 -2
- package/src/types/ChartConfig.ts +4 -0
- package/tests/fixtures/chart-config-with-metadata.json +29 -0
- package/tests/fixtures/data-with-metadata.json +10 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lastUpdated": "January 15, 2026",
|
|
3
|
+
"source": "CDC NREVSS",
|
|
4
|
+
"data": [
|
|
5
|
+
{ "STATE": "AL", "Rate": "10", "Location": "Home" },
|
|
6
|
+
{ "STATE": "AK", "Rate": "12", "Location": "Home" },
|
|
7
|
+
{ "STATE": "FL", "Rate": "10", "Location": "Work" },
|
|
8
|
+
{ "STATE": "GA", "Rate": "12", "Location": "Work" }
|
|
9
|
+
]
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "chart",
|
|
3
|
+
"title": "Rates by State",
|
|
4
|
+
"showTitle": true,
|
|
5
|
+
"theme": "theme-blue",
|
|
6
|
+
"visualizationType": "Bar",
|
|
7
|
+
"visualizationSubType": "regular",
|
|
8
|
+
"orientation": "vertical",
|
|
9
|
+
"dataUrl": "/examples/data/data-with-metadata.json",
|
|
10
|
+
"enableMarkupVariables": true,
|
|
11
|
+
"markupVariables": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Last Updated",
|
|
14
|
+
"tag": "{{lastUpdated}}",
|
|
15
|
+
"metadataKey": "lastUpdated",
|
|
16
|
+
"conditions": []
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "Source",
|
|
20
|
+
"tag": "{{source}}",
|
|
21
|
+
"metadataKey": "source",
|
|
22
|
+
"conditions": []
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"description": "Data last updated {{lastUpdated}}. Source: {{source}}.",
|
|
26
|
+
"xAxis": {
|
|
27
|
+
"dataKey": "STATE",
|
|
28
|
+
"label": "State"
|
|
29
|
+
},
|
|
30
|
+
"yAxis": {
|
|
31
|
+
"label": "Rate"
|
|
32
|
+
},
|
|
33
|
+
"series": [
|
|
34
|
+
{
|
|
35
|
+
"dataKey": "Rate",
|
|
36
|
+
"type": "Bar",
|
|
37
|
+
"tooltip": true
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"table": {
|
|
41
|
+
"show": true,
|
|
42
|
+
"label": "Data Table"
|
|
43
|
+
},
|
|
44
|
+
"general": {
|
|
45
|
+
"showDownloadButton": false
|
|
46
|
+
},
|
|
47
|
+
"visual": {
|
|
48
|
+
"border": true,
|
|
49
|
+
"accent": true,
|
|
50
|
+
"background": true
|
|
51
|
+
},
|
|
52
|
+
"palette": "qualitative3",
|
|
53
|
+
"dataFormat": {
|
|
54
|
+
"commas": false,
|
|
55
|
+
"prefix": "",
|
|
56
|
+
"suffix": ""
|
|
57
|
+
}
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/chart",
|
|
3
|
-
"version": "4.26.
|
|
3
|
+
"version": "4.26.3",
|
|
4
4
|
"description": "React component for visualizing tabular data in various types of charts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Matthew Pallansch <mpallansch@adittech.com>",
|
|
7
7
|
"bugs": "https://github.com/CDCgov/cdc-open-viz/issues",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@cdc/core": "^4.26.
|
|
9
|
+
"@cdc/core": "^4.26.3",
|
|
10
10
|
"@hello-pangea/dnd": "^16.2.0",
|
|
11
11
|
"@react-spring/web": "^9.7.5",
|
|
12
12
|
"@rollup/plugin-dsv": "^3.0.2",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@types/d3-sankey": "^0.12.4",
|
|
57
57
|
"@types/d3-time-format": "^4.0.3"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "d50e45a074fbefa56cac904917e707d57f237737",
|
|
60
60
|
"main": "dist/cdcchart",
|
|
61
61
|
"moduleName": "CdcChart",
|
|
62
62
|
"peerDependencies": {
|
package/src/CdcChart.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { getFileExtension } from '@cdc/core/helpers/getFileExtension'
|
|
|
5
5
|
import { isSolrCsv, isSolrJson } from '@cdc/core/helpers/isSolr'
|
|
6
6
|
import { parseCsvWithQuotes } from '@cdc/core/helpers/parseCsvWithQuotes'
|
|
7
7
|
import cacheBustingString from '@cdc/core/helpers/cacheBustingString'
|
|
8
|
+
import { extractDataAndMetadata } from '@cdc/core/helpers/extractDataAndMetadata'
|
|
8
9
|
import Loading from '@cdc/core/components/Loading'
|
|
9
10
|
import _ from 'lodash'
|
|
10
11
|
import EditorContext from '@cdc/core/contexts/EditorContext'
|
|
@@ -60,11 +61,12 @@ const CdcChartWrapper: React.FC<CdcChartProps> = ({
|
|
|
60
61
|
|
|
61
62
|
const finalUrl = `${dataUrl.origin}${dataUrl.pathname}${new URLSearchParams(qsParams)}`
|
|
62
63
|
const ext = getFileExtension(finalUrl)
|
|
63
|
-
const data = await fetchAndParseData(finalUrl, ext)
|
|
64
|
+
const { data, dataMetadata } = await fetchAndParseData(finalUrl, ext)
|
|
64
65
|
|
|
65
66
|
setConfig(prev => ({
|
|
66
67
|
...prev,
|
|
67
68
|
data: { ...data, urlFiltered: true },
|
|
69
|
+
dataMetadata,
|
|
68
70
|
runtimeDataUrl: finalUrl,
|
|
69
71
|
formattedData: { ...data, urlFiltered: true }
|
|
70
72
|
}))
|
|
@@ -113,12 +115,14 @@ const fetchAndParseData = async (url: string, ext: string) => {
|
|
|
113
115
|
const response = await fetch(url)
|
|
114
116
|
if (ext === 'csv' || isSolrCsv(url)) {
|
|
115
117
|
const responseText = await response.text()
|
|
116
|
-
return parseCsv(responseText)
|
|
118
|
+
return { data: parseCsv(responseText), dataMetadata: {} }
|
|
117
119
|
} else if (ext === 'json' || isSolrJson(url)) {
|
|
118
|
-
|
|
120
|
+
const json = await response.json()
|
|
121
|
+
return extractDataAndMetadata(json)
|
|
119
122
|
}
|
|
120
123
|
} catch (error) {
|
|
121
124
|
console.error(`Error parsing URL: ${url}`, error)
|
|
122
|
-
return []
|
|
125
|
+
return { data: [], dataMetadata: {} }
|
|
123
126
|
}
|
|
127
|
+
return { data: [], dataMetadata: {} }
|
|
124
128
|
}
|