Skip to content

Commit 525632a

Browse files
Merge pull request #183 from CivicDataLab/182-add-image-flow-in-dataset-creation
Update charts
2 parents b1227c9 + 294bab8 commit 525632a

File tree

5 files changed

+12213
-12
lines changed

5 files changed

+12213
-12
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { useRef } from 'react';
22
import Link from 'next/link';
33
import { useParams } from 'next/navigation';
4+
import assam_geojson from '@/geo_json/assam_geojson';
5+
import { renderGeoJSON } from '@/geo_json/render_geojson';
46
import { graphql } from '@/gql';
57
import { useQuery } from '@tanstack/react-query';
68
import ReactECharts from 'echarts-for-react';
@@ -19,7 +21,6 @@ import {
1921

2022
import { GraphQL } from '@/lib/api';
2123
import { Icons } from '@/components/icons';
22-
import assam_geojson from '@/geo_json/assam_geojson';
2324

2425
const charts = graphql(`
2526
query chartsData($datasetId: UUID!) {
@@ -60,9 +61,12 @@ const Details = () => {
6061
);
6162

6263
const renderChart = (item: any) => {
63-
if (item.chartType === 'ASSAM_DISTRICT') {
64+
if (item.chartType === 'ASSAM_DISTRICT' || item.chartType === 'ASSAM_RC') {
6465
// Register the map
65-
echarts.registerMap(item.chartType.toLowerCase(), assam_geojson);
66+
echarts.registerMap(
67+
item.chartType.toLowerCase(),
68+
renderGeoJSON(item.chartType.toLowerCase())
69+
);
6670
}
6771

6872
return <ReactECharts option={item.chart} ref={chartRef} />;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const deleteResourceChart: any = graphql(`
3939
}
4040
`);
4141

42+
43+
44+
45+
4246
const ChartsList: React.FC<ChartsListProps> = ({
4347
setType,
4448
type,
@@ -106,7 +110,7 @@ const ChartsList: React.FC<ChartsListProps> = ({
106110
return [
107111
{
108112
accessorKey: 'name',
109-
header: 'Name of Access Type',
113+
header: 'Name of Chart',
110114
cell: ({ row }: any) => (
111115
<div
112116
style={{ cursor: 'pointer', textDecoration: 'underline' }}
@@ -165,7 +169,7 @@ const ChartsList: React.FC<ChartsListProps> = ({
165169
) : (
166170
<>
167171
<div className=" my-6 flex flex-wrap items-center justify-between gap-3 px-3 py-4">
168-
<Text>Showing Access Types</Text>
172+
<Text>Showing Charts</Text>
169173
<SearchInput
170174
className="w-1/2 "
171175
placeholder="Search in charts"

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
22
import { useParams } from 'next/navigation';
3+
import { renderGeoJSON } from '@/geo_json/render_geojson';
34
import { graphql } from '@/gql';
45
import {
56
AggregateType,
@@ -24,7 +25,6 @@ import {
2425

2526
import { GraphQL } from '@/lib/api';
2627
import { Icons } from '@/components/icons';
27-
import assam_geojson from '../../../../../../../../../../geo_json/assam_geojson';
2828

2929
interface VisualizationProps {
3030
setType: any;
@@ -151,11 +151,15 @@ const ChartsVisualize: React.FC<VisualizationProps> = ({
151151
{
152152
[params.entityType]: params.entitySlug,
153153
},
154-
{ chartDetailsId: chartId }
154+
{
155+
chartDetailsId: chartId,
156+
157+
options: {
158+
skip: chartId === '',
159+
},
160+
}
155161
),
156-
{
157-
enabled: !!chartId, // Fetch only if chartId is available
158-
}
162+
{}
159163
);
160164
const {
161165
data: chartsList,
@@ -225,7 +229,15 @@ const ChartsVisualize: React.FC<VisualizationProps> = ({
225229
}, [chartId, chartDetails]);
226230

227231
const updateChartData = (resourceChart: any) => {
228-
echarts.registerMap(resourceChart.chartType.toLowerCase(), assam_geojson);
232+
if (
233+
resourceChart.chartType === 'ASSAM_DISTRICT' ||
234+
resourceChart.chartType === 'ASSAM_RC'
235+
) {
236+
echarts.registerMap(
237+
resourceChart.chartType.toLowerCase(),
238+
renderGeoJSON(resourceChart.chartType.toLowerCase())
239+
);
240+
}
229241
const updatedData = {
230242
aggregateType: resourceChart.aggregateType as AggregateType,
231243
chartType: resourceChart.chartType as ChartTypes,
@@ -417,7 +429,6 @@ const ChartsVisualize: React.FC<VisualizationProps> = ({
417429
options={[
418430
{ label: 'Bar Vertical', value: 'BAR_VERTICAL' },
419431
{ label: 'Bar Horizontal', value: 'BAR_HORIZONTAL' },
420-
{ label: 'Column', value: 'COLUMN' },
421432
{ label: 'Line', value: 'LINE' },
422433
{ label: 'Assam District', value: 'ASSAM_DISTRICT' },
423434
{ label: 'ASSAM RC', value: 'ASSAM_RC' },

0 commit comments

Comments
 (0)