mirror of https://github.com/buster-so/buster.git
Merge pull request #1086 from buster-so/big-nate-bus-1893-combo-chart-with-negative-is-broken
Big nate bus 1893 combo chart with negative is broken
This commit is contained in:
commit
2fc6e11466
|
@ -47,20 +47,49 @@ export const useYAxis = ({
|
|||
gridLines: BusterChartProps['gridLines'];
|
||||
}): DeepPartial<ScaleChartOptions<'bar'>['scales']['y']> | undefined => {
|
||||
const yAxisKeys = selectedAxis.y;
|
||||
const hasY2Axis = (selectedAxis as ComboChartAxis)?.y2?.length > 0;
|
||||
const y2AxisKeys = (selectedAxis as ComboChartAxis)?.y2 || [];
|
||||
const hasY2Axis = y2AxisKeys.length > 0;
|
||||
|
||||
const useMinValue = useMemo(() => {
|
||||
if (!hasY2Axis) return false;
|
||||
if (selectedChartType !== 'combo') return false;
|
||||
if (!columnMetadata) return false;
|
||||
return columnMetadata?.some((column) => {
|
||||
return (
|
||||
yAxisKeys.includes(column.name) &&
|
||||
(columnSettings[column.name]?.columnVisualization ||
|
||||
DEFAULT_COLUMN_SETTINGS.columnVisualization) === 'bar'
|
||||
);
|
||||
});
|
||||
}, [hasY2Axis, yAxisKeys, selectedChartType]);
|
||||
|
||||
const checkVales = [...yAxisKeys, ...y2AxisKeys];
|
||||
|
||||
// Create lookup map for O(1) column access
|
||||
const columnMap = new Map(columnMetadata.map((col) => [col.name, col]));
|
||||
|
||||
let allBarValues = true;
|
||||
let hasNegativeValues = false;
|
||||
|
||||
// Single pass to check both conditions
|
||||
for (const key of checkVales) {
|
||||
const column = columnMap.get(key);
|
||||
if (!column) {
|
||||
allBarValues = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if this column is a bar
|
||||
const visualization =
|
||||
columnSettings[column.name]?.columnVisualization ||
|
||||
DEFAULT_COLUMN_SETTINGS.columnVisualization;
|
||||
if (visualization !== 'bar') {
|
||||
allBarValues = false;
|
||||
}
|
||||
|
||||
// Check if this column has negative values
|
||||
if (Number(column.min_value ?? 0) < 0) {
|
||||
hasNegativeValues = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (allBarValues) return true;
|
||||
if (hasNegativeValues) return false;
|
||||
|
||||
return false;
|
||||
}, [hasY2Axis, yAxisKeys, y2AxisKeys, selectedChartType, columnMetadata, columnSettings]);
|
||||
|
||||
const isSupportedType = useMemo(() => {
|
||||
return selectedChartType !== 'pie';
|
||||
|
|
|
@ -1271,3 +1271,208 @@ export const ComboChartWithNegativeNumbers: Story = {
|
|||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const ComboChartWithNegativeNumbers2: Story = {
|
||||
args: {
|
||||
selectedChartType: 'combo',
|
||||
gridLines: true,
|
||||
showLegend: true,
|
||||
colors: ['#4682B4', '#DC143C'],
|
||||
comboChartAxis: {
|
||||
x: ['region'],
|
||||
y: ['avg_individual_growth'],
|
||||
y2: ['avg_territory_growth'],
|
||||
tooltip: null,
|
||||
category: [],
|
||||
},
|
||||
columnLabelFormats: {
|
||||
region: {
|
||||
isUTC: false,
|
||||
style: 'string',
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
currency: 'USD',
|
||||
columnType: 'text',
|
||||
dateFormat: 'auto',
|
||||
multiplier: 1,
|
||||
displayName: '',
|
||||
compactNumbers: false,
|
||||
convertNumberTo: null,
|
||||
useRelativeTime: false,
|
||||
numberSeparatorStyle: null,
|
||||
maximumFractionDigits: 2,
|
||||
minimumFractionDigits: 0,
|
||||
makeLabelHumanReadable: true,
|
||||
replaceMissingDataWith: null,
|
||||
},
|
||||
salespeople_count: {
|
||||
isUTC: false,
|
||||
style: 'number',
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
currency: 'USD',
|
||||
columnType: 'number',
|
||||
dateFormat: 'auto',
|
||||
multiplier: 1,
|
||||
displayName: '',
|
||||
compactNumbers: false,
|
||||
convertNumberTo: null,
|
||||
useRelativeTime: false,
|
||||
numberSeparatorStyle: ',',
|
||||
maximumFractionDigits: 2,
|
||||
minimumFractionDigits: 0,
|
||||
makeLabelHumanReadable: true,
|
||||
replaceMissingDataWith: 0,
|
||||
},
|
||||
avg_individual_sales: {
|
||||
isUTC: false,
|
||||
style: 'currency',
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
currency: 'USD',
|
||||
columnType: 'number',
|
||||
dateFormat: 'auto',
|
||||
multiplier: 1,
|
||||
displayName: 'Avg Individual Sales',
|
||||
compactNumbers: true,
|
||||
convertNumberTo: null,
|
||||
useRelativeTime: false,
|
||||
numberSeparatorStyle: ',',
|
||||
maximumFractionDigits: 0,
|
||||
minimumFractionDigits: 0,
|
||||
makeLabelHumanReadable: true,
|
||||
replaceMissingDataWith: 0,
|
||||
},
|
||||
avg_territory_growth: {
|
||||
isUTC: false,
|
||||
style: 'percent',
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
currency: 'USD',
|
||||
columnType: 'number',
|
||||
dateFormat: 'auto',
|
||||
multiplier: 1,
|
||||
displayName: 'Avg Territory Growth',
|
||||
compactNumbers: false,
|
||||
convertNumberTo: null,
|
||||
useRelativeTime: false,
|
||||
numberSeparatorStyle: ',',
|
||||
maximumFractionDigits: 1,
|
||||
minimumFractionDigits: 1,
|
||||
makeLabelHumanReadable: true,
|
||||
replaceMissingDataWith: 0,
|
||||
},
|
||||
avg_individual_growth: {
|
||||
isUTC: false,
|
||||
style: 'percent',
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
currency: 'USD',
|
||||
columnType: 'number',
|
||||
dateFormat: 'auto',
|
||||
multiplier: 1,
|
||||
displayName: 'Avg Individual Growth',
|
||||
compactNumbers: false,
|
||||
convertNumberTo: null,
|
||||
useRelativeTime: false,
|
||||
numberSeparatorStyle: ',',
|
||||
maximumFractionDigits: 1,
|
||||
minimumFractionDigits: 1,
|
||||
makeLabelHumanReadable: true,
|
||||
replaceMissingDataWith: 0,
|
||||
},
|
||||
},
|
||||
columnSettings: {
|
||||
avg_territory_growth: {
|
||||
lineType: 'normal',
|
||||
lineStyle: 'line',
|
||||
lineWidth: 3,
|
||||
barRoundness: 8,
|
||||
lineSymbolSize: 0,
|
||||
showDataLabels: false,
|
||||
columnVisualization: 'line',
|
||||
showDataLabelsAsPercentage: false,
|
||||
},
|
||||
avg_individual_growth: {
|
||||
lineType: 'normal',
|
||||
lineStyle: 'line',
|
||||
lineWidth: 2,
|
||||
barRoundness: 8,
|
||||
lineSymbolSize: 0,
|
||||
showDataLabels: false,
|
||||
columnVisualization: 'bar',
|
||||
showDataLabelsAsPercentage: false,
|
||||
},
|
||||
},
|
||||
disableTooltip: false,
|
||||
yAxisScaleType: 'linear',
|
||||
y2AxisScaleType: 'linear',
|
||||
yAxisStartAxisAtZero: true,
|
||||
y2AxisStartAxisAtZero: true,
|
||||
columnMetadata: [
|
||||
{
|
||||
name: 'region',
|
||||
min_value: 'Europe',
|
||||
max_value: 'Pacific',
|
||||
unique_values: 3,
|
||||
simple_type: 'text',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'salespeople_count',
|
||||
min_value: 1,
|
||||
max_value: 10,
|
||||
unique_values: 3,
|
||||
simple_type: 'number',
|
||||
type: 'int8',
|
||||
},
|
||||
{
|
||||
name: 'avg_individual_sales',
|
||||
min_value: 1421810.9242,
|
||||
max_value: 3021851.4199,
|
||||
unique_values: 3,
|
||||
simple_type: 'number',
|
||||
type: 'numeric',
|
||||
},
|
||||
{
|
||||
name: 'avg_individual_growth',
|
||||
min_value: -37.60015965522074,
|
||||
max_value: 73.87138949847761,
|
||||
unique_values: 3,
|
||||
simple_type: 'number',
|
||||
type: 'numeric',
|
||||
},
|
||||
{
|
||||
name: 'avg_territory_growth',
|
||||
min_value: 57.40035218769629,
|
||||
max_value: 165.50373514146028,
|
||||
unique_values: 3,
|
||||
simple_type: 'number',
|
||||
type: 'numeric',
|
||||
},
|
||||
],
|
||||
data: [
|
||||
{
|
||||
region: 'Europe',
|
||||
salespeople_count: 3,
|
||||
avg_individual_sales: 3021851.4199,
|
||||
avg_individual_growth: 73.87138949847761,
|
||||
avg_territory_growth: 165.50373514146028,
|
||||
},
|
||||
{
|
||||
region: 'Pacific',
|
||||
salespeople_count: 1,
|
||||
avg_individual_sales: 1421810.9242,
|
||||
avg_individual_growth: -37.60015965522074,
|
||||
avg_territory_growth: 162.3518289124706,
|
||||
},
|
||||
{
|
||||
region: 'North America',
|
||||
salespeople_count: 10,
|
||||
avg_individual_sales: 2453809.87724,
|
||||
avg_individual_growth: 46.244973907779894,
|
||||
avg_territory_growth: 57.40035218769629,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue