Commit 2f92794c by Leon Sorokin Committed by GitHub

GraphNG: rename GraphMode to DrawStyle (#29623)

parent a36bd895
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
import { alignDataFrames } from './utils'; import { alignDataFrames } from './utils';
import { UPlotChart } from '../uPlot/Plot'; import { UPlotChart } from '../uPlot/Plot';
import { PlotProps } from '../uPlot/types'; import { PlotProps } from '../uPlot/types';
import { AxisPlacement, GraphFieldConfig, GraphMode, PointMode } from '../uPlot/config'; import { AxisPlacement, GraphFieldConfig, DrawStyle, PointMode } from '../uPlot/config';
import { useTheme } from '../../themes'; import { useTheme } from '../../themes';
import { VizLayout } from '../VizLayout/VizLayout'; import { VizLayout } from '../VizLayout/VizLayout';
import { LegendDisplayMode, LegendItem, LegendOptions } from '../Legend/Legend'; import { LegendDisplayMode, LegendItem, LegendOptions } from '../Legend/Legend';
...@@ -34,7 +34,7 @@ export interface GraphNGProps extends Omit<PlotProps, 'data' | 'config'> { ...@@ -34,7 +34,7 @@ export interface GraphNGProps extends Omit<PlotProps, 'data' | 'config'> {
} }
const defaultConfig: GraphFieldConfig = { const defaultConfig: GraphFieldConfig = {
mode: GraphMode.Line, drawStyle: DrawStyle.Line,
points: PointMode.Auto, points: PointMode.Auto,
axisPlacement: AxisPlacement.Auto, axisPlacement: AxisPlacement.Auto,
}; };
...@@ -134,11 +134,11 @@ export const GraphNG: React.FC<GraphNGProps> = ({ ...@@ -134,11 +134,11 @@ export const GraphNG: React.FC<GraphNGProps> = ({
const colorMode = getFieldColorModeForField(field); const colorMode = getFieldColorModeForField(field);
const seriesColor = colorMode.getCalculator(field, theme)(0, 0); const seriesColor = colorMode.getCalculator(field, theme)(0, 0);
const pointsMode = customConfig.mode === GraphMode.Points ? PointMode.Always : customConfig.points; const pointsMode = customConfig.drawStyle === DrawStyle.Points ? PointMode.Always : customConfig.points;
builder.addSeries({ builder.addSeries({
scaleKey, scaleKey,
mode: customConfig.mode!, drawStyle: customConfig.drawStyle!,
lineColor: seriesColor, lineColor: seriesColor,
lineWidth: customConfig.lineWidth, lineWidth: customConfig.lineWidth,
lineInterpolation: customConfig.lineInterpolation, lineInterpolation: customConfig.lineInterpolation,
......
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import { UPlotChart } from './Plot'; import { UPlotChart } from './Plot';
import { act, render } from '@testing-library/react'; import { act, render } from '@testing-library/react';
import { ArrayVector, dateTime, FieldConfig, FieldType, MutableDataFrame } from '@grafana/data'; import { ArrayVector, dateTime, FieldConfig, FieldType, MutableDataFrame } from '@grafana/data';
import { GraphFieldConfig, GraphMode } from '../uPlot/config'; import { GraphFieldConfig, DrawStyle } from '../uPlot/config';
import uPlot from 'uplot'; import uPlot from 'uplot';
import createMockRaf from 'mock-raf'; import createMockRaf from 'mock-raf';
import { UPlotConfigBuilder } from './config/UPlotConfigBuilder'; import { UPlotConfigBuilder } from './config/UPlotConfigBuilder';
...@@ -40,7 +40,7 @@ const mockData = () => { ...@@ -40,7 +40,7 @@ const mockData = () => {
values: new ArrayVector([10, 20, 5]), values: new ArrayVector([10, 20, 5]),
config: { config: {
custom: { custom: {
mode: GraphMode.Line, drawStyle: DrawStyle.Line,
}, },
} as FieldConfig<GraphFieldConfig>, } as FieldConfig<GraphFieldConfig>,
}); });
......
...@@ -15,7 +15,7 @@ export enum PointMode { ...@@ -15,7 +15,7 @@ export enum PointMode {
Always = 'always', Always = 'always',
} }
export enum GraphMode { export enum DrawStyle {
Line = 'line', // default Line = 'line', // default
Bars = 'bars', // will also have a gap percent Bars = 'bars', // will also have a gap percent
Points = 'points', // Only show points Points = 'points', // Only show points
...@@ -54,17 +54,16 @@ export interface AxisConfig { ...@@ -54,17 +54,16 @@ export interface AxisConfig {
} }
export interface GraphFieldConfig extends LineConfig, AreaConfig, PointsConfig, AxisConfig { export interface GraphFieldConfig extends LineConfig, AreaConfig, PointsConfig, AxisConfig {
mode?: GraphMode; drawStyle?: DrawStyle;
spanNulls?: boolean; spanNulls?: boolean;
} }
export const graphFieldOptions = { export const graphFieldOptions = {
mode: [ drawStyle: [
{ label: 'Lines', value: GraphMode.Line }, { label: 'Lines', value: DrawStyle.Line },
{ label: 'Bars', value: GraphMode.Bars }, { label: 'Bars', value: DrawStyle.Bars },
{ label: 'Points', value: GraphMode.Points }, { label: 'Points', value: DrawStyle.Points },
] as Array<SelectableValue<GraphMode>>, ] as Array<SelectableValue<DrawStyle>>,
lineInterpolation: [ lineInterpolation: [
{ label: 'Linear', value: LineInterpolation.Linear }, { label: 'Linear', value: LineInterpolation.Linear },
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import { UPlotConfigBuilder } from './UPlotConfigBuilder'; import { UPlotConfigBuilder } from './UPlotConfigBuilder';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
import { expect } from '../../../../../../public/test/lib/common'; import { expect } from '../../../../../../public/test/lib/common';
import { AxisPlacement, GraphMode, PointMode } from '../config'; import { AxisPlacement, DrawStyle, PointMode } from '../config';
describe('UPlotConfigBuilder', () => { describe('UPlotConfigBuilder', () => {
describe('scales config', () => { describe('scales config', () => {
...@@ -121,7 +121,7 @@ describe('UPlotConfigBuilder', () => { ...@@ -121,7 +121,7 @@ describe('UPlotConfigBuilder', () => {
it('allows series configuration', () => { it('allows series configuration', () => {
const builder = new UPlotConfigBuilder(); const builder = new UPlotConfigBuilder();
builder.addSeries({ builder.addSeries({
mode: GraphMode.Line, drawStyle: DrawStyle.Line,
scaleKey: 'scale-x', scaleKey: 'scale-x',
fillColor: '#ff0000', fillColor: '#ff0000',
fillOpacity: 0.5, fillOpacity: 0.5,
......
import tinycolor from 'tinycolor2'; import tinycolor from 'tinycolor2';
import uPlot, { Series } from 'uplot'; import uPlot, { Series } from 'uplot';
import { GraphMode, LineConfig, AreaConfig, PointsConfig, PointMode, LineInterpolation } from '../config'; import { DrawStyle, LineConfig, AreaConfig, PointsConfig, PointMode, LineInterpolation } from '../config';
import { barsBuilder, smoothBuilder, stepBeforeBuilder, stepAfterBuilder } from '../paths'; import { barsBuilder, smoothBuilder, stepBeforeBuilder, stepAfterBuilder } from '../paths';
import { PlotConfigBuilder } from '../types'; import { PlotConfigBuilder } from '../types';
export interface SeriesProps extends LineConfig, AreaConfig, PointsConfig { export interface SeriesProps extends LineConfig, AreaConfig, PointsConfig {
mode: GraphMode; drawStyle: DrawStyle;
scaleKey: string; scaleKey: string;
} }
export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> { export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> {
getConfig() { getConfig() {
const { const {
mode, drawStyle,
lineInterpolation, lineInterpolation,
lineColor, lineColor,
lineWidth, lineWidth,
...@@ -26,7 +26,7 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> { ...@@ -26,7 +26,7 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> {
let lineConfig: Partial<Series> = {}; let lineConfig: Partial<Series> = {};
if (mode === GraphMode.Points) { if (drawStyle === DrawStyle.Points) {
lineConfig.paths = () => null; lineConfig.paths = () => null;
} else { } else {
lineConfig.stroke = lineColor; lineConfig.stroke = lineColor;
...@@ -41,9 +41,9 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> { ...@@ -41,9 +41,9 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> {
) => { ) => {
let pathsBuilder = self.paths; let pathsBuilder = self.paths;
if (mode === GraphMode.Bars) { if (drawStyle === DrawStyle.Bars) {
pathsBuilder = barsBuilder; pathsBuilder = barsBuilder;
} else if (mode === GraphMode.Line) { } else if (drawStyle === DrawStyle.Line) {
if (lineInterpolation === LineInterpolation.StepBefore) { if (lineInterpolation === LineInterpolation.StepBefore) {
pathsBuilder = stepBeforeBuilder; pathsBuilder = stepBeforeBuilder;
} else if (lineInterpolation === LineInterpolation.StepAfter) { } else if (lineInterpolation === LineInterpolation.StepAfter) {
...@@ -67,7 +67,7 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> { ...@@ -67,7 +67,7 @@ export class UPlotSeriesBuilder extends PlotConfigBuilder<SeriesProps, Series> {
// we cannot set points.show property above (even to undefined) as that will clear uPlot's default auto behavior // we cannot set points.show property above (even to undefined) as that will clear uPlot's default auto behavior
if (points === PointMode.Auto) { if (points === PointMode.Auto) {
if (mode === GraphMode.Bars) { if (drawStyle === DrawStyle.Bars) {
pointsConfig.points!.show = false; pointsConfig.points!.show = false;
} }
} else if (points === PointMode.Never) { } else if (points === PointMode.Never) {
......
...@@ -3,7 +3,7 @@ import { LegendDisplayMode } from '@grafana/ui'; ...@@ -3,7 +3,7 @@ import { LegendDisplayMode } from '@grafana/ui';
import { import {
GraphFieldConfig, GraphFieldConfig,
PointMode, PointMode,
GraphMode, DrawStyle,
AxisPlacement, AxisPlacement,
graphFieldOptions, graphFieldOptions,
} from '@grafana/ui/src/components/uPlot/config'; } from '@grafana/ui/src/components/uPlot/config';
...@@ -25,11 +25,11 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel) ...@@ -25,11 +25,11 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel)
useCustomConfig: builder => { useCustomConfig: builder => {
builder builder
.addRadio({ .addRadio({
path: 'mode', path: 'drawStyle',
name: 'Display', name: 'Style',
defaultValue: graphFieldOptions.mode[0].value, defaultValue: graphFieldOptions.drawStyle[0].value,
settings: { settings: {
options: graphFieldOptions.mode, options: graphFieldOptions.drawStyle,
}, },
}) })
.addRadio({ .addRadio({
...@@ -39,7 +39,7 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel) ...@@ -39,7 +39,7 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel)
settings: { settings: {
options: graphFieldOptions.lineInterpolation, options: graphFieldOptions.lineInterpolation,
}, },
showIf: c => c.mode === GraphMode.Line, showIf: c => c.drawStyle === DrawStyle.Line,
}) })
.addSliderInput({ .addSliderInput({
path: 'lineWidth', path: 'lineWidth',
...@@ -50,7 +50,7 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel) ...@@ -50,7 +50,7 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel)
max: 10, max: 10,
step: 1, step: 1,
}, },
showIf: c => c.mode !== GraphMode.Points, showIf: c => c.drawStyle !== DrawStyle.Points,
}) })
.addSliderInput({ .addSliderInput({
path: 'fillOpacity', path: 'fillOpacity',
...@@ -61,7 +61,7 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel) ...@@ -61,7 +61,7 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(GraphPanel)
max: 1, max: 1,
step: 0.1, step: 0.1,
}, },
showIf: c => c.mode !== GraphMode.Points, showIf: c => c.drawStyle !== DrawStyle.Points,
}) })
.addRadio({ .addRadio({
path: 'points', path: 'points',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment