Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/dashboard/Data/Browser/GraphDialog.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export default class GraphDialog extends React.Component {
<div>
<TextInput
value={s.title || ''}
onChange={title => this.updateSeries(index, 'title', title)}
onChange={title => this.updateSeries(index, 'title', title.replace(/[()]/g, ''))}
placeholder="Auto-generated from fields"
/>
</div>
Expand Down Expand Up @@ -707,7 +707,7 @@ export default class GraphDialog extends React.Component {
<div>
<TextInput
value={calc.name}
onChange={name => this.updateCalculatedValue(index, 'name', name)}
onChange={name => this.updateCalculatedValue(index, 'name', name.replace(/[()]/g, ''))}
placeholder="Enter name"
/>
</div>
Expand Down
36 changes: 14 additions & 22 deletions src/lib/GraphDataUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,7 @@ export function processPieData(data, series, groupByColumn, calculatedValues = n

// Apply aggregation to each group
Object.keys(groups).forEach(groupKey => {
const labelKey = seriesArray.length > 1 || hasCalculatedValues
? `${seriesLabel} (${groupKey})`
: groupKey;
const labelKey = `${seriesLabel} (${groupKey})`;
aggregatedData[labelKey] = aggregateValues(groups[groupKey], s.aggregationType || 'count');
});
});
Expand Down Expand Up @@ -594,9 +592,7 @@ export function processPieData(data, series, groupByColumn, calculatedValues = n

// Aggregate each group
Object.keys(groups).forEach(groupKey => {
const labelKey = seriesArray.length > 0 || calculatedValues.length > 1
? `${calc.name} (${groupKey})`
: groupKey;
const labelKey = `${calc.name} (${groupKey})`;

// For percent operator, calculate (sum of numerators / sum of denominators) * 100
if (calc.operator === 'percent' && percentComponents[groupKey]) {
Expand Down Expand Up @@ -817,11 +813,7 @@ export function processBarLineData(data, xColumn, series, groupByColumn, calcula
let groupKeyValue = seriesLabel; // Use series label as default group
if (groupByColumn && (Array.isArray(groupByColumn) ? groupByColumn.length > 0 : true)) {
const compositeKey = createGroupKey(item, groupByColumn);
groupKeyValue = compositeKey;
// When groupBy is specified, combine with series label for unique series
if (seriesArray.length > 1 || hasCalculatedValues) {
groupKeyValue = `${seriesLabel} (${compositeKey})`;
}
groupKeyValue = `${seriesLabel} (${compositeKey})`;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const groupKey = groupKeyValue;

Expand Down Expand Up @@ -883,11 +875,7 @@ export function processBarLineData(data, xColumn, series, groupByColumn, calcula
let groupKeyValue = calc.name;
if (groupByColumn && (Array.isArray(groupByColumn) ? groupByColumn.length > 0 : true)) {
const compositeKey = createGroupKey(item, groupByColumn);
groupKeyValue = compositeKey;
// When groupBy is specified, combine with calc name for unique series
if (calculatedValues.length > 1 || seriesArray.length > 0) {
groupKeyValue = `${calc.name} (${compositeKey})`;
}
groupKeyValue = `${calc.name} (${compositeKey})`;
}
const groupKey = groupKeyValue;

Expand Down Expand Up @@ -983,9 +971,11 @@ export function processBarLineData(data, xColumn, series, groupByColumn, calcula
const seriesLabel = getSeriesLabel(s, idx);
// Map all possible variations of this series' group keys
groupKeys.forEach(groupKey => {
// Check if this groupKey is for this series
// It either matches exactly, or starts with "SeriesLabel ("
if (groupKey === seriesLabel || groupKey.startsWith(`${seriesLabel} (`)) {
// Check if this groupKey belongs to this series
// Series/calc names cannot contain parentheses, so startsWith is safe
const belongsToSeries = groupKey === seriesLabel || groupKey.startsWith(`${seriesLabel} (`);

if (belongsToSeries) {
seriesAggregationMap.set(groupKey, s.aggregationType || 'count');
if (s.chartType) {
seriesChartTypeMap.set(groupKey, s.chartType);
Expand Down Expand Up @@ -1023,9 +1013,11 @@ export function processBarLineData(data, xColumn, series, groupByColumn, calcula
if (calc.name && calc.operator) {
// Map all possible variations of this calculated value's group keys
groupKeys.forEach(groupKey => {
// Check if this groupKey is for this calculated value
// It either matches exactly, or starts with "CalcName ("
if (groupKey === calc.name || groupKey.startsWith(`${calc.name} (`)) {
// Check if this groupKey belongs to this calculated value
// Calc names cannot contain parentheses, so startsWith is safe
const belongsToCalc = groupKey === calc.name || groupKey.startsWith(`${calc.name} (`);

if (belongsToCalc) {
calcValueOperatorMap.set(groupKey, calc.operator);
if (calc.chartType) {
calcValueChartTypeMap.set(groupKey, calc.chartType);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/tests/GraphDataUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ describe('GraphDataUtils', () => {
];

it('should process pie data with grouping', () => {
const series = [{ fields: ['value'], aggregationType: 'sum' }];
const series = [{ fields: ['value'], aggregationType: 'sum', title: 'Value' }];
const result = processPieData(mockData, series, 'category');

expect(result).toHaveProperty('labels');
expect(result).toHaveProperty('datasets');
expect(result.labels).toContain('A');
expect(result.labels).toContain('B');
expect(result.labels).toContain('Value (A)');
expect(result.labels).toContain('Value (B)');
expect(result.datasets[0].data).toContain(30); // A: 10 + 20
expect(result.datasets[0].data).toContain(30); // B: 30
});
Expand Down Expand Up @@ -291,9 +291,9 @@ describe('GraphDataUtils', () => {
// Labels are category values ('A', 'B')
expect(result.datasets[0].data).toEqual([40, 50]);

// Verify labels match the categories from mockData
// Verify labels match the categories from mockData with calc name prefix
expect(result.labels).toHaveLength(2);
expect(result.labels).toEqual(['A', 'B']);
expect(result.labels).toEqual(['Profit (A)', 'Profit (B)']);
});
});

Expand Down
Loading