import React from 'react'; import { Checkbox } from '@material-ui/core'; import * as ColorMath from 'color-math'; // define legendItems props export interface LegendItemsProps { label: string; marker: string; markerColor?: string; hasData: boolean; group?: number; rank?: number; } export interface PlotListLegendProps { legendItems: LegendItemsProps[]; checkedLegendItems: string[] | undefined; onCheckedLegendItemsChange?: (checkedLegendItems: string[]) => void; // add a condition to show legend for single overlay data showOverlayLegend?: boolean; // define markerBodyOpaciy prop markerBodyOpacity?: number; } export default function PlotListLegend({ legendItems, checkedLegendItems, onCheckedLegendItemsChange, showOverlayLegend = false, markerBodyOpacity = 1, }: PlotListLegendProps) { // change checkbox state by click const handleLegendCheckboxClick = (checked: boolean, id: string) => { if (checkedLegendItems != null) { if (checked) { // for vizconfig.checkedLegendItems if (onCheckedLegendItemsChange != null) onCheckedLegendItemsChange([...checkedLegendItems, id]); } else { // for vizconfig.checkedLegendItems if (onCheckedLegendItemsChange != null) onCheckedLegendItemsChange( checkedLegendItems.filter((el: string) => el !== id) ); } } }; // set some default sizes const defaultMarkerSize = '0.8em'; const legendTextSize = '1.0em'; const circleMarkerSize = '0.7em'; const scatterMarkerSpace = '2em'; return ( <> {/* add a condition to show legend for single overlay data */} {(legendItems.length > 1 || showOverlayLegend) && (