XYChart: Minor improvements (#78506)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
Co-authored-by: Adela Almasan <adela.almasan@grafana.com>
This commit is contained in:
Nathan Marrs
2023-11-22 11:50:02 -08:00
committed by GitHub
co-authored by Leon Sorokin Adela Almasan
parent 72e8672203
commit d269a123e7
3 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -93,11 +93,11 @@ export function getTextDimensionFromData(
}
export function findField(frame?: DataFrame, name?: string): Field | undefined {
const idx = findFieldIndex(frame, name);
const idx = findFieldIndex(name, frame);
return idx == null ? undefined : frame!.fields[idx];
}
export function findFieldIndex(frame?: DataFrame, name?: string): number | undefined {
export function findFieldIndex(name?: string, frame?: DataFrame, frames?: DataFrame[]): number | undefined {
if (!frame || !name?.length) {
return undefined;
}
@@ -107,7 +107,7 @@ export function findFieldIndex(frame?: DataFrame, name?: string): number | undef
if (name === field.name) {
return i;
}
const disp = getFieldDisplayName(field, frame);
const disp = getFieldDisplayName(field, frame, frames);
if (name === disp) {
return i;
}
@@ -49,7 +49,7 @@ export const TrendPanel = ({
let frames = data.series;
let xFieldIdx: number | undefined;
if (options.xField) {
xFieldIdx = findFieldIndex(frames[0], options.xField);
xFieldIdx = findFieldIndex(options.xField, frames[0]);
if (xFieldIdx == null) {
return {
warning: 'Unable to find field: ' + options.xField,
+5 -5
View File
@@ -225,11 +225,11 @@ function prepSeries(options: Options, frames: DataFrame[]): ScatterSeries[] {
for (let frameIndex = 0; frameIndex < frames.length; frameIndex++) {
const frame = frames[frameIndex];
const xIndex = findFieldIndex(frame, series.x);
const xIndex = findFieldIndex(series.x, frame, frames);
if (xIndex != null) {
// TODO: this should find multiple y fields
const yIndex = findFieldIndex(frame, series.y);
const yIndex = findFieldIndex(series.y, frame, frames);
if (yIndex == null) {
throw 'Y must be in the same frame as X';
@@ -237,9 +237,9 @@ function prepSeries(options: Options, frames: DataFrame[]): ScatterSeries[] {
const dims: Dims = {
pointColorFixed: series.pointColor?.fixed,
pointColorIndex: findFieldIndex(frame, series.pointColor?.field),
pointColorIndex: findFieldIndex(series.pointColor?.field, frame, frames),
pointSizeConfig: series.pointSize,
pointSizeIndex: findFieldIndex(frame, series.pointSize?.field),
pointSizeIndex: findFieldIndex(series.pointSize?.field, frame, frames),
};
scatterSeries.push(getScatterSeries(seriesIndex++, frames, frameIndex, xIndex, yIndex, dims));
}
@@ -255,7 +255,7 @@ function prepSeries(options: Options, frames: DataFrame[]): ScatterSeries[] {
const frame = frames[frameIndex];
const numericIndices: number[] = [];
let xIndex = findFieldIndex(frame, dims.x);
let xIndex = findFieldIndex(dims.x, frame, frames);
for (let i = 0; i < frame.fields.length; i++) {
if (isGraphable(frame.fields[i])) {
if (xIndex == null || i === xIndex) {