@cdc/chart 4.25.11 → 4.26.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.
- package/dist/cdcchart.js +38898 -40013
- package/examples/feature/pie/planet-pie-example-config.json +48 -2
- package/examples/private/DEV-12100.json +1303 -0
- package/examples/private/cat-y.json +1235 -0
- package/examples/private/data-points.json +228 -0
- package/examples/private/height.json +3915 -0
- package/examples/private/links.json +569 -0
- package/examples/private/quadrant.txt +30 -0
- package/examples/private/test-forecast.json +5510 -0
- package/examples/private/warming-stripe-test.json +2578 -0
- package/examples/private/warming-stripes.json +4763 -0
- package/examples/tech-adoption-with-links.json +560 -0
- package/index.html +15 -20
- package/package.json +5 -4
- package/preview.html +1616 -0
- package/src/CdcChartComponent.tsx +111 -75
- package/src/_stories/Chart.Regions.Categorical.stories.tsx +148 -0
- package/src/_stories/Chart.Regions.DateScale.stories.tsx +197 -0
- package/src/_stories/Chart.Regions.DateTimeScale.stories.tsx +297 -0
- package/src/_stories/Chart.stories.tsx +8 -0
- package/src/_stories/ChartBar.Editor.stories.tsx +11 -6
- package/src/_stories/ChartBrush.Editor.stories.tsx +295 -0
- package/src/_stories/ChartBrush.stories.tsx +50 -0
- package/src/_stories/ChartEditor.Editor.stories.tsx +3 -5
- package/src/_stories/TechAdoptionWithLinks.stories.tsx +27 -0
- package/src/_stories/_mock/brush_enabled.json +326 -0
- package/src/_stories/_mock/brush_mock.json +2 -69
- package/src/_stories/_mock/horizontal-bars-dynamic-y-axis.json +413 -0
- package/src/components/AreaChart/components/AreaChart.Stacked.jsx +1 -2
- package/src/components/Axis/Categorical.Axis.tsx +6 -7
- package/src/components/BarChart/components/BarChart.Horizontal.tsx +178 -24
- package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +3 -1
- package/src/components/BarChart/components/BarChart.StackedVertical.tsx +1 -0
- package/src/components/BarChart/components/BarChart.Vertical.tsx +6 -8
- package/src/components/BarChart/components/context.tsx +1 -0
- package/src/components/BarChart/helpers/useBarChart.ts +14 -2
- package/src/components/Brush/BrushSelector.tsx +1258 -0
- package/src/components/Brush/MiniChartPreview.tsx +283 -0
- package/src/components/DeviationBar.jsx +9 -7
- package/src/components/EditorPanel/EditorPanel.tsx +2711 -2586
- package/src/components/EditorPanel/components/Panels/Panel.ForestPlotSettings.tsx +56 -34
- package/src/components/EditorPanel/components/Panels/Panel.General.tsx +57 -30
- package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +2 -0
- package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.tsx +30 -25
- package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +21 -27
- package/src/components/EditorPanel/useEditorPermissions.ts +31 -18
- package/src/components/Legend/Legend.tsx +3 -2
- package/src/components/Legend/helpers/createFormatLabels.tsx +151 -2
- package/src/components/Legend/helpers/index.ts +10 -6
- package/src/components/LinearChart.tsx +495 -430
- package/src/components/PairedBarChart.jsx +20 -3
- package/src/components/Regions/components/Regions.tsx +365 -122
- package/src/components/ScatterPlot/ScatterPlot.jsx +2 -2
- package/src/components/SmallMultiples/SmallMultipleTile.tsx +5 -1
- package/src/components/WarmingStripes/WarmingStripes.tsx +160 -0
- package/src/components/WarmingStripes/WarmingStripesGradientLegend.css +35 -0
- package/src/components/WarmingStripes/WarmingStripesGradientLegend.tsx +104 -0
- package/src/components/WarmingStripes/index.tsx +3 -0
- package/src/data/initial-state.js +3 -1
- package/src/helpers/calculateHorizontalBarCategoryLabelWidth.ts +57 -0
- package/src/helpers/getMinMax.ts +12 -7
- package/src/helpers/sizeHelpers.ts +0 -20
- package/src/helpers/smallMultiplesHelpers.ts +1 -1
- package/src/hooks/useChartHoverAnalytics.tsx +10 -9
- package/src/hooks/useScales.ts +11 -1
- package/src/hooks/useTooltip.tsx +31 -10
- package/src/scss/DataTable.scss +0 -4
- package/src/scss/main.scss +17 -3
- package/src/test/CdcChart.test.jsx +1 -1
- package/src/types/ChartConfig.ts +3 -0
- package/src/types/Label.ts +1 -0
- package/src/utils/analyticsTracking.ts +19 -0
- package/LICENSE +0 -201
- package/src/components/Brush/BrushChart.tsx +0 -128
- package/src/components/Brush/BrushController.tsx +0 -71
- package/src/components/Brush/types.tsx +0 -8
- package/src/components/BrushChart.tsx +0 -223
|
@@ -37,6 +37,7 @@ import { filterChartColorPalettes } from '@cdc/core/helpers/filterColorPalettes'
|
|
|
37
37
|
|
|
38
38
|
import SparkLine from './components/Sparkline'
|
|
39
39
|
import Legend from './components/Legend'
|
|
40
|
+
import WarmingStripesGradientLegend from './components/WarmingStripes/WarmingStripesGradientLegend'
|
|
40
41
|
import defaults from './data/initial-state'
|
|
41
42
|
import EditorPanel from './components/EditorPanel'
|
|
42
43
|
import { abbreviateNumber } from './helpers/abbreviateNumber'
|
|
@@ -239,6 +240,14 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
239
240
|
|
|
240
241
|
const convertLineToBarGraph = isConvertLineToBarGraph(config, filteredData)
|
|
241
242
|
|
|
243
|
+
// Declaratively calculate series keys for pie charts based on filtered data
|
|
244
|
+
const pieSeriesKeys = useMemo(() => {
|
|
245
|
+
if (config.visualizationType !== 'Pie' || !config.xAxis?.dataKey) return null
|
|
246
|
+
const data = filteredData?.length > 0 ? filteredData : excludedData
|
|
247
|
+
if (!data) return null
|
|
248
|
+
return _.uniq(data.map(d => d[config.xAxis.dataKey]))
|
|
249
|
+
}, [config.visualizationType, config.xAxis?.dataKey, filteredData, excludedData])
|
|
250
|
+
|
|
242
251
|
const prepareConfig = (loadedConfig: ChartConfig) => {
|
|
243
252
|
// Create defaults without version to avoid overriding legacy configs
|
|
244
253
|
const defaultsWithoutPalette = { ...defaults }
|
|
@@ -375,6 +384,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
375
384
|
const pieData = currentData.length > 0 ? currentData : newExcludedData
|
|
376
385
|
newConfig.runtime.seriesKeys = _.uniq(pieData.map(d => d[newConfig.xAxis.dataKey]))
|
|
377
386
|
newConfig.runtime.seriesLabelsAll = newConfig.runtime.seriesKeys
|
|
387
|
+
newConfig.runtime.isPieChart = true // Flag to know when to use derived keys
|
|
378
388
|
} else {
|
|
379
389
|
const finalData = dataOverride || newConfig.formattedData || newConfig.data
|
|
380
390
|
newConfig.runtime.seriesKeys = (newConfig.runtime.series || []).flatMap(series => {
|
|
@@ -559,7 +569,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
559
569
|
for (let entry of entries) {
|
|
560
570
|
let { width, height } = entry.contentRect
|
|
561
571
|
|
|
562
|
-
const editorIsOpen = isEditor
|
|
572
|
+
const editorIsOpen = isEditor
|
|
563
573
|
width = editorIsOpen ? width - EDITOR_WIDTH : width
|
|
564
574
|
|
|
565
575
|
const newViewport = getViewport(width)
|
|
@@ -709,6 +719,19 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
709
719
|
}
|
|
710
720
|
}, [externalFilters]) // eslint-disable-line
|
|
711
721
|
|
|
722
|
+
// Declaratively update runtime series keys for pie charts when derived value changes
|
|
723
|
+
if (config.runtime?.isPieChart && pieSeriesKeys && !_.isEqual(pieSeriesKeys, config.runtime?.seriesKeys)) {
|
|
724
|
+
const newConfig = {
|
|
725
|
+
...config,
|
|
726
|
+
runtime: {
|
|
727
|
+
...config.runtime,
|
|
728
|
+
seriesKeys: pieSeriesKeys,
|
|
729
|
+
seriesLabelsAll: pieSeriesKeys
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
setConfig(newConfig)
|
|
733
|
+
}
|
|
734
|
+
|
|
712
735
|
// Generates color palette to pass to child chart component
|
|
713
736
|
useEffect(() => {
|
|
714
737
|
if (stateData && config.xAxis && config.runtime?.seriesKeys) {
|
|
@@ -819,15 +842,17 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
819
842
|
}
|
|
820
843
|
|
|
821
844
|
const formatDate = (date, i, ticks) => {
|
|
822
|
-
|
|
845
|
+
const displayFormat =
|
|
846
|
+
config.runtime[section].dateDisplayFormat || config.runtime[section].dateParseFormat || '%Y-%m-%d'
|
|
847
|
+
let formattedDate = timeFormat(displayFormat)(date)
|
|
823
848
|
// Handle the case where all months work with '%b.' except for May
|
|
824
|
-
if (
|
|
849
|
+
if (displayFormat?.includes('%b.') && formattedDate.includes('May.')) {
|
|
825
850
|
formattedDate = formattedDate.replace(/May\./g, 'May')
|
|
826
851
|
}
|
|
827
852
|
// Show years only once
|
|
828
|
-
if (config.xAxis.showYearsOnce &&
|
|
853
|
+
if (config.xAxis.showYearsOnce && displayFormat?.includes('%Y') && ticks) {
|
|
829
854
|
const prevDate = ticks[i - 1] ? ticks[i - 1].value : null
|
|
830
|
-
const prevFormattedDate = timeFormat(
|
|
855
|
+
const prevFormattedDate = timeFormat(displayFormat)(prevDate)
|
|
831
856
|
const year = formattedDate.match(/\d{4}/)
|
|
832
857
|
const prevYear = prevFormattedDate.match(/\d{4}/)
|
|
833
858
|
if (year && prevYear && year[0] === prevYear[0]) {
|
|
@@ -1125,8 +1150,6 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
1125
1150
|
const isLegendOnBottom = legend?.position === 'bottom' || isLegendWrapViewport(currentViewport)
|
|
1126
1151
|
|
|
1127
1152
|
if (config.isResponsiveTicks) classes.push('subtext--responsive-ticks ')
|
|
1128
|
-
if (config.xAxis.brushActive && !isLegendOnBottom) classes.push('subtext--brush-active ')
|
|
1129
|
-
if (config.xAxis.brushActive && config.legend.hide) classes.push('subtext--brush-active ')
|
|
1130
1153
|
return classes
|
|
1131
1154
|
}
|
|
1132
1155
|
|
|
@@ -1154,6 +1177,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
1154
1177
|
isDashboard={isDashboard}
|
|
1155
1178
|
title={title}
|
|
1156
1179
|
superTitle={processedSuperTitle}
|
|
1180
|
+
titleStyle={config.titleStyle}
|
|
1157
1181
|
classes={['chart-title', `${config.theme}`, 'cove-component__header', 'mb-3']}
|
|
1158
1182
|
style={undefined}
|
|
1159
1183
|
config={config}
|
|
@@ -1305,13 +1329,18 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
1305
1329
|
{/* Legend */}
|
|
1306
1330
|
{!config.legend.hide &&
|
|
1307
1331
|
config.visualizationType !== 'Spark Line' &&
|
|
1308
|
-
config.visualizationType !== 'Sankey' &&
|
|
1332
|
+
config.visualizationType !== 'Sankey' &&
|
|
1333
|
+
!(config.visualizationType === 'Warming Stripes' && config.legend?.style === 'gradient') &&
|
|
1334
|
+
!(config.visualizationType === 'Warming Stripes' && config.smallMultiples?.mode) && (
|
|
1309
1335
|
<Legend
|
|
1310
1336
|
ref={legendRef}
|
|
1311
1337
|
skipId={handleChartTabbing(config, legendId)}
|
|
1312
1338
|
interactionLabel={interactionLabel}
|
|
1313
1339
|
/>
|
|
1314
1340
|
)}
|
|
1341
|
+
{config.visualizationType === 'Warming Stripes' &&
|
|
1342
|
+
config.legend?.style === 'gradient' &&
|
|
1343
|
+
!config.smallMultiples?.mode && <WarmingStripesGradientLegend />}
|
|
1315
1344
|
</LegendWrapper>
|
|
1316
1345
|
{/* Link */}
|
|
1317
1346
|
{isDashboard && config.table && config.table.show && config.table.showDataTableLink
|
|
@@ -1323,79 +1352,86 @@ const CdcChart: React.FC<CdcChartProps> = ({
|
|
|
1323
1352
|
<div className={getChartSubTextClasses().join(' ')}>{parse(processedDescription)}</div>
|
|
1324
1353
|
)}
|
|
1325
1354
|
|
|
1326
|
-
{/* buttons */}
|
|
1327
|
-
<MediaControls.Section classes={['download-buttons']}>
|
|
1328
|
-
{config.table.showDownloadImgButton && (
|
|
1329
|
-
<MediaControls.Button
|
|
1330
|
-
text='Download Image'
|
|
1331
|
-
title='Download Chart as Image'
|
|
1332
|
-
type='image'
|
|
1333
|
-
state={config}
|
|
1334
|
-
elementToCapture={imageId}
|
|
1335
|
-
interactionLabel={interactionLabel}
|
|
1336
|
-
/>
|
|
1337
|
-
)}
|
|
1338
|
-
{config.table.showDownloadPdfButton && (
|
|
1339
|
-
<MediaControls.Button
|
|
1340
|
-
text='Download PDF'
|
|
1341
|
-
title='Download Chart as PDF'
|
|
1342
|
-
type='pdf'
|
|
1343
|
-
state={config}
|
|
1344
|
-
elementToCapture={imageId}
|
|
1345
|
-
interactionLabel={interactionLabel}
|
|
1346
|
-
/>
|
|
1347
|
-
)}
|
|
1348
|
-
</MediaControls.Section>
|
|
1349
1355
|
{/* Data Table */}
|
|
1350
|
-
{(
|
|
1356
|
+
{(config.xAxis.dataKey &&
|
|
1351
1357
|
config.table.show &&
|
|
1352
1358
|
config.visualizationType !== 'Spark Line' &&
|
|
1353
1359
|
config.visualizationType !== 'Sankey') ||
|
|
1354
|
-
|
|
1355
|
-
(() => {
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1360
|
+
(config.visualizationType === 'Sankey' && config.table.show)
|
|
1361
|
+
? (() => {
|
|
1362
|
+
let dataTableConfig = pivotDynamicSeries(config)
|
|
1363
|
+
let dataTableColumns = config.columns
|
|
1364
|
+
let dataTableRuntimeData = getTableRuntimeData()
|
|
1365
|
+
let dataTableRawData =
|
|
1366
|
+
config.visualizationType === 'Sankey'
|
|
1367
|
+
? config?.data?.[0]?.tableData
|
|
1368
|
+
: config.table.customTableConfig
|
|
1369
|
+
? filterVizData(config.filters, config.data)
|
|
1370
|
+
: config.data
|
|
1371
|
+
|
|
1372
|
+
if (config.smallMultiples?.mode) {
|
|
1373
|
+
const prepared = prepareSmallMultiplesDataTable(config, config.columns, dataTableRuntimeData)
|
|
1374
|
+
dataTableConfig = prepared.config
|
|
1375
|
+
dataTableColumns = prepared.columns
|
|
1376
|
+
dataTableRuntimeData = prepared.runtimeData
|
|
1377
|
+
if (config.smallMultiples.mode === 'by-column') {
|
|
1378
|
+
dataTableRawData = prepared.config.data
|
|
1379
|
+
}
|
|
1373
1380
|
}
|
|
1374
|
-
}
|
|
1375
1381
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1382
|
+
return (
|
|
1383
|
+
<DataTable
|
|
1384
|
+
/* changing the "key" will force the table to re-render
|
|
1385
|
+
when the default sort changes while editing */
|
|
1386
|
+
key={dataTableDefaultSortBy}
|
|
1387
|
+
config={dataTableConfig}
|
|
1388
|
+
rawData={dataTableRawData}
|
|
1389
|
+
runtimeData={dataTableRuntimeData}
|
|
1390
|
+
expandDataTable={config.table.expanded}
|
|
1391
|
+
columns={dataTableColumns}
|
|
1392
|
+
defaultSortBy={dataTableDefaultSortBy}
|
|
1393
|
+
displayGeoName={name => name}
|
|
1394
|
+
applyLegendToRow={applyLegendToRow}
|
|
1395
|
+
tableTitle={config.table.label}
|
|
1396
|
+
indexTitle={config.table.indexLabel}
|
|
1397
|
+
vizTitle={title}
|
|
1398
|
+
viewport={currentViewport}
|
|
1399
|
+
tabbingId={handleChartTabbing(config, legendId)}
|
|
1400
|
+
colorScale={colorScale}
|
|
1401
|
+
imageRef={imageId}
|
|
1402
|
+
showDownloadImgButton={config.table.showDownloadImgButton}
|
|
1403
|
+
showDownloadPdfButton={config.table.showDownloadPdfButton}
|
|
1404
|
+
includeContextInDownload={config.table?.includeContextInDownload}
|
|
1405
|
+
interactionLabel={interactionLabel}
|
|
1406
|
+
/>
|
|
1407
|
+
)
|
|
1408
|
+
})()
|
|
1409
|
+
: (config.table.showDownloadImgButton || config.table.showDownloadPdfButton) && (
|
|
1410
|
+
<div className='w-100 d-flex justify-content-end'>
|
|
1411
|
+
<MediaControls.Section classes={['download-links', 'mt-4', 'mb-2']}>
|
|
1412
|
+
{config.table.showDownloadImgButton && (
|
|
1413
|
+
<MediaControls.DownloadLink
|
|
1414
|
+
type='image'
|
|
1415
|
+
title='Download Chart as Image'
|
|
1416
|
+
state={config}
|
|
1417
|
+
elementToCapture={imageId}
|
|
1418
|
+
interactionLabel={interactionLabel}
|
|
1419
|
+
includeContextInDownload={config.table?.includeContextInDownload}
|
|
1420
|
+
/>
|
|
1421
|
+
)}
|
|
1422
|
+
{config.table.showDownloadPdfButton && (
|
|
1423
|
+
<MediaControls.DownloadLink
|
|
1424
|
+
type='pdf'
|
|
1425
|
+
title='Download Chart as PDF'
|
|
1426
|
+
state={config}
|
|
1427
|
+
elementToCapture={imageId}
|
|
1428
|
+
interactionLabel={interactionLabel}
|
|
1429
|
+
includeContextInDownload={config.table?.includeContextInDownload}
|
|
1430
|
+
/>
|
|
1431
|
+
)}
|
|
1432
|
+
</MediaControls.Section>
|
|
1433
|
+
</div>
|
|
1434
|
+
)}
|
|
1399
1435
|
{config?.annotations?.length > 0 && <Annotation.Dropdown />}
|
|
1400
1436
|
{/* show pdf or image button */}
|
|
1401
1437
|
{processedLegacyFootnotes && (
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import Chart from '../CdcChart'
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Chart> = {
|
|
5
|
+
title: 'Components/Templates/Chart/Regions/Categorical',
|
|
6
|
+
component: Chart
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type Story = StoryObj<typeof Chart>
|
|
10
|
+
|
|
11
|
+
const categoricalData = [
|
|
12
|
+
{ category: 'Jan 1', value: 10 },
|
|
13
|
+
{ category: 'Jan 8', value: 25 },
|
|
14
|
+
{ category: 'Jan 15', value: 35 },
|
|
15
|
+
{ category: 'Jan 22', value: 45 },
|
|
16
|
+
{ category: 'Jan 29', value: 55 },
|
|
17
|
+
{ category: 'Feb 5', value: 40 },
|
|
18
|
+
{ category: 'Feb 12', value: 60 },
|
|
19
|
+
{ category: 'Feb 19', value: 75 },
|
|
20
|
+
{ category: 'Feb 26', value: 65 },
|
|
21
|
+
{ category: 'Mar 4', value: 80 }
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
const baseCategoricalConfig = {
|
|
25
|
+
type: 'chart',
|
|
26
|
+
visualizationType: 'Line',
|
|
27
|
+
orientation: 'vertical',
|
|
28
|
+
showTitle: true,
|
|
29
|
+
theme: 'theme-blue',
|
|
30
|
+
animate: false,
|
|
31
|
+
xAxis: {
|
|
32
|
+
type: 'categorical',
|
|
33
|
+
dataKey: 'category',
|
|
34
|
+
size: '0',
|
|
35
|
+
hideAxis: false,
|
|
36
|
+
hideTicks: false
|
|
37
|
+
},
|
|
38
|
+
yAxis: {
|
|
39
|
+
size: '50',
|
|
40
|
+
hideAxis: false,
|
|
41
|
+
hideTicks: false,
|
|
42
|
+
gridLines: true,
|
|
43
|
+
min: '0',
|
|
44
|
+
max: '100'
|
|
45
|
+
},
|
|
46
|
+
series: [{ dataKey: 'value', type: 'Line', axis: 'Left', tooltip: true, name: 'Value' }],
|
|
47
|
+
legend: { hide: true },
|
|
48
|
+
data: categoricalData,
|
|
49
|
+
regions: []
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// LINE CHARTS
|
|
53
|
+
|
|
54
|
+
export const Line_Fixed_From_Fixed_To: Story = {
|
|
55
|
+
args: {
|
|
56
|
+
config: {
|
|
57
|
+
...baseCategoricalConfig,
|
|
58
|
+
title: 'Categorical - Line: Fixed From + Fixed To',
|
|
59
|
+
regions: [
|
|
60
|
+
{
|
|
61
|
+
from: 'Jan 15',
|
|
62
|
+
to: 'Feb 12',
|
|
63
|
+
fromType: 'Fixed',
|
|
64
|
+
toType: 'Fixed',
|
|
65
|
+
label: 'Fixed Region',
|
|
66
|
+
background: '#0077cc',
|
|
67
|
+
color: '#000000',
|
|
68
|
+
range: 'Custom'
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
isEditor: true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const Line_Fixed_From_Last_Date: Story = {
|
|
77
|
+
args: {
|
|
78
|
+
config: {
|
|
79
|
+
...baseCategoricalConfig,
|
|
80
|
+
title: 'Categorical - Line: Fixed From + Last Date',
|
|
81
|
+
regions: [
|
|
82
|
+
{
|
|
83
|
+
from: 'Feb 5',
|
|
84
|
+
to: '',
|
|
85
|
+
fromType: 'Fixed',
|
|
86
|
+
toType: 'Last Date',
|
|
87
|
+
label: 'To Last Date',
|
|
88
|
+
background: '#00aa55',
|
|
89
|
+
color: '#000000',
|
|
90
|
+
range: 'Custom'
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
isEditor: true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// BAR CHARTS
|
|
99
|
+
|
|
100
|
+
export const Bar_Fixed_From_Fixed_To: Story = {
|
|
101
|
+
args: {
|
|
102
|
+
config: {
|
|
103
|
+
...baseCategoricalConfig,
|
|
104
|
+
visualizationType: 'Bar',
|
|
105
|
+
barThickness: 0.7,
|
|
106
|
+
title: 'Categorical - Bar: Fixed From + Fixed To',
|
|
107
|
+
regions: [
|
|
108
|
+
{
|
|
109
|
+
from: 'Jan 15',
|
|
110
|
+
to: 'Feb 12',
|
|
111
|
+
fromType: 'Fixed',
|
|
112
|
+
toType: 'Fixed',
|
|
113
|
+
label: 'Fixed Region',
|
|
114
|
+
background: '#0077cc',
|
|
115
|
+
color: '#000000',
|
|
116
|
+
range: 'Custom'
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
isEditor: true
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const Bar_Fixed_From_Last_Date: Story = {
|
|
125
|
+
args: {
|
|
126
|
+
config: {
|
|
127
|
+
...baseCategoricalConfig,
|
|
128
|
+
visualizationType: 'Bar',
|
|
129
|
+
barThickness: 0.7,
|
|
130
|
+
title: 'Categorical - Bar: Fixed From + Last Date',
|
|
131
|
+
regions: [
|
|
132
|
+
{
|
|
133
|
+
from: 'Feb 5',
|
|
134
|
+
to: '',
|
|
135
|
+
fromType: 'Fixed',
|
|
136
|
+
toType: 'Last Date',
|
|
137
|
+
label: 'To Last Date',
|
|
138
|
+
background: '#00aa55',
|
|
139
|
+
color: '#000000',
|
|
140
|
+
range: 'Custom'
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
isEditor: true
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default meta
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import Chart from '../CdcChart'
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Chart> = {
|
|
5
|
+
title: 'Components/Templates/Chart/Regions/Date Scale (Band)',
|
|
6
|
+
component: Chart
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type Story = StoryObj<typeof Chart>
|
|
10
|
+
|
|
11
|
+
const dateData = [
|
|
12
|
+
{ date: '2024-01-01', value: 10 },
|
|
13
|
+
{ date: '2024-01-08', value: 25 },
|
|
14
|
+
{ date: '2024-01-15', value: 35 },
|
|
15
|
+
{ date: '2024-01-22', value: 45 },
|
|
16
|
+
{ date: '2024-01-29', value: 55 },
|
|
17
|
+
{ date: '2024-02-05', value: 40 },
|
|
18
|
+
{ date: '2024-02-12', value: 60 },
|
|
19
|
+
{ date: '2024-02-19', value: 75 },
|
|
20
|
+
{ date: '2024-02-26', value: 65 },
|
|
21
|
+
{ date: '2024-03-04', value: 80 }
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
const baseDateConfig = {
|
|
25
|
+
type: 'chart',
|
|
26
|
+
visualizationType: 'Line',
|
|
27
|
+
orientation: 'vertical',
|
|
28
|
+
showTitle: true,
|
|
29
|
+
theme: 'theme-blue',
|
|
30
|
+
animate: false,
|
|
31
|
+
xAxis: {
|
|
32
|
+
type: 'date',
|
|
33
|
+
dataKey: 'date',
|
|
34
|
+
dateParseFormat: '%Y-%m-%d',
|
|
35
|
+
dateDisplayFormat: '%b %-d',
|
|
36
|
+
size: '0',
|
|
37
|
+
hideAxis: false,
|
|
38
|
+
hideTicks: false,
|
|
39
|
+
numTicks: '6'
|
|
40
|
+
},
|
|
41
|
+
yAxis: {
|
|
42
|
+
size: '50',
|
|
43
|
+
hideAxis: false,
|
|
44
|
+
hideTicks: false,
|
|
45
|
+
gridLines: true,
|
|
46
|
+
min: '0',
|
|
47
|
+
max: '100'
|
|
48
|
+
},
|
|
49
|
+
series: [{ dataKey: 'value', type: 'Line', axis: 'Left', tooltip: true, name: 'Value' }],
|
|
50
|
+
legend: { hide: true },
|
|
51
|
+
data: dateData,
|
|
52
|
+
regions: []
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// LINE CHARTS
|
|
56
|
+
|
|
57
|
+
export const Line_Fixed_From_Fixed_To: Story = {
|
|
58
|
+
args: {
|
|
59
|
+
config: {
|
|
60
|
+
...baseDateConfig,
|
|
61
|
+
title: 'Date Scale - Line: Fixed From + Fixed To',
|
|
62
|
+
regions: [
|
|
63
|
+
{
|
|
64
|
+
from: '2024-01-15',
|
|
65
|
+
to: '2024-02-12',
|
|
66
|
+
fromType: 'Fixed',
|
|
67
|
+
toType: 'Fixed',
|
|
68
|
+
label: 'Fixed Region',
|
|
69
|
+
background: '#0077cc',
|
|
70
|
+
color: '#000000',
|
|
71
|
+
range: 'Custom'
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
isEditor: true
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const Line_Fixed_From_Last_Date: Story = {
|
|
80
|
+
args: {
|
|
81
|
+
config: {
|
|
82
|
+
...baseDateConfig,
|
|
83
|
+
title: 'Date Scale - Line: Fixed From + Last Date',
|
|
84
|
+
regions: [
|
|
85
|
+
{
|
|
86
|
+
from: '2024-02-05',
|
|
87
|
+
to: '',
|
|
88
|
+
fromType: 'Fixed',
|
|
89
|
+
toType: 'Last Date',
|
|
90
|
+
label: 'To Last Date',
|
|
91
|
+
background: '#00aa55',
|
|
92
|
+
color: '#000000',
|
|
93
|
+
range: 'Custom'
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
isEditor: true
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const Line_Previous_Days_Last_Date: Story = {
|
|
102
|
+
args: {
|
|
103
|
+
config: {
|
|
104
|
+
...baseDateConfig,
|
|
105
|
+
title: 'Date Scale - Line: Previous Days + Last Date',
|
|
106
|
+
regions: [
|
|
107
|
+
{
|
|
108
|
+
from: '28',
|
|
109
|
+
to: '',
|
|
110
|
+
fromType: 'Previous Days',
|
|
111
|
+
toType: 'Last Date',
|
|
112
|
+
label: 'Last 28 Days',
|
|
113
|
+
background: '#aa0077',
|
|
114
|
+
color: '#000000',
|
|
115
|
+
range: 'Custom'
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
isEditor: true
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// BAR CHARTS
|
|
124
|
+
|
|
125
|
+
export const Bar_Fixed_From_Fixed_To: Story = {
|
|
126
|
+
args: {
|
|
127
|
+
config: {
|
|
128
|
+
...baseDateConfig,
|
|
129
|
+
visualizationType: 'Bar',
|
|
130
|
+
barThickness: 0.7,
|
|
131
|
+
title: 'Date Scale - Bar: Fixed From + Fixed To',
|
|
132
|
+
regions: [
|
|
133
|
+
{
|
|
134
|
+
from: '2024-01-15',
|
|
135
|
+
to: '2024-02-12',
|
|
136
|
+
fromType: 'Fixed',
|
|
137
|
+
toType: 'Fixed',
|
|
138
|
+
label: 'Fixed Region',
|
|
139
|
+
background: '#0077cc',
|
|
140
|
+
color: '#000000',
|
|
141
|
+
range: 'Custom'
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
isEditor: true
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const Bar_Fixed_From_Last_Date: Story = {
|
|
150
|
+
args: {
|
|
151
|
+
config: {
|
|
152
|
+
...baseDateConfig,
|
|
153
|
+
visualizationType: 'Bar',
|
|
154
|
+
barThickness: 0.7,
|
|
155
|
+
title: 'Date Scale - Bar: Fixed From + Last Date',
|
|
156
|
+
regions: [
|
|
157
|
+
{
|
|
158
|
+
from: '2024-02-05',
|
|
159
|
+
to: '',
|
|
160
|
+
fromType: 'Fixed',
|
|
161
|
+
toType: 'Last Date',
|
|
162
|
+
label: 'To Last Date',
|
|
163
|
+
background: '#00aa55',
|
|
164
|
+
color: '#000000',
|
|
165
|
+
range: 'Custom'
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
isEditor: true
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export const Bar_Previous_Days_Last_Date: Story = {
|
|
174
|
+
args: {
|
|
175
|
+
config: {
|
|
176
|
+
...baseDateConfig,
|
|
177
|
+
visualizationType: 'Bar',
|
|
178
|
+
barThickness: 0.7,
|
|
179
|
+
title: 'Date Scale - Bar: Previous Days + Last Date',
|
|
180
|
+
regions: [
|
|
181
|
+
{
|
|
182
|
+
from: '28',
|
|
183
|
+
to: '',
|
|
184
|
+
fromType: 'Previous Days',
|
|
185
|
+
toType: 'Last Date',
|
|
186
|
+
label: 'Last 28 Days',
|
|
187
|
+
background: '#aa0077',
|
|
188
|
+
color: '#000000',
|
|
189
|
+
range: 'Custom'
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
},
|
|
193
|
+
isEditor: true
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export default meta
|