Skip to content

Commit

Permalink
Proper checking of loadData
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelte Lagendijk committed May 10, 2017
1 parent 8a13907 commit c1a55e5
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 115 deletions.
78 changes: 41 additions & 37 deletions src/ChartJS/widgets/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,49 +173,53 @@ define([
};

this._executeMicroflow(this.datasourcemf, lang.hitch(this, function (objs) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null,
pointguids = null,
guids = obj.get(this._dataset);

this._data.object = obj;
this._data.datasets = [];

if (!guids) {
logger.warn(this.id + "._loadData failed, no _dataset. Not rendering Chart");
return;
}
if (objs && objs.length > 0) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null,
pointguids = null,
guids = obj.get(this._dataset);

this._data.object = obj;
this._data.datasets = [];

if (!guids) {
logger.warn(this.id + "._loadData failed, no _dataset. Not rendering Chart");
return;
}

this._chartEntityObject = obj;
this._chartEntityObject = obj;

// Retrieve datasets
mx.data.get({
guids: guids,
callback: lang.hitch(this, function (datasets) {
var set = {};
// Retrieve datasets
mx.data.get({
guids: guids,
callback: lang.hitch(this, function (datasets) {
var set = {};

this._datasetCounter = datasets.length;
this._data.datasets = [];
this._datasetCounter = datasets.length;
this._data.datasets = [];

for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];
pointguids = dataset.get(this._datapoint);
if (typeof pointguids === "string" && pointguids !== "") {
pointguids = [pointguids];
}
if (typeof pointguids !== "string") {
mx.data.get({
guids: pointguids,
callback: lang.hitch(this, this.datasetAdd, dataset)
});
} else {
this.datasetAdd(dataset, []);
for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];
pointguids = dataset.get(this._datapoint);
if (typeof pointguids === "string" && pointguids !== "") {
pointguids = [pointguids];
}
if (typeof pointguids !== "string") {
mx.data.get({
guids: pointguids,
callback: lang.hitch(this, this.datasetAdd, dataset)
});
} else {
this.datasetAdd(dataset, []);
}
}
}

})
});
})
});
} else {
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
}
}), this._mxObj);

},
Expand Down
57 changes: 31 additions & 26 deletions src/ChartJS/widgets/DoughnutChart/widget/DoughnutChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,37 @@ define([
_loadData: function() {
logger.debug(this.id + "._loadData");
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null;

this._data.object = obj;
this._chartEntityObject = obj;

// Retrieve datasets
mx.data.get({
guids: obj.get(this._dataset),
callback: lang.hitch(this, function(datasets) {
var set = null;
this._data.datasets = [];

for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];

set = {
dataset: dataset,
sorting: +(dataset.get(this.datasetsorting))
};
this._data.datasets.push(set);
}
this._processData();
})
});
if (objs && objs.length > 0) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null;

this._data.object = obj;
this._chartEntityObject = obj;

// Retrieve datasets
mx.data.get({
guids: obj.get(this._dataset),
callback: lang.hitch(this, function(datasets) {
var set = null;
this._data.datasets = [];

for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];

set = {
dataset: dataset,
sorting: +(dataset.get(this.datasetsorting))
};
this._data.datasets.push(set);
}
this._processData();
})
});
} else {
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
}

}), this._mxObj);

},
Expand Down
56 changes: 30 additions & 26 deletions src/ChartJS/widgets/PieChart/widget/PieChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,36 @@ define([
_loadData: function() {
logger.debug(this.id + "._loadData");
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null;

this._data.object = obj;
this._chartEntityObject = obj;

// Retrieve datasets
mx.data.get({
guids: obj.get(this._dataset),
callback: lang.hitch(this, function(datasets) {
var set = null;
this._data.datasets = [];

for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];

set = {
dataset: dataset,
sorting: +(dataset.get(this.datasetsorting))
};
this._data.datasets.push(set);
}
this._processData();
})
});
if (objs && objs.length > 0) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null;

this._data.object = obj;
this._chartEntityObject = obj;

// Retrieve datasets
mx.data.get({
guids: obj.get(this._dataset),
callback: lang.hitch(this, function(datasets) {
var set = null;
this._data.datasets = [];

for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];

set = {
dataset: dataset,
sorting: +(dataset.get(this.datasetsorting))
};
this._data.datasets.push(set);
}
this._processData();
})
});
} else {
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
}
}), this._mxObj);

},
Expand Down
56 changes: 30 additions & 26 deletions src/ChartJS/widgets/PolarChart/widget/PolarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,36 @@ define([
logger.debug(this.id + "._loadData");

this._executeMicroflow(this.datasourcemf, lang.hitch(this, function (objs) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null;

this._data.object = obj;
this._chartEntityObject = obj;

// Retrieve datasets
mx.data.get({
guids : obj.get(this._dataset),
callback : lang.hitch(this, function (datasets) {
var set = null;
this._data.datasets = [];

for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];

set = {
dataset : dataset,
sorting : +(dataset.get(this.datasetsorting))
};
this._data.datasets.push(set);
}
this._processData();
})
});
if (objs && objs.length > 0) {
var obj = objs[0], // Chart object is always only one.
j = null,
dataset = null;

this._data.object = obj;
this._chartEntityObject = obj;

// Retrieve datasets
mx.data.get({
guids : obj.get(this._dataset),
callback : lang.hitch(this, function (datasets) {
var set = null;
this._data.datasets = [];

for (j = 0; j < datasets.length; j++) {
dataset = datasets[j];

set = {
dataset : dataset,
sorting : +(dataset.get(this.datasetsorting))
};
this._data.datasets.push(set);
}
this._processData();
})
});
} else {
console.warn(this.id + "._loadData execution of microflow:" + this.datasourcemf + " has not returned any objects.");
}
}), this._mxObj);

},
Expand Down

0 comments on commit c1a55e5

Please sign in to comment.