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

Fix Line chart axis labels #1046

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 19 additions & 2 deletions apps/climatemappedafrica/src/components/HURUmap/Chart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ChartTooltip, IndicatorTitle, Download, Share } from "@hurumap/core";
import { Source } from "@hurumap/next";
import { Box, useMediaQuery, useTheme } from "@mui/material";
import { debounce } from "lodash";
import React, { useState, useRef, useCallback, useEffect } from "react";
import * as vega from "vega";
import embed from "vega-embed";
Expand Down Expand Up @@ -67,9 +68,25 @@

const handler = useCallback(
(_, event, item, value) => {
setTooltipData({ item, value, id, geoCode, event });
const debouncedTooltip = debounce((e, i, v) => {
if (!v) {
setTooltipData(null);
return;
}
if (
!tooltipData ||
tooltipData.value?.group !== v?.group ||
tooltipData.event?.clientX !== e?.clientX ||
tooltipData.event?.clientY !== e?.clientY
) {
setTooltipData({ item: i, value: v, id, geoCode, event: e });
}
}, 50);

debouncedTooltip(event, item, value);
return () => debouncedTooltip.cancel();
},
[id, geoCode],
[id, geoCode, tooltipData],
);

useEffect(() => {
Expand All @@ -93,7 +110,7 @@

setView(newView.view);
} catch (error) {
console.error("Error rendering chart", error);

Check warning on line 113 in apps/climatemappedafrica/src/components/HURUmap/Chart/index.js

View workflow job for this annotation

GitHub Actions / Build and Test (20.16, ubuntu-latest)

Unexpected console statement
}
}
}
Expand All @@ -114,7 +131,7 @@
setDownloadView(viewProp);
}
} catch (error) {
console.error("Error creating view", error);

Check warning on line 134 in apps/climatemappedafrica/src/components/HURUmap/Chart/index.js

View workflow job for this annotation

GitHub Actions / Build and Test (20.16, ubuntu-latest)

Unexpected console statement
}
}, [cSpec]);

Expand Down
24 changes: 16 additions & 8 deletions packages/hurumap-core/src/Scope/LineChartScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ export default function LineChartScope({
y: { scale: "yscale", field: { signal: "datatype[Units]" } },
size: { value: 5 },
tooltip: {
signal:
"{'group': datum[mainGroup], 'count': format(datum.count, numberFormat.value)}",
signal: `{
'group': datum[mainGroup],
'count': isValid(datum.count) ? format(datum.count, numberFormat.value) : 'N/A'
}`,
},
},
hover: {
Expand Down Expand Up @@ -347,8 +349,10 @@ export default function LineChartScope({
y: { scale: "yscale", field: { signal: "datatype[Units]" } },
size: { value: 5 },
tooltip: {
signal:
"{'group': datum[mainGroup], 'count': format(datum.count, numberFormat.value)}",
signal: `{
'group': datum[mainGroup],
'count': isValid(datum.count) ? format(datum.count, numberFormat.value) : 'N/A'
}`,
},
},
hover: {
Expand Down Expand Up @@ -464,8 +468,10 @@ export default function LineChartScope({
update: {
size: { value: 5 },
tooltip: {
signal:
"{'group': datum[mainGroup], 'count': format(datum.count, numberFormat.value)}",
signal: `{
'group': datum[mainGroup],
'count': isValid(datum.count) ? format(datum.count, numberFormat.value) : 'N/A'
}`,
},
},
hover: {
Expand Down Expand Up @@ -567,8 +573,10 @@ export default function LineChartScope({
update: {
size: { value: 5 },
tooltip: {
signal:
"{'group': datum[mainGroup], 'count': format(datum.count, numberFormat.value)}",
signal: `{
'group': datum[mainGroup],
'count': isValid(datum.count) ? format(datum.count, numberFormat.value) : 'N/A'
}`,
},
},
hover: {
Expand Down
Loading