mirror of https://github.com/vitalif/dimple
Merge pull request #46 from PMSI-AlignAlytics/pr/45
Extended David's idea to cover unlinked datasetsmaster
commit
b90908bb33
|
@ -228,14 +228,17 @@ var dimple = {
|
||||||
origin,
|
origin,
|
||||||
getOrderedCategories = function (self, axPos, oppPos) {
|
getOrderedCategories = function (self, axPos, oppPos) {
|
||||||
var category = self.categoryFields[0],
|
var category = self.categoryFields[0],
|
||||||
|
chartData = self.chart._getAllData(),
|
||||||
sortBy = category,
|
sortBy = category,
|
||||||
desc = false,
|
desc = false,
|
||||||
isDate = true,
|
isDate = true,
|
||||||
|
currentValue = null,
|
||||||
i,
|
i,
|
||||||
definitions = [];
|
definitions = [];
|
||||||
// Check whether this field is a date
|
// Check whether this field is a date
|
||||||
for (i = 0; i < self.chart.data.length; i += 1) {
|
for (i = 0; i < chartData.length; i += 1) {
|
||||||
if (isNaN(self._parseDate(self.chart.data[i][category]))) {
|
currentValue = self._parseDate(chartData[i][category]);
|
||||||
|
if (currentValue !== null && currentValue !== undefined && isNaN(currentValue)) {
|
||||||
isDate = false;
|
isDate = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +253,7 @@ var dimple = {
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
definitions = self._orderRules.concat({ ordering : sortBy, desc : desc });
|
definitions = self._orderRules.concat({ ordering : sortBy, desc : desc });
|
||||||
return dimple._getOrderedList(self.chart.data, category, definitions);
|
return dimple._getOrderedList(chartData, category, definitions);
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the axis is a percentage type axis the bounds must be between -1 and 1. Sometimes
|
// If the axis is a percentage type axis the bounds must be between -1 and 1. Sometimes
|
||||||
|
@ -495,6 +498,30 @@ var dimple = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Copyright: 2013 PMSI-AlignAlytics
|
||||||
|
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
|
||||||
|
// Source: /src/objects/chart/methods/_getAllData.js
|
||||||
|
// Mash together all of the datasets
|
||||||
|
this._getAllData = function () {
|
||||||
|
// The return array will include all data for chart as well as an series
|
||||||
|
var returnData = [];
|
||||||
|
// If there is data at the chart level
|
||||||
|
if (this.data !== null && this.data !== undefined && this.data.length > 0) {
|
||||||
|
returnData = returnData.concat(this.data);
|
||||||
|
}
|
||||||
|
// If there are series defined
|
||||||
|
if (this.series !== null && this.series !== undefined && this.series.length > 0) {
|
||||||
|
this.series.forEach(function (s) {
|
||||||
|
if (s.data !== null && s.data !== undefined && s.data.length > 0) {
|
||||||
|
returnData = returnData.concat(s.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Return the final dataset
|
||||||
|
return returnData;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Copyright: 2013 PMSI-AlignAlytics
|
// Copyright: 2013 PMSI-AlignAlytics
|
||||||
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
|
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
|
||||||
// Source: /src/objects/chart/methods/_getSeriesData.js
|
// Source: /src/objects/chart/methods/_getSeriesData.js
|
||||||
|
@ -544,22 +571,22 @@ var dimple = {
|
||||||
yCat = "",
|
yCat = "",
|
||||||
ySortArray = [],
|
ySortArray = [],
|
||||||
rules = [],
|
rules = [],
|
||||||
sortedData =series.data || this.data,
|
sortedData = series.data || this.data,
|
||||||
groupRules = [];
|
groupRules = [];
|
||||||
|
|
||||||
if (this.storyboard !== null && this.storyboard !== undefined && this.storyboard.categoryFields.length > 0) {
|
if (this.storyboard !== null && this.storyboard !== undefined && this.storyboard.categoryFields.length > 0) {
|
||||||
storyCat = this.storyboard.categoryFields[0];
|
storyCat = this.storyboard.categoryFields[0];
|
||||||
orderedStoryboardArray = dimple._getOrderedList(this.data, storyCat, this.storyboard._orderRules);
|
orderedStoryboardArray = dimple._getOrderedList(sortedData, storyCat, this.storyboard._orderRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deal with mekkos
|
// Deal with mekkos
|
||||||
if (series.x._hasCategories() && series.x._hasMeasure()) {
|
if (series.x._hasCategories() && series.x._hasMeasure()) {
|
||||||
xCat = series.x.categoryFields[0];
|
xCat = series.x.categoryFields[0];
|
||||||
xSortArray = dimple._getOrderedList(this.data, xCat, series.x._orderRules.concat([{ ordering : series.x.measure, desc : true }]));
|
xSortArray = dimple._getOrderedList(sortedData, xCat, series.x._orderRules.concat([{ ordering : series.x.measure, desc : true }]));
|
||||||
}
|
}
|
||||||
if (series.y._hasCategories() && series.y._hasMeasure()) {
|
if (series.y._hasCategories() && series.y._hasMeasure()) {
|
||||||
yCat = series.y.categoryFields[0];
|
yCat = series.y.categoryFields[0];
|
||||||
ySortArray = dimple._getOrderedList(this.data, yCat, series.y._orderRules.concat([{ ordering : series.y.measure, desc : true }]));
|
ySortArray = dimple._getOrderedList(sortedData, yCat, series.y._orderRules.concat([{ ordering : series.y.measure, desc : true }]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (series.categoryFields !== null && series.categoryFields !== undefined && series.categoryFields.length > 0) {
|
if (series.categoryFields !== null && series.categoryFields !== undefined && series.categoryFields.length > 0) {
|
||||||
|
@ -576,7 +603,7 @@ var dimple = {
|
||||||
} else if (series.y._hasMeasure()) {
|
} else if (series.y._hasMeasure()) {
|
||||||
rules.push({ ordering : series.y.measure, desc : true });
|
rules.push({ ordering : series.y.measure, desc : true });
|
||||||
}
|
}
|
||||||
orderedSeriesArray = dimple._getOrderedList(this.data, seriesCat, rules);
|
orderedSeriesArray = dimple._getOrderedList(sortedData, seriesCat, rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortedData.sort(function (a, b) {
|
sortedData.sort(function (a, b) {
|
||||||
|
@ -721,14 +748,14 @@ var dimple = {
|
||||||
if (series.y._hasMeasure()) {
|
if (series.y._hasMeasure()) {
|
||||||
groupRules.push({ ordering : series.y.measure, desc : true });
|
groupRules.push({ ordering : series.y.measure, desc : true });
|
||||||
}
|
}
|
||||||
secondaryElements.x = dimple._getOrderedList(this.data, series.x.categoryFields[1], series.x._groupOrderRules.concat(groupRules));
|
secondaryElements.x = dimple._getOrderedList(sortedData, series.x.categoryFields[1], series.x._groupOrderRules.concat(groupRules));
|
||||||
}
|
}
|
||||||
if (series.y !== null && series.y !== undefined && series.y._hasCategories() && series.y.categoryFields.length > 1 && secondaryElements.y !== undefined) {
|
if (series.y !== null && series.y !== undefined && series.y._hasCategories() && series.y.categoryFields.length > 1 && secondaryElements.y !== undefined) {
|
||||||
groupRules = [];
|
groupRules = [];
|
||||||
if (series.x._hasMeasure()) {
|
if (series.x._hasMeasure()) {
|
||||||
groupRules.push({ ordering : series.x.measure, desc : true });
|
groupRules.push({ ordering : series.x.measure, desc : true });
|
||||||
}
|
}
|
||||||
secondaryElements.y = dimple._getOrderedList(this.data, series.y.categoryFields[1], series.y._groupOrderRules.concat(groupRules));
|
secondaryElements.y = dimple._getOrderedList(sortedData, series.y.categoryFields[1], series.y._groupOrderRules.concat(groupRules));
|
||||||
secondaryElements.y.reverse();
|
secondaryElements.y.reverse();
|
||||||
}
|
}
|
||||||
returnData.forEach(function (ret) {
|
returnData.forEach(function (ret) {
|
||||||
|
@ -1147,7 +1174,7 @@ var dimple = {
|
||||||
// in a real context, but when developing it is nice to see axes before any series have
|
// in a real context, but when developing it is nice to see axes before any series have
|
||||||
// been added.
|
// been added.
|
||||||
if (!linked) {
|
if (!linked) {
|
||||||
this.data.forEach(function (d) {
|
this._getAllData().forEach(function (d) {
|
||||||
if (axis._min > d[axis.measure]) { axis._min = d[axis.measure]; }
|
if (axis._min > d[axis.measure]) { axis._min = d[axis.measure]; }
|
||||||
if (axis._max < d[axis.measure]) { axis._max = d[axis.measure]; }
|
if (axis._max < d[axis.measure]) { axis._max = d[axis.measure]; }
|
||||||
}, this);
|
}, this);
|
||||||
|
@ -1156,7 +1183,7 @@ var dimple = {
|
||||||
// Parse the dates and assign the min and max
|
// Parse the dates and assign the min and max
|
||||||
axis._min = null;
|
axis._min = null;
|
||||||
axis._max = null;
|
axis._max = null;
|
||||||
this.data.forEach(function (d) {
|
this._getAllData().forEach(function (d) {
|
||||||
var dt = axis._parseDate(d[axis.timeField]);
|
var dt = axis._parseDate(d[axis.timeField]);
|
||||||
if (axis._min === null || dt < axis._min) {
|
if (axis._min === null || dt < axis._min) {
|
||||||
axis._min = dt;
|
axis._min = dt;
|
||||||
|
@ -1169,7 +1196,7 @@ var dimple = {
|
||||||
// A category axis is just set to show the number of categories
|
// A category axis is just set to show the number of categories
|
||||||
axis._min = 0;
|
axis._min = 0;
|
||||||
distinctCats = [];
|
distinctCats = [];
|
||||||
this.data.forEach(function (d) {
|
this._getAllData().forEach(function (d) {
|
||||||
if (distinctCats.indexOf(d[axis.categoryFields[0]]) === -1) {
|
if (distinctCats.indexOf(d[axis.categoryFields[0]]) === -1) {
|
||||||
distinctCats.push(d[axis.categoryFields[0]]);
|
distinctCats.push(d[axis.categoryFields[0]]);
|
||||||
}
|
}
|
||||||
|
@ -2122,7 +2149,7 @@ var dimple = {
|
||||||
// Clear the array
|
// Clear the array
|
||||||
this._categories = [];
|
this._categories = [];
|
||||||
// Iterate every row in the data
|
// Iterate every row in the data
|
||||||
this.chart.data.forEach(function (d) {
|
this.chart._getAllData().forEach(function (d) {
|
||||||
// Initialise the index of the categories array matching the current row
|
// Initialise the index of the categories array matching the current row
|
||||||
var index = -1,
|
var index = -1,
|
||||||
field = "";
|
field = "";
|
||||||
|
@ -4260,4 +4287,4 @@ var dimple = {
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
// End dimple
|
// End dimple
|
File diff suppressed because one or more lines are too long
|
@ -10,14 +10,17 @@
|
||||||
origin,
|
origin,
|
||||||
getOrderedCategories = function (self, axPos, oppPos) {
|
getOrderedCategories = function (self, axPos, oppPos) {
|
||||||
var category = self.categoryFields[0],
|
var category = self.categoryFields[0],
|
||||||
|
chartData = self.chart._getAllData(),
|
||||||
sortBy = category,
|
sortBy = category,
|
||||||
desc = false,
|
desc = false,
|
||||||
isDate = true,
|
isDate = true,
|
||||||
|
currentValue = null,
|
||||||
i,
|
i,
|
||||||
definitions = [];
|
definitions = [];
|
||||||
// Check whether this field is a date
|
// Check whether this field is a date
|
||||||
for (i = 0; i < self.chart.data.length; i += 1) {
|
for (i = 0; i < chartData.length; i += 1) {
|
||||||
if (isNaN(self._parseDate(self.chart.data[i][category]))) {
|
currentValue = self._parseDate(chartData[i][category]);
|
||||||
|
if (currentValue !== null && currentValue !== undefined && isNaN(currentValue)) {
|
||||||
isDate = false;
|
isDate = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +35,7 @@
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
definitions = self._orderRules.concat({ ordering : sortBy, desc : desc });
|
definitions = self._orderRules.concat({ ordering : sortBy, desc : desc });
|
||||||
return dimple._getOrderedList(self.chart.data, category, definitions);
|
return dimple._getOrderedList(chartData, category, definitions);
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the axis is a percentage type axis the bounds must be between -1 and 1. Sometimes
|
// If the axis is a percentage type axis the bounds must be between -1 and 1. Sometimes
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright: 2013 PMSI-AlignAlytics
|
||||||
|
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
|
||||||
|
// Source: /src/objects/chart/methods/_getAllData.js
|
||||||
|
// Mash together all of the datasets
|
||||||
|
this._getAllData = function () {
|
||||||
|
// The return array will include all data for chart as well as an series
|
||||||
|
var returnData = [];
|
||||||
|
// If there is data at the chart level
|
||||||
|
if (this.data !== null && this.data !== undefined && this.data.length > 0) {
|
||||||
|
returnData = returnData.concat(this.data);
|
||||||
|
}
|
||||||
|
// If there are series defined
|
||||||
|
if (this.series !== null && this.series !== undefined && this.series.length > 0) {
|
||||||
|
this.series.forEach(function (s) {
|
||||||
|
if (s.data !== null && s.data !== undefined && s.data.length > 0) {
|
||||||
|
returnData = returnData.concat(s.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Return the final dataset
|
||||||
|
return returnData;
|
||||||
|
};
|
||||||
|
|
|
@ -47,22 +47,22 @@
|
||||||
yCat = "",
|
yCat = "",
|
||||||
ySortArray = [],
|
ySortArray = [],
|
||||||
rules = [],
|
rules = [],
|
||||||
sortedData = this.data,
|
sortedData = series.data || this.data,
|
||||||
groupRules = [];
|
groupRules = [];
|
||||||
|
|
||||||
if (this.storyboard !== null && this.storyboard !== undefined && this.storyboard.categoryFields.length > 0) {
|
if (this.storyboard !== null && this.storyboard !== undefined && this.storyboard.categoryFields.length > 0) {
|
||||||
storyCat = this.storyboard.categoryFields[0];
|
storyCat = this.storyboard.categoryFields[0];
|
||||||
orderedStoryboardArray = dimple._getOrderedList(this.data, storyCat, this.storyboard._orderRules);
|
orderedStoryboardArray = dimple._getOrderedList(sortedData, storyCat, this.storyboard._orderRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deal with mekkos
|
// Deal with mekkos
|
||||||
if (series.x._hasCategories() && series.x._hasMeasure()) {
|
if (series.x._hasCategories() && series.x._hasMeasure()) {
|
||||||
xCat = series.x.categoryFields[0];
|
xCat = series.x.categoryFields[0];
|
||||||
xSortArray = dimple._getOrderedList(this.data, xCat, series.x._orderRules.concat([{ ordering : series.x.measure, desc : true }]));
|
xSortArray = dimple._getOrderedList(sortedData, xCat, series.x._orderRules.concat([{ ordering : series.x.measure, desc : true }]));
|
||||||
}
|
}
|
||||||
if (series.y._hasCategories() && series.y._hasMeasure()) {
|
if (series.y._hasCategories() && series.y._hasMeasure()) {
|
||||||
yCat = series.y.categoryFields[0];
|
yCat = series.y.categoryFields[0];
|
||||||
ySortArray = dimple._getOrderedList(this.data, yCat, series.y._orderRules.concat([{ ordering : series.y.measure, desc : true }]));
|
ySortArray = dimple._getOrderedList(sortedData, yCat, series.y._orderRules.concat([{ ordering : series.y.measure, desc : true }]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (series.categoryFields !== null && series.categoryFields !== undefined && series.categoryFields.length > 0) {
|
if (series.categoryFields !== null && series.categoryFields !== undefined && series.categoryFields.length > 0) {
|
||||||
|
@ -79,7 +79,7 @@
|
||||||
} else if (series.y._hasMeasure()) {
|
} else if (series.y._hasMeasure()) {
|
||||||
rules.push({ ordering : series.y.measure, desc : true });
|
rules.push({ ordering : series.y.measure, desc : true });
|
||||||
}
|
}
|
||||||
orderedSeriesArray = dimple._getOrderedList(this.data, seriesCat, rules);
|
orderedSeriesArray = dimple._getOrderedList(sortedData, seriesCat, rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortedData.sort(function (a, b) {
|
sortedData.sort(function (a, b) {
|
||||||
|
@ -224,14 +224,14 @@
|
||||||
if (series.y._hasMeasure()) {
|
if (series.y._hasMeasure()) {
|
||||||
groupRules.push({ ordering : series.y.measure, desc : true });
|
groupRules.push({ ordering : series.y.measure, desc : true });
|
||||||
}
|
}
|
||||||
secondaryElements.x = dimple._getOrderedList(this.data, series.x.categoryFields[1], series.x._groupOrderRules.concat(groupRules));
|
secondaryElements.x = dimple._getOrderedList(sortedData, series.x.categoryFields[1], series.x._groupOrderRules.concat(groupRules));
|
||||||
}
|
}
|
||||||
if (series.y !== null && series.y !== undefined && series.y._hasCategories() && series.y.categoryFields.length > 1 && secondaryElements.y !== undefined) {
|
if (series.y !== null && series.y !== undefined && series.y._hasCategories() && series.y.categoryFields.length > 1 && secondaryElements.y !== undefined) {
|
||||||
groupRules = [];
|
groupRules = [];
|
||||||
if (series.x._hasMeasure()) {
|
if (series.x._hasMeasure()) {
|
||||||
groupRules.push({ ordering : series.x.measure, desc : true });
|
groupRules.push({ ordering : series.x.measure, desc : true });
|
||||||
}
|
}
|
||||||
secondaryElements.y = dimple._getOrderedList(this.data, series.y.categoryFields[1], series.y._groupOrderRules.concat(groupRules));
|
secondaryElements.y = dimple._getOrderedList(sortedData, series.y.categoryFields[1], series.y._groupOrderRules.concat(groupRules));
|
||||||
secondaryElements.y.reverse();
|
secondaryElements.y.reverse();
|
||||||
}
|
}
|
||||||
returnData.forEach(function (ret) {
|
returnData.forEach(function (ret) {
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
// in a real context, but when developing it is nice to see axes before any series have
|
// in a real context, but when developing it is nice to see axes before any series have
|
||||||
// been added.
|
// been added.
|
||||||
if (!linked) {
|
if (!linked) {
|
||||||
this.data.forEach(function (d) {
|
this._getAllData().forEach(function (d) {
|
||||||
if (axis._min > d[axis.measure]) { axis._min = d[axis.measure]; }
|
if (axis._min > d[axis.measure]) { axis._min = d[axis.measure]; }
|
||||||
if (axis._max < d[axis.measure]) { axis._max = d[axis.measure]; }
|
if (axis._max < d[axis.measure]) { axis._max = d[axis.measure]; }
|
||||||
}, this);
|
}, this);
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
// Parse the dates and assign the min and max
|
// Parse the dates and assign the min and max
|
||||||
axis._min = null;
|
axis._min = null;
|
||||||
axis._max = null;
|
axis._max = null;
|
||||||
this.data.forEach(function (d) {
|
this._getAllData().forEach(function (d) {
|
||||||
var dt = axis._parseDate(d[axis.timeField]);
|
var dt = axis._parseDate(d[axis.timeField]);
|
||||||
if (axis._min === null || dt < axis._min) {
|
if (axis._min === null || dt < axis._min) {
|
||||||
axis._min = dt;
|
axis._min = dt;
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
// A category axis is just set to show the number of categories
|
// A category axis is just set to show the number of categories
|
||||||
axis._min = 0;
|
axis._min = 0;
|
||||||
distinctCats = [];
|
distinctCats = [];
|
||||||
this.data.forEach(function (d) {
|
this._getAllData().forEach(function (d) {
|
||||||
if (distinctCats.indexOf(d[axis.categoryFields[0]]) === -1) {
|
if (distinctCats.indexOf(d[axis.categoryFields[0]]) === -1) {
|
||||||
distinctCats.push(d[axis.categoryFields[0]]);
|
distinctCats.push(d[axis.categoryFields[0]]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
// Clear the array
|
// Clear the array
|
||||||
this._categories = [];
|
this._categories = [];
|
||||||
// Iterate every row in the data
|
// Iterate every row in the data
|
||||||
this.chart.data.forEach(function (d) {
|
this.chart._getAllData().forEach(function (d) {
|
||||||
// Initialise the index of the categories array matching the current row
|
// Initialise the index of the categories array matching the current row
|
||||||
var index = -1,
|
var index = -1,
|
||||||
field = "";
|
field = "";
|
||||||
|
|
Loading…
Reference in New Issue