Skip to content

Commit

Permalink
Refactor method loadData for single set widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelte Lagendijk committed May 10, 2017
1 parent e547bac commit 208cf07
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 112 deletions.
36 changes: 36 additions & 0 deletions src/ChartJS/widgets/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,42 @@ define([

},

_loadDataSingleSet: function () {
logger.debug(this.id + "._loadDataSingleSet");
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
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 + "._loadDataSingleSet execution of microflow:" + this.datasourcemf + " has not returned any objects.");
}
}), this._mxObj);
},

uninitialize: function () {
logger.debug(this.id + ".uninitialize");

Expand Down
44 changes: 5 additions & 39 deletions src/ChartJS/widgets/DoughnutChart/widget/DoughnutChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,7 @@ define([
},

_loadData: function() {
logger.debug(this.id + "._loadData");
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
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);

this._loadDataSingleSet();
},

_createChart: function(data) {
Expand Down Expand Up @@ -138,10 +104,10 @@ define([
this._resize();
}));

var content = this._data.object.get(this.numberInside);

// Set the con
html.set(this._numberNode, content !== null ? content.toString() : "");
if (this.numberInside) {
var content = this._data.object.get(this.numberInside);
html.set(this._numberNode, content !== null ? content.toString() : "");
}

// Add class to determain chart type
this._addChartClass("chartjs-doughnut-chart");
Expand Down
43 changes: 5 additions & 38 deletions src/ChartJS/widgets/PieChart/widget/PieChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,7 @@ define([
},

_loadData: function() {
logger.debug(this.id + "._loadData");
this._executeMicroflow(this.datasourcemf, lang.hitch(this, function(objs) {
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);

this._loadDataSingleSet();
},

_createChart: function(data) {
Expand Down Expand Up @@ -139,10 +106,10 @@ define([
};
this._chart = new this._chartJS(this._ctx, chartProperties);

var content = this._data.object.get(this.numberInside);

// Set the con
html.set(this._numberNode, content !== null ? content.toString() : "");
if (this.numberInside) {
var content = this._data.object.get(this.numberInside);
html.set(this._numberNode, content !== null ? content.toString() : "");
}

// Add class to determain chart type
this._addChartClass("chartjs-pie-chart");
Expand Down
36 changes: 1 addition & 35 deletions src/ChartJS/widgets/PolarChart/widget/PolarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,7 @@ define([
},

_loadData : function () {
logger.debug(this.id + "._loadData");

this._executeMicroflow(this.datasourcemf, lang.hitch(this, function (objs) {
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);

this._loadDataSingleSet();
},

_createChart : function (data) {
Expand Down

0 comments on commit 208cf07

Please sign in to comment.