Skip to content

Commit 4e8109b

Browse files
authored
Merge pull request #2193 from CDCgov/dev
Dev
2 parents 8084563 + 033e079 commit 4e8109b

File tree

139 files changed

+60104
-3476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+60104
-3476
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
"lodash.get": "^4.4.2",
6565
"lodash.merge": "^4.6.2",
6666
"mini-svg-data-uri": "^1.2.3",
67+
"patch-package": "^8.0.0",
6768
"pathe": "^1.1.0",
69+
"postinstall-postinstall": "^2.1.0",
6870
"prettier": "^2.8.1",
6971
"pretty": "^2.0.0",
7072
"prop-types": "^15.8.1",
@@ -99,14 +101,15 @@
99101
"test-storybook": "npx test-storybook",
100102
"storybook-docs": "storybook dev --docs",
101103
"build-storybook": "storybook build",
104+
"postinstall": "patch-package",
102105
"predeploy": "storybook build --output-dir .storybook_build && touch .storybook_build/.nojekyll",
103106
"deploy": "gh-pages -d .storybook_build -t true",
104107
"lint": "eslint packages/*/src/**/*.{js,jsx,ts,tsx}",
105108
"prepare": "husky install"
106109
},
107110
"dependencies": {
108111
"@visx/annotation": "^3.3.0",
109-
"@visx/brush": "^3.0.1",
112+
"@visx/brush": "^3.12.0",
110113
"@visx/legend": "3.12.0",
111114
"@visx/pattern": "^3.0.0",
112115
"@visx/responsive": "^2.10.0",

packages/chart/index.html

Lines changed: 130 additions & 130 deletions
Large diffs are not rendered by default.

packages/chart/src/CdcChartComponent.tsx

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,16 @@ import { getBoxPlotConfig } from './helpers/getBoxPlotConfig'
7171
import { getComboChartConfig } from './helpers/getComboChartConfig'
7272
import { getExcludedData } from './helpers/getExcludedData'
7373
import { getColorScale } from './helpers/getColorScale'
74+
import { getTransformedData } from './helpers/getTransformedData'
75+
import { getPiePercent } from './helpers/getPiePercent'
76+
7477
// styles
7578
import './scss/main.scss'
7679
import { getInitialState, reducer } from './store/chart.reducer'
80+
import { VizFilter } from '@cdc/core/types/VizFilter'
81+
import { getNewRuntime } from './helpers/getNewRuntime'
82+
import FootnotesStandAlone from '@cdc/core/components/Footnotes/FootnotesStandAlone'
83+
import { Datasets } from '@cdc/core/types/DataSet'
7784

7885
interface CdcChartProps {
7986
config?: ChartConfig
@@ -87,6 +94,7 @@ interface CdcChartProps {
8794
setSharedFilter?: (filter: any) => void
8895
setSharedFilterValue?: (value: any) => void
8996
dashboardConfig?: DashboardConfig
97+
datasets?: Datasets
9098
}
9199
const CdcChart: React.FC<CdcChartProps> = ({
92100
config: configObj,
@@ -98,7 +106,8 @@ const CdcChart: React.FC<CdcChartProps> = ({
98106
link,
99107
setSharedFilter,
100108
setSharedFilterValue,
101-
dashboardConfig
109+
dashboardConfig,
110+
datasets
102111
}) => {
103112
const transform = new DataTransform()
104113
const initialState = getInitialState(configObj)
@@ -130,10 +139,6 @@ const CdcChart: React.FC<CdcChartProps> = ({
130139
}
131140
}
132141

133-
const setFiltersData = (filteredData: object[]): void => {
134-
dispatch({ type: 'SET_FILTERED_DATA', payload: filteredData })
135-
}
136-
137142
const legendRef = useRef(null)
138143
const parentRef = useRef(null)
139144

@@ -160,7 +165,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
160165

161166
const convertLineToBarGraph = isConvertLineToBarGraph(config, filteredData)
162167

163-
const prepareConfig = async (loadedConfig: ChartConfig) => {
168+
const prepareConfig = (loadedConfig: ChartConfig) => {
164169
let newConfig = _.defaultsDeep(loadedConfig, defaults)
165170
_.defaultsDeep(newConfig, {
166171
table: { showVertical: false }
@@ -340,6 +345,30 @@ const CdcChart: React.FC<CdcChartProps> = ({
340345
}
341346
}
342347

348+
const setFilters = (newFilters: VizFilter[]) => {
349+
if (!config.dynamicSeries) {
350+
const _newFilters = addValuesToFilters(newFilters, excludedData)
351+
setConfig({
352+
...config,
353+
filters: _newFilters
354+
})
355+
}
356+
357+
if (config.filterBehavior === 'Filter Change' || config.filterBehavior === 'Apply Button') {
358+
const newFilteredData = filterVizData(newFilters, excludedData)
359+
360+
dispatch({ type: 'SET_FILTERED_DATA', payload: newFilteredData })
361+
if (config.dynamicSeries) {
362+
const runtime = getNewRuntime(config, newFilteredData)
363+
setConfig({
364+
...config,
365+
filters: newFilters,
366+
runtime
367+
})
368+
}
369+
}
370+
}
371+
343372
// Observes changes to outermost container and changes viewport size in state
344373
const resizeObserver = new ResizeObserver(entries => {
345374
for (let entry of entries) {
@@ -378,7 +407,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
378407
if (newConfig.dataUrl && !urlFilters) {
379408
// handle urls with spaces in the name.
380409
if (newConfig.dataUrl) newConfig.dataUrl = `${newConfig.dataUrl}`
381-
let newData = await fetchRemoteData(newConfig.dataUrl, 'Chart')
410+
let newData = await fetchRemoteData(newConfig.dataUrl)
382411

383412
if (newData && newConfig.dataDescription) {
384413
newData = transform.autoStandardize(newData)
@@ -399,12 +428,18 @@ const CdcChart: React.FC<CdcChartProps> = ({
399428
}
400429
return newConfig
401430
}
431+
402432
useEffect(() => {
403433
const load = async () => {
404434
try {
405435
if (configObj) {
406436
const preparedConfig = await prepareConfig(configObj)
407437
const preppedData = await prepareData(preparedConfig)
438+
439+
if (preparedConfig?.formattedData?.length) {
440+
preppedData.data = preparedConfig.formattedData
441+
}
442+
408443
dispatch({ type: 'SET_STATE_DATA', payload: preppedData.data })
409444
dispatch({ type: 'SET_EXCLUDED_DATA', payload: preppedData.data })
410445
updateConfig(preparedConfig, preppedData.data)
@@ -491,7 +526,11 @@ const CdcChart: React.FC<CdcChartProps> = ({
491526

492527
// Called on legend click, highlights/unhighlights the data series with the given label
493528
const highlight = (label: Label): void => {
494-
if (seriesHighlight.length + 1 === config.runtime.seriesKeys.length && config.visualizationType !== 'Forecasting') {
529+
if (
530+
seriesHighlight.length + 1 === config.runtime.seriesKeys.length &&
531+
config.visualizationType !== 'Forecasting' &&
532+
!seriesHighlight.includes(label.datum)
533+
) {
495534
return handleShowAll()
496535
}
497536

@@ -589,8 +628,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
589628
rightSuffix,
590629
bottomPrefix,
591630
bottomSuffix,
592-
bottomAbbreviated,
593-
onlyShowTopPrefixSuffix
631+
bottomAbbreviated
594632
}
595633
} = config
596634

@@ -683,9 +721,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
683721
if (addColPrefix && axis === 'left') {
684722
result = addColPrefix + result
685723
} else {
686-
// if onlyShowTopPrefixSuffix only show top prefix
687-
const suppressAllButLast = onlyShowTopPrefixSuffix && length - 1 !== index
688-
if (prefix && axis === 'left' && !suppressAllButLast) {
724+
if (prefix && axis === 'left') {
689725
result += prefix
690726
}
691727
}
@@ -704,7 +740,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
704740
if (addColSuffix && axis === 'left') {
705741
result += addColSuffix
706742
} else {
707-
if (suffix && axis === 'left' && !onlyShowTopPrefixSuffix) {
743+
if (suffix && axis === 'left') {
708744
result += suffix
709745
}
710746
}
@@ -759,6 +795,10 @@ const CdcChart: React.FC<CdcChartProps> = ({
759795
const getTableRuntimeData = () => {
760796
if (visualizationType === 'Sankey') return config?.data?.[0]?.tableData
761797
const data = filteredData || excludedData
798+
if (config.visualizationType === 'Pie' && !config.dataFormat?.showPiePercent) {
799+
return getPiePercent(data, config?.yAxis?.dataKey)
800+
}
801+
762802
const dynamicSeries = config.series.find(series => !!series.dynamicCategory)
763803
if (!dynamicSeries) return data
764804
const usedColumns = Object.values(config.columns)
@@ -825,7 +865,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
825865

826866
body = (
827867
<>
828-
{isEditor && <EditorPanel />}
868+
{isEditor && <EditorPanel datasets={datasets} />}
829869
<Layout.Responsive isEditor={isEditor}>
830870
{config.newViz && <Confirm updateConfig={updateConfig} config={config} />}
831871
{undefined === config.newViz && isEditor && config.runtime && config.runtime?.editorErrorMessage && (
@@ -859,11 +899,8 @@ const CdcChart: React.FC<CdcChartProps> = ({
859899
{config.filters && !externalFilters && config.visualizationType !== 'Spark Line' && (
860900
<Filters
861901
config={config}
862-
setConfig={setConfig}
863-
setFilteredData={setFiltersData}
864-
filteredData={filteredData}
902+
setFilters={setFilters}
865903
excludedData={excludedData}
866-
filterData={filterVizData}
867904
dimensions={dimensions}
868905
/>
869906
)}
@@ -940,11 +977,8 @@ const CdcChart: React.FC<CdcChartProps> = ({
940977
<>
941978
<Filters
942979
config={config}
943-
setConfig={setConfig}
944-
setFilteredData={setFiltersData}
945-
filteredData={filteredData}
980+
setFilters={setFilters}
946981
excludedData={excludedData}
947-
filterData={filterVizData}
948982
dimensions={dimensions}
949983
/>
950984
{config?.introText && (
@@ -1015,7 +1049,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
10151049
(config.visualizationType === 'Sankey' && config.table.show)) && (
10161050
<DataTable
10171051
/* changing the "key" will force the table to re-render
1018-
when the default sort changes while editing */
1052+
when the default sort changes while editing */
10191053
key={dataTableDefaultSortBy}
10201054
config={pivotDynamicSeries(config)}
10211055
rawData={
@@ -1041,8 +1075,14 @@ const CdcChart: React.FC<CdcChartProps> = ({
10411075
)}
10421076
{config?.annotations?.length > 0 && <Annotation.Dropdown />}
10431077
{/* show pdf or image button */}
1044-
{config?.footnotes && <section className='footnotes pt-2 mt-4'>{parse(config.footnotes)}</section>}
1078+
{config?.legacyFootnotes && (
1079+
<section className='footnotes pt-2 mt-4'>{parse(config.legacyFootnotes)}</section>
1080+
)}
10451081
</div>
1082+
<FootnotesStandAlone
1083+
config={configObj.footnotes}
1084+
filters={config.filters?.filter(f => f.filterFootnotes)}
1085+
/>
10461086
</div>
10471087
)}
10481088
</Layout.Responsive>
@@ -1100,7 +1140,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
11001140
setSharedFilterValue,
11011141
svgRef,
11021142
tableData: filteredData || excludedData,
1103-
transformedData: clean(filteredData || excludedData),
1143+
transformedData: getTransformedData({ brushData: state.brushData, filteredData, excludedData, clean }),
11041144
twoColorPalette,
11051145
unfilteredData: _.cloneDeep(stateData),
11061146
updateConfig

0 commit comments

Comments
 (0)