mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import React, { MouseEvent, memo } from 'react';
|
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
import { stylesFactory, useTheme } from '@grafana/ui';
|
|
|
|
import { NodesMarker } from './types';
|
|
|
|
const nodeR = 40;
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => ({
|
|
mainGroup: css`
|
|
cursor: pointer;
|
|
font-size: 10px;
|
|
`,
|
|
|
|
mainCircle: css`
|
|
fill: ${theme.colors.panelBg};
|
|
stroke: ${theme.colors.border3};
|
|
`,
|
|
text: css`
|
|
width: 50px;
|
|
height: 50px;
|
|
text-align: center;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
`,
|
|
}));
|
|
|
|
export const Marker = memo(function Marker(props: {
|
|
marker: NodesMarker;
|
|
onClick?: (event: MouseEvent<SVGElement>, marker: NodesMarker) => void;
|
|
}) {
|
|
const { marker, onClick } = props;
|
|
const { node } = marker;
|
|
const styles = getStyles(useTheme());
|
|
|
|
if (!(node.x !== undefined && node.y !== undefined)) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<g
|
|
data-node-id={node.id}
|
|
className={styles.mainGroup}
|
|
onClick={(event) => {
|
|
onClick?.(event, marker);
|
|
}}
|
|
aria-label={`Hidden nodes marker: ${node.id}`}
|
|
>
|
|
<circle className={styles.mainCircle} r={nodeR} cx={node.x} cy={node.y} />
|
|
<g>
|
|
<foreignObject x={node.x - 25} y={node.y - 25} width="50" height="50">
|
|
<div className={styles.text}>
|
|
{/* we limit the count to 101 so if we have more than 100 nodes we don't have exact count */}
|
|
<span>{marker.count > 100 ? '>100' : marker.count} nodes</span>
|
|
</div>
|
|
</foreignObject>
|
|
</g>
|
|
</g>
|
|
);
|
|
});
|