diff --git a/examples/district/app/[locale]/[district]/[department]/[scheme]/components/BarView.tsx b/examples/district/app/[locale]/[district]/[department]/[scheme]/components/BarView.tsx new file mode 100644 index 00000000..8c798a57 --- /dev/null +++ b/examples/district/app/[locale]/[district]/[department]/[scheme]/components/BarView.tsx @@ -0,0 +1,10 @@ +import { BarChart } from 'opub-viz/src'; +import React from 'react'; + +export const BarView = React.forwardRef(({ data }: { data: any }, ref: any) => { + return ( +
+ +
+ ); +}); diff --git a/examples/district/app/[locale]/[district]/[department]/[scheme]/components/Explorer.tsx b/examples/district/app/[locale]/[district]/[department]/[scheme]/components/Explorer.tsx index 51572a4c..93c6e7d1 100644 --- a/examples/district/app/[locale]/[district]/[department]/[scheme]/components/Explorer.tsx +++ b/examples/district/app/[locale]/[district]/[department]/[scheme]/components/Explorer.tsx @@ -2,88 +2,134 @@ import { Indicators } from './Indicators'; import { IChartData } from './scheme-layout'; import { ckan } from '@/config/site'; import { useFetch } from '@/lib/api'; -import { cn } from '@/lib/utils'; -import { Select, Tab, TabList, TabPanel, Tabs, Text } from 'opub-ui'; -import { BarChart, MapChart } from 'opub-viz'; +import { cn, copyURLToClipboard, exportAsImage } from '@/lib/utils'; +import { + Button, + Combobox, + ComboboxMulti, + Select, + Tab, + TabList, + TabPanel, + Tabs, + Text, + useToast, +} from 'opub-ui'; import React from 'react'; import { ErrorBoundary } from 'react-error-boundary'; +import { useQueryState } from 'next-usequerystate'; +import dynamic from 'next/dynamic'; +import { BarView } from './BarView'; -export const Explorer = ({ - scheme, - chartData, - district, -}: { - scheme?: string; - chartData: IChartData; - district: string; -}) => { - const years = Object.values(chartData)[0].years; - const [selectedYear, setYear] = React.useState(Object.keys(years)[0]); - const [selectedIndicator, setIndicator] = React.useState('cpapr'); - const [selectedTab, setTab] = React.useState<'map' | 'bar'>('bar'); - - const { data: indicatorData, isLoading } = useFetch( - 'indicators', - ckan.indicators - ); - const indicatorRef = React.useRef(null); +const LeafletChoropleth = dynamic( + () => import('opub-viz').then((mod) => mod.LeafletChoropleth), + { ssr: false } +); +export const Explorer = React.forwardRef( + ( + { + scheme, + chartData, + district, + }: { + scheme?: string; + chartData: IChartData; + district: string; + }, + ref: any + ) => { + const years = Object.values(chartData)[0].years; + const [selectedYear, setYear] = React.useState(Object.keys(years)[0]); + const [selectedTab, setTab] = React.useState<'map' | 'bar'>('bar'); + const [indicator, setIndicator] = useQueryState('indicator'); - React.useEffect(() => { - if (indicatorData) { - const initialSlug = - indicatorData[scheme as string]['District Performance'][0].slug; - setIndicator(initialSlug); - } - }, [indicatorData]); + const { data: indicatorData, isLoading } = useFetch( + 'indicators', + ckan.indicators + ); + const indicatorRef = React.useRef(null); - return ( -
- {isLoading ? ( -
- Loading... -
- ) : indicatorData ? ( - - ) : ( -
- No indicators available -
- )} + React.useEffect(() => { + if (indicatorData || indicator) { + const initialSlug = + indicator || + indicatorData[scheme as string]['District Performance'][0].slug; + setIndicator(initialSlug); + } + }, [indicatorData, indicator]); -
- - Error loading Explorer - - } - > - +
+ {isLoading ? ( +
+ Loading... +
+ ) : indicatorData ? ( + + ) : ( +
+ No indicators available +
+ )} +
+ {/*
+ ({ - label: year, - value: year, - }) - )} - /> -
+ {tabs.map((tab) => ( -
{tab.content}
+
+ {tab.content} +
))}
+
+ + +
+
+ ); +}; + +const Filters = ({ + states, + chartData, + barOptions, + setSelectedBlocks, + tab, + selectedBlocks, +}: { + states: any; + chartData: IChartData; + barOptions: any; + setSelectedBlocks: any; + tab: 'map' | 'bar'; + selectedBlocks: string[]; +}) => { + const options = Object.keys(Object.values(chartData)[0].years).map( + (year) => ({ + label: year, + value: year, + }) + ); + + return ( +
+ {tab === 'bar' && ( + { + setSelectedBlocks(values); + }} + verticalContent + /> + )} + +
+