Skip to content

Commit

Permalink
Added data compliance testing and bug fixes to the charts.
Browse files Browse the repository at this point in the history
  • Loading branch information
laceysanderson committed Dec 29, 2017
1 parent 4ba09f5 commit 7c25f97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 44 deletions.
6 changes: 4 additions & 2 deletions js/tripalD3.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ tripalD3.bar = {
console.error("The data should be an ARRAY where each element has a label and a count.");
return false;
}
var errors = false;
data.forEach(function(element) {
if (!("label" in element)) {
console.error("Every element must be an object with a LABEL key. This element doesn't comply: " + JSON.stringify(element));
return false;
errors = true;
}
if (!("count" in element)) {
console.error("Every element must be an object with a COUNT key. This element doesn't comply: " + JSON.stringify(element));
return false;
errors = true;
}
});
if (errors) { return false; }

// Set Defaults.
if (!options.hasOwnProperty('xAxisTitle')) {
Expand Down
46 changes: 4 additions & 42 deletions js/tripalD3.pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,8 @@ tripalD3.pie = {
drawSimpleDonut: function(svg, data, options) {

// Check the data is compliant.
if (!Array.isArray(data)) {
console.error("The data should be an ARRAY where each element has a label and a count.");
return false;
}
data.forEach(function(element) {
if (!("label" in element)) {
console.error("Every element must be an object with a LABEL key. This element doesn't comply: " + JSON.stringify(element));
return false;
}
if (!("count" in element)) {
console.error("Every element must be an object with a COUNT key. This element doesn't comply: " + JSON.stringify(element));
return false;
}
});
var compliant = tripalD3.test.isSingleSeriesCompliant(data);
if (!compliant) {return false; }

// Set defaults.
if (!options.hasOwnProperty('width')) {
Expand Down Expand Up @@ -182,34 +170,8 @@ tripalD3.pie = {
drawMultiDonut: function(svg, data, options) {

// Check the data is compliant.
if (!Array.isArray(data)) {
console.error("The data should be an ARRAY where each element has a series label and a parts array.");
return false;
}
data.forEach(function(element) {
if (!("label" in element)) {
console.error("Every element must be an object with a LABEL key. This element doesn't comply: " + JSON.stringify(element));
return false;
}
if (!("parts" in element)) {
console.error("Every element must be an object with a PARTS key. This element doesn't comply: " + JSON.stringify(element));
return false;
}
if (!Array.isArray(data)) {
console.error("The value of the PARTS key should be an ARRAY. This element doesn't comply: " + JSON.stringify(element));
return false;
}
element.parts.forEach(function(subElement) {
if (!("label" in subElement)) {
console.error("Every PARTS element must be an object with a LABEL key. This element doesn't comply: " + JSON.stringify(subElement));
return false;
}
if (!("count" in subElement)) {
console.error("Every PARTS element must be an object with a COUNT key. This element doesn't comply: " + JSON.stringify(subElement));
return false;
}
});
});
var compliant = tripalD3.test.isMultiSeriesCompliant(data);
if (!compliant) { return false; }

// Set defaults.
if (!options.hasOwnProperty('width')) {
Expand Down

0 comments on commit 7c25f97

Please sign in to comment.