points 그래프 데이터 처리
This commit is contained in:
parent
f67359ba35
commit
b9ff8908d7
@ -109,6 +109,7 @@ export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
|||||||
|
|
||||||
constructor(props: GraphNGProps) {
|
constructor(props: GraphNGProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
// console.log(props);
|
||||||
let state = this.prepState(props);
|
let state = this.prepState(props);
|
||||||
state.alignedData = state.config!.prepData!([state.alignedFrame]) as AlignedData;
|
state.alignedData = state.config!.prepData!([state.alignedFrame]) as AlignedData;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
|||||||
@ -28,7 +28,6 @@ export const TimeSeriesPanel = ({
|
|||||||
const preparePlotFrame =
|
const preparePlotFrame =
|
||||||
fieldConfig.defaults.custom.drawStyle === DrawStyle.Points ? preparePlotFramePoints : undefined;
|
fieldConfig.defaults.custom.drawStyle === DrawStyle.Points ? preparePlotFramePoints : undefined;
|
||||||
if (fieldConfig.defaults.custom.drawStyle === DrawStyle.Points) {
|
if (fieldConfig.defaults.custom.drawStyle === DrawStyle.Points) {
|
||||||
console.log('points');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vertical orientation is not available for users through config.
|
// Vertical orientation is not available for users through config.
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import {
|
|||||||
isBooleanUnit,
|
isBooleanUnit,
|
||||||
TimeRange,
|
TimeRange,
|
||||||
cacheFieldDisplayNames,
|
cacheFieldDisplayNames,
|
||||||
|
fieldMatchers,
|
||||||
|
FieldMatcherID,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { convertFieldType } from '@grafana/data/src/transformations/transformers/convertFieldType';
|
import { convertFieldType } from '@grafana/data/src/transformations/transformers/convertFieldType';
|
||||||
import { applyNullInsertThreshold } from '@grafana/data/src/transformations/transformers/nulls/nullInsertThreshold';
|
import { applyNullInsertThreshold } from '@grafana/data/src/transformations/transformers/nulls/nullInsertThreshold';
|
||||||
@ -68,12 +70,83 @@ function reEnumFields(frames: DataFrame[]): DataFrame[] {
|
|||||||
return frames2;
|
return frames2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 그룹화 되어 있는 값들을 풀어주는 함수(포인트 그래프에 제한적)
|
||||||
|
function assembleData(series: DataFrame[]): DataFrame[] | null {
|
||||||
|
let timeField: Field | null = null; // 시간 필드
|
||||||
|
const matchTimefn = fieldMatchers.get(FieldMatcherID.firstTimeField).get({});
|
||||||
|
for (let frame of series) {
|
||||||
|
for (let field of frame.fields) {
|
||||||
|
if (matchTimefn(field, frame, series)) {
|
||||||
|
timeField = field;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timeField) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fields = series[0].fields.filter((f) => f.type === FieldType.string);
|
||||||
|
if (fields.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const alignedFieldTimes: number[] = [];
|
||||||
|
const alignedFieldValues: number[] = [];
|
||||||
|
const alignedFieldIDs: number[] = [];
|
||||||
|
|
||||||
|
timeField.values.forEach((v, vi) => {
|
||||||
|
const arrValues = JSON.parse(fields[0].values[vi]);
|
||||||
|
const arrIDs = JSON.parse(fields[1].values[vi]);
|
||||||
|
arrValues.forEach((f: number, i: number) => {
|
||||||
|
alignedFieldTimes.push(v);
|
||||||
|
alignedFieldValues.push(f);
|
||||||
|
alignedFieldIDs.push(arrIDs[i]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const newFieldTime: Field = {
|
||||||
|
values: alignedFieldTimes,
|
||||||
|
name: timeField.name,
|
||||||
|
type: timeField.type,
|
||||||
|
config: timeField.config,
|
||||||
|
state: timeField.state,
|
||||||
|
display: timeField.display,
|
||||||
|
};
|
||||||
|
|
||||||
|
const newFieldValues: Field = {
|
||||||
|
values: alignedFieldValues,
|
||||||
|
name: fields[0].name,
|
||||||
|
type: FieldType.number,
|
||||||
|
config: fields[0].config,
|
||||||
|
state: fields[0].state,
|
||||||
|
display: fields[0].display,
|
||||||
|
};
|
||||||
|
|
||||||
|
const newFieldIDs: Field = {
|
||||||
|
values: alignedFieldIDs,
|
||||||
|
name: fields[1].name,
|
||||||
|
type: FieldType.number,
|
||||||
|
config: fields[1].config,
|
||||||
|
state: fields[1].state,
|
||||||
|
display: fields[1].display,
|
||||||
|
};
|
||||||
|
|
||||||
|
const newFrame: DataFrame = {
|
||||||
|
//length: series[0].length,
|
||||||
|
fields: [newFieldTime, newFieldValues, newFieldIDs],
|
||||||
|
length: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
return [newFrame];
|
||||||
|
}
|
||||||
|
|
||||||
export function preparePlotFramePoints(frames: DataFrame[], dimFields: XYFieldMatchers, timeRange?: TimeRange | null) {
|
export function preparePlotFramePoints(frames: DataFrame[], dimFields: XYFieldMatchers, timeRange?: TimeRange | null) {
|
||||||
const dataFrame: DataFrame = {
|
const dataFrame: DataFrame = {
|
||||||
...frames[0],
|
length: frames[0].length,
|
||||||
fields: frames[0].fields.filter((f) => f.type === FieldType.number),
|
fields: frames[0].fields,
|
||||||
};
|
};
|
||||||
console.log(dataFrame);
|
|
||||||
return dataFrame;
|
return dataFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +164,11 @@ export function prepareGraphableFields(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pointSeries = assembleData(series)!;
|
||||||
|
if (pointSeries) {
|
||||||
|
series = pointSeries;
|
||||||
|
}
|
||||||
|
|
||||||
cacheFieldDisplayNames(series);
|
cacheFieldDisplayNames(series);
|
||||||
|
|
||||||
let useNumericX = xNumFieldIdx != null;
|
let useNumericX = xNumFieldIdx != null;
|
||||||
@ -130,7 +208,6 @@ export function prepareGraphableFields(
|
|||||||
let copy: Field;
|
let copy: Field;
|
||||||
|
|
||||||
const frames: DataFrame[] = [];
|
const frames: DataFrame[] = [];
|
||||||
|
|
||||||
for (let frame of series) {
|
for (let frame of series) {
|
||||||
const fields: Field[] = [];
|
const fields: Field[] = [];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user