Skip to content

Commit

Permalink
Fix spinner that gets in the way of mouseover events (#63)
Browse files Browse the repository at this point in the history
* Fixes #62: mouseover interactions with charts not working due to spinner container getting in the way. this ensures we remove the container as well as the spinner once chart data is loaded.

* Make sure tests load in spin.js, add tests for ensuring spinner container are removed upon stopping, add a "spinner-container" class to the created spinner container.
  • Loading branch information
filmaj authored and larsxschneider committed Dec 14, 2017
1 parent 1ad0910 commit 6d1ee9c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
10 changes: 8 additions & 2 deletions docs/assets/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ var stackedBarChartDefaults =

function createSpinner(canvas)
{
let parent = $("<div style=\"position:absolute;height:100%;width:100%;\"></div>");
let parent = $("<div style=\"position:absolute;height:100%;width:100%;\" class=\"spinner-container\"></div>");
parent.insertBefore($(canvas));
return new Spinner().spin(parent[0]);
let spinner = new Spinner().spin(parent[0]);
return {
stop: function() {
spinner.stop();
parent.remove();
}
};
}

function createHistoryChart(canvas)
Expand Down
27 changes: 26 additions & 1 deletion docs/spec/charts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global createCollaborationChart, createHistoryChart, createList, createTable */
/* global createCollaborationChart, createHistoryChart, createList, createTable, createSpinner */

describe("global charts.js", function() {
describe("createCollaborationChart function", function() {
Expand All @@ -21,4 +21,29 @@ describe("global charts.js", function() {
expect(createTable).toBeDefined();
});
});
describe("createSpinner function", function() {
let canvas;
beforeEach(function() {
canvas = $("<div id=\"test\"></div>");
$("body").append(canvas);
});
afterEach(function() {
canvas.remove();
});
it("should exist", function() {
expect(createSpinner).toBeDefined();
});
it("should return an object with a stop method", function() {
let spinner = createSpinner(canvas[0]);
expect(spinner.stop).toBeDefined();
spinner.stop();
});
describe("stop method", function() {
it("should destroy the spinner container after execution", function() {
let spinner = createSpinner(canvas[0]);
spinner.stop();
expect($(".spinner-container").length).toEqual(0);
});
});
});
});
1 change: 1 addition & 0 deletions docs/spec/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = function(config) {
'assets/js/vendor/d3.v4.min.js',
'assets/js/vendor/moment-with-locales.min.js',
'assets/js/vendor/Chart-2.7.1.min.js',
'assets/js/vendor/spin-2.3.2.min.js',
'assets/js/charts.js',
'spec/*.js'
],
Expand Down

0 comments on commit 6d1ee9c

Please sign in to comment.