updating based on brandons review

This commit is contained in:
ppisljar 2017-02-10 12:05:54 +01:00
parent 87804d1942
commit 7e742627f8
8 changed files with 252 additions and 64 deletions

View file

@ -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();
} else {
const serie = makeSerie(agg.makeLabel());
$scope.vis.params.seriesParams.push(serie);
}
serieCount++;
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 series = makeSerie(agg.makeLabel());
return series;
}
});
$scope.vis.params.seriesParams = $scope.vis.params.seriesParams.slice(0, serieCount);
});
$scope.$watch(() => {

View file

@ -1,11 +0,0 @@
<!-- vis type specific options -->
<div>
<label>
Chart Mode
<select class="form-control" ng-model="vis.params.mode"
ng-options="mode for mode in vis.type.params.modes"></select>
</label>
</div>
<line-interpolation-option></line-interpolation-option>
<point-series-options></point-series-options>
<vislib-basic-options></vislib-basic-options>

View file

@ -1,13 +0,0 @@
<!-- vis type specific options -->
<div class="vis-option-item form-group">
<label>
Bar Mode
</label>
<select class="form-control" ng-model="vis.params.mode" ng-options="mode for mode in vis.type.params.modes"></select>
<label>
Y-Axis Scale
</label>
<select class="form-control" ng-model="vis.params.scale" ng-options="mode for mode in vis.type.params.scales"></select>
</div>
<point-series-options></point-series-options>
<vislib-basic-options></vislib-basic-options>

View file

@ -1,23 +0,0 @@
<div>
<label>
Y-Axis Scale
</label>
<select class="form-control" ng-model="vis.params.scale" ng-options="mode for mode in vis.type.params.scales"></select>
<!-- vis type specific options -->
<line-interpolation-option></line-interpolation-option>
<div class="vis-option-item">
<div>
<label>
<input type="checkbox" value="{{drawLinesBetweenPoints}}" ng-disabled="!vis.params.showCircles" ng-model="vis.params.drawLinesBetweenPoints" name="drawLinesBetweenPoints" ng-checked="vis.params.drawLinesBetweenPoints">
Show Connecting Lines
</label>
</div>
<div>
<label>
<input type="checkbox" value="{{showCircles}}" ng-disabled="!vis.params.drawLinesBetweenPoints" ng-model="vis.params.showCircles" name="showCircles" ng-checked="vis.params.showCircles">
Show Circles
</label>
</div>
</div>
<point-series-options></point-series-options>
<vislib-basic-options></vislib-basic-options>

View file

@ -15,7 +15,9 @@ export default function PointSeriesVisType(Private) {
defaults: {
grid: {
categoryLines: false,
color: '#eee'
style: {
color: '#eee'
}
},
categoryAxes: [
{
@ -40,6 +42,7 @@ export default function PointSeriesVisType(Private) {
valueAxes: [
{
id: 'ValueAxis-1',
name: 'LeftAxis-1',
type: 'value',
position: 'bottom',
show: true,
@ -64,7 +67,9 @@ export default function PointSeriesVisType(Private) {
mode: 'normal',
data: {
label: 'Count'
}
},
drawLinesBetweenPoints: true,
showCircles: true
}],
addTooltip: true,
addLegend: true,

View file

@ -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);
});
});
});

View file

@ -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,

View file

@ -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;