Skip to content

Commit

Permalink
Donut Chart
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Aug 2, 2024
1 parent 887527f commit 59dbd22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export default function configureScope(

let vegaSpec;
const chartType = configuration?.chart_type?.toLowerCase();
const scopeOptions = [
/**
* @deprecated Use scopeOptions for implementing new charts
* This will be completely removed once all charts scopes
* are moved to Hurumap package
*/
// eslint-disable-next-line no-underscore-dangle
const _scopeOptions = [
indicator?.data,
indicator?.metadata,
configuration,
Expand All @@ -41,7 +47,7 @@ export default function configureScope(
isCompare,
isMobile,
];
const donutScopeOptions = {
const scopeOptions = {
primaryData: indicator?.data,
metadata: indicator?.metadata,
config: configuration,
Expand All @@ -57,16 +63,16 @@ export default function configureScope(
switch (chartType) {
case "line":
if (configuration?.stacked_field) {
vegaSpec = MultiLineChartScope(...scopeOptions);
vegaSpec = MultiLineChartScope(..._scopeOptions);
} else {
vegaSpec = LineChartScope(...scopeOptions);
vegaSpec = LineChartScope(..._scopeOptions);
}
break;
case "donut":
vegaSpec = DonutChartScope(donutScopeOptions);
vegaSpec = DonutChartScope(scopeOptions);
break;
case "treemap":
vegaSpec = TreemapChartScope(...scopeOptions);
vegaSpec = TreemapChartScope(..._scopeOptions);
break;
case "stacked":
if (isMobile) {
Expand Down Expand Up @@ -105,21 +111,7 @@ export default function configureScope(
isCompare,
);
} else {
const barChartArgs = {
primaryData: indicator?.data,
metadata: indicator?.metadata,
config: configuration,
secondaryData: secondaryIndicator?.data ?? null,
primaryParentData: showParent ? indicator?.parentData : [{}],
secondaryParentData: showParent
? secondaryIndicator?.parentData
: [{}],
profileNames,
isCompare,
theme,
args: hurumapArgs,
};
vegaSpec = BarChartScope(barChartArgs);
vegaSpec = BarChartScope(scopeOptions);
}
break;
}
Expand Down
34 changes: 13 additions & 21 deletions apps/pesayetu/src/components/HURUmap/Chart/configureScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export default function configureScope(

let vegaSpec;
const chartType = configuration?.chart_type?.toLowerCase();
const scopeOptions = [
/**
* @deprecated Use scopeOptions for implementing new charts
* This will be completely removed once all charts scopes
* are moved to Hurumap package
*/
// eslint-disable-next-line no-underscore-dangle
const _scopeOptions = [
indicator?.data,
indicator?.metadata,
configuration,
Expand All @@ -41,7 +47,7 @@ export default function configureScope(
isCompare,
isMobile,
];
const donutScopeOptions = {
const scopeOptions = {
primaryData: indicator?.data,
metadata: indicator?.metadata,
config: configuration,
Expand All @@ -57,16 +63,16 @@ export default function configureScope(
switch (chartType) {
case "line":
if (configuration?.stacked_field) {
vegaSpec = MultiLineChartScope(...scopeOptions);
vegaSpec = MultiLineChartScope(..._scopeOptions);
} else {
vegaSpec = LineChartScope(...scopeOptions);
vegaSpec = LineChartScope(..._scopeOptions);
}
break;
case "donut":
vegaSpec = DonutChartScope(donutScopeOptions);
vegaSpec = DonutChartScope(scopeOptions);
break;
case "treemap":
vegaSpec = TreemapChartScope(...scopeOptions);
vegaSpec = TreemapChartScope(..._scopeOptions);
break;
case "stacked":
if (isMobile) {
Expand Down Expand Up @@ -105,21 +111,7 @@ export default function configureScope(
isCompare,
);
} else {
const barChartArgs = {
primaryData: indicator?.data,
metadata: indicator?.metadata,
config: configuration,
secondaryData: secondaryIndicator?.data ?? null,
primaryParentData: showParent ? indicator?.parentData : [{}],
secondaryParentData: showParent
? secondaryIndicator?.parentData
: [{}],
profileNames,
isCompare,
theme,
args: hurumapArgs,
};
vegaSpec = BarChartScope(barChartArgs);
vegaSpec = BarChartScope(scopeOptions);
}
break;
}
Expand Down

0 comments on commit 59dbd22

Please sign in to comment.