// sample legend import React from 'react'; // use react-html-parser import ReactHtmlParser from 'react-html-parser'; // define prototype truncate function import './custom.d.ts'; // type def for legend: some are set to optional for now //perhaps this goes to Types.ts to avoid duplicate and legendProps can be an extension interface legendListProps { // className: string data: { label: string; // categorical e.g. "Anopheles gambiae" // numeric e.g. "10-20" value: number; color: string; }[]; // add this legendType: string; // used for legend info text, e.g., Collections legendInfoNumberText?: string; } // truncate any string longer than *max* and append *add* at the end (three ellipses by default) // to avoid type error on this custom function, truncate, it needs to be defined at custom.d.ts String.prototype.truncate = function (max: number, add: string) { add = add || '...'; return this.length > max ? this.substring(0, max) + add : this; }; // add commas function numberWithCommas(x: number) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); } export default function LegendListSquare(props: legendListProps) { let labels = []; let maxList: number = 10; // maximum number of list = 10 // add a class to handle circle or square in the list let legendIconClass = ''; if (props.legendType === 'numeric') { legendIconClass = ' legend-square-icon'; } // check if number of data is larger than maxList if (props.data.length <= maxList) { maxList = props.data.length; } //DKDDK # text from props.legendInfoNumberText labels.push( '