The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/dashboard/row/row_model.ts

83 lines
1.7 KiB

///<reference path="../../../headers/common.d.ts" />
import _ from 'lodash';
import {Emitter, contextSrv} from 'app/core/core';
import {assignModelProperties} from 'app/core/core';
export class DashboardRow {
panels: any;
title: any;
showTitle: any;
titleSize: any;
events: Emitter;
span: number;
defaults = {
title: 'Dashboard Row',
panels: [],
showTitle: false,
titleSize: 'h6',
height: 250,
isNew: false,
};
constructor(private model) {
console.log(model.isNew);
assignModelProperties(this, model, this.defaults);
this.events = new Emitter();
this.updateRowSpan();
}
getSaveModel() {
assignModelProperties(this.model, this, this.defaults);
return this.model;
}
updateRowSpan() {
this.span = 0;
for (let panel of this.panels) {
this.span += panel.span;
}
}
panelSpanChanged() {
var oldSpan = this.span;
this.updateRowSpan();
if (oldSpan !== this.span) {
this.events.emit('span-changed');
}
}
addPanel(panel) {
var rowSpan = this.span;
var panelCount = this.panels.length;
var space = (12 - rowSpan) - panel.span;
// try to make room of there is no space left
if (space <= 0) {
if (panelCount === 1) {
this.panels[0].span = 6;
panel.span = 6;
} else if (panelCount === 2) {
this.panels[0].span = 4;
this.panels[1].span = 4;
panel.span = 4;
}
}
this.panels.push(panel);
this.events.emit('panel-added', panel);
this.panelSpanChanged();
}
removePanel(panel) {
var index = _.indexOf(this.panels, panel);
this.panels.splice(index, 1);
this.events.emit('panel-removed', panel);
this.panelSpanChanged();
}
}