@cdc/chart 4.25.3-6 → 4.25.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/dist/cdcchart-1a1724a1.es.js +4886 -0
- package/dist/cdcchart.js +51921 -76151
- package/index.html +1 -1
- package/package.json +2 -2
- package/src/CdcChart.tsx +1 -22
- package/src/CdcChartComponent.tsx +27 -13
- package/src/_stories/Chart.CI.stories.tsx +33 -0
- package/src/_stories/Chart.Legend.Gradient.stories.tsx +6 -0
- package/src/_stories/Chart.stories.tsx +0 -16
- package/src/_stories/_mock/bar_chart_ci_labels.json +620 -0
- package/src/_stories/_mock/legend_groupBy_mock.json +474 -0
- package/src/components/BarChart/components/BarChart.Horizontal.tsx +1 -1
- package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +1 -1
- package/src/components/BarChart/components/BarChart.StackedVertical.tsx +1 -1
- package/src/components/BarChart/components/BarChart.Vertical.tsx +2 -2
- package/src/components/EditorPanel/EditorPanel.tsx +60 -24
- package/src/components/EditorPanel/helpers/updateFieldRankByValue.ts +4 -3
- package/src/components/Legend/Legend.Component.tsx +69 -58
- package/src/components/Legend/Legend.tsx +3 -1
- package/src/components/Legend/LegendGroup/LegendGroup.styles.css +40 -0
- package/src/components/Legend/LegendGroup/LegendGroup.tsx +103 -0
- package/src/components/Legend/LegendGroup/index.tsx +3 -0
- package/src/components/LineChart/components/LineChart.Circle.tsx +14 -9
- package/src/components/LineChart/index.tsx +18 -7
- package/src/components/LinearChart.tsx +38 -30
- package/src/data/initial-state.js +1 -1
- package/src/helpers/dataHelpers.ts +10 -0
- package/src/helpers/sizeHelpers.ts +23 -0
- package/src/hooks/useBarChart.ts +2 -1
- package/src/hooks/useScales.ts +2 -8
- package/src/store/chart.actions.ts +1 -1
- package/src/types/ChartConfig.ts +2 -1
package/index.html
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
-->
|
|
46
46
|
|
|
47
47
|
<!-- GENERIC CHART TYPES -->
|
|
48
|
-
|
|
48
|
+
<div class="react-container" data-config="/examples/private/ari-other-conditions-1.json"></div>
|
|
49
49
|
<!-- <div class="react-container" data-config="/examples/cases-year.json"></div>-->
|
|
50
50
|
<!-- <div class="react-container" data-config="/examples/test.json"></div> -->
|
|
51
51
|
<!-- <div class="react-container" data-config="/examples/feature/line/line-chart.json"></div> -->
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/chart",
|
|
3
|
-
"version": "4.25.3
|
|
3
|
+
"version": "4.25.3",
|
|
4
4
|
"description": "React component for visualizing tabular data in various types of charts",
|
|
5
5
|
"moduleName": "CdcChart",
|
|
6
6
|
"main": "dist/cdcchart",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"react": "^18.2.0",
|
|
62
62
|
"react-dom": "^18.2.0"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "b09566f5a7d57c8d0109e5f407257729d6b36846",
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/d3-sankey": "^0.12.4",
|
|
67
67
|
"resize-observer-polyfill": "^1.5.1"
|
package/src/CdcChart.tsx
CHANGED
|
@@ -69,12 +69,7 @@ const CdcChartWrapper: React.FC<CdcChartProps> = ({ configUrl, isEditor, isDebug
|
|
|
69
69
|
setIsLoading(true)
|
|
70
70
|
try {
|
|
71
71
|
const loadedConfig = await loadConfig(configUrl)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
setConfig({
|
|
75
|
-
...loadedConfig,
|
|
76
|
-
data
|
|
77
|
-
})
|
|
72
|
+
setConfig(loadedConfig)
|
|
78
73
|
} catch (error) {
|
|
79
74
|
console.error('Failed to load configuration or data', error)
|
|
80
75
|
} finally {
|
|
@@ -124,19 +119,3 @@ const fetchAndParseData = async (url: string, ext: string) => {
|
|
|
124
119
|
return []
|
|
125
120
|
}
|
|
126
121
|
}
|
|
127
|
-
|
|
128
|
-
const loadDataFromConfig = async (response: any) => {
|
|
129
|
-
if (!response.dataUrl || _.some(_.get(response, 'filters', []), { type: 'url' })) {
|
|
130
|
-
return response.data || []
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const ext = getFileExtension(response.dataUrl)
|
|
134
|
-
const urlWithCacheBuster = `${response.dataUrl}`
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
return await fetchAndParseData(urlWithCacheBuster, ext)
|
|
138
|
-
} catch {
|
|
139
|
-
console.error(`Cannot parse URL: ${response.dataUrl}`)
|
|
140
|
-
return []
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -74,6 +74,8 @@ import { getColorScale } from './helpers/getColorScale'
|
|
|
74
74
|
import './scss/main.scss'
|
|
75
75
|
import { getInitialState, reducer } from './store/chart.reducer'
|
|
76
76
|
|
|
77
|
+
export const EDITOR_WIDTH = 350
|
|
78
|
+
|
|
77
79
|
interface CdcChartProps {
|
|
78
80
|
config?: ChartConfig
|
|
79
81
|
isEditor?: boolean
|
|
@@ -179,8 +181,8 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
179
181
|
if (newConfig.visualizationType === 'Bump Chart') {
|
|
180
182
|
newConfig.xAxis.type === 'date-time'
|
|
181
183
|
}
|
|
182
|
-
|
|
183
|
-
return
|
|
184
|
+
if (!isDashboard) return coveUpdateWorker(newConfig)
|
|
185
|
+
return newConfig
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
const updateConfig = (_config: AllChartsConfig, dataOverride?: any[]) => {
|
|
@@ -344,10 +346,8 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
344
346
|
const resizeObserver = new ResizeObserver(entries => {
|
|
345
347
|
for (let entry of entries) {
|
|
346
348
|
let { width, height } = entry.contentRect
|
|
347
|
-
const svgMarginWidth = 15
|
|
348
|
-
const editorWidth = 350
|
|
349
349
|
|
|
350
|
-
width = isEditor ? width -
|
|
350
|
+
width = isEditor ? width - EDITOR_WIDTH : width
|
|
351
351
|
|
|
352
352
|
const newViewport = getViewport(width)
|
|
353
353
|
|
|
@@ -357,7 +357,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
357
357
|
width = width - 2.5
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
-
width = width
|
|
360
|
+
width = width
|
|
361
361
|
dispatch({ type: 'SET_DIMENSIONS', payload: [width, height] })
|
|
362
362
|
}
|
|
363
363
|
})
|
|
@@ -565,6 +565,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
565
565
|
addColRoundTo,
|
|
566
566
|
{ index, length } = { index: null, length: null }
|
|
567
567
|
) => {
|
|
568
|
+
if (num === '') return 'N/A'
|
|
568
569
|
// if num is NaN return num
|
|
569
570
|
if (isNaN(num) || !num) return num
|
|
570
571
|
// Check if the input number is negative
|
|
@@ -749,9 +750,10 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
749
750
|
if (!Array.isArray(data)) return []
|
|
750
751
|
if (config.visualizationType === 'Forecasting') return data
|
|
751
752
|
// specify keys that needs to be cleaned to render chart and skip rest
|
|
752
|
-
const CIkeys: string[] = Object.values(config
|
|
753
|
-
const seriesKeys: string[] = config
|
|
754
|
-
const keysToClean: string[] = seriesKeys
|
|
753
|
+
const CIkeys: string[] = Object.values(_.get(config, 'confidenceKeys', {})) as string[]
|
|
754
|
+
const seriesKeys: string[] = _.get(config, 'series', []).map((s: any) => s.dataKey)
|
|
755
|
+
const keysToClean: string[] = [...(seriesKeys ?? []), ...(CIkeys ?? [])]
|
|
756
|
+
|
|
755
757
|
// key that does not need to be cleaned
|
|
756
758
|
const excludedKey = config.xAxis.dataKey
|
|
757
759
|
return config?.xAxis?.dataKey ? transform.cleanData(data, excludedKey, keysToClean) : data
|
|
@@ -913,11 +915,23 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
913
915
|
</ParentSize>
|
|
914
916
|
</div>
|
|
915
917
|
) : (
|
|
916
|
-
<div ref={parentRef} style={{ width:
|
|
918
|
+
<div ref={parentRef} style={{ width: '100%' }}>
|
|
917
919
|
<ParentSize>
|
|
918
|
-
{parent =>
|
|
919
|
-
|
|
920
|
-
|
|
920
|
+
{parent => {
|
|
921
|
+
const labelMargin = 120
|
|
922
|
+
const widthReduction =
|
|
923
|
+
config.showLineSeriesLabels &&
|
|
924
|
+
(config.legend.position !== 'right' || config.legend.hide)
|
|
925
|
+
? labelMargin
|
|
926
|
+
: 0
|
|
927
|
+
return (
|
|
928
|
+
<LinearChart
|
|
929
|
+
ref={svgRef}
|
|
930
|
+
parentWidth={parent.width - widthReduction}
|
|
931
|
+
parentHeight={parent.height}
|
|
932
|
+
/>
|
|
933
|
+
)
|
|
934
|
+
}}
|
|
921
935
|
</ParentSize>
|
|
922
936
|
</div>
|
|
923
937
|
))}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react'
|
|
2
|
+
import barChartCiLabels from './_mock/bar_chart_ci_labels.json'
|
|
3
|
+
import lineChartDynamicCI from './_mock/line_chart_dynamic_ci.json'
|
|
4
|
+
import lineChartNonDynamicCI from './_mock/line_chart_non_dynamic_ci.json'
|
|
5
|
+
|
|
6
|
+
import Chart from '../CdcChartComponent'
|
|
7
|
+
|
|
8
|
+
const meta: Meta<typeof Chart> = {
|
|
9
|
+
title: 'Components/Templates/Chart/Confidence Intervals',
|
|
10
|
+
component: Chart
|
|
11
|
+
}
|
|
12
|
+
type Story = StoryObj<typeof Chart>
|
|
13
|
+
export const bar_chart_with_labels: Story = {
|
|
14
|
+
args: {
|
|
15
|
+
config: barChartCiLabels,
|
|
16
|
+
isEditor: false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const line_Chart_Dynamic_Confidence_Intervals: Story = {
|
|
21
|
+
args: {
|
|
22
|
+
config: lineChartDynamicCI,
|
|
23
|
+
isEditor: false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const line_Chart_Non_Dynamic_Confidence_Intervals: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
config: lineChartNonDynamicCI,
|
|
30
|
+
isEditor: false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default meta
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react'
|
|
2
2
|
import chartGradientConfig from './_mock/legend.gradient_mock.json'
|
|
3
|
+
import chartGroupedLagend from './_mock/legend_groupBy_mock.json'
|
|
3
4
|
import SimplifiedLineConfig from './_mock/simplified_line.json'
|
|
4
5
|
|
|
5
6
|
import Chart from '../CdcChartComponent'
|
|
@@ -17,6 +18,11 @@ export const Legend_Gradient_Smooth: Story = {
|
|
|
17
18
|
config: chartGradientConfig
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
export const Legend_Group_By: Story = {
|
|
22
|
+
args: {
|
|
23
|
+
config: chartGroupedLagend
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
|
|
21
27
|
export const Legend_Gradient_Linear_Blocks: Story = {
|
|
22
28
|
args: {
|
|
@@ -11,8 +11,6 @@ import pieConfig from './_mock/pie_with_data.json'
|
|
|
11
11
|
import boxPlotConfig from './_mock/boxplot_multiseries.json'
|
|
12
12
|
import areaChartStacked from './_mock/area_chart_stacked.json'
|
|
13
13
|
import multipleLines from './_mock/short_dates.json'
|
|
14
|
-
import lineChartDynamicCI from './_mock/line_chart_dynamic_ci.json'
|
|
15
|
-
import lineChartNonDynamicCI from './_mock/line_chart_non_dynamic_ci.json'
|
|
16
14
|
import { editConfigKeys } from '../helpers/configHelpers'
|
|
17
15
|
|
|
18
16
|
const meta: Meta<typeof Chart> = {
|
|
@@ -22,20 +20,6 @@ const meta: Meta<typeof Chart> = {
|
|
|
22
20
|
|
|
23
21
|
type Story = StoryObj<typeof Chart>
|
|
24
22
|
|
|
25
|
-
export const line_Chart_Dynamic_Confidence_Intervals: Story = {
|
|
26
|
-
args: {
|
|
27
|
-
config: lineChartDynamicCI,
|
|
28
|
-
isEditor: false
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const line_Chart_Non_Dynamic_Confidence_Intervals: Story = {
|
|
33
|
-
args: {
|
|
34
|
-
config: lineChartNonDynamicCI,
|
|
35
|
-
isEditor: false
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
23
|
export const line_Chart_Two_Points_Regression_Test: Story = {
|
|
40
24
|
args: {
|
|
41
25
|
config: lineChartTwoPointsRegressionTest,
|