MCPcopy
hub / github.com/microsoft/SandDance / LegendView

Function LegendView

packages/vega-deck.gl/src/legend.tsx:12–58  ·  view source on GitHub ↗
(props: StatelessProps<LegendViewProps>)

Source from the content-addressed store, hash-verified

10}
11
12export const LegendView: StatelessComponent<LegendViewProps> = (props: StatelessProps<LegendViewProps>) => {
13 const rows: TableRow[] = [];
14
15 const addRow = (row: LegendRow, i: number) => {
16 const fn = symbolMap[row.symbol.shape];
17 let jsx: JSX.Element;
18 if (fn) {
19 jsx = fn(row.symbol);
20 } else {
21 jsx = <span>x</span>;
22 //console.log(`need to render ${row.symbol.shape} symbol shape`);
23 }
24 rows.push({
25 cells: [
26 { className: 'symbol', content: jsx },
27 { className: 'label', content: row.label, title: row.label },
28 ],
29 });
30 };
31
32 const sorted = Object.keys(props.legend.rows).sort((a, b) => +a - +b);
33 sorted.forEach(i => addRow(props.legend.rows[i], +i));
34
35 if (sorted.length) {
36 return (
37 <Table
38 rows={rows}
39 rowClassName="legend-row"
40 onRowClick={(e, i) => props.onClick(e, props.legend, i)}
41 >
42 {props.legend.title !== undefined && (
43 <tr
44 tabIndex={props.onClick ? 0 : -1}
45 onClick={e => props.onClick(e as any as MouseEvent, props.legend, null)}
46 onKeyUp={e => {
47 if (e.key === KeyCodes.ENTER && props.onClick) {
48 props.onClick(e as any as MouseEvent, props.legend, null);
49 }
50 }}
51 >
52 <th colSpan={2}>{props.legend.title}</th>
53 </tr>
54 )}
55 </Table>
56 );
57 }
58};
59
60const symbolMap: { [shape: string]: (symbol: LegendRowSymbol) => JSX.Element } = {
61

Callers 1

presentMethod · 0.90

Calls 3

addRowFunction · 0.70
forEachMethod · 0.45
onClickMethod · 0.45

Tested by

no test coverage detected