mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: use @grafana/ui legend (#17027)
This commit is contained in:
@@ -14,10 +14,10 @@ interface GraphLegendProps extends LegendProps {
|
||||
displayMode: LegendDisplayMode;
|
||||
sortBy?: string;
|
||||
sortDesc?: boolean;
|
||||
onSeriesColorChange: SeriesColorChangeHandler;
|
||||
onSeriesColorChange?: SeriesColorChangeHandler;
|
||||
onSeriesAxisToggle?: SeriesAxisToggleHandler;
|
||||
onToggleSort: (sortBy: string) => void;
|
||||
onLabelClick: (item: LegendItem, event: React.MouseEvent<HTMLElement>) => void;
|
||||
onToggleSort?: (sortBy: string) => void;
|
||||
onLabelClick?: (item: LegendItem, event: React.MouseEvent<HTMLElement>) => void;
|
||||
}
|
||||
|
||||
export const GraphLegend: React.FunctionComponent<GraphLegendProps> = ({
|
||||
@@ -116,3 +116,5 @@ export const GraphLegend: React.FunctionComponent<GraphLegendProps> = ({
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
GraphLegend.displayName = 'GraphLegend';
|
||||
|
||||
@@ -10,9 +10,9 @@ export interface GraphLegendItemProps {
|
||||
key?: React.Key;
|
||||
item: LegendItem;
|
||||
className?: string;
|
||||
onLabelClick: (item: LegendItem, event: React.MouseEvent<HTMLDivElement>) => void;
|
||||
onSeriesColorChange: SeriesColorChangeHandler;
|
||||
onToggleAxis: () => void;
|
||||
onLabelClick?: (item: LegendItem, event: React.MouseEvent<HTMLDivElement>) => void;
|
||||
onSeriesColorChange?: SeriesColorChangeHandler;
|
||||
onToggleAxis?: () => void;
|
||||
}
|
||||
|
||||
export const GraphLegendListItem: React.FunctionComponent<GraphLegendItemProps> = ({
|
||||
@@ -21,19 +21,31 @@ export const GraphLegendListItem: React.FunctionComponent<GraphLegendItemProps>
|
||||
onToggleAxis,
|
||||
onLabelClick,
|
||||
}) => {
|
||||
const theme = useContext(ThemeContext);
|
||||
|
||||
return (
|
||||
<>
|
||||
<LegendSeriesIcon
|
||||
disabled={!onSeriesColorChange}
|
||||
color={item.color}
|
||||
onColorChange={color => onSeriesColorChange(item.label, color)}
|
||||
onColorChange={color => {
|
||||
if (onSeriesColorChange) {
|
||||
onSeriesColorChange(item.label, color);
|
||||
}
|
||||
}}
|
||||
onToggleAxis={onToggleAxis}
|
||||
yAxis={item.yAxis}
|
||||
/>
|
||||
<div
|
||||
onClick={event => onLabelClick(item, event)}
|
||||
onClick={event => {
|
||||
if (onLabelClick) {
|
||||
onLabelClick(item, event);
|
||||
}
|
||||
}}
|
||||
className={css`
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
color: ${!item.isVisible && theme.colors.linkDisabled};
|
||||
`}
|
||||
>
|
||||
{item.label}
|
||||
@@ -74,13 +86,22 @@ export const GraphLegendTableRow: React.FunctionComponent<GraphLegendItemProps>
|
||||
`}
|
||||
>
|
||||
<LegendSeriesIcon
|
||||
disabled={!!onSeriesColorChange}
|
||||
color={item.color}
|
||||
onColorChange={color => onSeriesColorChange(item.label, color)}
|
||||
onColorChange={color => {
|
||||
if (onSeriesColorChange) {
|
||||
onSeriesColorChange(item.label, color);
|
||||
}
|
||||
}}
|
||||
onToggleAxis={onToggleAxis}
|
||||
yAxis={item.yAxis}
|
||||
/>
|
||||
<div
|
||||
onClick={event => onLabelClick(item, event)}
|
||||
onClick={event => {
|
||||
if (onLabelClick) {
|
||||
onLabelClick(item, event);
|
||||
}
|
||||
}}
|
||||
className={css`
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -28,7 +28,7 @@ export const LegendList: React.FunctionComponent<LegendComponentProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
const getItemKey = (item: LegendItem) => item.label;
|
||||
const getItemKey = (item: LegendItem) => `${item.label}`;
|
||||
|
||||
const styles = {
|
||||
wrapper: cx(
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import React from 'react';
|
||||
import { css, cx } from 'emotion';
|
||||
import { SeriesColorPicker } from '../ColorPicker/ColorPicker';
|
||||
import { SeriesIcon } from './SeriesIcon';
|
||||
import { SeriesIcon, SeriesIconProps } from './SeriesIcon';
|
||||
|
||||
interface LegendSeriesIconProps {
|
||||
disabled: boolean;
|
||||
color: string;
|
||||
yAxis: number;
|
||||
onColorChange: (color: string) => void;
|
||||
@@ -10,12 +12,36 @@ interface LegendSeriesIconProps {
|
||||
}
|
||||
|
||||
export const LegendSeriesIcon: React.FunctionComponent<LegendSeriesIconProps> = ({
|
||||
disabled,
|
||||
yAxis,
|
||||
color,
|
||||
onColorChange,
|
||||
onToggleAxis,
|
||||
}) => {
|
||||
return (
|
||||
let iconProps: SeriesIconProps = {
|
||||
color,
|
||||
};
|
||||
|
||||
if (!disabled) {
|
||||
iconProps = {
|
||||
...iconProps,
|
||||
className: 'pointer',
|
||||
};
|
||||
}
|
||||
|
||||
return disabled ? (
|
||||
<span
|
||||
className={cx(
|
||||
'graph-legend-icon',
|
||||
disabled &&
|
||||
css`
|
||||
cursor: default;
|
||||
`
|
||||
)}
|
||||
>
|
||||
<SeriesIcon {...iconProps} />
|
||||
</span>
|
||||
) : (
|
||||
<SeriesColorPicker
|
||||
yaxis={yAxis}
|
||||
color={color}
|
||||
@@ -25,7 +51,7 @@ export const LegendSeriesIcon: React.FunctionComponent<LegendSeriesIconProps> =
|
||||
>
|
||||
{({ ref, showColorPicker, hideColorPicker }) => (
|
||||
<span ref={ref} onClick={showColorPicker} onMouseLeave={hideColorPicker} className="graph-legend-icon">
|
||||
<SeriesIcon color={color} />
|
||||
<SeriesIcon {...iconProps} />
|
||||
</span>
|
||||
)}
|
||||
</SeriesColorPicker>
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import React from 'react';
|
||||
import { cx } from 'emotion';
|
||||
|
||||
export const SeriesIcon: React.FunctionComponent<{ color: string }> = ({ color }) => {
|
||||
return <i className="fa fa-minus pointer" style={{ color }} />;
|
||||
export interface SeriesIconProps {
|
||||
color: string;
|
||||
className?: string;
|
||||
}
|
||||
export const SeriesIcon: React.FunctionComponent<SeriesIconProps> = ({ color, className }) => {
|
||||
return <i className={cx('fa', 'fa-minus', className)} style={{ color }} />;
|
||||
};
|
||||
|
||||
@@ -45,10 +45,20 @@ export { TableInputCSV } from './Table/TableInputCSV';
|
||||
export { BigValue } from './BigValue/BigValue';
|
||||
export { Gauge } from './Gauge/Gauge';
|
||||
export { Graph } from './Graph/Graph';
|
||||
export { GraphLegend } from './Graph/GraphLegend';
|
||||
export { GraphWithLegend } from './Graph/GraphWithLegend';
|
||||
export { BarGauge } from './BarGauge/BarGauge';
|
||||
export { VizRepeater } from './VizRepeater/VizRepeater';
|
||||
export { LegendOptions, LegendBasicOptions, LegendRenderOptions, LegendList, LegendTable } from './Legend/Legend';
|
||||
export {
|
||||
LegendOptions,
|
||||
LegendBasicOptions,
|
||||
LegendRenderOptions,
|
||||
LegendList,
|
||||
LegendTable,
|
||||
LegendItem,
|
||||
LegendPlacement,
|
||||
LegendDisplayMode,
|
||||
} from './Legend/Legend';
|
||||
// Panel editors
|
||||
export { ThresholdsEditor } from './ThresholdsEditor/ThresholdsEditor';
|
||||
export { ClickOutsideWrapper } from './ClickOutsideWrapper/ClickOutsideWrapper';
|
||||
|
||||
Reference in New Issue
Block a user