mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* graph: initial histogram support #600 * graph histogram mode: add Bars number option * graph histogram mode: fix X axis ticks calculation * graph histogram mode: change bar style (align and width) * refactor(graph): move histogram functions into separate module * graph histogram mode: rename series to "count" * graph histogram mode: fix errors if no data * refactor(graph and heatmap): move shared code into app/core * graph: add tests for histogram mode
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
///<reference path="../../../../headers/common.d.ts" />
|
|
|
|
import { describe, beforeEach, it, expect } from '../../../../../test/lib/common';
|
|
|
|
import { convertValuesToHistogram, getSeriesValues } from '../histogram';
|
|
|
|
describe('Graph Histogam Converter', function () {
|
|
|
|
describe('Values to histogram converter', () => {
|
|
let values;
|
|
let bucketSize = 10;
|
|
|
|
beforeEach(() => {
|
|
values = [1, 2, 10, 11, 17, 20, 29];
|
|
});
|
|
|
|
it('Should convert to series-like array', () => {
|
|
bucketSize = 10;
|
|
let expected = [
|
|
[0, 2], [10, 3], [20, 2]
|
|
];
|
|
|
|
let histogram = convertValuesToHistogram(values, bucketSize);
|
|
expect(histogram).to.eql(expected);
|
|
});
|
|
|
|
it('Should not add empty buckets', () => {
|
|
bucketSize = 5;
|
|
let expected = [
|
|
[0, 2], [10, 2], [15, 1], [20, 1], [25, 1]
|
|
];
|
|
|
|
let histogram = convertValuesToHistogram(values, bucketSize);
|
|
expect(histogram).to.eql(expected);
|
|
});
|
|
});
|
|
|
|
describe('Series to values converter', () => {
|
|
let data;
|
|
|
|
beforeEach(() => {
|
|
data = [
|
|
{
|
|
data: [[0, 1], [0, 2], [0, 10], [0, 11], [0, 17], [0, 20], [0, 29]]
|
|
}
|
|
];
|
|
});
|
|
|
|
it('Should convert to values array', () => {
|
|
let expected = [1, 2, 10, 11, 17, 20, 29];
|
|
|
|
let values = getSeriesValues(data);
|
|
expect(values).to.eql(expected);
|
|
});
|
|
|
|
it('Should skip null values', () => {
|
|
data[0].data.push([0, null]);
|
|
|
|
let expected = [1, 2, 10, 11, 17, 20, 29];
|
|
|
|
let values = getSeriesValues(data);
|
|
expect(values).to.eql(expected);
|
|
});
|
|
});
|
|
});
|