Skip to content

Commit c1a55e5

Browse files
author
Jelte Lagendijk
committed
Proper checking of loadData
1 parent 8a13907 commit c1a55e5

4 files changed

Lines changed: 132 additions & 115 deletions

File tree

src/ChartJS/widgets/Core.js

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -173,49 +173,53 @@ define([
173173
};
174174

175175
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function (objs) {
176-
var obj = objs[0], // Chart object is always only one.
177-
j = null,
178-
dataset = null,
179-
pointguids = null,
180-
guids = obj.get(this._dataset);
181-
182-
this._data.object = obj;
183-
this._data.datasets = [];
184-
185-
if (!guids) {
186-
logger.warn(this.id + "._loadData failed, no _dataset. Not rendering Chart");
187-
return;
188-
}
176+
if (objs && objs.length > 0) {
177+
var obj = objs[0], // Chart object is always only one.
178+
j = null,
179+
dataset = null,
180+
pointguids = null,
181+
guids = obj.get(this._dataset);
182+
183+
this._data.object = obj;
184+
this._data.datasets = [];
185+
186+
if (!guids) {
187+
logger.warn(this.id + "._loadData failed, no _dataset. Not rendering Chart");
188+
return;
189+
}
189190

190-
this._chartEntityObject = obj;
191+
this._chartEntityObject = obj;
191192

192-
// Retrieve datasets
193-
mx.data.get({
194-
guids: guids,
195-
callback: lang.hitch(this, function (datasets) {
196-
var set = {};
193+
// Retrieve datasets
194+
mx.data.get({
195+
guids: guids,
196+
callback: lang.hitch(this, function (datasets) {
197+
var set = {};
197198

198-
this._datasetCounter = datasets.length;
199-
this._data.datasets = [];
199+
this._datasetCounter = datasets.length;
200+
this._data.datasets = [];
200201

201-
for (j = 0; j < datasets.length; j++) {
202-
dataset = datasets[j];
203-
pointguids = dataset.get(this._datapoint);
204-
if (typeof pointguids === "string" && pointguids !== "") {
205-
pointguids = [pointguids];
206-
}
207-
if (typeof pointguids !== "string") {
208-
mx.data.get({
209-
guids: pointguids,
210-
callback: lang.hitch(this, this.datasetAdd, dataset)
211-
});
212-
} else {
213-
this.datasetAdd(dataset, []);
202+
for (j = 0; j < datasets.length; j++) {
203+
dataset = datasets[j];
204+
pointguids = dataset.get(this._datapoint);
205+
if (typeof pointguids === "string" && pointguids !== "") {
206+
pointguids = [pointguids];
207+
}
208+
if (typeof pointguids !== "string") {
209+
mx.data.get({
210+
guids: pointguids,
211+
callback: lang.hitch(this, this.datasetAdd, dataset)
212+
});
213+
} else {
214+
this.datasetAdd(dataset, []);
215+
}
214216
}
215-
}
216217

217-
})
218-
});
218+
})
219+
});
220+
} else {
221+
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
222+
}
219223
}), this._mxObj);
220224

221225
},

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,37 @@ define([
6363
_loadData: function() {
6464
logger.debug(this.id + "._loadData");
6565
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
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-
});
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+
9297
}), this._mxObj);
9398

9499
},

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,36 @@ define([
6262
_loadData: function() {
6363
logger.debug(this.id + "._loadData");
6464
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
65-
var obj = objs[0], // Chart object is always only one.
66-
j = null,
67-
dataset = null;
68-
69-
this._data.object = obj;
70-
this._chartEntityObject = obj;
71-
72-
// Retrieve datasets
73-
mx.data.get({
74-
guids: obj.get(this._dataset),
75-
callback: lang.hitch(this, function(datasets) {
76-
var set = null;
77-
this._data.datasets = [];
78-
79-
for (j = 0; j < datasets.length; j++) {
80-
dataset = datasets[j];
81-
82-
set = {
83-
dataset: dataset,
84-
sorting: +(dataset.get(this.datasetsorting))
85-
};
86-
this._data.datasets.push(set);
87-
}
88-
this._processData();
89-
})
90-
});
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+
}
9195
}), this._mxObj);
9296

9397
},

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,36 @@ define([
6464
logger.debug(this.id + "._loadData");
6565

6666
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function (objs) {
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-
});
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+
}
9397
}), this._mxObj);
9498

9599
},

0 commit comments

Comments
 (0)