import React, { ReactElement, useState, useCallback } from 'react'; import { Story, Meta } from '@storybook/react/types-6-0'; // import { action } from '@storybook/addon-actions'; // import MapVEuMap from './MapVEuMap'; import { BoundsViewport, Bounds } from '../map/Types'; import { BoundsDriftMarkerProps } from '../map/BoundsDriftMarker'; import { defaultAnimationDuration } from '../map/config/map'; import { Viewport } from '../map/MapVEuMap'; //let's use new approach for data retrieval import { getSpeciesDonuts } from './api/getMarkersFromFixtureData'; // below was an attempt to lazy load... // it seemed to cause a 'black screen' error in Storybook if you refreshed the page in your browser // // let speciesData : any = undefined; // import('./test-data/geoclust-species-testing-all-levels.json').then((json) => speciesData = json); import { LeafletMouseEvent } from 'leaflet'; //load sidebar CSS import { Sidebar, Tab } from '../map/Sidebar'; //testing to separate a component for tab content import TabHomeContent from '../map/TabHomeContent'; //testing Pie Chart in sidebar import TabPieChartContent from '../map/TabPieChartContent'; //map import MapVEuMap, { MapVEuMapProps } from '../map/MapVEuMap'; //anim // import Geohash from 'latlon-geohash'; // import {DriftMarker} from "leaflet-drift-marker"; import geohashAnimation from '../map/animation_functions/geohash'; export default { title: 'Sidebar/Sidebar in map', component: Sidebar, subcomponents: { Tab }, }; const defaultAnimation = { method: 'geohash', animationFunction: geohashAnimation, duration: defaultAnimationDuration, }; //a generic function to remove a class: here it is used for removing highlight-marker function removeClassName(targetClass: string) { //much convenient to use jquery here but try not to use it let targetElement = document.getElementsByClassName(targetClass)[0]; if (targetElement != null) { targetElement.classList.remove(targetClass); } } //this onClick event may need to be changed in the future like onMouseOver event const handleMarkerClick = (e: LeafletMouseEvent) => { /** * this only works when selecting other marker: not working when clicking map * it may be achieved by setting all desirable events (e.g., map click, preserving highlight, etc.) * just stop here and leave detailed events to be handled later */ // use a resuable function to remove a class removeClassName('highlight-marker'); //native manner, but not React style? Either way this is arguably the simplest solution e.target._icon.classList.add('highlight-marker'); //here, perhaps we can add additional click event, like opening sidebar when clicking //console.log("I've been clicked") }; export const SidebarResize: Story = (args) => { //MapVeuMap stuff const [markerElements, setMarkerElements] = useState< ReactElement[] >([]); //make a no-op function instead of setLegendData as this story does not use legend // const [legendData, setLegendData] = useState([]); const noop = () => {}; const handleViewportChanged = useCallback( async (bvp: BoundsViewport) => { const markers = await getSpeciesDonuts( bvp, defaultAnimationDuration, noop, handleMarkerClick ); setMarkerElements(markers); }, [setMarkerElements] ); //Sidebar state managements (for categorical) const [sidebarCollapsed, setSidebarCollapsed] = useState(true); const [tabSelected, setTabSelected] = useState(''); //could be used to set default active tab, e.g., 'Home', but leave blank const [viewport] = useState({ center: [13, 16], zoom: 4 }); //this is X button/icon behavior considering sidebar resize const sidebarOnClose = () => { setSidebarCollapsed(true); //add this to fix a bug setTabSelected(''); //this works! let el: Element | null = document.getElementsByClassName( 'leaflet-sidebar-content' )[0] ? document.getElementsByClassName('leaflet-sidebar-content')[0] : null; // let el: any = document.getElementById("leaflet-sidebar-content")? document.getElementById("leaflet-sidebar-content"): ''; let tabStyle = el?.getAttributeNode('style'); if (tabStyle) { el?.removeAttributeNode(tabStyle); } }; //this is sidebar opening considering sidebar resize const sidebarOnOpen = (id: string) => { //removing style for re-resizable here may help for 1st click bug - yes let el: Element | null = document.getElementsByClassName( 'leaflet-sidebar-content' )[0] ? document.getElementsByClassName('leaflet-sidebar-content')[0] : null; // let el: any = document.getElementById("leaflet-sidebar-content")? document.getElementById("leaflet-sidebar-content"): ''; let tabStyle = el?.getAttributeNode('style'); if (tabStyle) { el?.removeAttributeNode(tabStyle); } //add a function to close drawer by clicking the same icon if (tabSelected != id) { setSidebarCollapsed(false); setTabSelected(id); } else { setSidebarCollapsed(true); //clear tabSelected so that the tab can be reopen setTabSelected(''); } }; //5 data // let pieChartData = [{color: "#FFB300", label: "Anopheles gambiae sensu stricto", value: 130},{color: "#803E75", label: "Anopheles coluzzii", value: 127},{color: "#C10020", label: "Anopheles gambiae sensu lato", value: 47},{color: "silver", label: "Anopheles funestus", value: 10},{color: "#FF7A5C", label: "Culex quinquefasciatus", value: 6}]; //test more data like 10 let pieChartData = { slices: [ { color: '#FFB300', label: 'Anopheles gambiae sensu stricto', value: 130, }, { color: '#803E75', label: 'Anopheles coluzzii', value: 127 }, { color: '#C10020', label: 'Anopheles gambiae sensu lato', value: 47 }, { color: 'silver', label: 'Anopheles funestus', value: 10 }, { color: '#FF7A5C', label: 'Culex quinquefasciatus', value: 6 }, { color: '#FFB300', label: 'Anopheles gambiae sensu stricto1', value: 130, }, { color: '#803E75', label: 'Anopheles coluzzii1', value: 127 }, { color: '#C10020', label: 'Anopheles gambiae sensu lato1', value: 47 }, { color: 'silver', label: 'Anopheles funestus1', value: 10 }, { color: '#FF7A5C', label: 'Culex quinquefasciatus1', value: 6 }, ], }; let testText = 'this is Home'; return ( <> {/* a test to separate tab contents into a component, TabHomeContent */} {/* testing disabled - greyish icon*/}

Change settings

{/* add disabled tap - no header & icon, use both diabled and divider */}

gap1

Detailed table???

Download data

{/* add disabled tap - no header & icon, use both diabled and divider */}

gap2

{/* a test to separate tab contents into a component, TabHomeContent */} {/* no box plot icon exists in fontawesome */}

Box plot

This is for chart

{/* placing bottom side using anchor="bottom" attribute */}

Help/Tutorial

); }; SidebarResize.args = { height: '100vh', width: '100vw', showGrid: true, showMouseToolbar: true, };