export class PanelModel<
Datasource = DatasourceMysql, Query = QueryMysqlSimple, ChartConfig = ChartConfigForm
> implements IPanelModel<Datasource, Query, ChartConfig> {
uid: string;
space_uid?: string;
// 图表类型 如 line-chart bar-chart status-chart group
type: string;
active?: string;
permissions: PermissionUser;
// 图表title
title: string;
sub_title: string;
data_type: string;
// 是否内置插件
build_in: boolean;
meta: BaseMetaInfo;
// 图表位置
gridPos = new IGridPos();
filters?: FilterType[] = [];
// 图表配置
options?: PanelModelOptions;
// 图表数据源
datasource: Datasource;
// 图表query配置
query: Query[];
// 组内视图列表
panels?: IPanelModel[] | PanelModel[];
chartStyle = new ChartStyle();
chartConfig: ChartConfig;
// 是否正在drag中
dragging = false;
// 是否折叠
collapsed?: boolean = false;
constructor(model?: Record<string, any>) {
if (model) {
Object.assign(this, model);
if (!this.chartStyle || JSON.stringify(this.chartStyle) === '{}') {
this.chartStyle = new ChartStyle();
}
this.updateGridPos(model.gridPos);
}
}
public updateGridPos(v: IGridPos) {
if (this.type === 'row') {
this.gridPos = {
...v,
w: GRID_COL_NUM,
h: 1,
minH: 1,
minW: GRID_COL_NUM,
maxH: 1,
maxW: GRID_COL_NUM,
i: this.uid,
};
return;
}
if (this.type === 'tab') {
this.gridPos = {
...v,
w: GRID_COL_NUM,
minH: GRID_CELL_MIN_HEIGHT,
minW: GRID_COL_NUM,
maxH: 100,
maxW: GRID_COL_NUM,
i: this.uid,
};
return;
}
this.gridPos = {
...v,
minH: GRID_CELL_MIN_HEIGHT,
minW: GRID_CELL_MIN_WIDTH,
maxH: GRID_CELL_MAX_HEIGHT,
maxW: GRID_COL_NUM,
i: this.uid,
};
}
}