-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new visualize type: sankey #4832
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da11929
new visualize type: sankey
chenryn 1e6dc7c
Merge remote-tracking branch 'upstream/master'
chenryn 88480f8
remove unused argument upgraded from 4.1.1
chenryn 80eedb7
add testing of sankey in agg_response and vislib
chenryn 617b3e9
use metric.getValue() instead of doc_count
chenryn ac6e0ed
add Data.prototype.getSankeyColorFunc and use it in sankey chart
chenryn 5e1d5d3
no need `_removeZeroSlices`
chenryn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- vis type specific options --> | ||
<div> | ||
<label> | ||
Sankey | ||
</label> | ||
</div> | ||
<vislib-basic-options></vislib-basic-options> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
define(function (require) { | ||
return function HistogramVisType(Private) { | ||
var VislibVisType = Private(require('ui/vislib_vis_type/VislibVisType')); | ||
var Schemas = Private(require('ui/Vis/Schemas')); | ||
var sankeyBuilder = Private(require('ui/agg_response/sankey/sankey')); | ||
|
||
return new VislibVisType({ | ||
name: 'sankey', | ||
title: 'Sankey chart', | ||
icon: 'fa-sankey-chart', | ||
description: 'Sankey charts are ideal for displaying the material, energy and cost flows.' + | ||
'Pro Tip: Sankey charts are best used sparingly, and with no more than 7 slices per sankey.', | ||
params: { | ||
defaults: { | ||
shareYAxis: false, | ||
isDonut: false | ||
}, | ||
editor: require('plugins/kbn_vislib_vis_types/editors/sankey.html') | ||
}, | ||
sankeyConverter: sankeyBuilder, | ||
hierarchicalData: false, | ||
schemas: new Schemas([ | ||
{ | ||
group: 'metrics', | ||
name: 'metric', | ||
title: 'Slice Size', | ||
min: 1, | ||
aggFilter: ['sum', 'count', 'cardinality', 'min', 'max', 'avg'], | ||
defaults: [ | ||
{ schema: 'metric', type: 'count' } | ||
] | ||
}, | ||
{ | ||
group: 'buckets', | ||
name: 'segment', | ||
icon: 'fa fa-scissors', | ||
title: 'Split Slices', | ||
min: 0, | ||
max: Infinity, | ||
aggFilter: '!geohash_grid' | ||
}, | ||
{ | ||
group: 'buckets', | ||
name: 'split', | ||
icon: 'fa fa-th', | ||
title: 'Split Chart', | ||
mustBeFirst: true, | ||
min: 0, | ||
max: 1, | ||
aggFilter: '!geohash_grid' | ||
} | ||
]) | ||
}); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
var _ = require('lodash'); | ||
var fixtures = require('fixtures/fake_hierarchical_data'); | ||
var sinon = require('auto-release-sinon'); | ||
var expect = require('expect.js'); | ||
var ngMock = require('ngMock'); | ||
|
||
var Vis; | ||
var Notifier; | ||
var AggConfigs; | ||
var indexPattern; | ||
var buildSankey; | ||
|
||
describe('sankey', function () { | ||
|
||
beforeEach(ngMock.module('kibana')); | ||
beforeEach(ngMock.inject(function (Private, $injector) { | ||
Notifier = $injector.get('Notifier'); | ||
sinon.stub(Notifier.prototype, 'error'); | ||
|
||
Vis = Private(require('ui/Vis')); | ||
AggConfigs = Private(require('ui/Vis/AggConfigs')); | ||
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern')); | ||
buildSankey = Private(require('ui/agg_response/sankey/sankey')); | ||
})); | ||
|
||
describe('threeTermBuckets', function () { | ||
var vis; | ||
var results; | ||
|
||
beforeEach(function () { | ||
var id = 1; | ||
vis = new Vis(indexPattern, { | ||
type: 'sankey', | ||
aggs: [ | ||
{ type: 'count', schema: 'metric' }, | ||
{ type: 'terms', schema: 'segment', params: { field: 'extension' }}, | ||
{ type: 'terms', schema: 'segment', params: { field: 'machine.os' }}, | ||
{ type: 'terms', schema: 'segment', params: { field: 'geo.src' }} | ||
] | ||
}); | ||
// We need to set the aggs to a known value. | ||
_.each(vis.aggs, function (agg) { agg.id = 'agg_' + id++; }); | ||
results = buildSankey(vis, fixtures.threeTermBuckets); | ||
}); | ||
|
||
it('should have nodes and links attributes for the results', function () { | ||
expect(results).to.have.property('slices'); | ||
expect(results.slices).to.have.property('nodes'); | ||
expect(results.slices).to.have.property('links'); | ||
}); | ||
|
||
it('should have name attributes for the nodes array', function () { | ||
expect(results.slices.nodes).to.have.length(11); | ||
_.each(results.slices.nodes, function (item) { | ||
expect(item).to.have.property('name'); | ||
}); | ||
expect(results.slices.nodes[0].name).to.equal('png'); | ||
}); | ||
|
||
it('should have source, target and value attributes for the links array', function () { | ||
expect(results.slices.links).to.have.length(16); | ||
_.each(results.slices.links, function (item) { | ||
expect(item).to.have.property('source'); | ||
expect(item).to.have.property('target'); | ||
expect(item).to.have.property('value'); | ||
}); | ||
expect(results.slices.links[0].source).to.equal(0); | ||
expect(results.slices.links[0].target).to.equal(1); | ||
expect(results.slices.links[0].value).to.equal(10); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
define(function (require) { | ||
return function sankeyProvider(Private, Notifier) { | ||
var _ = require('lodash'); | ||
var arrayToLinkedList = require('ui/agg_response/hierarchical/_array_to_linked_list'); | ||
var notify = new Notifier({ | ||
location: 'Sankey chart response converter' | ||
}); | ||
var nodes = {}; | ||
var links = {}; | ||
var lastNode = -1; | ||
|
||
function processEntry(aggConfig, metric, aggData, prevNode) { | ||
_.each(aggData.buckets, function (b) { | ||
if (isNaN(nodes[b.key])) { | ||
nodes[b.key] = lastNode + 1; | ||
lastNode = _.max(_.values(nodes)); | ||
} | ||
if (aggConfig._previous) { | ||
var k = prevNode + 'sankeysplitchar' + nodes[b.key]; | ||
if (isNaN(links[k])) { | ||
links[k] = metric.getValue(b); | ||
} else { | ||
links[k] += metric.getValue(b); | ||
} | ||
} | ||
if (aggConfig._next) { | ||
processEntry(aggConfig._next, metric, b[aggConfig._next.id], nodes[b.key]); | ||
} | ||
}); | ||
} | ||
|
||
return function (vis, resp) { | ||
|
||
var metric = vis.aggs.bySchemaGroup.metrics[0]; | ||
var buckets = vis.aggs.bySchemaGroup.buckets; | ||
buckets = arrayToLinkedList(buckets); | ||
if (!buckets) { | ||
return {'slices':{'nodes':[],'links':[]}}; | ||
} | ||
|
||
var firstAgg = buckets[0]; | ||
var aggData = resp.aggregations[firstAgg.id]; | ||
|
||
if (!firstAgg._next) { | ||
notify.error('need more than one sub aggs'); | ||
} | ||
|
||
processEntry(firstAgg, metric, aggData, -1); | ||
|
||
var invertNodes = _.invert(nodes); | ||
var chart = { | ||
'slices': { | ||
'nodes' : _.map(_.keys(invertNodes), function (k) { return {'name':invertNodes[k]}; }), | ||
'links' : _.map(_.keys(links), function (k) { | ||
var s = k.split('sankeysplitchar'); | ||
return {'source': parseInt(s[0]), 'target': parseInt(s[1]), 'value': links[k]}; | ||
}) | ||
} | ||
}; | ||
|
||
return chart; | ||
}; | ||
}; | ||
}); |
59 changes: 59 additions & 0 deletions
59
src/ui/public/vislib/__tests__/visualizations/sankey_chart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var d3 = require('d3'); | ||
var angular = require('angular'); | ||
var expect = require('expect.js'); | ||
var ngMock = require('ngMock'); | ||
var _ = require('lodash'); | ||
var $ = require('jquery'); | ||
var fixtures = require('fixtures/fake_hierarchical_data'); | ||
|
||
var sliceAgg = [ | ||
{ type: 'count', schema: 'metric' }, | ||
{ type: 'terms', schema: 'segment', params: { field: 'extension' }}, | ||
{ type: 'terms', schema: 'segment', params: { field: 'machine.os' }}, | ||
{ type: 'terms', schema: 'segment', params: { field: 'geo.src' }} | ||
]; | ||
|
||
describe('Vislib SankeyChart Class Test Suite for slice data', function () { | ||
var visLibParams = { | ||
type: 'sankey' | ||
}; | ||
var vis; | ||
var Vis; | ||
var indexPattern; | ||
var buildSankey; | ||
var data; | ||
|
||
beforeEach(ngMock.module('kibana')); | ||
beforeEach(ngMock.inject(function (Private) { | ||
vis = Private(require('fixtures/vislib/_vis_fixture'))(visLibParams); | ||
Vis = Private(require('ui/Vis')); | ||
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern')); | ||
buildSankey = Private(require('ui/agg_response/sankey/sankey')); | ||
|
||
var id = 1; | ||
var stubVis = new Vis(indexPattern, { | ||
type: 'sankey', | ||
aggs: sliceAgg | ||
}); | ||
|
||
_.each(stubVis.aggs, function (agg) { agg.id = 'agg_' + id++; }); | ||
|
||
data = buildSankey(stubVis, fixtures.threeTermBuckets); | ||
|
||
vis.render(data); | ||
})); | ||
|
||
afterEach(function () { | ||
$(vis.el).remove(); | ||
vis = null; | ||
}); | ||
|
||
describe('draw method', function () { | ||
it('should return a function', function () { | ||
vis.handler.charts.forEach(function (chart) { | ||
expect(_.isFunction(chart.draw())).to.be(true); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
define(function (require) { | ||
return function sankeyHandler(Private) { | ||
var Handler = Private(require('ui/vislib/lib/handler/handler')); | ||
var Data = Private(require('ui/vislib/lib/data')); | ||
|
||
return function (vis) { | ||
var data = new Data(vis.data, vis._attr); | ||
|
||
var sankeyHandler = new Handler(vis, { | ||
data: data | ||
}); | ||
|
||
return sankeyHandler; | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true? Was this just a search/replace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right^-^.
Wrote a real sankey descirption now.