diff --git a/packages/grafana-ui/src/components/VizLegend/SeriesIcon.tsx b/packages/grafana-ui/src/components/VizLegend/SeriesIcon.tsx index c658fe0f072..981bad51eb6 100644 --- a/packages/grafana-ui/src/components/VizLegend/SeriesIcon.tsx +++ b/packages/grafana-ui/src/components/VizLegend/SeriesIcon.tsx @@ -1,19 +1,21 @@ import { css, cx } from '@emotion/css'; import React, { CSSProperties } from 'react'; -import { fieldColorModeRegistry } from '@grafana/data'; +import { GrafanaTheme2, fieldColorModeRegistry } from '@grafana/data'; +import { LineStyle } from '@grafana/schema'; import { useTheme2, useStyles2 } from '../../themes'; export interface Props extends React.HTMLAttributes { color?: string; gradient?: string; + lineStyle?: LineStyle; } export const SeriesIcon = React.memo( - React.forwardRef(({ color, className, gradient, ...restProps }, ref) => { + React.forwardRef(({ color, className, gradient, lineStyle, ...restProps }, ref) => { const theme = useTheme2(); - const styles2 = useStyles2(getStyles); + const styles = useStyles2(getStyles); let cssColor: string; @@ -29,28 +31,48 @@ export const SeriesIcon = React.memo( cssColor = color!; } - const styles: CSSProperties = { - background: cssColor, - width: '14px', - height: '4px', - borderRadius: theme.shape.radius.pill, - display: 'inline-block', - marginRight: '8px', - }; + let customStyle: CSSProperties; + + if (lineStyle?.fill === 'dot' && !gradient) { + // make a circle bg image and repeat it + customStyle = { + backgroundImage: `radial-gradient(circle at 2px 2px, ${color} 2px, transparent 0)`, + backgroundSize: '4px 4px', + backgroundRepeat: 'space', + }; + } else if (lineStyle?.fill === 'dash' && !gradient) { + // make a rectangle bg image and repeat it + customStyle = { + backgroundImage: `linear-gradient(to right, ${color} 100%, transparent 0%)`, + backgroundSize: '6px 4px', + backgroundRepeat: 'space', + }; + } else { + customStyle = { + background: cssColor, + borderRadius: theme.shape.radius.pill, + }; + } return (
); }) ); -const getStyles = () => ({ +const getStyles = (theme: GrafanaTheme2) => ({ + container: css({ + marginRight: '8px', + display: 'inline-block', + width: '14px', + height: '4px', + }), forcedColors: css({ '@media (forced-colors: active)': { forcedColorAdjust: 'none', diff --git a/packages/grafana-ui/src/components/VizLegend/VizLegendListItem.tsx b/packages/grafana-ui/src/components/VizLegend/VizLegendListItem.tsx index 5a43727e728..f19b2d61d8f 100644 --- a/packages/grafana-ui/src/components/VizLegend/VizLegendListItem.tsx +++ b/packages/grafana-ui/src/components/VizLegend/VizLegendListItem.tsx @@ -75,6 +75,7 @@ export const VizLegendListItem = ({ color={item.color} gradient={item.gradient} readonly={readonly} + lineStyle={item.lineStyle} />