Skip to content

Commit 72ab3c1

Browse files
committed
Added sanity checks on data
1 parent 665f4db commit 72ab3c1

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

appserver/static/visualizations/ohlc/package-lock.json

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

appserver/static/visualizations/ohlc/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"c3": "^0.6.6",
1818
"d3": "^5.5.0",
1919
"jquery": "^2.2.4",
20-
"plotly": "^1.0.6",
2120
"plotly.js-dist": "^1.46.0",
2221
"regexp-replace-loader": "^1.0.1",
2322
"save": "^2.3.2",

appserver/static/visualizations/ohlc/src/visualization_source.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,24 @@ define([
6464
return;
6565
}
6666

67-
//This checks if all data being passed in are numbers and displays an error if not.
68-
// if (_.isNaN(data)) {
69-
// throw new SplunkVisualizationBase.VisualizationError(
70-
// 'This chart only supports numbers'
71-
// );
72-
// }
73-
7467
var columns = data.columns,
7568
retData = {};
7669

7770
$.each(data.fields, function(i, field){
7871
if (CURRENCY_PAIR_FIELDNAME === field.name.toLowerCase()) {
79-
retData[field.name.toLowerCase()] = $.unique(columns[i])[0];
72+
// Removing null values to avoid errors
73+
var filtered = columns[i].filter(function (el) {
74+
return el != null;
75+
});
76+
retData[field.name.toLowerCase()] = $.unique(filtered)[0];
8077
return true;
8178
}
79+
// Raise if null values found
80+
if ($.inArray(null, columns[i]) >= 0 && field.name.toLowerCase().indexOf("point") < 0) {
81+
throw new SplunkVisualizationBase.VisualizationError(
82+
'Null values for field "' + field.name + '" are not supported'
83+
);
84+
}
8285
retData[field.name.toLowerCase()] = columns[i];
8386
});
8487

appserver/static/visualizations/ohlc/visualization.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,24 @@ define(["api/SplunkVisualizationBase","api/SplunkVisualizationUtils"], function(
109109
return;
110110
}
111111

112-
//This checks if all data being passed in are numbers and displays an error if not.
113-
// if (_.isNaN(data)) {
114-
// throw new SplunkVisualizationBase.VisualizationError(
115-
// 'This chart only supports numbers'
116-
// );
117-
// }
118-
119112
var columns = data.columns,
120113
retData = {};
121114

122115
$.each(data.fields, function(i, field){
123116
if (CURRENCY_PAIR_FIELDNAME === field.name.toLowerCase()) {
124-
retData[field.name.toLowerCase()] = $.unique(columns[i])[0];
117+
// Removing null values to avoid errors
118+
var filtered = columns[i].filter(function (el) {
119+
return el != null;
120+
});
121+
retData[field.name.toLowerCase()] = $.unique(filtered)[0];
125122
return true;
126123
}
124+
// Raise if null values found
125+
if ($.inArray(null, columns[i]) >= 0 && field.name.toLowerCase().indexOf("point") < 0) {
126+
throw new SplunkVisualizationBase.VisualizationError(
127+
'Null values for field "' + field.name + '" are not supported'
128+
);
129+
}
127130
retData[field.name.toLowerCase()] = columns[i];
128131
});
129132

0 commit comments

Comments
 (0)