mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Add an error message if the graph placeholder isn't found.
This commit is contained in:
parent
c66a723acc
commit
2108baaf4e
@ -14,6 +14,10 @@ class Morris.Line
|
|||||||
@el = $ document.getElementById(options.element)
|
@el = $ document.getElementById(options.element)
|
||||||
else
|
else
|
||||||
@el = $ options.element
|
@el = $ options.element
|
||||||
|
|
||||||
|
if @el == null || @el.length == 0
|
||||||
|
throw new Error("Graph placeholder not found.")
|
||||||
|
|
||||||
@options = $.extend {}, @defaults, options
|
@options = $.extend {}, @defaults, options
|
||||||
# backwards compatibility for units -> postUnits
|
# backwards compatibility for units -> postUnits
|
||||||
if typeof @options.units is 'string'
|
if typeof @options.units is 'string'
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
} else {
|
} else {
|
||||||
this.el = $(options.element);
|
this.el = $(options.element);
|
||||||
}
|
}
|
||||||
|
if (this.el === null || this.el.length === 0) {
|
||||||
|
throw new Error("Graph placeholder not found.");
|
||||||
|
}
|
||||||
this.options = $.extend({}, this.defaults, options);
|
this.options = $.extend({}, this.defaults, options);
|
||||||
if (typeof this.options.units === 'string') {
|
if (typeof this.options.units === 'string') {
|
||||||
this.options.postUnits = options.units;
|
this.options.postUnits = options.units;
|
||||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
module("Morris");
|
module("Morris");
|
||||||
|
|
||||||
test("Input data remains untouched", function() {
|
test("Input data remains untouched", function () {
|
||||||
var my_data = [{x: 1, y: 1}, {x: 2, y: 2}];
|
var my_data = [{x: 1, y: 1}, {x: 2, y: 2}];
|
||||||
var expected_data = [{x: 1, y: 1}, {x: 2, y: 2}];
|
var expected_data = [{x: 1, y: 1}, {x: 2, y: 2}];
|
||||||
Morris.Line({
|
Morris.Line({
|
||||||
@ -24,6 +24,18 @@
|
|||||||
deepEqual(my_data, expected_data);
|
deepEqual(my_data, expected_data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Nicer error when the placeholder was not found.", function () {
|
||||||
|
var my_data = [{x: 1, y: 1}, {x: 2, y: 2}];
|
||||||
|
raises(function() {
|
||||||
|
Morris.Line({
|
||||||
|
element: "thisplacedoesnotexist",
|
||||||
|
data: my_data,
|
||||||
|
xkey: 'x',
|
||||||
|
ykeys: ['y'],
|
||||||
|
labels: ['dontcare']})
|
||||||
|
}, "Graph placeholder not found.");
|
||||||
|
});
|
||||||
|
|
||||||
test("Morris.commas", function () {
|
test("Morris.commas", function () {
|
||||||
// zero
|
// zero
|
||||||
equal(Morris.commas(0), "0", "commas(0) = 0")
|
equal(Morris.commas(0), "0", "commas(0) = 0")
|
||||||
|
Loading…
Reference in New Issue
Block a user