-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapChart.tsx
More file actions
89 lines (77 loc) · 2.73 KB
/
MapChart.tsx
File metadata and controls
89 lines (77 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { useEffect } from "react";
import * as am5 from "@amcharts/amcharts5";
import * as am5map from "@amcharts/amcharts5/map";
import am5geodata_worldLow from "@amcharts/amcharts5-geodata/worldLow";
import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
// import { useTheme } from "colbrush/client";
import GraphContainer from "./GraphContainer";
const MapChart = () => {
const rootStyle = getComputedStyle(document.documentElement);
const colors = {
red: rootStyle.getPropertyValue("--color-deep-red").trim(),
yellow: rootStyle.getPropertyValue("--color-yellow").trim(),
green: rootStyle.getPropertyValue("--color-green").trim(),
blue: rootStyle.getPropertyValue("--color-deep-blue").trim(),
purple: rootStyle.getPropertyValue("--color-purple").trim(),
};
// const theme = useTheme().theme;
useEffect(() => {
const root = am5.Root.new("mapdiv");
root._rootContainer.set(
"background",
am5.Rectangle.new(root, {
fill: am5.color(0xffffff),
fillOpacity: 1,
}),
);
root.setThemes([am5themes_Animated.new(root)]);
const chart = root.container.children.push(
am5map.MapChart.new(root, {
panX: "none",
panY: "none",
projection: am5map.geoMercator(),
wheelX: "none",
wheelY: "none",
}),
);
const polygonSeries = chart.series.push(
am5map.MapPolygonSeries.new(root, {
geoJSON: am5geodata_worldLow,
exclude: ["AQ"],
}),
);
polygonSeries.mapPolygons.template.setAll({
fill: am5.color(0xececec),
stroke: am5.color(0xececec),
strokeOpacity: 0,
});
polygonSeries.mapPolygons.template.adapters.add("fill", (fill, target) => {
const context = target.dataItem?.dataContext as { id?: string };
const id = context.id;
if (id === "US") return am5.color(colors.yellow);
if (id === "BR") return am5.color(colors.red);
if (id === "CD") return am5.color(colors.blue);
if (id === "SA") return am5.color(colors.green);
if (id === "CN") return am5.color(colors.purple);
return fill;
});
return () => {
root.dispose();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Colbrush 테스트용: theme 의존성 비활성화
// }, [theme]); // Colbrush 활성화: 이 줄의 주석을 해제하고 위 줄을 주석 처리
return (
<GraphContainer>
<p
className={`mb-4 text-start text-gray-100 max-lg:text-[14px] lg:text-[18px]`}
>
국가별 통계
</p>
<div className={`flex shrink-0 grow items-center justify-center`}>
<div id="mapdiv" className={`aspect-5/3 w-full`} />
</div>
</GraphContainer>
);
};
export default MapChart;