Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.10 Release #246

Merged
merged 13 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixed bug coming from a race condition in record objects for bar/pie …
…charts (#233)
  • Loading branch information
nielsdejong authored Oct 13, 2022
commit 4011c9815eb85c4f3853e44cd97bd71ecdd37ac8
42 changes: 23 additions & 19 deletions src/chart/bar/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,32 @@ const NeoBarChart = (props: ChartProps) => {

const keys = {};
const data: Record<string, any>[] = records.reduce((data: Record<string, any>[], row: Record<string, any>) => {
if (!selection || !selection['index'] || !selection['value']) {
return data;
}
const index = convertRecordObjectToString(row.get(selection['index']));
const idx = data.findIndex(item => item.index === index)
try {
if (!selection || !selection['index'] || !selection['value']) {
return data;
}
const index = convertRecordObjectToString(row.get(selection['index']));
const idx = data.findIndex(item => item.index === index)

const key = selection['key'] !== "(none)" ? recordToNative(row.get(selection['key'])) : selection['value'];
const value = recordToNative(row.get(selection['value']));
const key = selection['key'] !== "(none)" ? recordToNative(row.get(selection['key'])) : selection['value'];
const value = recordToNative(row.get(selection['value']));

if (isNaN(value)) {
return data;
}
keys[key] = true;
if (isNaN(value)) {
return data;
}
keys[key] = true;

if (idx > -1) {
data[idx][key] = value
}
else {
data.push({ index, [key]: value })
if (idx > -1) {
data[idx][key] = value
}
else {
data.push({ index, [key]: value })
}
return data
} catch (e) {
console.error(e);
return [];
}

return data
}, [])
.map(row => {
Object.keys(keys).forEach(key => {
Expand Down Expand Up @@ -104,7 +108,7 @@ const NeoBarChart = (props: ChartProps) => {
}

// TODO: Get rid of duplicate pie slice names...

return <ResponsiveBar
layout={settings.layout == "horizontal" ? 'horizontal' : 'vertical'}
groupMode={groupMode == "stacked" ? 'stacked' : 'grouped'}
Expand Down
42 changes: 23 additions & 19 deletions src/chart/pie/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,33 @@ const NeoPieChart = (props: ChartProps) => {

const keys = {};
const data: Record<string, any>[] = records.reduce((data: Record<string, any>[], row: Record<string, any>) => {
if (!selection || !selection['index'] || !selection['value']) {
return data;
}
try {
if (!selection || !selection['index'] || !selection['value']) {
return data;
}

const index = convertRecordObjectToString(row.get(selection['index']));
const idx = data.findIndex(item => item.index === index)
const index = convertRecordObjectToString(row.get(selection['index']));
const idx = data.findIndex(item => item.index === index)
const key = selection['key'] !== "(none)" ? recordToNative(row.get(selection['key'])) : selection['value'];
const value = recordToNative(row.get(selection['value']));

const key = selection['key'] !== "(none)" ? recordToNative(row.get(selection['key'])) : selection['value'];
const value = recordToNative(row.get(selection['value']));
if (isNaN(value)) {
return data;
}
keys[key] = true;

if (isNaN(value)) {
return data;
}
keys[key] = true;
if (idx > -1) {
data[idx][key] = value
}
else {
data.push({ id: index, label: index, value: value })
}

if (idx > -1) {
data[idx][key] = value
}
else {
data.push({ id: index, label: index, value: value })
return data
} catch (e) {
console.error(e);
return [];
}

return data
}, [])
.map(row => {
Object.keys(keys).forEach(key => {
Expand Down Expand Up @@ -99,7 +103,7 @@ const NeoPieChart = (props: ChartProps) => {
if (data.length == 0) {
return <NoDrawableDataErrorMessage />
}

return <ResponsivePie
data={data}
sortByValue={sortByValue}
Expand Down