| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950 |
- jest.mock('app/features/annotations/all', () => ({
- EventManager: () => {
- return {
- on: () => {},
- addFlotEvents: () => {},
- };
- },
- }));
- jest.mock('app/core/core', () => ({
- coreModule: {
- directive: () => {},
- },
- appEvents: {
- on: () => {},
- },
- }));
- import '../module';
- import { GraphCtrl } from '../module';
- import { MetricsPanelCtrl } from 'app/features/panel/metrics_panel_ctrl';
- import { PanelCtrl } from 'app/features/panel/panel_ctrl';
- import config from 'app/core/config';
- import TimeSeries from 'app/core/time_series2';
- import $ from 'jquery';
- import { graphDirective } from '../graph';
- import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
- const ctx = {} as any;
- let ctrl: any;
- const scope = {
- ctrl: {},
- range: {
- from: dateTime([2015, 1, 1]),
- to: dateTime([2015, 11, 20]),
- },
- $on: () => {},
- };
- let link;
- describe('grafanaGraph', () => {
- const setupCtx = (beforeRender?: any) => {
- config.bootData = {
- user: {
- lightTheme: false,
- },
- };
- GraphCtrl.prototype = {
- ...MetricsPanelCtrl.prototype,
- ...PanelCtrl.prototype,
- ...GraphCtrl.prototype,
- height: 200,
- panel: {
- events: {
- on: () => {},
- },
- legend: {},
- grid: {},
- yaxes: [
- {
- min: null,
- max: null,
- format: 'short',
- logBase: 1,
- },
- {
- min: null,
- max: null,
- format: 'short',
- logBase: 1,
- },
- ],
- thresholds: [],
- xaxis: {},
- seriesOverrides: [],
- tooltip: {
- shared: true,
- },
- },
- renderingCompleted: jest.fn(),
- hiddenSeries: {},
- dashboard: {
- getTimezone: () => 'browser',
- },
- range: {
- from: dateTime([2015, 1, 1, 10]),
- to: dateTime([2015, 1, 1, 22]),
- },
- } as any;
- ctx.data = [];
- ctx.data.push(
- new TimeSeries({
- datapoints: [[1, 1], [2, 2]],
- alias: 'series1',
- })
- );
- ctx.data.push(
- new TimeSeries({
- datapoints: [[10, 1], [20, 2]],
- alias: 'series2',
- })
- );
- ctrl = new GraphCtrl(
- {
- $on: () => {},
- },
- {
- get: () => {},
- } as any,
- {} as any
- );
- // @ts-ignore
- $.plot = ctrl.plot = jest.fn();
- scope.ctrl = ctrl;
- link = graphDirective({} as any, {}, {} as any, {} as any).link(scope, {
- width: () => 500,
- mouseleave: () => {},
- bind: () => {},
- } as any);
- if (typeof beforeRender === 'function') {
- beforeRender();
- }
- link.data = ctx.data;
- //Emulate functions called by event listeners
- link.buildFlotPairs(link.data);
- link.renderPanel();
- ctx.plotData = ctrl.plot.mock.calls[0][1];
- ctx.plotOptions = ctrl.plot.mock.calls[0][2];
- };
- describe('simple lines options', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.lines = true;
- ctrl.panel.fill = 5;
- ctrl.panel.linewidth = 3;
- ctrl.panel.steppedLine = true;
- });
- });
- it('should configure plot with correct options', () => {
- expect(ctx.plotOptions.series.lines.show).toBe(true);
- expect(ctx.plotOptions.series.lines.fill).toBe(0.5);
- expect(ctx.plotOptions.series.lines.lineWidth).toBe(3);
- expect(ctx.plotOptions.series.lines.steps).toBe(true);
- });
- });
- describe('sorting stacked series as legend. disabled', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.legend.sort = undefined;
- ctrl.panel.stack = false;
- });
- });
- it('should not modify order of time series', () => {
- expect(ctx.plotData[0].alias).toBe('series1');
- expect(ctx.plotData[1].alias).toBe('series2');
- });
- });
- describe('sorting stacked series as legend. min descending order', () => {
- beforeEach(() => {
- setupCtx(() => {
- const sortKey = 'min';
- ctrl.panel.legend.sort = sortKey;
- ctrl.panel.legend.sortDesc = true;
- ctrl.panel.legend.alignAsTable = true;
- ctrl.panel.legend[sortKey] = true;
- ctrl.panel.stack = true;
- });
- });
- it('highest value should be first', () => {
- expect(ctx.plotData[0].alias).toBe('series2');
- expect(ctx.plotData[1].alias).toBe('series1');
- });
- });
- describe('sorting stacked series as legend. min ascending order', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.legend.sort = 'min';
- ctrl.panel.legend.sortDesc = false;
- ctrl.panel.stack = true;
- });
- });
- it('lowest value should be first', () => {
- expect(ctx.plotData[0].alias).toBe('series1');
- expect(ctx.plotData[1].alias).toBe('series2');
- });
- });
- describe('sorting stacked series as legend. stacking disabled', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.legend.sort = 'min';
- ctrl.panel.legend.sortDesc = true;
- ctrl.panel.stack = false;
- });
- });
- it('highest value should be first', () => {
- expect(ctx.plotData[0].alias).toBe('series1');
- expect(ctx.plotData[1].alias).toBe('series2');
- });
- });
- describe('sorting stacked series as legend. current descending order', () => {
- beforeEach(() => {
- setupCtx(() => {
- const sortKey = 'current';
- ctrl.panel.legend.sort = sortKey;
- ctrl.panel.legend.sortDesc = true;
- ctrl.panel.legend.alignAsTable = true;
- ctrl.panel.legend[sortKey] = true;
- ctrl.panel.stack = true;
- });
- });
- it('highest last value should be first', () => {
- expect(ctx.plotData[0].alias).toBe('series2');
- expect(ctx.plotData[1].alias).toBe('series1');
- });
- });
- describe('stacked series should not sort if legend is not as table or sort key column is not visible', () => {
- beforeEach(() => {
- setupCtx(() => {
- const sortKey = 'min';
- ctrl.panel.legend.sort = sortKey;
- ctrl.panel.legend.sortDesc = true;
- ctrl.panel.legend.alignAsTable = false;
- ctrl.panel.legend[sortKey] = false;
- ctrl.panel.stack = true;
- });
- });
- it('highest value should be first', () => {
- expect(ctx.plotData[0].alias).toBe('series1');
- expect(ctx.plotData[1].alias).toBe('series2');
- });
- });
- describe('when logBase is log 10', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctx.data[0] = new TimeSeries({
- datapoints: [[2000, 1], [0.002, 2], [0, 3], [-1, 4]],
- alias: 'seriesAutoscale',
- });
- ctx.data[0].yaxis = 1;
- ctx.data[1] = new TimeSeries({
- datapoints: [[2000, 1], [0.002, 2], [0, 3], [-1, 4]],
- alias: 'seriesFixedscale',
- });
- ctx.data[1].yaxis = 2;
- ctrl.panel.yaxes[0].logBase = 10;
- ctrl.panel.yaxes[1].logBase = 10;
- ctrl.panel.yaxes[1].min = '0.05';
- ctrl.panel.yaxes[1].max = '1500';
- });
- });
- it('should apply axis transform, autoscaling (if necessary) and ticks', () => {
- const axisAutoscale = ctx.plotOptions.yaxes[0];
- expect(axisAutoscale.transform(100)).toBe(2);
- expect(axisAutoscale.inverseTransform(-3)).toBeCloseTo(0.001);
- expect(axisAutoscale.min).toBeCloseTo(0.001);
- expect(axisAutoscale.max).toBe(10000);
- expect(axisAutoscale.ticks.length).toBeCloseTo(8);
- expect(axisAutoscale.ticks[0]).toBeCloseTo(0.001);
- if (axisAutoscale.ticks.length === 7) {
- expect(axisAutoscale.ticks[axisAutoscale.ticks.length - 1]).toBeCloseTo(1000);
- } else {
- expect(axisAutoscale.ticks[axisAutoscale.ticks.length - 1]).toBe(10000);
- }
- const axisFixedscale = ctx.plotOptions.yaxes[1];
- expect(axisFixedscale.min).toBe(0.05);
- expect(axisFixedscale.max).toBe(1500);
- expect(axisFixedscale.ticks.length).toBe(5);
- expect(axisFixedscale.ticks[0]).toBe(0.1);
- expect(axisFixedscale.ticks[4]).toBe(1000);
- });
- });
- describe('when logBase is log 10 and data points contain only zeroes', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.yaxes[0].logBase = 10;
- ctx.data[0] = new TimeSeries({
- datapoints: [[0, 1], [0, 2], [0, 3], [0, 4]],
- alias: 'seriesAutoscale',
- });
- ctx.data[0].yaxis = 1;
- });
- });
- it('should not set min and max and should create some fake ticks', () => {
- const axisAutoscale = ctx.plotOptions.yaxes[0];
- expect(axisAutoscale.transform(100)).toBe(2);
- expect(axisAutoscale.inverseTransform(-3)).toBeCloseTo(0.001);
- expect(axisAutoscale.min).toBe(undefined);
- expect(axisAutoscale.max).toBe(undefined);
- expect(axisAutoscale.ticks.length).toBe(2);
- expect(axisAutoscale.ticks[0]).toBe(1);
- expect(axisAutoscale.ticks[1]).toBe(2);
- });
- });
- // y-min set 0 is a special case for log scale,
- // this approximates it by setting min to 0.1
- describe('when logBase is log 10 and y-min is set to 0 and auto min is > 0.1', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.yaxes[0].logBase = 10;
- ctrl.panel.yaxes[0].min = '0';
- ctx.data[0] = new TimeSeries({
- datapoints: [[2000, 1], [4, 2], [500, 3], [3000, 4]],
- alias: 'seriesAutoscale',
- });
- ctx.data[0].yaxis = 1;
- });
- });
- it('should set min to 0.1 and add a tick for 0.1', () => {
- const axisAutoscale = ctx.plotOptions.yaxes[0];
- expect(axisAutoscale.transform(100)).toBe(2);
- expect(axisAutoscale.inverseTransform(-3)).toBeCloseTo(0.001);
- expect(axisAutoscale.min).toBe(0.1);
- expect(axisAutoscale.max).toBe(10000);
- expect(axisAutoscale.ticks.length).toBe(6);
- expect(axisAutoscale.ticks[0]).toBe(0.1);
- expect(axisAutoscale.ticks[5]).toBe(10000);
- });
- });
- describe('when logBase is log 2 and y-min is set to 0 and num of ticks exceeds max', () => {
- beforeEach(() => {
- setupCtx(() => {
- const heightForApprox5Ticks = 125;
- ctrl.height = heightForApprox5Ticks;
- ctrl.panel.yaxes[0].logBase = 2;
- ctrl.panel.yaxes[0].min = '0';
- ctx.data[0] = new TimeSeries({
- datapoints: [[2000, 1], [4, 2], [500, 3], [3000, 4], [10000, 5], [100000, 6]],
- alias: 'seriesAutoscale',
- });
- ctx.data[0].yaxis = 1;
- });
- });
- it('should regenerate ticks so that if fits on the y-axis', () => {
- const axisAutoscale = ctx.plotOptions.yaxes[0];
- expect(axisAutoscale.min).toBe(0.1);
- expect(axisAutoscale.ticks.length).toBe(8);
- expect(axisAutoscale.ticks[0]).toBe(0.1);
- expect(axisAutoscale.ticks[7]).toBe(262144);
- expect(axisAutoscale.max).toBe(262144);
- });
- it('should set axis max to be max tick value', () => {
- expect(ctx.plotOptions.yaxes[0].max).toBe(262144);
- });
- });
- describe('dashed lines options', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.lines = true;
- ctrl.panel.linewidth = 2;
- ctrl.panel.dashes = true;
- });
- });
- it('should configure dashed plot with correct options', () => {
- expect(ctx.plotOptions.series.lines.show).toBe(true);
- expect(ctx.plotOptions.series.dashes.lineWidth).toBe(2);
- expect(ctx.plotOptions.series.dashes.show).toBe(true);
- });
- });
- describe('should use timeStep for barWidth', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.bars = true;
- ctx.data[0] = new TimeSeries({
- datapoints: [[1, 10], [2, 20]],
- alias: 'series1',
- });
- });
- });
- it('should set barWidth', () => {
- expect(ctx.plotOptions.series.bars.barWidth).toBe(1 / 1.5);
- });
- });
- describe('series option overrides, fill & points', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.lines = true;
- ctrl.panel.fill = 5;
- ctx.data[0].zindex = 10;
- ctx.data[1].alias = 'test';
- ctx.data[1].lines = { fill: 0.001 };
- ctx.data[1].points = { show: true };
- });
- });
- it('should match second series and fill zero, and enable points', () => {
- expect(ctx.plotOptions.series.lines.fill).toBe(0.5);
- expect(ctx.plotData[1].lines.fill).toBe(0.001);
- expect(ctx.plotData[1].points.show).toBe(true);
- });
- });
- describe('should order series order according to zindex', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctx.data[1].zindex = 1;
- ctx.data[0].zindex = 10;
- });
- });
- it('should move zindex 2 last', () => {
- expect(ctx.plotData[0].alias).toBe('series2');
- expect(ctx.plotData[1].alias).toBe('series1');
- });
- });
- describe('when series is hidden', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.hiddenSeries = { series2: true };
- });
- });
- it('should remove datapoints and disable stack', () => {
- expect(ctx.plotData[0].alias).toBe('series1');
- expect(ctx.plotData[1].data.length).toBe(0);
- expect(ctx.plotData[1].stack).toBe(false);
- });
- });
- describe('when stack and percent', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.percentage = true;
- ctrl.panel.stack = true;
- });
- });
- it('should show percentage', () => {
- const axis = ctx.plotOptions.yaxes[0];
- expect(axis.tickFormatter(100, axis)).toBe('100%');
- });
- });
- describe('when panel too narrow to show x-axis dates in same granularity as wide panels', () => {
- //Set width to 10px
- describe('and the range is less than 24 hours', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.range.from = dateTime([2015, 1, 1, 10]);
- ctrl.range.to = dateTime([2015, 1, 1, 22]);
- });
- });
- it('should format dates as hours minutes', () => {
- const axis = ctx.plotOptions.xaxis;
- expect(axis.timeformat).toBe('%H:%M');
- });
- });
- describe('and the range is less than one year', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.range.from = dateTime([2015, 1, 1]);
- ctrl.range.to = dateTime([2015, 11, 20]);
- });
- });
- it('should format dates as month days', () => {
- const axis = ctx.plotOptions.xaxis;
- expect(axis.timeformat).toBe('%m/%d');
- });
- });
- });
- describe('when graph is histogram, and enable stack', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.stack = true;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- ctx.data[1] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series2',
- });
- });
- });
- it('should calculate correct histogram', () => {
- expect(ctx.plotData[0].data[0][0]).toBe(100);
- expect(ctx.plotData[0].data[0][1]).toBe(2);
- expect(ctx.plotData[1].data[0][0]).toBe(100);
- expect(ctx.plotData[1].data[0][1]).toBe(2);
- });
- });
- describe('when graph is histogram, and some series are hidden', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = { series2: true };
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- ctx.data[1] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series2',
- });
- });
- });
- it('should calculate correct histogram', () => {
- expect(ctx.plotData[0].data[0][0]).toBe(100);
- expect(ctx.plotData[0].data[0][1]).toBe(2);
- });
- });
- describe('when graph is histogram, and xaxis min is set', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 150;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should not contain values lower than min', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(200);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min is zero', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 0;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[-100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should not contain values lower than zero', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min is null', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = null;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[-100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis min should not affect the histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(-100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min is undefined', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = undefined;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[-100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis min should not affect the histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(-100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis max is set', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.max = 250;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should not contain values greater than max', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(200);
- });
- });
- describe('when graph is histogram, and xaxis max is zero', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.max = 0;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[-100, 1], [100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should not contain values greater than zero', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(-100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(-100);
- });
- });
- describe('when graph is histogram, and xaxis max is null', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.max = null;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[-100, 1], [100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis max should not affect the histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(-100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis max is undefined', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.max = undefined;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[-100, 1], [100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis max should not should node affect the histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(-100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min and max are set', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 150;
- ctrl.panel.xaxis.max = 250;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should not contain values lower than min and greater than max', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(200);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(200);
- });
- });
- describe('when graph is histogram, and xaxis min and max are zero', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 0;
- ctrl.panel.xaxis.max = 0;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[-100, 1], [100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis max should be ignored otherwise the bucketSize is zero', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min and max are null', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = null;
- ctrl.panel.xaxis.max = null;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis min and max should not affect the histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min and max are undefined', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = undefined;
- ctrl.panel.xaxis.max = undefined;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis min and max should not affect the histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min is greater than xaxis max', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 150;
- ctrl.panel.xaxis.max = 100;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis max should be ignored otherwise the bucketSize is negative', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(200);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- // aaa
- describe('when graph is histogram, and xaxis min is greater than the maximum value', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 301;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis min should be ignored otherwise the bucketSize is negative', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min is equal to the maximum value', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 300;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis min should be ignored otherwise the bucketSize is zero', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis min is lower than the minimum value', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.min = 99;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('xaxis min should not affect the histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- describe('when graph is histogram, and xaxis max is equal to the minimum value', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.max = 100;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should calculate correct histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- });
- });
- describe('when graph is histogram, and xaxis max is a lower than the minimum value', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.max = 99;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should calculate empty histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(nonZero.length).toBe(0);
- });
- });
- describe('when graph is histogram, and xaxis max is greater than the maximum value', () => {
- beforeEach(() => {
- setupCtx(() => {
- ctrl.panel.xaxis.mode = 'histogram';
- ctrl.panel.xaxis.max = 301;
- ctrl.panel.stack = false;
- ctrl.hiddenSeries = {};
- ctx.data[0] = new TimeSeries({
- datapoints: [[100, 1], [100, 2], [200, 3], [300, 4]],
- alias: 'series1',
- });
- });
- });
- it('should calculate correct histogram', () => {
- const nonZero = ctx.plotData[0].data.filter((t: number[]) => t[1] > 0);
- expect(Math.min.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(100);
- expect(Math.max.apply(Math, nonZero.map((t: number[]) => t[0]))).toBe(300);
- });
- });
- });
|