Skip to content

Commit b1227c9

Browse files
Merge pull request #181 from CivicDataLab/assam_map
Integrate district maps in charts
2 parents 0f595d8 + 3454d58 commit b1227c9

File tree

4 files changed

+202
-207
lines changed

4 files changed

+202
-207
lines changed

app/[locale]/(user)/datasets/[datasetIdentifier]/components/Details/index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22
import Link from 'next/link';
33
import { useParams } from 'next/navigation';
44
import { graphql } from '@/gql';
55
import { useQuery } from '@tanstack/react-query';
6+
import ReactECharts from 'echarts-for-react';
7+
import * as echarts from 'echarts/core';
68
import {
79
Button,
810
Carousel,
@@ -14,12 +16,12 @@ import {
1416
Spinner,
1517
Text,
1618
} from 'opub-ui';
17-
import { BarChart } from 'opub-ui/viz';
1819

1920
import { GraphQL } from '@/lib/api';
2021
import { Icons } from '@/components/icons';
22+
import assam_geojson from '@/geo_json/assam_geojson';
2123

22-
const charts: any = graphql(`
24+
const charts = graphql(`
2325
query chartsData($datasetId: UUID!) {
2426
chartsDetails(datasetId: $datasetId) {
2527
aggregateType
@@ -37,6 +39,7 @@ const charts: any = graphql(`
3739

3840
const Details = () => {
3941
const params = useParams();
42+
const chartRef = useRef<ReactECharts>(null);
4043

4144
const {
4245
data,
@@ -56,6 +59,15 @@ const Details = () => {
5659
)
5760
);
5861

62+
const renderChart = (item: any) => {
63+
if (item.chartType === 'ASSAM_DISTRICT') {
64+
// Register the map
65+
echarts.registerMap(item.chartType.toLowerCase(), assam_geojson);
66+
}
67+
68+
return <ReactECharts option={item.chart} ref={chartRef} />;
69+
};
70+
5971
return (
6072
<div className="mb-8 flex w-full flex-col gap-4 p-2">
6173
{isLoading ? (
@@ -75,7 +87,8 @@ const Details = () => {
7587
<CarouselItem key={index} className="m-auto">
7688
<div className="w-full border-2 border-solid border-baseGraySlateSolid4 bg-surfaceDefault p-6 text-center shadow-basicLg max-sm:p-2">
7789
<div className="lg:p-10">
78-
<BarChart options={item.chart} height={'450px'} />
90+
{renderChart(item)}{' '}
91+
{/* Call the renderChart function */}
7992
</div>
8093
<div className="flex items-center justify-between gap-2 max-sm:flex-wrap">
8194
<div className="flex flex-col gap-1 py-2 text-start">

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/charts/components/ChartsVisualize.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@/gql/generated/graphql';
99
import { useMutation, useQuery } from '@tanstack/react-query';
1010
import ReactECharts from 'echarts-for-react';
11+
import * as echarts from 'echarts/core';
1112
import {
1213
Button,
1314
Checkbox,
@@ -23,7 +24,7 @@ import {
2324

2425
import { GraphQL } from '@/lib/api';
2526
import { Icons } from '@/components/icons';
26-
import { vizdata } from './data';
27+
import assam_geojson from '../../../../../../../../../../geo_json/assam_geojson';
2728

2829
interface VisualizationProps {
2930
setType: any;
@@ -224,6 +225,7 @@ const ChartsVisualize: React.FC<VisualizationProps> = ({
224225
}, [chartId, chartDetails]);
225226

226227
const updateChartData = (resourceChart: any) => {
228+
echarts.registerMap(resourceChart.chartType.toLowerCase(), assam_geojson);
227229
const updatedData = {
228230
aggregateType: resourceChart.aggregateType as AggregateType,
229231
chartType: resourceChart.chartType as ChartTypes,
@@ -538,7 +540,7 @@ const ChartsVisualize: React.FC<VisualizationProps> = ({
538540
</div>
539541
<div className="mb-6 flex flex-col gap-6 p-8 text-center">
540542
<Text>Preview</Text>
541-
{Object.keys(chartData.chart).length > 0 && (
543+
{Object?.keys(chartData.chart).length > 0 && (
542544
<ReactECharts option={chartData.chart} ref={chartRef} />
543545
)}
544546
</div>

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/charts/components/data.tsx

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)