|
|
|
|
@ -30,6 +30,7 @@ import { |
|
|
|
|
GraphTransform, |
|
|
|
|
AxisColorMode, |
|
|
|
|
GraphGradientMode, |
|
|
|
|
VizOrientation, |
|
|
|
|
} from '@grafana/schema'; |
|
|
|
|
|
|
|
|
|
// unit lookup needed to determine if we want power-of-2 or power-of-10 axis ticks
|
|
|
|
|
@ -90,7 +91,10 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ |
|
|
|
|
tweakAxis = (opts) => opts, |
|
|
|
|
eventsScope = '__global_', |
|
|
|
|
hoverProximity, |
|
|
|
|
orientation = VizOrientation.Horizontal, |
|
|
|
|
}) => { |
|
|
|
|
// we want the Auto and Horizontal orientation to default to Horizontal
|
|
|
|
|
const isHorizontal = orientation !== VizOrientation.Vertical; |
|
|
|
|
const builder = new UPlotConfigBuilder(timeZones[0]); |
|
|
|
|
|
|
|
|
|
let alignedFrame: DataFrame; |
|
|
|
|
@ -113,15 +117,19 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ |
|
|
|
|
let yScaleKey = ''; |
|
|
|
|
|
|
|
|
|
const xFieldAxisPlacement = |
|
|
|
|
xField.config.custom?.axisPlacement !== AxisPlacement.Hidden ? AxisPlacement.Bottom : AxisPlacement.Hidden; |
|
|
|
|
xField.config.custom?.axisPlacement === AxisPlacement.Hidden |
|
|
|
|
? AxisPlacement.Hidden |
|
|
|
|
: isHorizontal |
|
|
|
|
? AxisPlacement.Bottom |
|
|
|
|
: AxisPlacement.Left; |
|
|
|
|
const xFieldAxisShow = xField.config.custom?.axisPlacement !== AxisPlacement.Hidden; |
|
|
|
|
|
|
|
|
|
if (xField.type === FieldType.time) { |
|
|
|
|
xScaleUnit = 'time'; |
|
|
|
|
builder.addScale({ |
|
|
|
|
scaleKey: xScaleKey, |
|
|
|
|
orientation: ScaleOrientation.Horizontal, |
|
|
|
|
direction: ScaleDirection.Right, |
|
|
|
|
orientation: isHorizontal ? ScaleOrientation.Horizontal : ScaleOrientation.Vertical, |
|
|
|
|
direction: isHorizontal ? ScaleDirection.Right : ScaleDirection.Up, |
|
|
|
|
isTime: true, |
|
|
|
|
range: () => { |
|
|
|
|
const r = getTimeRange(); |
|
|
|
|
@ -133,7 +141,10 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ |
|
|
|
|
const filterTicks: uPlot.Axis.Filter | undefined = |
|
|
|
|
timeZones.length > 1 |
|
|
|
|
? (u, splits) => { |
|
|
|
|
return splits.map((v, i) => (i < 2 ? null : v)); |
|
|
|
|
if (isHorizontal) { |
|
|
|
|
return splits.map((v, i) => (i < 2 ? null : v)); |
|
|
|
|
} |
|
|
|
|
return splits; |
|
|
|
|
} |
|
|
|
|
: undefined; |
|
|
|
|
|
|
|
|
|
@ -157,13 +168,12 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ |
|
|
|
|
builder.addHook('drawAxes', (u: uPlot) => { |
|
|
|
|
u.ctx.save(); |
|
|
|
|
|
|
|
|
|
u.ctx.fillStyle = theme.colors.text.primary; |
|
|
|
|
u.ctx.textAlign = 'left'; |
|
|
|
|
u.ctx.textBaseline = 'bottom'; |
|
|
|
|
|
|
|
|
|
let i = 0; |
|
|
|
|
u.axes.forEach((a) => { |
|
|
|
|
if (a.side === 2) { |
|
|
|
|
if (isHorizontal && a.side === 2) { |
|
|
|
|
u.ctx.fillStyle = theme.colors.text.primary; |
|
|
|
|
u.ctx.textAlign = 'left'; |
|
|
|
|
u.ctx.textBaseline = 'bottom'; |
|
|
|
|
//@ts-ignore
|
|
|
|
|
let cssBaseline: number = a._pos + a._size; |
|
|
|
|
u.ctx.fillText(timeZones[i], u.bbox.left, cssBaseline * uPlot.pxRatio); |
|
|
|
|
@ -182,8 +192,8 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ |
|
|
|
|
|
|
|
|
|
builder.addScale({ |
|
|
|
|
scaleKey: xScaleKey, |
|
|
|
|
orientation: ScaleOrientation.Horizontal, |
|
|
|
|
direction: ScaleDirection.Right, |
|
|
|
|
orientation: isHorizontal ? ScaleOrientation.Horizontal : ScaleOrientation.Vertical, |
|
|
|
|
direction: isHorizontal ? ScaleDirection.Right : ScaleDirection.Up, |
|
|
|
|
range: (u, dataMin, dataMax) => [xField.config.min ?? dataMin, xField.config.max ?? dataMax], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -243,8 +253,8 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ |
|
|
|
|
tweakScale( |
|
|
|
|
{ |
|
|
|
|
scaleKey, |
|
|
|
|
orientation: ScaleOrientation.Vertical, |
|
|
|
|
direction: ScaleDirection.Up, |
|
|
|
|
orientation: isHorizontal ? ScaleOrientation.Vertical : ScaleOrientation.Horizontal, |
|
|
|
|
direction: isHorizontal ? ScaleDirection.Up : ScaleDirection.Right, |
|
|
|
|
distribution: customConfig.scaleDistribution?.type, |
|
|
|
|
log: customConfig.scaleDistribution?.log, |
|
|
|
|
linearThreshold: customConfig.scaleDistribution?.linearThreshold, |
|
|
|
|
@ -329,7 +339,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ |
|
|
|
|
scaleKey, |
|
|
|
|
label: customConfig.axisLabel, |
|
|
|
|
size: customConfig.axisWidth, |
|
|
|
|
placement: customConfig.axisPlacement ?? AxisPlacement.Auto, |
|
|
|
|
placement: isHorizontal ? customConfig.axisPlacement ?? AxisPlacement.Auto : AxisPlacement.Bottom, |
|
|
|
|
formatValue: (v, decimals) => formattedValueToString(fmt(v, decimals)), |
|
|
|
|
theme, |
|
|
|
|
grid: { show: customConfig.axisGridShow }, |
|
|
|
|
|