Skip to content
Merged

Test #2539

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/storybook-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
env:
NODE_OPTIONS: --max-old-space-size=6144

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -48,3 +50,4 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action

24 changes: 23 additions & 1 deletion packages/chart/src/CdcChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ const CdcChart: React.FC<CdcChartProps> = ({

const convertLineToBarGraph = isConvertLineToBarGraph(config, filteredData)

// Declaratively calculate series keys for pie charts based on filtered data
const pieSeriesKeys = useMemo(() => {
if (config.visualizationType !== 'Pie' || !config.xAxis?.dataKey) return null
const data = filteredData?.length > 0 ? filteredData : excludedData
if (!data) return null
return _.uniq(data.map(d => d[config.xAxis.dataKey]))
}, [config.visualizationType, config.xAxis?.dataKey, filteredData, excludedData])

const prepareConfig = (loadedConfig: ChartConfig) => {
// Create defaults without version to avoid overriding legacy configs
const defaultsWithoutPalette = { ...defaults }
Expand Down Expand Up @@ -376,6 +384,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
const pieData = currentData.length > 0 ? currentData : newExcludedData
newConfig.runtime.seriesKeys = _.uniq(pieData.map(d => d[newConfig.xAxis.dataKey]))
newConfig.runtime.seriesLabelsAll = newConfig.runtime.seriesKeys
newConfig.runtime.isPieChart = true // Flag to know when to use derived keys
} else {
const finalData = dataOverride || newConfig.formattedData || newConfig.data
newConfig.runtime.seriesKeys = (newConfig.runtime.series || []).flatMap(series => {
Expand Down Expand Up @@ -710,6 +719,19 @@ const CdcChart: React.FC<CdcChartProps> = ({
}
}, [externalFilters]) // eslint-disable-line

// Declaratively update runtime series keys for pie charts when derived value changes
if (config.runtime?.isPieChart && pieSeriesKeys && !_.isEqual(pieSeriesKeys, config.runtime?.seriesKeys)) {
const newConfig = {
...config,
runtime: {
...config.runtime,
seriesKeys: pieSeriesKeys,
seriesLabelsAll: pieSeriesKeys
}
}
setConfig(newConfig)
}

// Generates color palette to pass to child chart component
useEffect(() => {
if (stateData && config.xAxis && config.runtime?.seriesKeys) {
Expand Down Expand Up @@ -1360,7 +1382,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
return (
<DataTable
/* changing the "key" will force the table to re-render
when the default sort changes while editing */
when the default sort changes while editing */
key={dataTableDefaultSortBy}
config={dataTableConfig}
rawData={dataTableRawData}
Expand Down
148 changes: 148 additions & 0 deletions packages/chart/src/_stories/Chart.Regions.Categorical.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import type { Meta, StoryObj } from '@storybook/react-vite'
import Chart from '../CdcChart'

const meta: Meta<typeof Chart> = {
title: 'Components/Templates/Chart/Regions/Categorical',
component: Chart
}

type Story = StoryObj<typeof Chart>

const categoricalData = [
{ category: 'Jan 1', value: 10 },
{ category: 'Jan 8', value: 25 },
{ category: 'Jan 15', value: 35 },
{ category: 'Jan 22', value: 45 },
{ category: 'Jan 29', value: 55 },
{ category: 'Feb 5', value: 40 },
{ category: 'Feb 12', value: 60 },
{ category: 'Feb 19', value: 75 },
{ category: 'Feb 26', value: 65 },
{ category: 'Mar 4', value: 80 }
]

const baseCategoricalConfig = {
type: 'chart',
visualizationType: 'Line',
orientation: 'vertical',
showTitle: true,
theme: 'theme-blue',
animate: false,
xAxis: {
type: 'categorical',
dataKey: 'category',
size: '0',
hideAxis: false,
hideTicks: false
},
yAxis: {
size: '50',
hideAxis: false,
hideTicks: false,
gridLines: true,
min: '0',
max: '100'
},
series: [{ dataKey: 'value', type: 'Line', axis: 'Left', tooltip: true, name: 'Value' }],
legend: { hide: true },
data: categoricalData,
regions: []
}

// LINE CHARTS

export const Line_Fixed_From_Fixed_To: Story = {
args: {
config: {
...baseCategoricalConfig,
title: 'Categorical - Line: Fixed From + Fixed To',
regions: [
{
from: 'Jan 15',
to: 'Feb 12',
fromType: 'Fixed',
toType: 'Fixed',
label: 'Fixed Region',
background: '#0077cc',
color: '#000000',
range: 'Custom'
}
]
},
isEditor: true
}
}

export const Line_Fixed_From_Last_Date: Story = {
args: {
config: {
...baseCategoricalConfig,
title: 'Categorical - Line: Fixed From + Last Date',
regions: [
{
from: 'Feb 5',
to: '',
fromType: 'Fixed',
toType: 'Last Date',
label: 'To Last Date',
background: '#00aa55',
color: '#000000',
range: 'Custom'
}
]
},
isEditor: true
}
}

// BAR CHARTS

export const Bar_Fixed_From_Fixed_To: Story = {
args: {
config: {
...baseCategoricalConfig,
visualizationType: 'Bar',
barThickness: 0.7,
title: 'Categorical - Bar: Fixed From + Fixed To',
regions: [
{
from: 'Jan 15',
to: 'Feb 12',
fromType: 'Fixed',
toType: 'Fixed',
label: 'Fixed Region',
background: '#0077cc',
color: '#000000',
range: 'Custom'
}
]
},
isEditor: true
}
}

export const Bar_Fixed_From_Last_Date: Story = {
args: {
config: {
...baseCategoricalConfig,
visualizationType: 'Bar',
barThickness: 0.7,
title: 'Categorical - Bar: Fixed From + Last Date',
regions: [
{
from: 'Feb 5',
to: '',
fromType: 'Fixed',
toType: 'Last Date',
label: 'To Last Date',
background: '#00aa55',
color: '#000000',
range: 'Custom'
}
]
},
isEditor: true
}
}

export default meta
Loading