')
.find('#test-container');
});
it('stores data in the internal buffer', function () {
var expected = [1, 2, 3, 4];
var plot = $.plot(placeholder, [], {});
plot.setData(data);
var series = plot.getData();
expect(series.length).toEqual(1);
expect(series[0].data).toEqual(data[0]);
expect(series[0].datapoints.points).toEqual(expected);
expect(series[0].datapoints.pointsize).toEqual(2);
});
it('reuses the internal buffer', function () {
var plot = $.plot(placeholder, [[]], {});
var buffer = plot.getData()[0].datapoints.points;
plot.setData(data);
expect(plot.getData()[0].datapoints.points).toBe(buffer);
});
it('expands the internal buffer as neccessary', function () {
var plot = $.plot(placeholder, [[[3, 4]]], {});
expect(plot.getData()[0].datapoints.points.length).toBe(2);
plot.setData(data);
expect(plot.getData()[0].datapoints.points.length).toBe(4);
});
it('shrinks the internal buffer as neccessary', function () {
var plot = $.plot(placeholder, [[[3, 4], [5, 6], [6, 7], [8, 9]]], {});
expect(plot.getData()[0].datapoints.points.length).toBe(8);
plot.setData(data);
expect(plot.getData()[0].datapoints.points.length).toBe(4);
});
});
describe('draw axis', function() {
var placeholder;
beforeEach(function() {
placeholder = setFixtures('
')
.find('#test-container');
});
['left', 'right'].forEach(function(axisPosition) {
it('should draw ' + axisPosition + ' y axis next to plot', function() {
var testVector = [
[200000000000, 4000000000000],
[200000000000000, 400000000000000],
[20000000000000000, 40000000000000000],
[200000000000000000, 400000000000000000],
[2000000000000000000, 4000000000000000000],
[200000000000000000000, 400000000000000000000],
[20000000000000000000000, 40000000000000000000000]];
testVector.forEach(function (testValue) {
var plot = $.plot(placeholder, [[1, 2, 3]], {
xaxis: {
autoScale: 'none',
min: testValue[0],
max: testValue[1],
showTickLabels: 'all'
},
yaxis: {
position: axisPosition
}});
var yaxis = plot.getYAxes()[0];
if (axisPosition === 'left') {
expect(yaxis.box.left + yaxis.box.width).toBeCloseTo(plot.getPlotOffset().left, -1);
} else {
expect(yaxis.box.left).toBeCloseTo(plot.getPlotOffset().left + plot.width(), -1);
}
});
});
});
['top', 'bottom'].forEach(function(axisPosition) {
it('should draw ' + axisPosition + ' x axis next to plot', function() {
var testVector = [20, 28, 36, 44, 52, 60, 68, 76, 84];
testVector.forEach(function (fontSize) {
var plot = $.plot(placeholder, [[1, 2, 3]], {
xaxis: {
position: axisPosition
},
yaxis: {
font: {
size: fontSize
}
}});
var xaxis = plot.getXAxes()[0];
if (axisPosition === 'top') {
expect(xaxis.box.top + xaxis.box.height).toBeCloseTo(plot.getPlotOffset().top, -1);
} else {
expect(xaxis.box.top).toBeCloseTo(plot.getPlotOffset().top + plot.height(), -1);
}
});
});
});
it('should draw y axis next to plot for multiple axis on the same side', function() {
var testVector = [
[200000000000, 4000000000000],
[200000000000000, 400000000000000],
[20000000000000000, 40000000000000000],
[200000000000000000, 400000000000000000],
[2000000000000000000, 4000000000000000000],
[200000000000000000000, 400000000000000000000],
[20000000000000000000000, 40000000000000000000000]];
testVector.forEach(function (testValue) {
var plot = $.plot(placeholder, [[1, 2, 3]], {
xaxis: {
autoScale: 'none',
min: testValue[0],
max: testValue[1],
showTickLabels: 'all',
font: {
size: 48
}
},
yaxes: [{
position: 'left',
show: true
}, {
position: 'left',
show: true
}, {
position: 'left',
show: true
}]});
var yaxis = plot.getYAxes()[0];
expect(yaxis.box.left + yaxis.box.width).toBeCloseTo(plot.getPlotOffset().left, -1);
});
});
});
describe('Grid margin', function() {
var placeholder, placeholder2, fixtures;
beforeEach(function() {
fixtures = setFixtures('
' +
'
');
placeholder = fixtures.find('#test-container');
placeholder2 = fixtures.find('#test-container2');
});
it('should change plot dimensions', function() {
var testVector = [
[-20, 0, 0, 0],
[20, 0, 0, 0],
[20, -20, 0, 0],
[-20, -20, 0, 0],
[-20, 20, 0, 0],
[20, 20, 0, 0],
[0, 0, -20, 0],
[0, 0, 20, 0],
[0, 0, -20, 20],
[0, 0, -20, -20],
[0, 0, 20, 20],
[0, 0, 20, -20],
[20, 20, 20, 20],
[-20, -20, -20, -20]
];
testVector.forEach(function (testValue) {
var plot1 = $.plot(placeholder, [[]], {}),
plot2 = $.plot(placeholder2, [[]], {
grid: { margin: {
left: testValue[0],
right: testValue[1],
top: testValue[2],
bottom: testValue[3]
}}});
expect(plot2.width()).toBe(plot1.width() - testValue[0] - testValue[1]);
expect(plot2.height()).toBe(plot1.height() - testValue[2] - testValue[3]);
});
});
it('should move the axis according to grid margin', function() {
var testVector = [
[-20, 0, 0, 0],
[20, 0, 0, 0],
[20, -20, 0, 0],
[-20, -20, 0, 0],
[-20, 20, 0, 0],
[20, 20, 0, 0],
[0, 0, -20, 0],
[0, 0, 20, 0],
[0, 0, -20, 20],
[0, 0, -20, -20],
[0, 0, 20, 20],
[0, 0, 20, -20],
[20, 20, 20, 20],
[-20, -20, -20, -20]
];
testVector.forEach(function (testValue) {
var plot1 = $.plot(placeholder, [[]], {
xaxes: [{
position: 'bottom',
show: true
}, {
position: 'top',
show: true
}],
yaxes: [{
position: 'left',
show: true
}, {
position: 'right',
show: true
}]
}),
plot2 = $.plot(placeholder2, [[]], {
xaxes: [{
position: 'bottom',
show: true
}, {
position: 'top',
show: true
}],
yaxes: [{
position: 'left',
show: true
}, {
position: 'right',
show: true
}],
grid: { margin: {
left: testValue[0],
right: testValue[1],
top: testValue[2],
bottom: testValue[3]
}}});
var yaxis1 = plot1.getYAxes()[0],
yaxis2 = plot2.getYAxes()[0];
expect(yaxis1.box.left + testValue[0]).toEqual(yaxis2.box.left);
yaxis1 = plot1.getYAxes()[1];
yaxis2 = plot2.getYAxes()[1];
expect(yaxis1.box.left - testValue[1]).toEqual(yaxis2.box.left);
var xaxis1 = plot1.getXAxes()[0],
xaxis2 = plot2.getXAxes()[0];
expect(xaxis1.box.top - testValue[3]).toEqual(xaxis2.box.top);
xaxis1 = plot1.getXAxes()[1];
xaxis2 = plot2.getXAxes()[1];
expect(xaxis1.box.top + testValue[2]).toEqual(xaxis2.box.top);
});
});
it('should work for margin: number', function() {
var plot1 = $.plot(placeholder, [[]], {}),
plot2 = $.plot(placeholder2, [[]], {
grid: { margin: 20 }
});
expect(plot2.width()).toBe(plot1.width() - 20 - 20);
expect(plot2.height()).toBe(plot1.height() - 20 - 20);
});
});
});