Skip to content

Commit

Permalink
fixes for EmptyRows/interactions/legends
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Oct 21, 2023
1 parent 053c419 commit b2d14d7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
29 changes: 17 additions & 12 deletions packages/desktop-client/src/components/reports/Custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default function Custom() {
end={end}
data={data}
split={split}
empty={empty}
OnChangeLegend={OnChangeLegend}
typeOp={typeOptions.find(opt => opt.value === type).format}
/>
Expand All @@ -210,6 +211,7 @@ export default function Custom() {
end={end}
data={data}
split={split}
empty={empty}
OnChangeLegend={OnChangeLegend}
typeOp={typeOptions.find(opt => opt.value === type).format}
/>
Expand Down Expand Up @@ -259,18 +261,21 @@ export default function Custom() {

function onChangeMode(cond) {
setMode(cond);
if (graphType === 'StackedBarGraph' && cond === 'total') {
setGraphType('BarGraph');
}
if (graphType === 'BarGraph' && cond === 'time') {
setGraphType('StackedBarGraph');
}
if (
cond === 'time' &&
(graphType === 'AreaGraph' || graphType === 'DonutGraph')
) {
setGraphType('TableGraph');
setViewSplit(false);
if (cond === 'time') {
if (graphType === 'BarGraph') {
setGraphType('StackedBarGraph');
}
if (['AreaGraph', 'DonutGraph'].includes(graphType)) {
setGraphType('TableGraph');
setViewSplit(false);
}
if ([5, 6].includes(split)) {
setSplit(1);
}
} else {
if (graphType === 'StackedBarGraph') {
setGraphType('BarGraph');
}
}
}

Expand Down
37 changes: 26 additions & 11 deletions packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type BarGraphProps = {
data;
split;
typeOp;
empty;
OnChangeLegend;
compact: boolean;
domain?: {
Expand All @@ -46,6 +47,7 @@ function BarGraph({
style,
data,
split,
empty,
typeOp,
OnChangeLegend,
compact,
Expand All @@ -63,6 +65,10 @@ function BarGraph({
totalTotals: number | string;
networth: number | string;
totalChange: number | string;
children: {
fill: string;
name: string;
};
};
};

Expand All @@ -79,14 +85,14 @@ function BarGraph({
};

const CustomLegend = ({ active, payload, label }: CustomLegendProps) => {
const agg = payload.map(leg => {
const agg = payload[0].payload.children.map(leg => {

Check failure on line 88 in packages/desktop-client/src/components/reports/graphs/BarGraph.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Property 'map' does not exist on type '{ fill: string; name: string; }'.
return {
name: leg.value,
//color: leg.color,
name: leg.props.name,
color: leg.props.fill,
};
});

OnChangeLegend(agg);
OnChangeLegend(agg.slice(0).reverse());

return <div />;
};
Expand Down Expand Up @@ -157,7 +163,13 @@ function BarGraph({
<BarChart
width={width}
height={height}
data={yAxis === 'date' ? data.monthData : data.data}
data={
yAxis === 'date'
? data.monthData.filter(i =>
empty ? i[typeOp] !== 0 : true,
)
: data.data.filter(i => (empty ? i[typeOp] !== 0 : true))
}
margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
>
<Legend content={<CustomLegend />} />
Expand All @@ -170,12 +182,15 @@ function BarGraph({
<XAxis dataKey={yAxis} />
<YAxis />
<Bar dataKey={...typeOp}>
{data.data.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={colorScale[index % colorScale.length]}
/>
))}
{data.data
.filter(i => (empty ? i[typeOp] !== 0 : true))
.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={colorScale[index % colorScale.length]}
name={entry.name}
/>
))}
</Bar>
</BarChart>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type DonutGraphProps = {
data;
split;
typeOp;
empty;
OnChangeLegend;
compact: boolean;
domain?: {
Expand All @@ -43,6 +44,7 @@ function DonutGraph({
style,
data,
split,
empty,
typeOp,
OnChangeLegend,
compact,
Expand Down Expand Up @@ -85,7 +87,7 @@ function DonutGraph({
};
});

OnChangeLegend(agg);
OnChangeLegend(agg.slice(0).reverse());

return <div />;
};
Expand Down Expand Up @@ -155,7 +157,13 @@ function DonutGraph({
dataKey={val => getVal(val)}
nameKey={yAxis}
isAnimationActive={false}
data={yAxis === 'date' ? data.monthData : data.data}
data={
yAxis === 'date'
? data.monthData.filter(i =>
empty ? i[typeOp] !== 0 : true,
)
: data.data.filter(i => (empty ? i[typeOp] !== 0 : true))
}
outerRadius={200}
innerRadius={100}
fill="#8884d8"
Expand Down

0 comments on commit b2d14d7

Please sign in to comment.