Skip to content

Commit 208cf07

Browse files
author
Jelte Lagendijk
committed
Refactor method loadData for single set widgets
1 parent e547bac commit 208cf07

File tree

4 files changed

+47
-112
lines changed

4 files changed

+47
-112
lines changed

src/ChartJS/widgets/Core.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,42 @@ define([
224224

225225
},
226226

227+
_loadDataSingleSet: function () {
228+
logger.debug(this.id + "._loadDataSingleSet");
229+
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
230+
if (objs && objs.length > 0) {
231+
var obj = objs[0], // Chart object is always only one.
232+
j = null,
233+
dataset = null;
234+
235+
this._data.object = obj;
236+
this._chartEntityObject = obj;
237+
238+
// Retrieve datasets
239+
mx.data.get({
240+
guids: obj.get(this._dataset),
241+
callback: lang.hitch(this, function(datasets) {
242+
var set = null;
243+
this._data.datasets = [];
244+
245+
for (j = 0; j < datasets.length; j++) {
246+
dataset = datasets[j];
247+
248+
set = {
249+
dataset: dataset,
250+
sorting: +(dataset.get(this.datasetsorting))
251+
};
252+
this._data.datasets.push(set);
253+
}
254+
this._processData();
255+
})
256+
});
257+
} else {
258+
console.warn(this.id + "._loadDataSingleSet execution of microflow:" + this.datasourcemf + " has not returned any objects.");
259+
}
260+
}), this._mxObj);
261+
},
262+
227263
uninitialize: function () {
228264
logger.debug(this.id + ".uninitialize");
229265

src/ChartJS/widgets/DoughnutChart/widget/DoughnutChart.js

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,7 @@ define([
6161
},
6262

6363
_loadData: function() {
64-
logger.debug(this.id + "._loadData");
65-
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
66-
if (objs && objs.length > 0) {
67-
var obj = objs[0], // Chart object is always only one.
68-
j = null,
69-
dataset = null;
70-
71-
this._data.object = obj;
72-
this._chartEntityObject = obj;
73-
74-
// Retrieve datasets
75-
mx.data.get({
76-
guids: obj.get(this._dataset),
77-
callback: lang.hitch(this, function(datasets) {
78-
var set = null;
79-
this._data.datasets = [];
80-
81-
for (j = 0; j < datasets.length; j++) {
82-
dataset = datasets[j];
83-
84-
set = {
85-
dataset: dataset,
86-
sorting: +(dataset.get(this.datasetsorting))
87-
};
88-
this._data.datasets.push(set);
89-
}
90-
this._processData();
91-
})
92-
});
93-
} else {
94-
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
95-
}
96-
97-
}), this._mxObj);
98-
64+
this._loadDataSingleSet();
9965
},
10066

10167
_createChart: function(data) {
@@ -138,10 +104,10 @@ define([
138104
this._resize();
139105
}));
140106

141-
var content = this._data.object.get(this.numberInside);
142-
143-
// Set the con
144-
html.set(this._numberNode, content !== null ? content.toString() : "");
107+
if (this.numberInside) {
108+
var content = this._data.object.get(this.numberInside);
109+
html.set(this._numberNode, content !== null ? content.toString() : "");
110+
}
145111

146112
// Add class to determain chart type
147113
this._addChartClass("chartjs-doughnut-chart");

src/ChartJS/widgets/PieChart/widget/PieChart.js

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -60,40 +60,7 @@ define([
6060
},
6161

6262
_loadData: function() {
63-
logger.debug(this.id + "._loadData");
64-
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
65-
if (objs && objs.length > 0) {
66-
var obj = objs[0], // Chart object is always only one.
67-
j = null,
68-
dataset = null;
69-
70-
this._data.object = obj;
71-
this._chartEntityObject = obj;
72-
73-
// Retrieve datasets
74-
mx.data.get({
75-
guids: obj.get(this._dataset),
76-
callback: lang.hitch(this, function(datasets) {
77-
var set = null;
78-
this._data.datasets = [];
79-
80-
for (j = 0; j < datasets.length; j++) {
81-
dataset = datasets[j];
82-
83-
set = {
84-
dataset: dataset,
85-
sorting: +(dataset.get(this.datasetsorting))
86-
};
87-
this._data.datasets.push(set);
88-
}
89-
this._processData();
90-
})
91-
});
92-
} else {
93-
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
94-
}
95-
}), this._mxObj);
96-
63+
this._loadDataSingleSet();
9764
},
9865

9966
_createChart: function(data) {
@@ -139,10 +106,10 @@ define([
139106
};
140107
this._chart = new this._chartJS(this._ctx, chartProperties);
141108

142-
var content = this._data.object.get(this.numberInside);
143-
144-
// Set the con
145-
html.set(this._numberNode, content !== null ? content.toString() : "");
109+
if (this.numberInside) {
110+
var content = this._data.object.get(this.numberInside);
111+
html.set(this._numberNode, content !== null ? content.toString() : "");
112+
}
146113

147114
// Add class to determain chart type
148115
this._addChartClass("chartjs-pie-chart");

src/ChartJS/widgets/PolarChart/widget/PolarChart.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,7 @@ define([
6161
},
6262

6363
_loadData : function () {
64-
logger.debug(this.id + "._loadData");
65-
66-
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function (objs) {
67-
if (objs && objs.length > 0) {
68-
var obj = objs[0], // Chart object is always only one.
69-
j = null,
70-
dataset = null;
71-
72-
this._data.object = obj;
73-
this._chartEntityObject = obj;
74-
75-
// Retrieve datasets
76-
mx.data.get({
77-
guids : obj.get(this._dataset),
78-
callback : lang.hitch(this, function (datasets) {
79-
var set = null;
80-
this._data.datasets = [];
81-
82-
for (j = 0; j < datasets.length; j++) {
83-
dataset = datasets[j];
84-
85-
set = {
86-
dataset : dataset,
87-
sorting : +(dataset.get(this.datasetsorting))
88-
};
89-
this._data.datasets.push(set);
90-
}
91-
this._processData();
92-
})
93-
});
94-
} else {
95-
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
96-
}
97-
}), this._mxObj);
98-
64+
this._loadDataSingleSet();
9965
},
10066

10167
_createChart : function (data) {

0 commit comments

Comments
 (0)