mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
removing duplicate file, adding functionality for choosing min and max values for y-axis using HTML5 validation
This commit is contained in:
parent
b70756a6cc
commit
7ba54eca2f
16 changed files with 63 additions and 76 deletions
|
@ -247,16 +247,6 @@ define(function (require) {
|
|||
};
|
||||
inherits(errors.PieContainsAllZeros, KbnError);
|
||||
|
||||
/**
|
||||
* y axis min value cannot be larger than y axis max value
|
||||
*/
|
||||
errors.YMinGreaterThanYMax = function YMinGreaterThanYMax() {
|
||||
KbnError.call(this,
|
||||
'The y-axis minimum value is greater than the y-axis maximum value',
|
||||
errors.YMinGreaterThanYMax);
|
||||
};
|
||||
inherits(errors.YMinGreaterThanYMax, KbnError);
|
||||
|
||||
/**
|
||||
* error thrown when no results are returned from an elasticsearch query
|
||||
*/
|
||||
|
|
|
@ -20,8 +20,7 @@ define(function (require) {
|
|||
opts = opts || {};
|
||||
|
||||
return function (vis) {
|
||||
var isUserDefinedYAxisMin = vis._attr.setYExtents.min;
|
||||
var isUserDefinedYAxisMax = vis._attr.setYExtents.max;
|
||||
var isUserDefinedYAxis = vis._attr.setYExtents;
|
||||
var data;
|
||||
|
||||
if (opts.zeroFill) {
|
||||
|
@ -46,8 +45,8 @@ define(function (require) {
|
|||
alerts: new Alerts(vis, data, opts.alerts),
|
||||
yAxis: new YAxis({
|
||||
el : vis.el,
|
||||
yMin : (isUserDefinedYAxisMin) ? vis._attr.yAxis.min : data.getYMin(),
|
||||
yMax : (isUserDefinedYAxisMax) ? vis._attr.yAxis.max : data.getYMax(),
|
||||
yMin : (isUserDefinedYAxis) ? vis._attr.yAxis.min : data.getYMin(),
|
||||
yMax : (isUserDefinedYAxis) ? vis._attr.yAxis.max : data.getYMax(),
|
||||
_attr: vis._attr
|
||||
})
|
||||
});
|
||||
|
|
|
@ -38,7 +38,7 @@ define(function (require) {
|
|||
};
|
||||
|
||||
YAxis.prototype._isUserDefined = function () {
|
||||
return (this._attr.setYExtents.min || this._attr.setYExtents.max);
|
||||
return (this._attr.setYExtents);
|
||||
};
|
||||
|
||||
YAxis.prototype._isYExtents = function () {
|
||||
|
@ -47,28 +47,20 @@ define(function (require) {
|
|||
|
||||
YAxis.prototype._validateUserExtents = function (domain) {
|
||||
var self = this;
|
||||
var extents = ['min', 'max'];
|
||||
|
||||
return domain.map(function (val, i) {
|
||||
var extent = extents[i];
|
||||
return domain.map(function (val) {
|
||||
val = parseInt(val, 10);
|
||||
|
||||
if (isNaN(val)) throw new Error(val + ' is not a valid number');
|
||||
if (self._isPercentage() && self._attr.setYExtents[extent]) return val / 100;
|
||||
if (self._isPercentage() && self._attr.setYExtents) return val / 100;
|
||||
return val;
|
||||
});
|
||||
};
|
||||
|
||||
YAxis.prototype._validateAxisExtents = function (min, max) {
|
||||
if (min === max) throw new errors.NoResults();
|
||||
if (min > max) throw new errors.YMinGreaterThanYMax();
|
||||
};
|
||||
|
||||
YAxis.prototype._getExtents = function (domain) {
|
||||
var min = domain[0];
|
||||
var max = domain[1];
|
||||
|
||||
this._validateAxisExtents(min, max);
|
||||
if (this._attr.scale === 'log') return this._logDomain(min, max); // Negative values cannot be displayed with a log scale.
|
||||
if (!this._isYExtents() && !this._isUserDefined()) return [Math.min(0, min), Math.max(0, max)];
|
||||
if (this._isUserDefined()) return this._validateUserExtents(domain);
|
||||
|
|
|
@ -83,7 +83,6 @@ define(function (require) {
|
|||
error instanceof errors.CannotLogScaleNegVals ||
|
||||
error instanceof errors.PieContainsAllZeros ||
|
||||
error instanceof errors.NotEnoughData ||
|
||||
error instanceof errors.YMinGreaterThanYMax ||
|
||||
error instanceof errors.NoResults) {
|
||||
this.handler.error(error.message);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<div>
|
||||
<div class="vis-option-item">
|
||||
<label>
|
||||
<input type="checkbox" ng-model="vis.params.setYExtents">
|
||||
Set Y-Axis Extents
|
||||
</label>
|
||||
<div ng-if="vis.params.setYExtents">
|
||||
<label>
|
||||
y-max
|
||||
<input name="yMax"
|
||||
class="form-control"
|
||||
type="number"
|
||||
step="0.1"
|
||||
min="{{vis.params.yAxis.min}}"
|
||||
ng-model="vis.params.yAxis.max"
|
||||
ng-required="vis.params.setYExtents">
|
||||
</label>
|
||||
<label>
|
||||
y-min
|
||||
<input name="yMin"
|
||||
class="form-control"
|
||||
type="number"
|
||||
step="0.1"
|
||||
max="{{vis.params.yAxis.max}}"
|
||||
ng-model="vis.params.yAxis.min"
|
||||
ng-required="vis.params.setYExtents">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,16 @@
|
|||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
var module = require('modules').get('kibana');
|
||||
|
||||
module.directive('pointSeriesOptions', function ($parse, $compile) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: require('text!plugins/vis_types/controls/point_series_options.html'),
|
||||
replace: true,
|
||||
link: function (scope, elem, attrs) {
|
||||
console.log(scope.$parent.visualizeEditor);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
|
@ -17,30 +17,4 @@
|
|||
Scale Y-Axis to Data Bounds
|
||||
</label>
|
||||
</div>
|
||||
<div class="vis-option-item">
|
||||
<label>
|
||||
<input type="checkbox" ng-model="vis.params.setYExtents.max">
|
||||
Set Y-Axis Max Value
|
||||
</label>
|
||||
<div ng-show="vis.params.setYExtents.max">
|
||||
<label>
|
||||
y-max
|
||||
<input name="y-max" class="form-control" type="number" step="0.1" ng-model="vis.params.yAxis.max"
|
||||
ng-required="vis.params.setYExtents.max">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="vis-option-item">
|
||||
<label>
|
||||
<input type="checkbox" ng-model="vis.params.setYExtents.min">
|
||||
Set Y-Axis Min Value
|
||||
</label>
|
||||
<div ng-show="vis.params.setYExtents.min">
|
||||
<label>
|
||||
y-min
|
||||
<input name="y-min" class="form-control" type="number" step="0.1" ng-model="vis.params.yAxis.min"
|
||||
ng-required="vis.params.setYExtents.min">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -8,6 +8,7 @@ define(function (require) {
|
|||
var VislibRenderbot = Private(require('plugins/vis_types/vislib/_vislib_renderbot'));
|
||||
|
||||
require('plugins/vis_types/controls/vislib_basic_options');
|
||||
require('plugins/vis_types/controls/point_series_options');
|
||||
require('plugins/vis_types/controls/line_interpolation_option');
|
||||
|
||||
_(VislibVisType).inherits(VisType);
|
||||
|
|
|
@ -21,10 +21,7 @@ define(function (require) {
|
|||
interpolate: 'linear',
|
||||
mode: 'stacked',
|
||||
defaultYExtents: false,
|
||||
setYExtents: {
|
||||
max: false,
|
||||
min: false
|
||||
},
|
||||
setYExtents: false,
|
||||
yAxis: {}
|
||||
},
|
||||
scales: ['linear', 'log', 'square root'],
|
||||
|
|
|
@ -7,4 +7,5 @@
|
|||
</label>
|
||||
</div>
|
||||
<line-interpolation-option></line-interpolation-option>
|
||||
<point-series-options></point-series-options>
|
||||
<vislib-basic-options></vislib-basic-options>
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
</label>
|
||||
<select class="form-control" ng-model="vis.params.mode" ng-options="mode for mode in vis.type.params.modes"></select>
|
||||
</div>
|
||||
<point-series-options></point-series-options>
|
||||
<vislib-basic-options></vislib-basic-options>
|
||||
|
|
|
@ -19,4 +19,5 @@
|
|||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<point-series-options></point-series-options>
|
||||
<vislib-basic-options></vislib-basic-options>
|
||||
|
|
|
@ -17,10 +17,7 @@ define(function (require) {
|
|||
scale: 'linear',
|
||||
mode: 'stacked',
|
||||
defaultYExtents: false,
|
||||
setYExtents: {
|
||||
max: false,
|
||||
min: false
|
||||
},
|
||||
setYExtents: false,
|
||||
yAxis: {}
|
||||
},
|
||||
scales: ['linear', 'log', 'square root'],
|
||||
|
|
|
@ -20,10 +20,7 @@ define(function (require) {
|
|||
drawLinesBetweenPoints: true,
|
||||
radiusRatio: 9,
|
||||
defaultYExtents: false,
|
||||
setYExtents: {
|
||||
max: false,
|
||||
min: false
|
||||
},
|
||||
setYExtents: false,
|
||||
yAxis: {},
|
||||
scale: 'linear'
|
||||
},
|
||||
|
|
|
@ -18,10 +18,7 @@ define(function (require) {
|
|||
addTooltip: true,
|
||||
addLegend: true,
|
||||
defaultYExtents: false,
|
||||
setYExtents: {
|
||||
max: false,
|
||||
min: false
|
||||
},
|
||||
setYExtents: false,
|
||||
yAxis: {},
|
||||
type: 'histogram'
|
||||
});
|
||||
|
|
|
@ -77,10 +77,7 @@ define(function (require) {
|
|||
_attr: {
|
||||
margin: { top: 0, right: 0, bottom: 0, left: 0 },
|
||||
defaultYMin: true,
|
||||
setYExtents: {
|
||||
max: false,
|
||||
min: false
|
||||
},
|
||||
setYExtents: false,
|
||||
yAxis: {}
|
||||
}
|
||||
});
|
||||
|
@ -233,8 +230,7 @@ define(function (require) {
|
|||
|
||||
beforeEach(function () {
|
||||
yAxis._attr.mode = 'stacked';
|
||||
yAxis._attr.setYExtents.min = false;
|
||||
yAxis._attr.setYExtents.max = false;
|
||||
yAxis._attr.setYExtents = false;
|
||||
yAxis._attr.yAxis = {};
|
||||
});
|
||||
|
||||
|
@ -249,8 +245,7 @@ define(function (require) {
|
|||
|
||||
it('should return a decimal value', function () {
|
||||
yAxis._attr.mode = 'percentage';
|
||||
yAxis._attr.setYExtents.min = true;
|
||||
yAxis._attr.setYExtents.max = true;
|
||||
yAxis._attr.setYExtents = true;
|
||||
domain = [];
|
||||
domain[0] = yAxis._attr.yAxis.min = 20;
|
||||
domain[1] = yAxis._attr.yAxis.max = 80;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue