Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

Commit

Permalink
Add stacking to bars and lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Apr 28, 2016
1 parent 401e753 commit 37a6652
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Show the seriesList as bars
Argument | Accepts | Description
--- | --- | ---
width | *number* | Width of bars in pixels
stack | *boolean* | Should bars be stacked, true by default

#### .color()
Change the color of the series
Expand Down Expand Up @@ -160,6 +161,7 @@ Argument | Accepts | Description
--- | --- | ---
width | *number* | Line thickness
fill | *number* | Number between 0 and 10. Use for making area charts
stack | *boolean* | Stack lines, often misleading. At least use some fill if you use this
show | *number* | Show or hide lines
steps | *number* | Show line as step, eg, do not interpolate between points

Expand Down
5 changes: 5 additions & 0 deletions handlers/lib/index_arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module.exports = function indexArguments(functionDef, unorderedArgs) {
// Validation, does not change the arguments
_.each(unorderedArgs, function (arg, i) {
var type = argType(arg);

if (!functionDef.args[i]) {
throw new Error ('Unknown argument #' + i + ' supplied to ' + functionDef.name);
}

var required = functionDef.args[i].types;
var multi = functionDef.args[i].multi;
var name = functionDef.args[i].name;
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module.exports = function (kibana) {
flotSelection$: {
path: path.resolve(__dirname, 'bower_components/flot/jquery.flot.selection'),
imports: 'flot'
},
flotStack$: {
path: path.resolve(__dirname, 'bower_components/flot/jquery.flot.stack'),
imports: 'flot'
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timelion",
"version": "5.0.0-0.1.269",
"version": "5.0.0-0.1.270",
"dependencies": {
"body-parser": "^1.12.0",
"boom": "^2.8.0",
Expand Down
1 change: 1 addition & 0 deletions public/directives/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require('flotCrosshair');
require('flotCanvas');
require('flotSelection');
require('flotSymbol');
require('flotStack');

var app = require('ui/modules').get('apps/timelion', []);
var template = '<div class="chart-title"></div><div class="chart-canvas"></div>';
Expand Down
8 changes: 7 additions & 1 deletion series_functions/bars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ module.exports = new Chainable('bars', {
name: 'width',
types: ['number', 'null'],
help: 'Width of bars in pixels'
},
{
name: 'stack',
types: ['boolean', 'null'],
help: 'Should bars be stacked, true by default'
}
],
help: 'Show the seriesList as bars',
fn: function barsFn(args) {
return alter(args, function (eachSeries, width) {
return alter(args, function (eachSeries, width, stack) {
eachSeries.bars = eachSeries.bars || {};
eachSeries.bars.show = width == null ? 1 : width;
eachSeries.bars.lineWidth = width == null ? 6 : width;
eachSeries.stack = stack == null ? true : stack;
return eachSeries;
});
}
Expand Down
8 changes: 7 additions & 1 deletion series_functions/lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module.exports = new Chainable('lines', {
types: ['number', 'null'],
help: 'Number between 0 and 10. Use for making area charts'
},
{
name: 'stack',
types: ['boolean', 'null'],
help: 'Stack lines, often misleading. At least use some fill if you use this'
},
{
name: 'show',
types: ['number', 'null'],
Expand All @@ -30,14 +35,15 @@ module.exports = new Chainable('lines', {
],
help: 'Show the seriesList as lines',
fn: function linesFn(args) {
return alter(args, function (eachSeries, width, fill, show, steps) {
return alter(args, function (eachSeries, width, fill, stack, show, steps) {
eachSeries.lines = eachSeries.lines || {};

// Defaults
if (eachSeries.lines.lineWidth == null) eachSeries.lines.lineWidth = 3;

if (width != null) eachSeries.lines.lineWidth = width;
if (fill != null) eachSeries.lines.fill = fill / 10;
if (stack != null) eachSeries.stack = stack;
if (show != null) eachSeries.lines.show = show;
if (steps != null) eachSeries.lines.steps = steps;

Expand Down

0 comments on commit 37a6652

Please sign in to comment.