var srcDir = './src/';
var outDir = './dist/';
+var testDir = './test/';
var header = "/*!\n" +
" * Chart.js\n" +
function lintTask() {
var files = [
srcDir + '**/*.js',
+ testDir + '**/*.js'
];
// NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
rules: {
'complexity': [1, 6],
'max-statements': [1, 30]
- }
+ },
+ globals: [
+ 'Chart',
+ 'acquireChart',
+ 'afterAll',
+ 'afterEach',
+ 'beforeAll',
+ 'beforeEach',
+ 'describe',
+ 'expect',
+ 'it',
+ 'jasmine',
+ 'moment',
+ 'spyOn'
+ ]
};
return gulp.src(files)
type: 'bar',
data: {
datasets: [
- { data: [] },
- { data: [] }
+ {data: []},
+ {data: []}
],
labels: []
}
type: 'bar',
data: {
datasets: [
- { data: [] },
- { data: [] }
+ {data: []},
+ {data: []}
],
labels: []
},
type: 'bar',
data: {
datasets: [
- { data: [], type: 'line' },
- { data: [], hidden: true },
- { data: [] },
- { data: [] }
+ {data: [], type: 'line'},
+ {data: [], hidden: true},
+ {data: []},
+ {data: []}
],
labels: []
}
type: 'bar',
data: {
datasets: [
- { data: [] },
- { data: [], hidden: true },
- { data: [], type: 'line' },
- { data: [] }
+ {data: []},
+ {data: [], hidden: true},
+ {data: [], type: 'line'},
+ {data: []}
],
labels: []
}
type: 'bar',
data: {
datasets: [
- { data: [] },
- { data: [10, 15, 0, -4] }
+ {data: []},
+ {data: [10, 15, 0, -4]}
],
labels: []
}
expect(meta.data.length).toBe(2);
- [ { x: 122, y: 484 },
- { x: 234, y: 32 }
+ [
+ {x: 122, y: 484},
+ {x: 234, y: 32}
].forEach(function(expected, i) {
expect(meta.data[i]._datasetIndex).toBe(1);
expect(meta.data[i]._index).toBe(i);
var meta0 = chart.getDatasetMeta(0);
- [ { b: 290, w: 91, x: 95, y: 161 },
- { b: 290, w: 91, x: 209, y: 419 },
- { b: 290, w: 91, x: 322, y: 161 },
- { b: 290, w: 91, x: 436, y: 419 }
+ [
+ {b: 290, w: 91, x: 95, y: 161},
+ {b: 290, w: 91, x: 209, y: 419},
+ {b: 290, w: 91, x: 322, y: 161},
+ {b: 290, w: 91, x: 436, y: 419}
].forEach(function(values, i) {
expect(meta0.data[i]._model.base).toBeCloseToPixel(values.b);
expect(meta0.data[i]._model.width).toBeCloseToPixel(values.w);
var meta1 = chart.getDatasetMeta(1);
- [ { b: 161, w: 91, x: 95, y: 32 },
- { b: 290, w: 91, x: 209, y: 97 },
- { b: 161, w: 91, x: 322, y: 161 },
- { b: 419, w: 91, x: 436, y: 471 }
+ [
+ {b: 161, w: 91, x: 95, y: 32},
+ {b: 290, w: 91, x: 209, y: 97},
+ {b: 161, w: 91, x: 322, y: 161},
+ {b: 419, w: 91, x: 436, y: 471}
].forEach(function(values, i) {
expect(meta1.data[i]._model.base).toBeCloseToPixel(values.b);
expect(meta1.data[i]._model.width).toBeCloseToPixel(values.w);
var meta0 = chart.getDatasetMeta(0);
- [ { b: 290, w: 91, x: 95, y: 161 },
- { b: 290, w: 91, x: 209, y: 419 },
- { b: 290, w: 91, x: 322, y: 161 },
- { b: 290, w: 91, x: 436, y: 419 }
+ [
+ {b: 290, w: 91, x: 95, y: 161},
+ {b: 290, w: 91, x: 209, y: 419},
+ {b: 290, w: 91, x: 322, y: 161},
+ {b: 290, w: 91, x: 436, y: 419}
].forEach(function(values, i) {
expect(meta0.data[i]._model.base).toBeCloseToPixel(values.b);
expect(meta0.data[i]._model.width).toBeCloseToPixel(values.w);
var meta1 = chart.getDatasetMeta(1);
- [ { b: 161, w: 91, x: 95, y: 32 },
- { b: 290, w: 91, x: 209, y: 97 },
- { b: 161, w: 91, x: 322, y: 161 },
- { b: 419, w: 91, x: 436, y: 471 }
+ [
+ {b: 161, w: 91, x: 95, y: 32},
+ {b: 290, w: 91, x: 209, y: 97},
+ {b: 161, w: 91, x: 322, y: 161},
+ {b: 419, w: 91, x: 436, y: 471}
].forEach(function(values, i) {
expect(meta1.data[i]._model.base).toBeCloseToPixel(values.b);
expect(meta1.data[i]._model.width).toBeCloseToPixel(values.w);
var meta = chart.getDatasetMeta(0);
- [ { r: 5, x: 38, y: 32 },
- { r: 1, x: 189, y: 484 },
- { r: 2, x: 341, y: 461 },
- { r: 1, x: 492, y: 32 }
+ [
+ {r: 5, x: 38, y: 32},
+ {r: 1, x: 189, y: 484},
+ {r: 2, x: 341, y: 461},
+ {r: 1, x: 492, y: 32}
].forEach(function(expected, i) {
expect(meta.data[i]._model.radius).toBe(expected.r);
expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x);
expect(meta.data.length).toBe(4);
- [ { c: 0 },
- { c: 0 },
- { c: 0, },
- { c: 0 }
+ [
+ {c: 0},
+ {c: 0},
+ {c: 0},
+ {c: 0}
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(256);
expect(meta.data[i]._model.y).toBeCloseToPixel(272);
borderColor: 'rgb(0, 0, 255)',
borderWidth: 2
}));
- })
+ });
chart.update();
- [ { c: 1.7453292519, s: -1.5707963267, e: 0.1745329251 },
- { c: 2.0943951023, s: 0.1745329251, e: 2.2689280275 },
- { c: 0, s: 2.2689280275, e: 2.2689280275 },
- { c: 2.4434609527, s: 2.2689280275, e: 4.7123889803 }
+ [
+ {c: 1.7453292519, s: -1.5707963267, e: 0.1745329251},
+ {c: 2.0943951023, s: 0.1745329251, e: 2.2689280275},
+ {c: 0, s: 2.2689280275, e: 2.2689280275},
+ {c: 2.4434609527, s: 2.2689280275, e: 4.7123889803}
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(256);
expect(meta.data[i]._model.y).toBeCloseToPixel(272);
borderColor: 'rgb(0, 0, 255)',
borderWidth: 2
}));
- })
+ });
// Change the amount of data and ensure that arcs are updated accordingly
chart.data.datasets[1].data = [1, 2]; // remove 2 elements from dataset 0
expect(meta.data.length).toBe(2);
// Only startAngle, endAngle and circumference should be different.
- [ { c: Math.PI / 8, s: Math.PI, e: Math.PI + Math.PI / 8 },
- { c: 3 * Math.PI / 8, s: Math.PI + Math.PI / 8, e: Math.PI + Math.PI / 2 }
+ [
+ {c: Math.PI / 8, s: Math.PI, e: Math.PI + Math.PI / 8},
+ {c: 3 * Math.PI / 8, s: Math.PI + Math.PI / 8, e: Math.PI + Math.PI / 2}
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(495);
expect(meta.data[i]._model.y).toBeCloseToPixel(511);
expect(meta.data[i]._model.outerRadius).toBeCloseToPixel(478);
expect(meta.data[i]._model.innerRadius).toBeCloseToPixel(359);
- expect(meta.data[i]._model.circumference).toBeCloseTo(expected.c,8);
+ expect(meta.data[i]._model.circumference).toBeCloseTo(expected.c, 8);
expect(meta.data[i]._model.startAngle).toBeCloseTo(expected.s, 8);
expect(meta.data[i]._model.endAngle).toBeCloseTo(expected.e, 8);
- })
+ });
});
it ('should draw all arcs', function() {
var chart = window.acquireChart({
type: 'line',
data: {
- datasets: [{
- data: [10, 15, 0, -4],
- label: 'dataset',
- xAxisID: 'firstXScaleID',
- yAxisID: 'firstYScaleID'
- }],
+ datasets: [{
+ data: [10, 15, 0, -4],
+ label: 'dataset',
+ xAxisID: 'firstXScaleID',
+ yAxisID: 'firstYScaleID'
+ }],
labels: ['label1', 'label2', 'label3', 'label4']
},
options: {
expect(meta.data.length).toBe(2);
- [ { x: 44, y: 484 },
- { x: 193, y: 32 }
+ [
+ {x: 44, y: 484},
+ {x: 193, y: 32}
].forEach(function(expected, i) {
expect(meta.data[i]._datasetIndex).toBe(0);
expect(meta.data[i]._index).toBe(i);
expect(meta.data.length).toBe(3); // should add a new meta data item
});
- it('should correctly calculate x scale for label and point', function(){
- var chart = window.acquireChart({
+ it('should correctly calculate x scale for label and point', function() {
+ var chart = window.acquireChart({
type: 'line',
- data: {
- labels: ["One"],
- datasets: [{
- data: [1],
- }]
+ data: {
+ labels: ['One'],
+ datasets: [{
+ data: [1],
+ }]
+ },
+ options: {
+ hover: {
+ mode: 'single'
},
- options: {
- hover: {
- mode: 'single'
- },
scales: {
yAxes: [{
ticks: {
- beginAtZero:true
+ beginAtZero: true
}
}]
}
expect(point._model.x).toBeCloseToPixel(267);
// 2 points
- chart.data.labels = ["One", "Two"];
+ chart.data.labels = ['One', 'Two'];
chart.data.datasets[0].data = [1, 2];
chart.update();
expect(points[1]._model.x).toBeCloseToPixel(498);
// 3 points
- chart.data.labels = ["One", "Two", "Three"];
+ chart.data.labels = ['One', 'Two', 'Three'];
chart.data.datasets[0].data = [1, 2, 3];
chart.update();
expect(points[2]._model.x).toBeCloseToPixel(493);
// 4 points
- chart.data.labels = ["One", "Two", "Three", "Four"];
+ chart.data.labels = ['One', 'Two', 'Three', 'Four'];
chart.data.datasets[0].data = [1, 2, 3, 4];
chart.update();
var meta0 = chart.getDatasetMeta(0);
- [ { x: 38, y: 161 },
- { x: 189, y: 419 },
- { x: 341, y: 161 },
- { x: 492, y: 419 }
+ [
+ {x: 38, y: 161},
+ {x: 189, y: 419},
+ {x: 341, y: 161},
+ {x: 492, y: 419}
].forEach(function(values, i) {
- expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
});
var meta1 = chart.getDatasetMeta(1);
- [ { x: 38, y: 32 },
- { x: 189, y: 97 },
- { x: 341, y: 161 },
- { x: 492, y: 471 }
+ [
+ {x: 38, y: 32},
+ {x: 189, y: 97},
+ {x: 341, y: 161},
+ {x: 492, y: 471}
].forEach(function(values, i) {
- expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
});
});
var meta0 = chart.getDatasetMeta(0);
- [ { x: 76, y: 161 },
- { x: 215, y: 419 },
- { x: 353, y: 161 },
- { x: 492, y: 419 }
+ [
+ {x: 76, y: 161},
+ {x: 215, y: 419},
+ {x: 353, y: 161},
+ {x: 492, y: 419}
].forEach(function(values, i) {
- expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
});
var meta1 = chart.getDatasetMeta(1);
- [ { x: 76, y: 32 },
- { x: 215, y: 97 },
- { x: 353, y: 161 },
- { x: 492, y: 471 }
+ [
+ {x: 76, y: 32},
+ {x: 215, y: 97},
+ {x: 353, y: 161},
+ {x: 492, y: 471}
].forEach(function(values, i) {
- expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
});
});
var meta0 = chart.getDatasetMeta(0);
- [ { x: 38, y: 161 },
- { x: 189, y: 419 },
- { x: 341, y: 161 },
- { x: 492, y: 419 }
+ [
+ {x: 38, y: 161},
+ {x: 189, y: 419},
+ {x: 341, y: 161},
+ {x: 492, y: 419}
].forEach(function(values, i) {
- expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
});
var meta1 = chart.getDatasetMeta(1);
- [ { x: 38, y: 32 },
- { x: 189, y: 97 },
- { x: 341, y: 161 },
- { x: 492, y: 471 }
+ [
+ {x: 38, y: 32},
+ {x: 189, y: 97},
+ {x: 341, y: 161},
+ {x: 492, y: 471}
].forEach(function(values, i) {
- expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
});
});
var meta0 = chart.getDatasetMeta(0);
- [ { x: 38, y: 161 },
- { x: 189, y: 419 },
- { x: 341, y: 161 },
- { x: 492, y: 419 }
+ [
+ {x: 38, y: 161},
+ {x: 189, y: 419},
+ {x: 341, y: 161},
+ {x: 492, y: 419}
].forEach(function(values, i) {
- expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
});
var meta1 = chart.getDatasetMeta(1);
- [ { x: 38, y: 32 },
- { x: 189, y: 97 },
- { x: 341, y: 161 },
- { x: 492, y: 471 }
+ [
+ {x: 38, y: 32},
+ {x: 189, y: 97},
+ {x: 341, y: 161},
+ {x: 492, y: 471}
].forEach(function(values, i) {
- expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
});
});
describe('Polar area controller tests', function() {
it('should be constructed', function() {
var chart = window.acquireChart({
- type: 'polarArea',
- data: {
- datasets: [
- { data: [] },
- { data: [] }
- ],
- labels: []
- }
+ type: 'polarArea',
+ data: {
+ datasets: [
+ {data: []},
+ {data: []}
+ ],
+ labels: []
+ }
});
var meta = chart.getDatasetMeta(1);
type: 'polarArea',
data: {
datasets: [
- { data: [] },
- { data: [10, 15, 0, -4] }
+ {data: []},
+ {data: [10, 15, 0, -4]}
],
labels: []
}
it('should draw all elements', function() {
var chart = window.acquireChart({
- type: 'polarArea',
- data: {
- datasets: [{
- data: [10, 15, 0, -4],
- label: 'dataset2'
- }],
- labels: ['label1', 'label2', 'label3', 'label4']
- }
+ type: 'polarArea',
+ data: {
+ datasets: [{
+ data: [10, 15, 0, -4],
+ label: 'dataset2'
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4']
+ }
});
var meta = chart.getDatasetMeta(0);
var meta = chart.getDatasetMeta(0);
expect(meta.data.length).toBe(4);
- [ { o: 156, s: -0.5 * Math.PI, e: 0 },
- { o: 211, s: 0, e: 0.5 * Math.PI },
- { o: 45, s: 0.5 * Math.PI, e: Math.PI },
- { o: 0, s: Math.PI, e: 1.5 * Math.PI }
+ [
+ {o: 156, s: -0.5 * Math.PI, e: 0},
+ {o: 211, s: 0, e: 0.5 * Math.PI},
+ {o: 45, s: 0.5 * Math.PI, e: Math.PI},
+ {o: 0, s: Math.PI, e: 1.5 * Math.PI}
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(256);
expect(meta.data[i]._model.y).toBeCloseToPixel(272);
var meta = chart.getDatasetMeta(0);
expect(meta.data.length).toBe(4);
- [ { o: 156, s: 0, e: 0.5 * Math.PI },
- { o: 211, s: 0.5 * Math.PI, e: Math.PI },
- { o: 45, s: Math.PI, e: 1.5 * Math.PI },
- { o: 0, s: 1.5 * Math.PI, e: 2.0 * Math.PI }
+ [
+ {o: 156, s: 0, e: 0.5 * Math.PI},
+ {o: 211, s: 0.5 * Math.PI, e: Math.PI},
+ {o: 45, s: Math.PI, e: 1.5 * Math.PI},
+ {o: 0, s: 1.5 * Math.PI, e: 2.0 * Math.PI}
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(256);
expect(meta.data[i]._model.y).toBeCloseToPixel(272);
expect(meta.data[0] instanceof Chart.elements.Arc).toBe(true);
expect(meta.data[1] instanceof Chart.elements.Arc).toBe(true);
- // add 3 items
+ // add 3 items
chart.data.labels = ['label1', 'label2', 'label3', 'label4', 'label5'];
chart.data.datasets[0].data = [1, 2, 3, 4, 5];
chart.update();
}
});
- var controller = new Chart.controllers.radar(chart, 0);
-
var meta = chart.getDatasetMeta(0);
expect(meta.dataset instanceof Chart.elements.Line).toBe(true); // line element
expect(meta.data.length).toBe(4); // 4 points created
}));
[
- { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
- { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
- { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
- { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
+ {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
+ {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
+ {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
+ {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272},
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x);
expect(meta.data[i]._model.y).toBeCloseToPixel(expected.y);
meta.controller.update();
[
- { x: 256, y: 133, cppx: 246, cppy: 133, cpnx: 272, cpny: 133 },
- { x: 464, y: 272, cppx: 464, cppy: 264, cpnx: 464, cpny: 278 },
- { x: 256, y: 272, cppx: 276.9, cppy: 272, cpnx: 250.4, cpny: 272 },
- { x: 200, y: 272, cppx: 200, cppy: 275, cpnx: 200, cpny: 261 },
+ {x: 256, y: 133, cppx: 246, cppy: 133, cpnx: 272, cpny: 133},
+ {x: 464, y: 272, cppx: 464, cppy: 264, cpnx: 464, cpny: 278},
+ {x: 256, y: 272, cppx: 276.9, cppy: 272, cpnx: 250.4, cpny: 272},
+ {x: 200, y: 272, cppx: 200, cppy: 275, cpnx: 200, cpny: 261},
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x);
expect(meta.data[i]._model.y).toBeCloseToPixel(expected.y);
// Since tension is now 0, we don't care about the control points
[
- { x: 256, y: 133 },
- { x: 464, y: 272 },
- { x: 256, y: 272 },
- { x: 200, y: 272 },
+ {x: 256, y: 133},
+ {x: 464, y: 272},
+ {x: 256, y: 272},
+ {x: 200, y: 272},
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x);
expect(meta.data[i]._model.y).toBeCloseToPixel(expected.y);
expect(point._model.borderWidth).toBe(5.5);
expect(point._model.radius).toBe(4.4);
});
-});
\ No newline at end of file
+});
element._model.numberProp = 100;
element._model.numberProp2 = 250;
element._model._underscoreProp = 200;
- element._model.stringProp = 'def'
+ element._model.stringProp = 'def';
element._model.newStringProp = 'newString';
- element._model.colorProp = 'rgb(255, 255, 0)'
+ element._model.colorProp = 'rgb(255, 255, 0)';
element.transition(0.25);
expect(element._view).toEqual({
colorProp: 'rgb(64, 64, 0)',
});
});
-});
\ No newline at end of file
+});
});
it('should iterate over an array and pass the extra data to that function', function() {
- var testData = [0, 9, "abc"];
+ var testData = [0, 9, 'abc'];
var scope = {}; // fake out the scope and ensure that 'this' is the correct thing
helpers.each(testData, function(item, index) {
display: true,
gridLines: {
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label
lineWidth: 1,
offsetGridLines: false,
display: true,
- zeroLineColor: "rgba(0,0,0,0.25)",
+ zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
},
- position: "right",
+ position: 'right',
scaleLabel: {
labelString: '',
display: false,
display: true,
gridLines: {
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label,
lineWidth: 1,
offsetGridLines: false,
display: true,
- zeroLineColor: "rgba(0,0,0,0.25)",
+ zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
},
- position: "left",
+ position: 'left',
scaleLabel: {
labelString: '',
display: false,
it('should filter an array', function() {
var data = [-10, 0, 6, 0, 7];
var callback = function(item) {
- return item > 2
+ return item > 2;
};
expect(helpers.where(data, callback)).toEqual([6, 7]);
expect(helpers.findNextWhere(data, callback)).toEqual(6);
it('should spline curves with monotone cubic interpolation', function() {
var dataPoints = [
- { _model: { x: 0, y: 0, skip: false } },
- { _model: { x: 3, y: 6, skip: false } },
- { _model: { x: 9, y: 6, skip: false } },
- { _model: { x: 12, y: 60, skip: false } },
- { _model: { x: 15, y: 60, skip: false } },
- { _model: { x: 18, y: 120, skip: false } },
- { _model: { x: null, y: null, skip: true } },
- { _model: { x: 21, y: 180, skip: false } },
- { _model: { x: 24, y: 120, skip: false } },
- { _model: { x: 27, y: 125, skip: false } },
- { _model: { x: 30, y: 105, skip: false } },
- { _model: { x: 33, y: 110, skip: false } },
- { _model: { x: 36, y: 170, skip: false } }
+ {_model: {x: 0, y: 0, skip: false}},
+ {_model: {x: 3, y: 6, skip: false}},
+ {_model: {x: 9, y: 6, skip: false}},
+ {_model: {x: 12, y: 60, skip: false}},
+ {_model: {x: 15, y: 60, skip: false}},
+ {_model: {x: 18, y: 120, skip: false}},
+ {_model: {x: null, y: null, skip: true}},
+ {_model: {x: 21, y: 180, skip: false}},
+ {_model: {x: 24, y: 120, skip: false}},
+ {_model: {x: 27, y: 125, skip: false}},
+ {_model: {x: 30, y: 105, skip: false}},
+ {_model: {x: 33, y: 110, skip: false}},
+ {_model: {x: 36, y: 170, skip: false}}
];
helpers.splineCurveMonotone(dataPoints);
expect(dataPoints).toEqual([{
it('should return the width of the longest text in an Array and 2D Array', function() {
var context = window.createMockContext();
var font = "normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
- var arrayOfThings_1D = ['FooBar','Bar'];
- var arrayOfThings_2D = [['FooBar_1','Bar_2'],'Foo_1'];
-
+ var arrayOfThings1D = ['FooBar', 'Bar'];
+ var arrayOfThings2D = [['FooBar_1', 'Bar_2'], 'Foo_1'];
+
// Regardless 'FooBar' is the longest label it should return (charcters * 10)
- expect(helpers.longestText(context, font, arrayOfThings_1D, {})).toEqual(60);
- expect(helpers.longestText(context, font, arrayOfThings_2D, {})).toEqual(80);
+ expect(helpers.longestText(context, font, arrayOfThings1D, {})).toEqual(60);
+ expect(helpers.longestText(context, font, arrayOfThings2D, {})).toEqual(80);
// We check to make sure we made the right calls to the canvas.
expect(context.getCalls()).toEqual([{
name: 'measureText',
});
it('count look at all the labels and return maximum number of lines', function() {
- var context = window.createMockContext();
- var arrayOfThings_1 = ['Foo','Bar'];
- var arrayOfThings_2 = [['Foo','Bar'],'Foo'];
- var arrayOfThings_3 = [['Foo','Bar','Boo'],['Foo','Bar'],'Foo'];
+ window.createMockContext();
+ var arrayOfThings1 = ['Foo', 'Bar'];
+ var arrayOfThings2 = [['Foo', 'Bar'], 'Foo'];
+ var arrayOfThings3 = [['Foo', 'Bar', 'Boo'], ['Foo', 'Bar'], 'Foo'];
- expect(helpers.numberOfLabelLines(arrayOfThings_1)).toEqual(1);
- expect(helpers.numberOfLabelLines(arrayOfThings_2)).toEqual(2);
- expect(helpers.numberOfLabelLines(arrayOfThings_3)).toEqual(3);
+ expect(helpers.numberOfLabelLines(arrayOfThings1)).toEqual(1);
+ expect(helpers.numberOfLabelLines(arrayOfThings2)).toEqual(2);
+ expect(helpers.numberOfLabelLines(arrayOfThings3)).toEqual(3);
});
it('should draw a rounded rectangle', function() {
}, {
name: 'closePath',
args: []
- }])
+ }]);
});
it ('should get the maximum width and height for a node', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
it ('should get the maximum width of a node that has a max-width style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create the div we want to get the max size for and set a max-width style
var innerDiv = document.createElement('div');
- innerDiv.style.maxWidth = "150px";
+ innerDiv.style.maxWidth = '150px';
div.appendChild(innerDiv);
expect(helpers.getMaximumWidth(innerDiv)).toBe(150);
it ('should get the maximum height of a node that has a max-height style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create the div we want to get the max size for and set a max-height style
var innerDiv = document.createElement('div');
- innerDiv.style.maxHeight = "150px";
+ innerDiv.style.maxHeight = '150px';
div.appendChild(innerDiv);
expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
it ('should get the maximum width of a node when the parent has a max-width style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create an inner wrapper around our div we want to size and give that a max-width style
var parentDiv = document.createElement('div');
- parentDiv.style.maxWidth = "150px";
+ parentDiv.style.maxWidth = '150px';
div.appendChild(parentDiv);
// Create the div we want to get the max size for
it ('should get the maximum height of a node when the parent has a max-height style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create an inner wrapper around our div we want to size and give that a max-height style
var parentDiv = document.createElement('div');
- parentDiv.style.maxHeight = "150px";
+ parentDiv.style.maxHeight = '150px';
div.appendChild(parentDiv);
// Create the div we want to get the max size for
var innerDiv = document.createElement('div');
- innerDiv.style.height = "300px"; // make it large
+ innerDiv.style.height = '300px'; // make it large
parentDiv.appendChild(innerDiv);
expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
it ('should get the maximum width of a node that has a percentage max-width style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create the div we want to get the max size for and set a max-width style
var innerDiv = document.createElement('div');
- innerDiv.style.maxWidth = "50%";
+ innerDiv.style.maxWidth = '50%';
div.appendChild(innerDiv);
expect(helpers.getMaximumWidth(innerDiv)).toBe(100);
it ('should get the maximum height of a node that has a percentage max-height style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create the div we want to get the max size for and set a max-height style
var innerDiv = document.createElement('div');
- innerDiv.style.maxHeight = "50%";
+ innerDiv.style.maxHeight = '50%';
div.appendChild(innerDiv);
expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
it ('should get the maximum width of a node when the parent has a percentage max-width style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create an inner wrapper around our div we want to size and give that a max-width style
var parentDiv = document.createElement('div');
- parentDiv.style.maxWidth = "50%";
+ parentDiv.style.maxWidth = '50%';
div.appendChild(parentDiv);
// Create the div we want to get the max size for
it ('should get the maximum height of a node when the parent has a percentage max-height style', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div');
- div.style.width = "200px";
- div.style.height = "300px";
+ div.style.width = '200px';
+ div.style.height = '300px';
document.body.appendChild(div);
// Create an inner wrapper around our div we want to size and give that a max-height style
var parentDiv = document.createElement('div');
- parentDiv.style.maxHeight = "50%";
+ parentDiv.style.maxHeight = '50%';
div.appendChild(parentDiv);
var innerDiv = document.createElement('div');
- innerDiv.style.height = "300px"; // make it large
+ innerDiv.style.height = '300px'; // make it large
parentDiv.appendChild(innerDiv);
expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
expect(backgroundColor instanceof CanvasPattern).toBe(true);
done();
- }
+ };
});
it('should return a modified version of color when called with a color', function() {
currentTarget: node
};
- var elements = Chart.Interaction.modes.index(chartInstance, evt, { intersect: true });
+ var elements = Chart.Interaction.modes.index(chartInstance, evt, {intersect: true});
expect(elements).toEqual([point, meta1.data[1]]);
});
currentTarget: node
};
- var elements = Chart.Interaction.modes.index(chartInstance, evt, { intersect: false });
+ var elements = Chart.Interaction.modes.index(chartInstance, evt, {intersect: false});
expect(elements).toEqual([meta0.data[0], meta1.data[0]]);
});
});
currentTarget: node
};
- var elements = Chart.Interaction.modes.dataset(chartInstance, evt, { intersect: true });
+ var elements = Chart.Interaction.modes.dataset(chartInstance, evt, {intersect: true});
expect(elements).toEqual(meta.data);
});
currentTarget: node
};
- var elements = Chart.Interaction.modes.dataset(chartInstance, evt, { intersect: false });
+ var elements = Chart.Interaction.modes.dataset(chartInstance, evt, {intersect: false});
var meta = chartInstance.getDatasetMeta(1);
expect(elements).toEqual(meta.data);
// Trigger an event over top of the
var meta = chartInstance.getDatasetMeta(1);
var node = chartInstance.chart.canvas;
- var rect = node.getBoundingClientRect();
var evt = {
view: window,
bubbles: true,
};
// Nearest to 0,0 (top left) will be first point of dataset 2
- var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: false });
+ var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: false});
expect(elements).toEqual([meta.data[0]]);
});
};
// Nearest to 0,0 (top left) will be first point of dataset 2
- var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: false });
+ var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: false});
expect(elements).toEqual([meta0.data[1]]);
});
};
// Nearest to 0,0 (top left) will be first point of dataset 2
- var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: false });
+ var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: false});
expect(elements).toEqual([meta0.data[1]]);
});
});
};
// Nothing intersects so find nothing
- var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true });
+ var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true});
expect(elements).toEqual([]);
evt = {
clientY: rect.top + point._view.y,
currentTarget: node
};
- elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true });
+ elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true});
expect(elements).toEqual([point]);
});
};
// Nearest to 0,0 (top left) will be first point of dataset 2
- var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true });
+ var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true});
expect(elements).toEqual([meta0.data[1]]);
});
};
// Nearest to 0,0 (top left) will be first point of dataset 2
- var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true });
+ var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true});
expect(elements).toEqual([meta0.data[1]]);
});
};
// Nearest to 0,0 (top left) will be first point of dataset 2
- var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true });
+ var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true});
expect(elements).toEqual([meta0.data[1]]);
});
});
type: 'bar',
data: {
datasets: [
- { data: [10, 5, 0, 25, 78, -10] }
+ {data: [10, 5, 0, 25, 78, -10]}
],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
type: 'bar',
data: {
datasets: [
- { data: [10, 5, 0, 25, 78, -10] }
+ {data: [10, 5, 0, 25, 78, -10]}
],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
expect(chart.scale.right).toBeCloseToPixel(512);
expect(chart.scale.top).toBeCloseToPixel(32);
expect(chart.scale.width).toBeCloseToPixel(512);
- expect(chart.scale.height).toBeCloseToPixel(480)
+ expect(chart.scale.height).toBeCloseToPixel(480);
});
it('should fit multiple axes in the same position', function() {
expect(chart.legend.legendHitBoxes.length).toBe(3);
- [ { h: 12, l: 101, t: 10, w: 93 },
- { h: 12, l: 205, t: 10, w: 93 },
- { h: 12, l: 308, t: 10, w: 93 }
+ [
+ {h: 12, l: 101, t: 10, w: 93},
+ {h: 12, l: 205, t: 10, w: 93},
+ {h: 12, l: 308, t: 10, w: 93}
].forEach(function(expected, i) {
expect(chart.legend.legendHitBoxes[i].height).toBeCloseToPixel(expected.h);
expect(chart.legend.legendHitBoxes[i].left).toBeCloseToPixel(expected.l);
expect(chart.legend.legendHitBoxes[i].top).toBeCloseToPixel(expected.t);
expect(chart.legend.legendHitBoxes[i].width).toBeCloseToPixel(expected.w);
- })
+ });
// NOTE(SB) We should get ride of the following tests and use image diff instead.
// For now, as discussed with Evert Timberg, simply comment out.
// See http://humblesoftware.github.io/js-imagediff/test.html
- /*chart.legend.ctx = window.createMockContext();
+ /* chart.legend.ctx = window.createMockContext();
chart.update();
expect(chart.legend.ctx .getCalls()).toEqual([{
};
Chart.plugins.register(myplugin);
- Chart.plugins.notify('trigger', [{ count: 10 }]);
+ Chart.plugins.notify('trigger', [{count: 10}]);
expect(myplugin.count).toBe(10);
});
it('should return TRUE if no plugin explicitly returns FALSE', function() {
- Chart.plugins.register({ check: function() {} });
- Chart.plugins.register({ check: function() { return; } });
- Chart.plugins.register({ check: function() { return null; } });
- Chart.plugins.register({ check: function() { return 42 } });
+ Chart.plugins.register({
+ check: function() {}
+ });
+ Chart.plugins.register({
+ check: function() {
+ return;
+ }
+ });
+ Chart.plugins.register({
+ check: function() {
+ return null;
+ }
+ });
+ Chart.plugins.register({
+ check: function() {
+ return 42;
+ }
+ });
var res = Chart.plugins.notify('check');
expect(res).toBeTruthy();
});
it('should return FALSE if no plugin explicitly returns FALSE', function() {
- Chart.plugins.register({ check: function() {} });
- Chart.plugins.register({ check: function() { return; } });
- Chart.plugins.register({ check: function() { return false; } });
- Chart.plugins.register({ check: function() { return 42 } });
+ Chart.plugins.register({
+ check: function() {}
+ });
+ Chart.plugins.register({
+ check: function() {
+ return;
+ }
+ });
+ Chart.plugins.register({
+ check: function() {
+ return false;
+ }
+ });
+ Chart.plugins.register({
+ check: function() {
+ return 42;
+ }
+ });
var res = Chart.plugins.notify('check');
expect(res).toBeFalsy();
});
expect(Chart.scaleService.getScaleDefaults(type)).toEqual(jasmine.objectContaining({
testProp: true
}));
-
+
Chart.scaleService.updateScaleDefaults(type, {
testProp: 'red',
newProp: 42
fontStyle: 'bold',
padding: 10,
text: ''
- })
+ });
});
it('should update correctly', function() {
var chart = {};
var options = Chart.helpers.clone(Chart.defaults.global.title);
- options.text = "My title";
+ options.text = 'My title';
var title = new Chart.Title({
chart: chart,
var chart = {};
var options = Chart.helpers.clone(Chart.defaults.global.title);
- options.text = "My title";
+ options.text = 'My title';
options.position = 'left';
var title = new Chart.Title({
var context = window.createMockContext();
var options = Chart.helpers.clone(Chart.defaults.global.title);
- options.text = "My title";
+ options.text = 'My title';
var title = new Chart.Title({
chart: chart,
var context = window.createMockContext();
var options = Chart.helpers.clone(Chart.defaults.global.title);
- options.text = "My title";
+ options.text = 'My title';
options.position = 'left';
var title = new Chart.Title({
return 'title';
},
afterTitle: function() {
- return 'afterTitle'
+ return 'afterTitle';
},
beforeBody: function() {
return 'beforeBody';
return 'footer';
},
afterFooter: function() {
- return 'afterFooter'
+ return 'afterFooter';
}
}
}
var meta0 = chartInstance.getDatasetMeta(0);
var point0 = meta0.data[1];
- var meta1 = chartInstance.getDatasetMeta(1);
- var point1 = meta1.data[1];
-
var node = chartInstance.chart.canvas;
var rect = node.getBoundingClientRect();
// Test the bubble chart default config
-describe("Default Configs", function() {
- describe("Bubble Chart", function() {
+describe('Default Configs', function() {
+ describe('Bubble Chart', function() {
it('should return correct tooltip strings', function() {
var config = Chart.defaults.bubble;
var chart = window.acquireChart({
chart.tooltip._active = [chart.getDatasetMeta(0).data[0]];
chart.tooltip.update();
- // Title is always blank
+ // Title is always blank
expect(chart.tooltip._model.title).toEqual([]);
expect(chart.tooltip._model.body).toEqual([{
before: [],
chart.tooltip._active = [chart.getDatasetMeta(0).data[1]];
chart.tooltip.update();
- // Title is always blank
+ // Title is always blank
expect(chart.tooltip._model.title).toEqual([]);
expect(chart.tooltip._model.body).toEqual([{
before: [],
chart.tooltip._active = [chart.getDatasetMeta(0).data[1]];
chart.tooltip.update();
- // Title is always blank
+ // Title is always blank
expect(chart.tooltip._model.title).toEqual([]);
expect(chart.tooltip._model.body).toEqual([{
before: [],
chart.tooltip._active = [chart.getDatasetMeta(0).data[1]];
chart.tooltip.update();
- // Title is always blank
+ // Title is always blank
expect(chart.tooltip._model.title).toEqual([]);
expect(chart.tooltip._model.body).toEqual([{
before: [],
options: config
});
var meta = chart.getDatasetMeta(0);
-
+
spyOn(chart, 'update').and.callThrough();
var legendItem = chart.legend.legendItems[0];
args: []
}]);
});
-});
\ No newline at end of file
+});
args: []
}]);
});
-});
\ No newline at end of file
+});
y: 10
};
- expect(point.getCenterPoint()).toEqual({ x: 10, y: 10 });
+ expect(point.getCenterPoint()).toEqual({x: 10, y: 10});
});
it ('should draw correctly', function() {
}, {
name: 'lineTo',
args: [12, 15],
- },{
+ }, {
name: 'closePath',
args: [],
}, {
}, {
name: 'lineTo',
args: [12, 15],
- },{
+ }, {
name: 'moveTo',
args: [10 - Math.cos(Math.PI / 4) * 2, 15 - Math.sin(Math.PI / 4) * 2]
}, {
expect(mockContext.getCalls()).toEqual([]);
});
-});
\ No newline at end of file
+});
y: 15
};
- expect(rectangle.getCenterPoint()).toEqual({ x: 10, y: 7.5 });
+ expect(rectangle.getCenterPoint()).toEqual({x: 10, y: 7.5});
});
it ('should draw correctly', function() {
}]);
});
- function testBorderSkipped (borderSkipped, expectedDrawCalls) {
+ function testBorderSkipped(borderSkipped, expectedDrawCalls) {
var mockContext = window.createMockContext();
var rectangle = new Chart.elements.Rectangle({
- _chart: { ctx: mockContext }
+ _chart: {ctx: mockContext}
});
// Attach a view object as if we were the controller
x: 10,
y: 15,
};
-
+
rectangle.draw();
- var drawCalls = rectangle._view.ctx.getCalls().splice(4, 4);
+ var drawCalls = rectangle._view.ctx.getCalls().splice(4, 4);
expect(drawCalls).toEqual(expectedDrawCalls);
}
-
+
it ('should draw correctly respecting "borderSkipped" == "bottom"', function() {
testBorderSkipped ('bottom', [
- { name: 'moveTo', args: [8, 0] },
- { name: 'lineTo', args: [8, 15] },
- { name: 'lineTo', args: [12, 15] },
- { name: 'lineTo', args: [12, 0] },
+ {name: 'moveTo', args: [8, 0]},
+ {name: 'lineTo', args: [8, 15]},
+ {name: 'lineTo', args: [12, 15]},
+ {name: 'lineTo', args: [12, 0]},
]);
});
it ('should draw correctly respecting "borderSkipped" == "left"', function() {
testBorderSkipped ('left', [
- { name: 'moveTo', args: [8, 15] },
- { name: 'lineTo', args: [12, 15] },
- { name: 'lineTo', args: [12, 0] },
- { name: 'lineTo', args: [8, 0] },
+ {name: 'moveTo', args: [8, 15]},
+ {name: 'lineTo', args: [12, 15]},
+ {name: 'lineTo', args: [12, 0]},
+ {name: 'lineTo', args: [8, 0]},
]);
});
it ('should draw correctly respecting "borderSkipped" == "top"', function() {
testBorderSkipped ('top', [
- { name: 'moveTo', args: [12, 15] },
- { name: 'lineTo', args: [12, 0] },
- { name: 'lineTo', args: [8, 0] },
- { name: 'lineTo', args: [8, 15] },
+ {name: 'moveTo', args: [12, 15]},
+ {name: 'lineTo', args: [12, 0]},
+ {name: 'lineTo', args: [8, 0]},
+ {name: 'lineTo', args: [8, 15]},
]);
});
it ('should draw correctly respecting "borderSkipped" == "right"', function() {
testBorderSkipped ('right', [
- { name: 'moveTo', args: [12, 0] },
- { name: 'lineTo', args: [8, 0] },
- { name: 'lineTo', args: [8, 15] },
- { name: 'lineTo', args: [12, 15] },
+ {name: 'moveTo', args: [12, 0]},
+ {name: 'lineTo', args: [8, 0]},
+ {name: 'lineTo', args: [8, 15]},
+ {name: 'lineTo', args: [12, 15]},
]);
});
-});
\ No newline at end of file
+});
+/* eslint guard-for-in: 1 */
+/* eslint camelcase: 1 */
(function() {
// Code from http://stackoverflow.com/questions/4406864/html-canvas-unit-testing
var Context = function() {
// Define properties here so that we can record each time they are set
Object.defineProperties(this, {
- "fillStyle": {
- 'get': function() { return this._fillStyle; },
- 'set': function(style) {
+ fillStyle: {
+ get: function() {
+ return this._fillStyle;
+ },
+ set: function(style) {
this._fillStyle = style;
this.record('setFillStyle', [style]);
}
},
- 'lineCap': {
- 'get': function() { return this._lineCap; },
- 'set': function(cap) {
+ lineCap: {
+ get: function() {
+ return this._lineCap;
+ },
+ set: function(cap) {
this._lineCap = cap;
this.record('setLineCap', [cap]);
}
},
- 'lineDashOffset': {
- 'get': function() { return this._lineDashOffset; },
- 'set': function(offset) {
+ lineDashOffset: {
+ get: function() {
+ return this._lineDashOffset;
+ },
+ set: function(offset) {
this._lineDashOffset = offset;
this.record('setLineDashOffset', [offset]);
}
},
- 'lineJoin': {
- 'get': function() { return this._lineJoin; },
- 'set': function(join) {
+ lineJoin: {
+ get: function() {
+ return this._lineJoin;
+ },
+ set: function(join) {
this._lineJoin = join;
this.record('setLineJoin', [join]);
}
},
- 'lineWidth': {
- 'get': function() { return this._lineWidth; },
- 'set': function (width) {
+ lineWidth: {
+ get: function() {
+ return this._lineWidth;
+ },
+ set: function(width) {
this._lineWidth = width;
this.record('setLineWidth', [width]);
}
},
- 'strokeStyle': {
- 'get': function() { return this._strokeStyle; },
- 'set': function(style) {
+ strokeStyle: {
+ get: function() {
+ return this._strokeStyle;
+ },
+ set: function(style) {
this._strokeStyle = style;
this.record('setStrokeStyle', [style]);
}
fill: function() {},
fillRect: function() {},
fillText: function() {},
- lineTo: function(x, y) {},
+ lineTo: function() {},
measureText: function(text) {
// return the number of characters * fixed size
- return text ? { width: text.length * 10 } : {width: 0};
+ return text ? {width: text.length * 10} : {width: 0};
},
- moveTo: function(x, y) {},
+ moveTo: function() {},
quadraticCurveTo: function() {},
restore: function() {},
rotate: function() {},
save: function() {},
setLineDash: function() {},
stroke: function() {},
- strokeRect: function(x, y, w, h) {},
- setTransform: function(a, b, c, d, e, f) {},
- translate: function(x, y) {},
+ strokeRect: function() {},
+ setTransform: function() {},
+ translate: function() {},
};
// attach methods to the class itself
- var scope = this;
+ var me = this;
+ var methodName;
+
var addMethod = function(name, method) {
- scope[methodName] = function() {
- scope.record(name, arguments);
- return method.apply(scope, arguments);
+ me[methodName] = function() {
+ me.record(name, arguments);
+ return method.apply(me, arguments);
};
- }
+ };
- for (var methodName in methods) {
+ for (methodName in methods) {
var method = methods[methodName];
addMethod(methodName, method);
name: methodName,
args: Array.prototype.slice.call(args)
});
- },
+ };
Context.prototype.getCalls = function() {
return this._calls;
- }
+ };
Context.prototype.resetCalls = function() {
this._calls = [];
result = (diff <= (A > B ? A : B) * percentDiff) || diff < 2; // 2 pixels is fine
}
- return { pass: result };
+ return {pass: result};
}
- }
- };
+ };
+ }
function toEqualOneOf() {
return {
* @param {boolean} options.persistent - If true, the chart will not be released after the spec.
*/
function acquireChart(config, options) {
- var wrapper = document.createElement("div");
- var canvas = document.createElement("canvas");
+ var wrapper = document.createElement('div');
+ var canvas = document.createElement('canvas');
var chart, key;
options = options || {};
- options.canvas = options.canvas || { height: 512, width: 512 };
- options.wrapper = options.wrapper || { class: 'chartjs-wrapper' };
+ options.canvas = options.canvas || {height: 512, width: 512};
+ options.wrapper = options.wrapper || {class: 'chartjs-wrapper'};
for (key in options.canvas) {
if (options.canvas.hasOwnProperty(key)) {
wrapper.appendChild(canvas);
window.document.body.appendChild(wrapper);
- chart = new Chart(canvas.getContext("2d"), config);
+ chart = new Chart(canvas.getContext('2d'), config);
chart._test_persistent = options.persistent;
chart._test_wrapper = wrapper;
charts[chart.id] = chart;
'.chartjs-wrapper {' +
'position: absolute' +
'}');
-})();
+}());
display: true,
gridLines: {
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label
lineWidth: 1,
offsetGridLines: false,
display: true,
- zeroLineColor: "rgba(0,0,0,0.25)",
+ zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
},
- position: "bottom",
+ position: 'bottom',
scaleLabel: {
labelString: '',
display: false
var mockContext = window.createMockContext();
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
config.gridLines.offsetGridLines = true;
- config.ticks.min = "tick2";
- config.ticks.max = "tick4";
+ config.ticks.min = 'tick2';
+ config.ticks.max = 'tick4';
var Constructor = Chart.scaleService.getScaleConstructor('category');
var scale = new Constructor({
var mockContext = window.createMockContext();
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
config.gridLines.offsetGridLines = true;
- config.position = "left";
+ config.position = 'left';
var Constructor = Chart.scaleService.getScaleConstructor('category');
var scale = new Constructor({
ctx: mockContext,
var mockContext = window.createMockContext();
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
config.gridLines.offsetGridLines = true;
- config.ticks.min = "tick2";
- config.ticks.max = "tick4";
- config.position = "left";
+ config.ticks.min = 'tick2';
+ config.ticks.max = 'tick4';
+ config.position = 'left';
var Constructor = Chart.scaleService.getScaleConstructor('category');
var scale = new Constructor({
display: true,
gridLines: {
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label
lineWidth: 1,
offsetGridLines: false,
display: true,
- zeroLineColor: "rgba(0,0,0,0.25)",
+ zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
},
- position: "left",
+ position: 'left',
scaleLabel: {
labelString: '',
display: false,
expect(defaultConfig).toEqual({
display: true,
gridLines: {
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true,
lineWidth: 1,
offsetGridLines: false,
display: true,
- zeroLineColor: "rgba(0,0,0,0.25)",
+ zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
},
- position: "left",
+ position: 'left',
scaleLabel: {
labelString: '',
display: false,
id: 'yScale1',
type: 'logarithmic'
},
- {
- id: 'yScale2',
- type: 'logarithmic'
- },
- {
- id: 'yScale3',
- type: 'logarithmic'
- }]
+ {
+ id: 'yScale2',
+ type: 'logarithmic'
+ },
+ {
+ id: 'yScale3',
+ type: 'logarithmic'
+ }]
}
}
});
data: ['20', '0', '150', '1800', '3040']
}, {
yAxisID: 'yScale3',
- data: ['67', '0.0004', '0', '820', '0.001']
+ data: ['67', '0.0004', '0', '820', '0.001']
}],
labels: ['a', 'b', 'c', 'd', 'e']
},
id: 'yScale2',
type: 'logarithmic'
},
- {
- id: 'yScale3',
- type: 'logarithmic'
- }]
+ {
+ id: 'yScale3',
+ type: 'logarithmic'
+ }]
}
}
});
data: [20, 0, 7400, 14, 291]
}, {
yAxisID: 'yScale2',
- data: [6, 0.0007, 9, 890, 60000],
- hidden: true
+ data: [6, 0.0007, 9, 890, 60000],
+ hidden: true
}],
labels: ['a', 'b', 'c', 'd', 'e']
},
yAxisID: 'yScale1',
data: [undefined, 0, null, 800, 9, NaN, 894, 21]
}],
- labels: ['a', 'b', 'c', 'd', 'e', 'f' ,'g', 'h', 'i']
+ labels: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
},
options: {
scales: {
data: {
datasets: [{
data: [
- { x: 10, y: 100 },
- { x: 2, y: 6 },
- { x: 65, y: 121 },
- { x: 99, y: 7 }
+ {x: 10, y: 100},
+ {x: 2, y: 6},
+ {x: 65, y: 121},
+ {x: 99, y: 7}
]
}]
},
data: {
datasets: [{
data: [
- { x: 7, y: 950 },
- { x: 289, y: 0 },
- { x: 0, y: 8 },
- { x: 23, y: 0.04 }
+ {x: 7, y: 950},
+ {x: 289, y: 0},
+ {x: 0, y: 8},
+ {x: 23, y: 0.04}
]
}]
},
var xScale = chart.scales.xScale;
expect(xScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(495); // right - paddingRight
- expect(xScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(48); // left + paddingLeft
+ expect(xScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(48); // left + paddingLeft
expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(283); // halfway
- expect(xScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(48); // 0 is invalid, put it on the left.
+ expect(xScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(48); // 0 is invalid, put it on the left.
expect(xScale.getValueForPixel(495)).toBeCloseTo(80, 1e-4);
expect(xScale.getValueForPixel(48)).toBeCloseTo(1, 1e-4);
var yScale = chart.scales.yScale;
expect(yScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
- expect(yScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(456); // bottom - paddingBottom
+ expect(yScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(456); // bottom - paddingBottom
expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(234); // halfway
- expect(yScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(32); // 0 is invalid. force it on top
+ expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(32); // 0 is invalid. force it on top
expect(yScale.getValueForPixel(32)).toBeCloseTo(80, 1e-4);
expect(yScale.getValueForPixel(456)).toBeCloseTo(1, 1e-4);
expect(defaultConfig).toEqual({
angleLines: {
display: true,
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
lineWidth: 1
},
animate: true,
display: true,
gridLines: {
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true,
lineWidth: 1,
offsetGridLines: false,
display: true,
- zeroLineColor: "rgba(0,0,0,0.25)",
+ zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
fontSize: 10,
callback: defaultConfig.pointLabels.callback, // make this nicer, then check explicitly below
},
- position: "chartArea",
+ position: 'chartArea',
scaleLabel: {
labelString: '',
display: false,
},
ticks: {
- backdropColor: "rgba(255,255,255,0.75)",
+ backdropColor: 'rgba(255,255,255,0.75)',
backdropPaddingY: 2,
backdropPaddingX: 2,
beginAtZero: false,
var radToNearestDegree = function(rad) {
return Math.round((360 * rad) / (2 * Math.PI));
- }
+ };
var slice = 72; // (360 / 5)
- for(var i = 0; i < 5; i++) {
+ for (var i = 0; i < 5; i++) {
expect(radToNearestDegree(chart.scale.getIndexAngle(i))).toBe(15 + (slice * i) - 90);
}
chart.options.startAngle = 0;
chart.update();
- for(var i = 0; i < 5; i++) {
- expect(radToNearestDegree(chart.scale.getIndexAngle(i))).toBe((slice * i) - 90);
+ for (var x = 0; x < 5; x++) {
+ expect(radToNearestDegree(chart.scale.getIndexAngle(x))).toBe((slice * x) - 90);
}
});
});
pass: result
};
}
- }
+ };
}
});
});
expect(defaultConfig).toEqual({
display: true,
gridLines: {
- color: "rgba(0, 0, 0, 0.1)",
+ color: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true,
lineWidth: 1,
offsetGridLines: false,
display: true,
- zeroLineColor: "rgba(0,0,0,0.25)",
+ zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
borderDash: [],
borderDashOffset: 0.0
},
- position: "bottom",
+ position: 'bottom',
scaleLabel: {
labelString: '',
display: false
displayFormat: false,
minUnit: 'millisecond',
displayFormats: {
- 'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM
- 'second': 'h:mm:ss a', // 11:20:01 AM
- 'minute': 'h:mm:ss a', // 11:20:01 AM
- 'hour': 'MMM D, hA', // Sept 4, 5PM
- 'day': 'll', // Sep 4 2015
- 'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ?
- 'month': 'MMM YYYY', // Sept 2015
- 'quarter': '[Q]Q - YYYY', // Q3
- 'year': 'YYYY' // 2015
+ millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM
+ second: 'h:mm:ss a', // 11:20:01 AM
+ minute: 'h:mm:ss a', // 11:20:01 AM
+ hour: 'MMM D, hA', // Sept 4, 5PM
+ day: 'll', // Sep 4 2015
+ week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
+ month: 'MMM YYYY', // Sept 2015
+ quarter: '[Q]Q - YYYY', // Q3
+ year: 'YYYY' // 2015
}
}
});
var scaleID = 'myScale';
var mockData = {
- labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00", "2015-01-03T22:00:00", "2015-01-05T23:00:00", "2015-01-07T03:00", "2015-01-08T10:00", "2015-01-10T12:00"], // days
+ labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days
};
var mockContext = window.createMockContext();
id: scaleID
});
- //scale.buildTicks();
+ // scale.buildTicks();
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015' ]);
+ expect(scale.ticks).toEqual(['Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015']);
});
it('should build ticks using date objects', function() {
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015' ]);
+ expect(scale.ticks).toEqual(['Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015']);
});
it('should build ticks when the data is xy points', function() {
// Counts down because the lines are drawn top to bottom
var xScale = chart.scales.xScale0;
- expect(xScale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015' ]);
+ expect(xScale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015']);
});
it('should allow custom time parsers', function() {
time: {
unit: 'day',
round: true,
- parser: function customTimeParser(label) {
+ parser: function(label) {
return moment.unix(label);
}
}
var scaleID = 'myScale';
var mockData = {
- labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00"], // days
+ labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00'], // days
};
var mockContext = window.createMockContext();
id: scaleID
});
- //scale.buildTicks();
+ // scale.buildTicks();
scale.update(400, 50);
expect(scale.ticks).toEqual(['Jan 1, 8PM', 'Jan 1, 9PM', 'Jan 1, 10PM', 'Jan 1, 11PM', 'Jan 2, 12AM', 'Jan 2, 1AM', 'Jan 2, 2AM', 'Jan 2, 3AM', 'Jan 2, 4AM', 'Jan 2, 5AM', 'Jan 2, 6AM', 'Jan 2, 7AM', 'Jan 2, 8AM', 'Jan 2, 9AM', 'Jan 2, 10AM', 'Jan 2, 11AM', 'Jan 2, 12PM', 'Jan 2, 1PM', 'Jan 2, 2PM', 'Jan 2, 3PM', 'Jan 2, 4PM', 'Jan 2, 5PM', 'Jan 2, 6PM', 'Jan 2, 7PM', 'Jan 2, 8PM', 'Jan 2, 9PM']);
});
var scaleID = 'myScale';
var mockData = {
- labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00"], // days
+ labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00'], // days
};
var mockContext = window.createMockContext();
id: scaleID
});
- //scale.buildTicks();
+ // scale.buildTicks();
scale.update(400, 50);
expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 2, 2015', 'Jan 3, 2015']);
});
var scaleID = 'myScale';
var mockData = {
- labels: ["2015-01-01T20:00:00", "2015-02-02T21:00:00", "2015-02-21T01:00:00"], // days
+ labels: ['2015-01-01T20:00:00', '2015-02-02T21:00:00', '2015-02-21T01:00:00'], // days
};
var mockContext = window.createMockContext();
id: scaleID
});
- //scale.buildTicks();
+ // scale.buildTicks();
scale.update(400, 50);
// last date is feb 15 because we round to start of week
var scaleID = 'myScale';
var mockData = {
- labels: ["2015-01-01T20:00:00", "2015-01-02T20:00:00", "2015-01-03T20:00:00"], // days
+ labels: ['2015-01-01T20:00:00', '2015-01-02T20:00:00', '2015-01-03T20:00:00'], // days
};
var mockContext = window.createMockContext();
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
- config.time.min = "2015-01-01T04:00:00";
- config.time.max = "2015-01-05T06:00:00"
+ config.time.min = '2015-01-01T04:00:00';
+ config.time.max = '2015-01-05T06:00:00';
var Constructor = Chart.scaleService.getScaleConstructor('time');
var scale = new Constructor({
ctx: mockContext,
});
scale.update(400, 50);
- expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 5, 2015' ]);
+ expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 5, 2015']);
});
it('Should use the isoWeekday option', function() {
var mockData = {
labels: [
- "2015-01-01T20:00:00", // Thursday
- "2015-01-02T20:00:00", // Friday
- "2015-01-03T20:00:00" // Saturday
+ '2015-01-01T20:00:00', // Thursday
+ '2015-01-02T20:00:00', // Friday
+ '2015-01-03T20:00:00' // Saturday
]
};
});
scale.update(400, 50);
- expect(scale.ticks).toEqual([ 'Dec 31, 2014', 'Jan 7, 2015' ]);
+ expect(scale.ticks).toEqual(['Dec 31, 2014', 'Jan 7, 2015']);
});
it('should get the correct pixel for a value', function() {
yAxisID: 'yScale0',
data: []
}],
- labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00", "2015-01-03T22:00:00", "2015-01-05T23:00:00", "2015-01-07T03:00", "2015-01-08T10:00", "2015-01-10T12:00"], // days
+ labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days
},
options: {
scales: {
yAxisID: 'yScale0',
data: []
}],
- labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00", "2015-01-03T22:00:00", "2015-01-05T23:00:00", "2015-01-07T03:00", "2015-01-08T10:00", "2015-01-10T12:00"], // days
+ labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days
},
options: {
scales: {
var chart = window.acquireChart({
type: 'line',
data: {
- labels: ["2016-05-27"],
+ labels: ['2016-05-27'],
datasets: [{
xAxisID: 'xScale0',
data: [5]
xAxes: [{
id: 'xScale0',
display: true,
- type: "time"
+ type: 'time'
}]
}
}
});
});
- it("should not throw an error if the datasetIndex is out of bounds", function() {
+ it('should not throw an error if the datasetIndex is out of bounds', function() {
var chart = window.acquireChart({
type: 'line',
data: {
- labels: ["2016-06-26"],
+ labels: ['2016-06-26'],
datasets: [{
xAxisID: 'xScale0',
data: [5]
xAxes: [{
id: 'xScale0',
display: true,
- type: "time",
+ type: 'time',
}]
}
}
expect(getOutOfBoundLabelMoment).not.toThrow();
});
- it("should not throw an error if the datasetIndex or index are null", function() {
+ it('should not throw an error if the datasetIndex or index are null', function() {
var chart = window.acquireChart({
type: 'line',
data: {
- labels: ["2016-06-26"],
+ labels: ['2016-06-26'],
datasets: [{
xAxisID: 'xScale0',
data: [5]
xAxes: [{
id: 'xScale0',
display: true,
- type: "time",
+ type: 'time',
}]
}
}