Skip to content

Commit

Permalink
updating based on brandons review
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Feb 15, 2017
1 parent 87804d1 commit 7e74262
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ module.directive('vislibSeries', function ($parse, $compile) {
}
}).join();
}, () => {
let serieCount = 0;
const schemaTitle = $scope.vis.type.schemas.metrics[0].title;
$scope.vis.aggs.forEach(agg => {
if (!agg.type) return;
if (agg.schema.title !== schemaTitle) return;
if (agg.type.type !== 'metrics') return;
if ($scope.vis.params.seriesParams[serieCount]) {
$scope.vis.params.seriesParams[serieCount].data.label = agg.makeLabel();

const metrics = $scope.vis.aggs.filter(agg => {
const isMetric = agg.type && agg.type.type === 'metrics';
return isMetric && agg.schema.title === schemaTitle;
});

// update labels for existing params or create new one
$scope.vis.params.seriesParams = metrics.map((agg, i) => {
const params = $scope.vis.params.seriesParams[i];
if (params) {
params.data.label = agg.makeLabel();
return params;
} else {
const serie = makeSerie(agg.makeLabel());
$scope.vis.params.seriesParams.push(serie);
const series = makeSerie(agg.makeLabel());
return series;
}
serieCount++;
});
$scope.vis.params.seriesParams = $scope.vis.params.seriesParams.slice(0, serieCount);
});

$scope.$watch(() => {
Expand Down
11 changes: 0 additions & 11 deletions src/core_plugins/kbn_vislib_vis_types/public/editors/area.html

This file was deleted.

This file was deleted.

23 changes: 0 additions & 23 deletions src/core_plugins/kbn_vislib_vis_types/public/editors/line.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default function PointSeriesVisType(Private) {
defaults: {
grid: {
categoryLines: false,
color: '#eee'
style: {
color: '#eee'
}
},
categoryAxes: [
{
Expand All @@ -40,6 +42,7 @@ export default function PointSeriesVisType(Private) {
valueAxes: [
{
id: 'ValueAxis-1',
name: 'LeftAxis-1',
type: 'value',
position: 'bottom',
show: true,
Expand All @@ -64,7 +67,9 @@ export default function PointSeriesVisType(Private) {
mode: 'normal',
data: {
label: 'Count'
}
},
drawLinesBetweenPoints: true,
showCircles: true
}],
addTooltip: true,
addLegend: true,
Expand Down
228 changes: 228 additions & 0 deletions src/ui/public/vislib/__tests__/lib/axis/axis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import d3 from 'd3';
import _ from 'lodash';
import ngMock from 'ng_mock';
import expect from 'expect.js';
import $ from 'jquery';
import VislibLibDataProvider from 'ui/vislib/lib/data';
import 'ui/persisted_state';
import VislibLibAxisProvider from 'ui/vislib/lib/axis';
import VislibVisConfig from 'ui/vislib/lib/vis_config';

describe('Vislib Axis Class Test Suite', function () {
let Axis;
let Data;
let persistedState;
let yAxis;
let el;
let fixture;
let VisConfig;
let seriesData;

const data = {
hits: 621,
ordered: {
date: true,
interval: 30000,
max: 1408734982458,
min: 1408734082458
},
series: [
{
label: 'Count',
values: [
{
x: 1408734060000,
y: 8
},
{
x: 1408734090000,
y: 23
},
{
x: 1408734120000,
y: 30
},
{
x: 1408734130000,
y: 30
},
{
x: 1408734150000,
y: 28
}
]
},
{
label: 'Count2',
values: [
{
x: 1408734060000,
y: 8
},
{
x: 1408734090000,
y: 23
},
{
x: 1408734120000,
y: 30
},
{
x: 1408734140000,
y: 30
},
{
x: 1408734150000,
y: 28
}
]
}
],
xAxisFormatter: function (thing) {
return new Date(thing);
},
xAxisLabel: 'Date Histogram',
yAxisLabel: 'Count'
};

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private, $injector) {
Data = Private(VislibLibDataProvider);
persistedState = new ($injector.get('PersistedState'))();
Axis = Private(VislibLibAxisProvider);
VisConfig = Private(VislibVisConfig);

el = d3.select('body').append('div')
.attr('class', 'x-axis-wrapper')
.style('height', '40px');

fixture = el.append('div')
.attr('class', 'x-axis-div');

const visConfig = new VisConfig({
type: 'histogram'
}, data, persistedState, $('.x-axis-div')[0]);
yAxis = new Axis(visConfig, {
type: 'value',
id: 'ValueAxis-1'
});

seriesData = data.series.map(series => {
return series.values;
});
}));

afterEach(function () {
fixture.remove();
el.remove();
});

describe('_stackNegAndPosVals Method', function () {

it('should correctly stack positive values', function () {
const expectedResult = [
{
x: 1408734060000,
y: 8,
y0: 8
},
{
x: 1408734090000,
y: 23,
y0: 23
},
{
x: 1408734120000,
y: 30,
y0: 30
},
{
x: 1408734140000,
y: 30,
y0: 0
},
{
x: 1408734150000,
y: 28,
y0: 28
}
];
const stackedData = yAxis._stackNegAndPosVals(seriesData);
expect(stackedData[1]).to.eql(expectedResult);
});

it('should correctly stack pos and neg values', function () {
const expectedResult = [
{
x: 1408734060000,
y: 8,
y0: 0
},
{
x: 1408734090000,
y: 23,
y0: 0
},
{
x: 1408734120000,
y: 30,
y0: 0
},
{
x: 1408734140000,
y: 30,
y0: 0
},
{
x: 1408734150000,
y: 28,
y0: 0
}
];
const dataClone = _.cloneDeep(seriesData);
dataClone[0].forEach(value => {
value.y = -value.y;
});
const stackedData = yAxis._stackNegAndPosVals(dataClone);
expect(stackedData[1]).to.eql(expectedResult);
});

it('should correctly stack mixed pos and neg values', function () {
const expectedResult = [
{
x: 1408734060000,
y: 8,
y0: 8
},
{
x: 1408734090000,
y: 23,
y0: 0
},
{
x: 1408734120000,
y: 30,
y0: 30
},
{
x: 1408734140000,
y: 30,
y0: 0
},
{
x: 1408734150000,
y: 28,
y0: 28
}
];
const dataClone = _.cloneDeep(seriesData);
dataClone[0].forEach((value, i) => {
if ((i % 2) === 1) value.y = -value.y;
});
const stackedData = yAxis._stackNegAndPosVals(dataClone);
expect(stackedData[1]).to.eql(expectedResult);
});

});

});
1 change: 1 addition & 0 deletions src/ui/public/vislib/lib/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function TypeFactory(Private) {
*/
return {
histogram: pointSeries.column,
horizontal_bar: pointSeries.column,
line: pointSeries.line,
pie: Private(VislibLibTypesPieProvider),
area: pointSeries.area,
Expand Down
2 changes: 0 additions & 2 deletions src/ui/public/vislib/lib/types/point_series.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import _ from 'lodash';
import errors from 'ui/errors';

export default function ColumnHandler(Private) {

const createSerieFromParams = (cfg, seri) => {
// todo this wont work with splits ... same issue exists in dispatch
const matchingSeriParams = cfg.seriesParams ? cfg.seriesParams.find(seriConfig => {
return seri.aggLabel === seriConfig.data.label;
}) : null;
Expand Down

0 comments on commit 7e74262

Please sign in to comment.