Skip to content

Commit

Permalink
Merge pull request #420 from yulichun/yulc_20240327
Browse files Browse the repository at this point in the history
y轴增加最大最小值的设置
  • Loading branch information
sunface authored Mar 30, 2024
2 parents d4349d3 + aed77fd commit ed51c0b
Show file tree
Hide file tree
Showing 7 changed files with 1,576 additions and 565 deletions.
2 changes: 2 additions & 0 deletions datav/frontend/src/types/panel/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export enum ThresholdDisplay {
export interface ValueSetting extends Units {
decimal: number
calc?: ValueCalculationType
min?: number
max?: number
}

export type UnitsType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,30 @@ const GraphPanelEditor = memo((props: GraphEditorProps) => {
}
/>
</PanelEditItem>
<PanelEditItem title="min">
<EditorNumberItem
value={panel.plugins.graph.value?.min}
step={1}
onChange={(v) =>
onChange((panel: GraphPanel) => {
panel.plugins.graph.value.min = v
dispatch(PanelForceRebuildEvent + panel.id)
})
}
/>
</PanelEditItem>
<PanelEditItem title="max">
<EditorNumberItem
value={panel.plugins.graph.value?.max}
step={1}
onChange={(v) =>
onChange((panel: GraphPanel) => {
panel.plugins.graph.value.max = v
dispatch(PanelForceRebuildEvent + panel.id)
})
}
/>
</PanelEditItem>
</PanelAccordion>
<PanelAccordion title={t1.alertCorrelation}>
<PanelEditItem title='Enable' desc={t1.alertCorrelationTips}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ const GraphOverridesEditor = ({ override, onChange, panel }: Props) => {
}}
/>
)
case GraphRules.SeriesScaleYMin:
return (
<EditorNumberItem
value={override.value}
step={1}
onChange={onChange}
/>
)
case GraphRules.SeriesScaleYMax:
return (
<EditorNumberItem
value={override.value}
step={1}
onChange={onChange}
/>
)
default:
return <></>
}
Expand All @@ -151,6 +167,8 @@ export enum GraphRules {
SeriesNegativeY = 'Series.negativeY',
SeriesYAxis = 'Series.separateYAxis',
SeriesThresholds = 'Series.thresholds',
SeriesScaleYMin = 'Series.scaleYMin',
SeriesScaleYMax = 'Series.scaleYMax',
}

export const getGraphOverrideTargets = (panel, data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export const parseOptions = (
},
]

const scales = {}

rawData.forEach((d, i) => {
const override: OverrideItem = findOverride(config.panel, d.rawName)
let opacity = config.panel.plugins.graph.styles.fillOpacity / 100
Expand Down Expand Up @@ -169,6 +171,31 @@ export const parseOptions = (
side: 1,
})


const scaleYMinOverride = findRuleInOverride(override, GraphRules.SeriesScaleYMin)
const scaleYMaxOverride = findRuleInOverride(override, GraphRules.SeriesScaleYMax)

scales[d.rawName] = {
auto: true,
dir: 1,
distr: config.panel.plugins.graph.axis?.scale == 'linear' ? 1 : 3,
ori: 1,
log: config.panel.plugins.graph.axis?.scaleBase,
range: {
min: {
soft: scaleYMinOverride? scaleYMinOverride : 0,
mode: 1,
hard: scaleYMinOverride? scaleYMinOverride : null,
},
max: {
mode: 2,
hard: scaleYMaxOverride? scaleYMaxOverride : null,
soft: scaleYMaxOverride? scaleYMaxOverride : null,
pad: 0.05,
},
}
}

scale = d.rawName
}

Expand Down Expand Up @@ -262,9 +289,9 @@ export const parseOptions = (
syncRect: [],
},
padding: [
padding[0] ?? 5,
padding[1] ?? 15,
padding[2] ?? -20,
padding[0] ?? 10, // 解决y轴上的数据被挡住的问题
padding[1] ?? 5,
padding[2] ?? 5,
padding[3] ?? (config.panel.plugins.graph.axis.showY ? 0 : 25),
],
plugins: [
Expand Down Expand Up @@ -295,8 +322,21 @@ export const parseOptions = (
distr: config.panel.plugins.graph.axis?.scale == 'linear' ? 1 : 3,
ori: 1,
log: config.panel.plugins.graph.axis?.scaleBase,
// min: 1
range: {
min: {
soft: config.panel.plugins.graph.value.min? config.panel.plugins.graph.value.min : 0,
mode: 1,
hard: config.panel.plugins.graph.value.min? config.panel.plugins.graph.value.min : null,
},
max: {
mode: 2,
hard: config.panel.plugins.graph.value.max? config.panel.plugins.graph.value.max : null,
soft: config.panel.plugins.graph.value.max? config.panel.plugins.graph.value.max : null,
pad: config.panel.plugins.graph.value.max? null : 0.1,
},
}
},
...scales,
},
axes: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ export function getStackedOpts(opts, data, interp) {
}
});

// force 0 to be the sum minimum this instead of the bottom series
opts.scales.y = {
...opts.scales.y,
range: (u, min, max) => {
let minMax = uPlot.rangeNum(0, max, 0.1, true);
return [0, minMax[1]];
}
};

// restack on toggle
opts.hooks.setSeries = [
(u, i) => {
Expand Down
2 changes: 1 addition & 1 deletion datav/query/datav.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ accesstoken:
provisioning:
## when enabled, pre set data sources and dashboards
enable: true
path: "./data/provisioning"
path: "./provisioning"
Loading

0 comments on commit ed51c0b

Please sign in to comment.