123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /* eslint-disable */
- /* global $, describe, it, xit, xdescribe, after, afterEach, expect*/
- describe('unit tests for the inverted scale functions', function () {
- var placeholder;
- beforeEach(function () {
- placeholder = setFixtures('<div id="test-container" style="width: 800px;height: 400px">')
- .find('#test-container');
- });
- it('should have reverse linear transform set properly', function () {
- var plot = $.plot(placeholder, [[0, 1, 2, 3]], {
- xaxes: [{
- mode: 'linear',
- inverted: true,
- }]
- });
- var axis = plot.getAxes().xaxis;
- expect(axis.options.transform.name).toBe('invertedTransform');
- expect(axis.options.inverseTransform.name).toBe('invertedTransform');
- });
- it('should have inverted log transform set properly', function () {
- var plot = $.plot(placeholder, [[0, 1, 2, 3]], {
- xaxes: [{
- mode: 'log',
- inverted: true,
- }]
- });
- var axis = plot.getAxes().xaxis;
- expect(axis.options.transform.name).toBe('invertedLogTransform');
- expect(axis.options.inverseTransform.name).toBe('invertedLogInverseTransform');
- });
- });
- describe("integration tests for the inverted scale functions", function () {
- var queryPlotForYTicks = function () {
- var actualTicks = [];
-
- var yAxisDivs = $('.yAxis');
- expect(yAxisDivs.length).toBe(1);
- var childDivs = yAxisDivs.find('.tickLabel');
- childDivs.each(function (i, e) {
- actualTicks.push({
- yPos: e.y.baseVal[0].value,
- tickName: e.textContent,
- });
- });
-
- return actualTicks
- .sort(function (a, b) { return b.yPos - a.yPos })
- .map(function (a) { return a.tickName });
- };
-
- var queryPlotForXTicks = function () {
- var actualTicks = [];
-
- var xAxisDivs = $('.xAxis');
- expect(xAxisDivs.length).toBe(1);
- var childDivs = xAxisDivs.find('.tickLabel');
- childDivs.each(function (i, e) {
- actualTicks.push({
- xPos: e.x.baseVal[0].value,
- tickName: e.textContent,
- });
- });
-
- return actualTicks
- .sort(function (a, b) { return a.xPos - b.xPos })
- .map(function (a) { return a.tickName });
- };
-
- var placeholder;
- beforeEach(function () {
- placeholder = setFixtures('<div id="test-container" style="width: 800px;height: 400px">')
- .find('#test-container');
- });
- it('first tick should be max, last tick should be min for linear axis (positive data)', function () {
- const data = [
- [0, 0],
- [1, 1],
- [2, 2],
- [3, 3]
- ];
- var plot = $.plot(placeholder, [data], {
- xaxis: {
- mode: 'linear',
- inverted: true,
- autoScale: 'exact'
- },
- yaxis: {
- mode: 'linear',
- inverted: true,
- autoScale: 'exact'
- }
- });
- const yTicks = queryPlotForYTicks();
- expect(yTicks[0]).toBe('3.0');
- expect(yTicks[yTicks.length - 1]).toBe('0.0');
- const xTicks = queryPlotForXTicks();
- expect(xTicks[0]).toBe('3.0');
- expect(xTicks[xTicks.length - 1]).toBe('0.0');
- });
- it('first tick should be max, last tick should be min for linear axis (negative data)', function () {
- const data = [
- [-0, -0],
- [-1, -1],
- [-2, -2],
- [-3, -3]
- ];
- var plot = $.plot(placeholder, [data], {
- xaxis: {
- mode: 'linear',
- inverted: true,
- autoScale: 'exact'
- },
- yaxis: {
- mode: 'linear',
- inverted: true,
- autoScale: 'exact'
- }
- });
- const yTicks = queryPlotForYTicks();
- expect(yTicks[0]).toBe('0.0');
- expect(yTicks[yTicks.length - 1]).toBe('-3.0');
- const xTicks = queryPlotForXTicks();
- expect(xTicks[0]).toBe('0.0');
- expect(xTicks[xTicks.length - 1]).toBe('-3.0');
- });
- it('first tick should be max, last tick should be min for log axis', function () {
- const data = [
- [0.1, 100],
- [1, 10],
- [10, 1],
- [100, 0.1]
- ];
- var plot = $.plot(placeholder, [data], {
- xaxis: {
- mode: 'log',
- inverted: true,
- autoScale: 'exact'
- },
- yaxis: {
- mode: 'log',
- inverted: true,
- autoScale: 'exact'
- }
- });
- const yTicks = queryPlotForYTicks();
- expect(yTicks[0]).toBe('100');
- expect(yTicks[yTicks.length - 1]).toBe('0.1');
- const xTicks = queryPlotForXTicks();
- expect(xTicks[0]).toBe('100');
- expect(xTicks[xTicks.length - 1]).toBe('0.1');
- });
- });
|