Skip to content
Snippets Groups Projects
Commit 4ac30af3 authored by Demian Katz's avatar Demian Katz
Browse files

Use variable instead of hard-coded value for clarity.

parent 4670dbbf
No related merge requests found
......@@ -51,6 +51,8 @@ function loadVis(facetFields, searchParams, baseURL, zooming) {
};
// AJAX call
var graphMargin = 5;
var url = baseURL + '/AJAX/json?method=getVisData&facetFields=' + encodeURIComponent(facetFields) + '&' + searchParams;
$.getJSON(url, function getVisDataJSON(data) {
$.each(data.data, function getVisDataEach(key, val) {
......@@ -73,24 +75,24 @@ function loadVis(facetFields, searchParams, baseURL, zooming) {
//check if the min and max value have been set otherwise set them to the ends of the graph
if (val.min === 0) {
val.min = val.data[0][0] - 5;
val.min = val.data[0][0] - graphMargin;
}
if (val.max === 0) {
val.max = parseInt(val.data[val.data.length - 1][0], 10) + 5;
val.max = parseInt(val.data[val.data.length - 1][0], 10) + graphMargin;
}
if (zooming && hasFilter) {
//check the first and last elements of the data array against min and max value (+padding)
//if the element exists leave it, otherwise create a new marker with a minus one value
if (val.data[val.data.length - 1][0] !== parseInt(val.max, 10) + 5) {
val.data.push([parseInt(val.max, 10) + 5, -1]);
if (val.data[val.data.length - 1][0] !== parseInt(val.max, 10) + graphMargin) {
val.data.push([parseInt(val.max, 10) + graphMargin, -1]);
}
if (val.data[0][0] !== val.min - 5) {
val.data.push([val.min - 5, -1]);
if (val.data[0][0] !== val.min - graphMargin) {
val.data.push([val.min - graphMargin, -1]);
}
//check for values outside the selected range and remove them by setting them to null
for (var i = 0; i < val.data.length; i++) {
if (val.data[i][0] < val.min - 5 || val.data[i][0] > parseInt(val.max, 10) + 5) {
if (val.data[i][0] < val.min - graphMargin || val.data[i][0] > parseInt(val.max, 10) + graphMargin) {
//remove this
val.data.splice(i, 1);
i--;
......@@ -100,9 +102,9 @@ function loadVis(facetFields, searchParams, baseURL, zooming) {
} else {
//no zooming means that we need to specifically set the margins
//do the last one first to avoid getting the new last element
val.data.push([parseInt(val.data[val.data.length - 1][0], 10) + 5, -1]);
val.data.push([parseInt(val.data[val.data.length - 1][0], 10) + graphMargin, -1]);
//now get the first element
val.data.push([val.data[0][0] - 5, -1]);
val.data.push([val.data[0][0] - graphMargin, -1]);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment