mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-03 01:10:10 +00:00
migrating widgets to nvd3
This commit is contained in:
parent
ac8bd534ea
commit
747980cf45
13 changed files with 268 additions and 187 deletions
60
httpdocs/js/widgets/templates/default-template.js
Normal file
60
httpdocs/js/widgets/templates/default-template.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* Pie Chart, Line Chart, Stacked Chart, Table,
|
||||
*/
|
||||
|
||||
export default class WidgetTemplate {
|
||||
|
||||
constructor(params) {
|
||||
|
||||
if (this.constructor == WidgetTemplate) {
|
||||
throw new Error('Cannot instantiate an abstract class!');
|
||||
}
|
||||
|
||||
const intervalTime = params.intervalTime || 0;
|
||||
|
||||
this._defaultOptions = {
|
||||
intervalTime: intervalTime,
|
||||
widgetKey: params.widgetKey,
|
||||
widgetName: params.widgetName,
|
||||
widgetType: params.widgetType
|
||||
};
|
||||
this._data = params.data || [];
|
||||
}
|
||||
|
||||
render() {
|
||||
const container = document.createElement('div');
|
||||
container.setAttribute('class', 'ntop-widget-container');
|
||||
container.setAttribute('id', `ntop-widget-${this._defaultOptions.widgetKey}-${this._defaultOptions.widgetType}`);
|
||||
|
||||
if (this._data.length == 0) {
|
||||
const emptyContainer = document.createElement('div');
|
||||
emptyContainer.classList = "border p-2";
|
||||
emptyContainer.innerHTML = `Widget <i>${this._defaultOptions.widgetName}</i>: <b>No data was found.</b>`;
|
||||
container.appendChild(emptyContainer);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
export class ChartTemplate extends WidgetTemplate {
|
||||
|
||||
constructor(params) {
|
||||
super(params);
|
||||
this._chart = {};
|
||||
this._width = params.width || 400;
|
||||
this._height = params.height || 400;
|
||||
}
|
||||
|
||||
_checkNVSupport() {
|
||||
if (!nv) throw new Error("NVD3 not found! Do you have included in your page?");
|
||||
}
|
||||
|
||||
_addGraph() {}
|
||||
_updateData() {}
|
||||
|
||||
render() {
|
||||
this._checkNVSupport();
|
||||
return super.render();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue