mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
refactored code in lib and the handler
This commit is contained in:
parent
234d6613d0
commit
1f2aaaaeab
23 changed files with 112 additions and 141 deletions
|
@ -1,9 +0,0 @@
|
|||
define(function (require) {
|
||||
return function LayoutTypeFactory(Private) {
|
||||
// visLib layout types
|
||||
return {
|
||||
histogram: Private(require('components/vislib/components/layouts/types/column_layout')),
|
||||
pie: Private(require('components/vislib/components/layouts/types/pie_layout'))
|
||||
};
|
||||
};
|
||||
});
|
|
@ -1,62 +0,0 @@
|
|||
define(function (require) {
|
||||
return function AxesHandlerClass(d3, Private) {
|
||||
var _ = require('lodash');
|
||||
|
||||
var Handler = Private(require('components/vislib/lib/handler/handler'));
|
||||
var Layout = Private(require('components/vislib/lib/layout'));
|
||||
var Legend = Private(require('components/vislib/lib/legend'));
|
||||
var XAxis = Private(require('components/vislib/lib/x_axis'));
|
||||
var YAxis = Private(require('components/vislib/lib/y_axis'));
|
||||
var AxisTitle = Private(require('components/vislib/lib/axis_title'));
|
||||
var ChartTitle = Private(require('components/vislib/lib/chart_title'));
|
||||
|
||||
_(AxesHandler).inherits(Handler);
|
||||
function AxesHandler(vis) {
|
||||
if (!(this instanceof AxesHandler)) {
|
||||
return new AxesHandler(vis);
|
||||
}
|
||||
AxesHandler.Super.apply(this, arguments);
|
||||
|
||||
var self = this;
|
||||
|
||||
// Visualization constructors
|
||||
this.layout = new Layout(this.el, this.data.injectZeros(), this._attr.type);
|
||||
|
||||
if (this._attr.addLegend) {
|
||||
this.legend = new Legend(this.vis, this.el, this.data.getLabels(), this.data.getColorFunc(), this._attr);
|
||||
}
|
||||
|
||||
this.axisTitle = new AxisTitle(this.el, this.data.get('xAxisLabel'), this.data.get('yAxisLabel'));
|
||||
this.chartTitle = new ChartTitle(this.el);
|
||||
|
||||
this.xAxis = new XAxis({
|
||||
el : this.el,
|
||||
xValues : this.data.xValues(),
|
||||
ordered : this.data.get('ordered'),
|
||||
xAxisFormatter: this.data.get('xAxisFormatter'),
|
||||
_attr : this._attr
|
||||
});
|
||||
|
||||
this.yAxis = new YAxis({
|
||||
el : this.el,
|
||||
yMax : this.data.getYMaxValue(),
|
||||
_attr: this._attr
|
||||
});
|
||||
|
||||
// Array of objects to render to the visualization
|
||||
_.forEach(_.filter([
|
||||
this.layout,
|
||||
this.legend,
|
||||
this.axisTitle,
|
||||
this.chartTitle,
|
||||
this.yAxis,
|
||||
this.xAxis
|
||||
], Boolean), function (_class) {
|
||||
self.renderArray.push(_class);
|
||||
});
|
||||
}
|
||||
|
||||
return AxesHandler;
|
||||
};
|
||||
});
|
||||
|
|
@ -3,6 +3,7 @@ define(function (require) {
|
|||
var _ = require('lodash');
|
||||
|
||||
var Data = Private(require('components/vislib/lib/data'));
|
||||
var Layout = Private(require('components/vislib/lib/layout/layout'));
|
||||
var Tooltip = Private(require('components/vislib/lib/tooltip'));
|
||||
|
||||
/*
|
||||
|
@ -13,12 +14,12 @@ define(function (require) {
|
|||
* returns an object with reference to the vis.prototype,
|
||||
* and news up all the constructors needed to build a visualization
|
||||
*/
|
||||
function Handler(vis) {
|
||||
function Handler(vis, opts) {
|
||||
if (!(this instanceof Handler)) {
|
||||
return new Handler(vis);
|
||||
return new Handler(vis, opts);
|
||||
}
|
||||
|
||||
this.data = new Data(vis.data, vis._attr);
|
||||
this.data = opts.data || new Data(vis.data, vis._attr);
|
||||
this.vis = vis;
|
||||
this.el = vis.el;
|
||||
this.ChartClass = vis.ChartClass;
|
||||
|
@ -27,12 +28,28 @@ define(function (require) {
|
|||
});
|
||||
|
||||
// Visualization constructors
|
||||
this.layout = new Layout(vis.el, vis.data, vis._attr.type);
|
||||
this.xAxis = opts.xAxis;
|
||||
this.yAxis = opts.yAxis;
|
||||
this.chartTitle = opts.chartTitle;
|
||||
this.axisTitle = opts.axisTitle;
|
||||
|
||||
if (this._attr.addTooltip) {
|
||||
this.tooltip = new Tooltip(this.el, this.data.get('tooltipFormatter'));
|
||||
}
|
||||
|
||||
if (this._attr.addLegend) {
|
||||
this.legend = opts.legend;
|
||||
}
|
||||
|
||||
// Array of objects to render to the visualization
|
||||
this.renderArray = _.filter([
|
||||
this.layout,
|
||||
this.xAxis,
|
||||
this.yAxis,
|
||||
this.chartTitle,
|
||||
this.axisTitle,
|
||||
this.legend,
|
||||
this.tooltip
|
||||
], Boolean);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,8 @@ define(function (require) {
|
|||
return function HandlerTypeFactory(Private) {
|
||||
// handler types
|
||||
return {
|
||||
histogram: Private(require('components/vislib/lib/handler/axes_handler')),
|
||||
line: Private(require('components/vislib/lib/handler/axes_handler')),
|
||||
pie: Private(require('components/vislib/lib/handler/pie_handler'))
|
||||
histogram: Private(require('components/vislib/lib/handler/types/column')),
|
||||
pie: Private(require('components/vislib/lib/handler/types/pie'))
|
||||
};
|
||||
};
|
||||
});
|
|
@ -1,40 +0,0 @@
|
|||
define(function (require) {
|
||||
return function PieHandlerClass(d3, Private) {
|
||||
var _ = require('lodash');
|
||||
|
||||
var Handler = Private(require('components/vislib/lib/handler/handler'));
|
||||
var Layout = Private(require('components/vislib/lib/layout'));
|
||||
var Legend = Private(require('components/vislib/lib/legend'));
|
||||
var ChartTitle = Private(require('components/vislib/lib/chart_title'));
|
||||
|
||||
_(PieHandler).inherits(Handler);
|
||||
function PieHandler(vis) {
|
||||
if (!(this instanceof PieHandler)) {
|
||||
return new PieHandler(vis);
|
||||
}
|
||||
PieHandler.Super.apply(this, arguments);
|
||||
|
||||
var self = this;
|
||||
|
||||
// Visualization constructors
|
||||
this.layout = new Layout(this.el, this.data.data, this._attr.type);
|
||||
|
||||
if (this._attr.addLegend) {
|
||||
this.legend = new Legend(this.vis, this.el, this.data.getPieNames(), this.data.getPieColorFunc(), this._attr);
|
||||
}
|
||||
|
||||
this.chartTitle = new ChartTitle(this.el);
|
||||
|
||||
// Array of objects to render to the visualization
|
||||
_.forEach(_.filter([
|
||||
this.layout,
|
||||
this.legend,
|
||||
this.chartTitle
|
||||
], Boolean), function (_class) {
|
||||
self.renderArray.push(_class);
|
||||
});
|
||||
}
|
||||
|
||||
return PieHandler;
|
||||
};
|
||||
});
|
40
src/kibana/components/vislib/lib/handler/types/column.js
Normal file
40
src/kibana/components/vislib/lib/handler/types/column.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
define(function (require) {
|
||||
return function ColumnHandler(d3, Private) {
|
||||
var _ = require('lodash');
|
||||
|
||||
var injectZeros = Private(require('components/vislib/components/zero_injection/inject_zeros'));
|
||||
var Handler = Private(require('components/vislib/lib/handler/handler'));
|
||||
var Data = Private(require('components/vislib/lib/data'));
|
||||
var Legend = Private(require('components/vislib/lib/legend'));
|
||||
var XAxis = Private(require('components/vislib/lib/x_axis'));
|
||||
var YAxis = Private(require('components/vislib/lib/y_axis'));
|
||||
var AxisTitle = Private(require('components/vislib/lib/axis_title'));
|
||||
var ChartTitle = Private(require('components/vislib/lib/chart_title'));
|
||||
|
||||
return function (vis) {
|
||||
var data = new Data(injectZeros(vis.data), vis._attr);
|
||||
|
||||
var ColumnHandler = new Handler(vis, {
|
||||
data: data,
|
||||
legend: new Legend(vis, vis.el, data.getLabels(), data.getColorFunc(), vis._attr),
|
||||
axisTitle: new AxisTitle(vis.el, data.get('xAxisLabel'), data.get('yAxisLabel')),
|
||||
chartTitle: new ChartTitle(vis.el),
|
||||
xAxis: new XAxis({
|
||||
el : vis.el,
|
||||
xValues : data.xValues(),
|
||||
ordered : data.get('ordered'),
|
||||
xAxisFormatter: data.get('xAxisFormatter'),
|
||||
_attr : vis._attr
|
||||
}),
|
||||
yAxis: new YAxis({
|
||||
el : vis.el,
|
||||
yMax : data.getYMaxValue(),
|
||||
_attr: vis._attr
|
||||
})
|
||||
});
|
||||
|
||||
return ColumnHandler;
|
||||
};
|
||||
};
|
||||
});
|
||||
|
20
src/kibana/components/vislib/lib/handler/types/pie.js
Normal file
20
src/kibana/components/vislib/lib/handler/types/pie.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
define(function (require) {
|
||||
return function PieHandler(d3, Private) {
|
||||
|
||||
var Handler = Private(require('components/vislib/lib/handler/handler'));
|
||||
var Data = Private(require('components/vislib/lib/data'));
|
||||
var Legend = Private(require('components/vislib/lib/legend'));
|
||||
var ChartTitle = Private(require('components/vislib/lib/chart_title'));
|
||||
|
||||
return function (vis) {
|
||||
var data = new Data(vis.data, vis._attr);
|
||||
|
||||
var PieHandler = new Handler(vis, {
|
||||
legend: new Legend(vis, vis.el, data.getPieNames(), data.getPieColorFunc(), vis._attr),
|
||||
chartTitle: new ChartTitle(vis.el)
|
||||
});
|
||||
|
||||
return PieHandler;
|
||||
};
|
||||
};
|
||||
});
|
|
@ -2,7 +2,7 @@ define(function (require) {
|
|||
return function LayoutFactory(d3, Private) {
|
||||
var _ = require('lodash');
|
||||
|
||||
var layoutType = Private(require('components/vislib/layout_types'));
|
||||
var layoutType = Private(require('components/vislib/lib/layout/layout_types'));
|
||||
|
||||
/*
|
||||
* The Layout Constructor is responsible for rendering the visualization
|
9
src/kibana/components/vislib/lib/layout/layout_types.js
Normal file
9
src/kibana/components/vislib/lib/layout/layout_types.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
define(function (require) {
|
||||
return function LayoutTypeFactory(Private) {
|
||||
// visLib layout types
|
||||
return {
|
||||
histogram: Private(require('components/vislib/lib/layout/types/column_layout')),
|
||||
pie: Private(require('components/vislib/lib/layout/types/pie_layout'))
|
||||
};
|
||||
};
|
||||
});
|
|
@ -1,10 +1,10 @@
|
|||
define(function (require) {
|
||||
return function ColumnLayoutFactory(d3, Private) {
|
||||
|
||||
var chartSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_split'));
|
||||
var yAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/y_axis_split'));
|
||||
var xAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/x_axis_split'));
|
||||
var chartTitleSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_title_split'));
|
||||
var chartSplit = Private(require('components/vislib/lib/layout/splits/column_chart/chart_split'));
|
||||
var yAxisSplit = Private(require('components/vislib/lib/layout/splits/column_chart/y_axis_split'));
|
||||
var xAxisSplit = Private(require('components/vislib/lib/layout/splits/column_chart/x_axis_split'));
|
||||
var chartTitleSplit = Private(require('components/vislib/lib/layout/splits/column_chart/chart_title_split'));
|
||||
|
||||
/*
|
||||
* Specifies the visualization layout for column charts.
|
|
@ -1,8 +1,8 @@
|
|||
define(function (require) {
|
||||
return function ColumnLayoutFactory(d3, Private) {
|
||||
|
||||
var chartSplit = Private(require('components/vislib/components/layouts/splits/pie_chart/chart_split'));
|
||||
var chartTitleSplit = Private(require('components/vislib/components/layouts/splits/pie_chart/chart_title_split'));
|
||||
var chartSplit = Private(require('components/vislib/lib/layout/splits/pie_chart/chart_split'));
|
||||
var chartTitleSplit = Private(require('components/vislib/lib/layout/splits/pie_chart/chart_title_split'));
|
||||
|
||||
/*
|
||||
* Specifies the visualization layout for column charts.
|
|
@ -5,7 +5,7 @@ define(function (require) {
|
|||
|
||||
var ResizeChecker = Private(require('components/vislib/lib/resize_checker'));
|
||||
var Events = Private(require('factories/events'));
|
||||
var handlerTypes = Private(require('components/vislib/handler_types'));
|
||||
var handlerTypes = Private(require('components/vislib/lib/handler/handler_types'));
|
||||
var chartTypes = Private(require('components/vislib/vis_types'));
|
||||
var errors = require('errors');
|
||||
require('css!components/vislib/components/styles/main.css');
|
||||
|
@ -45,7 +45,7 @@ define(function (require) {
|
|||
|
||||
// Save data to this object and new up the Handler constructor
|
||||
this.data = data;
|
||||
this.handler = new handlerTypes[chartType](this);
|
||||
this.handler = new handlerTypes[chartType](this) || handlerTypes.column(this);
|
||||
|
||||
try {
|
||||
this.handler.render();
|
||||
|
|
|
@ -73,7 +73,7 @@ define(function (require) {
|
|||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
layoutType = Private(require('components/vislib/layout_types'));
|
||||
layoutType = Private(require('components/vislib/lib/layout/layout_types'));
|
||||
el = d3.select('body').append('div').attr('class', 'visualization');
|
||||
columnLayout = layoutType.histogram(el, data);
|
||||
});
|
||||
|
|
|
@ -12,6 +12,7 @@ define(function (require) {
|
|||
var Data;
|
||||
var Handler;
|
||||
var handler;
|
||||
var ColumnHandler;
|
||||
var vis;
|
||||
var el;
|
||||
var example;
|
||||
|
@ -93,6 +94,7 @@ define(function (require) {
|
|||
Vis = Private(require('components/vislib/vis'));
|
||||
Data = Private(require('components/vislib/lib/data'));
|
||||
Handler = Private(require('components/vislib/lib/handler/handler'));
|
||||
ColumnHandler = Private(require('components/vislib/lib/handler/types/column'));
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'visualize');
|
||||
|
@ -105,14 +107,9 @@ define(function (require) {
|
|||
};
|
||||
|
||||
vis = new Vis(el[0][0], config);
|
||||
vis.data = data;
|
||||
|
||||
handler = new Handler({
|
||||
vis: vis,
|
||||
el: el[0][0],
|
||||
data: data,
|
||||
ChartClass: vis.ChartClass,
|
||||
_attr: config
|
||||
});
|
||||
handler = ColumnHandler(vis);
|
||||
|
||||
// handler.render(data);
|
||||
});
|
||||
|
|
|
@ -77,8 +77,8 @@ define(function (require) {
|
|||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
Layout = Private(require('components/vislib/lib/layout'));
|
||||
xAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/x_axis_split'));
|
||||
Layout = Private(require('components/vislib/lib/layout/layout'));
|
||||
xAxisSplit = Private(require('components/vislib/lib/layout/splits/column_chart/x_axis_split'));
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'visualize-chart');
|
||||
|
|
|
@ -14,7 +14,7 @@ define(function (require) {
|
|||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
layoutType = Private(require('components/vislib/layout_types'));
|
||||
layoutType = Private(require('components/vislib/lib/layout/layout_types'));
|
||||
layoutFunc = layoutType.histogram;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -144,10 +144,10 @@ define(function (require) {
|
|||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
chartSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_split'));
|
||||
chartTitleSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_title_split'));
|
||||
xAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/x_axis_split'));
|
||||
yAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/y_axis_split'));
|
||||
chartSplit = Private(require('components/vislib/lib/layout/splits/column_chart/chart_split'));
|
||||
chartTitleSplit = Private(require('components/vislib/lib/layout/splits/column_chart/chart_title_split'));
|
||||
xAxisSplit = Private(require('components/vislib/lib/layout/splits/column_chart/x_axis_split'));
|
||||
yAxisSplit = Private(require('components/vislib/lib/layout/splits/column_chart/y_axis_split'));
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'visualization')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue