Skip to content

Commit

Permalink
Merge pull request #820 from CodeForAfrica/feat/treemapchart_hurumap_…
Browse files Browse the repository at this point in the history
…package

@hurumap/TreemapChart
  • Loading branch information
m453h authored Aug 6, 2024
2 parents 4f19336 + f1cb325 commit 07435b0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 274 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Scope } from "@hurumap/core";

import MultiLineChartScope from "./MultiLineChartScope";
import StackedChartScope from "./StackedChartScope";
import TreemapChartScope from "./TreemapChartScope";
import VerticalBarChartScope from "./VerticalBarChartScope";
import VerticalStackedChartScope from "./VerticalStackedChartScope";

import { hurumapArgs } from "@/climatemappedafrica/config";
import theme from "@/climatemappedafrica/theme";

const { BarChartScope, LineChartScope, DonutChartScope } = Scope;
const { BarChartScope, LineChartScope, DonutChartScope, TreemapChartScope } =
Scope;

export default function configureScope(
indicator,
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function configureScope(
vegaSpec = DonutChartScope(scopeOptions);
break;
case "treemap":
vegaSpec = TreemapChartScope(..._scopeOptions);
vegaSpec = TreemapChartScope(scopeOptions);
break;
case "stacked":
if (isMobile) {
Expand Down
6 changes: 3 additions & 3 deletions apps/pesayetu/src/components/HURUmap/Chart/configureScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Scope } from "@hurumap/core";

import MultiLineChartScope from "./MultiLineChartScope";
import StackedChartScope from "./StackedChartScope";
import TreemapChartScope from "./TreemapChartScope";
import VerticalBarChartScope from "./VerticalBarChartScope";
import VerticalStackedChartScope from "./VerticalStackedChartScope";

import { hurumapArgs } from "@/pesayetu/config";
import theme from "@/pesayetu/theme";

const { BarChartScope, LineChartScope, DonutChartScope } = Scope;
const { BarChartScope, LineChartScope, DonutChartScope, TreemapChartScope } =
Scope;

export default function configureScope(
indicator,
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function configureScope(
vegaSpec = DonutChartScope(scopeOptions);
break;
case "treemap":
vegaSpec = TreemapChartScope(..._scopeOptions);
vegaSpec = TreemapChartScope(scopeOptions);
break;
case "stacked":
if (isMobile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import merge from "deepmerge";

import Scope from "./Scope";

import theme from "@/pesayetu/theme";

export default function TreemapChartScope(
export default function TreemapChartScope({
primaryData,
metadata,
config,
Expand All @@ -14,39 +12,44 @@ export default function TreemapChartScope(
profileNames,
isCompare,
isMobile,
) {
theme,
args,
}) {
const { primary_group: primaryGroup } = metadata;
const nestedFields = config?.nest_fields ?? [primaryGroup]; // if nest fields are undefined, make use primaryGroup
const transform = [
{
type: "nest",
keys: nestedFields,
},
{
type: "treemap",
field: { signal: "datatype[Units]" },
method: { signal: "layout" },
ratio: { signal: "aspectRatio" },
size: [
{
signal:
"isCompare && data('secondary').length > 1 && !isMobile ? width/2 -30: width",
},
{ signal: "isCompare && isMobile ? height/2 : height" },
],
},
];

return merge(
Scope(
Scope({
primaryData,
metadata,
config,
secondaryData,
primaryParentData,
secondaryParentData,
"treemap",
[
{
type: "nest",
keys: nestedFields,
},
{
type: "treemap",
field: { signal: "datatype[Units]" },
method: { signal: "layout" },
ratio: { signal: "aspectRatio" },
size: [
{
signal:
"isCompare && data('secondary').length > 1 && !isMobile ? width/2 -30: width",
},
{ signal: "isCompare && isMobile ? height/2 : height" },
],
},
],
),
chartType: "treemap",
transform,
theme,
args,
}),
{
height: isMobile && isCompare && secondaryData?.length > 1 ? 760 : 380,
signals: [
Expand Down
2 changes: 2 additions & 0 deletions packages/hurumap-core/src/Scope/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import BarChartScope from "./BarChartScope";
import DonutChartScope from "./DonutChartScope";
import LineChartScope from "./LineChartScope";
import Scope from "./Scope";
import TreemapChartScope from "./TreemapChartScope";

export default {
Scope,
BarChartScope,
LineChartScope,
DonutChartScope,
TreemapChartScope,
};

0 comments on commit 07435b0

Please sign in to comment.