-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chart.js
89 lines (85 loc) · 2.16 KB
/
Chart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*!
* ${copyright}
*/
// Provides a shim for the chartist library
sap.ui.loader.config({
shim: {
"ui5con20/library/thirdparty/chartist/chartist": {
amd: true,
exports: "Chartist"
}
}
});
// Provides control ui5con20.library.Chart
sap.ui.define([
"sap/ui/core/Control",
"sap/ui/core/HTML",
"./ChartRenderer",
"./thirdparty/chartist/chartist",
"./library"
], function(Control, HTML, ChartRenderer, Chartist /*, library*/) {
"use strict";
var Chart = Control.extend("ui5con20.library.Chart", {
metadata: {
properties: {
"data": {
type: "object"
},
"options": {
type: "object"
},
"type": {
type: "string",
defaultValue: "Line"
}
},
aggregations: {
"_html": {
type: "sap.ui.core.HTML",
multiple: false,
visibility: "hidden"
}
},
events: {
chartInitialized: {}
}
},
init: function() {
var sHtmlId = this.getId() + "-html";
this.setAggregation("_html", new HTML(sHtmlId, {
content: "<div id=\"" + sHtmlId + "\"></div>"
}));
},
onAfterRendering: function() {
if (!this._chartistChart) {
this._chartistChart = new Chartist[this.getType()](this.getAggregation("_html").getDomRef(), this.getData(), this.getOptions());
this.fireChartInitialized({
chart: this._chartistChart
});
}
},
setData: function(data) {
this.setProperty("data", data, /* bSuppressInvalidate */ true);
if (this._chartistChart) {
this._chartistChart.update(data || {});
}
return this;
},
setOptions: function(options, bSuppressInvalidate) {
this.setProperty("options", options, bSuppressInvalidate);
if (this._chartistChart) {
this._chartistChart.detach();
}
this._chartistChart = new Chartist[this.getType()](this.getAggregation("_html").getDomRef(), this.getData(), this.getOptions());
},
setType: function(type, bSuppressInvalidate) {
this.setProperty("type", type, bSuppressInvalidate);
if (this._chartistChart) {
this._chartistChart.detach();
}
this._chartistChart = new Chartist[this.getType()](this.getAggregation("_html").getDomRef(), this.getData(), this.getOptions());
},
renderer: ChartRenderer
});
return Chart;
});