Improving the parallel coordinate viz (#452)

* Improving the parallel coordinate viz

* Clear container on refresh
* Order of columns is kept
* Option to show/hide the series column in viz
* Color metric not shown by default

* JS linting
This commit is contained in:
Maxime Beauchemin 2016-05-10 09:39:33 -07:00
parent c4e3020369
commit d79089c587
3 changed files with 24 additions and 5 deletions

View File

@ -12,8 +12,20 @@ function parallelCoordVis(slice) {
function refresh() {
$('#code').attr('rows', '15');
$.getJSON(slice.jsonEndpoint(), function (payload) {
var data = payload.data;
var fd = payload.form_data;
var data = payload.data;
var cols = fd.metrics;
if (fd.include_series) {
cols = [fd.series].concat(fd.metrics);
}
var ttypes = {};
ttypes[fd.series] = 'string';
fd.metrics.forEach(function (v) {
ttypes[v] = 'number';
});
var ext = d3.extent(data, function (d) {
return d[fd.secondary_metric];
});
@ -27,6 +39,7 @@ function parallelCoordVis(slice) {
return cScale(d[fd.secondary_metric]);
};
var container = d3.select(slice.selector);
container.selectAll('*').remove();
var eff_height = fd.show_datatable ? (slice.height() / 2) : slice.height();
container.append('div')
@ -40,7 +53,9 @@ function parallelCoordVis(slice) {
.alpha(0.5)
.composite("darken")
.height(eff_height)
.data(payload.data)
.data(data)
.dimensions(cols)
.types(ttypes)
.render()
.createAxes()
.shadows()

View File

@ -187,6 +187,10 @@ class FormFactory(object):
'Stacked Bars',
default=False,
description=""),
'include_series': BetterBooleanField(
'Include Series',
default=False,
description="Include series name as an axis"),
'secondary_metric': SelectField(
'Color Metric', choices=datasource.metrics_combo,
default=default_metric,

View File

@ -8,6 +8,7 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import copy
import hashlib
import json
import logging
@ -1461,14 +1462,14 @@ class ParallelCoordinatesViz(BaseViz):
'metrics',
'secondary_metric',
'limit',
('show_datatable', None),
('show_datatable', 'include_series'),
)
},)
def query_obj(self):
d = super(ParallelCoordinatesViz, self).query_obj()
fd = self.form_data
d['metrics'] = fd.get('metrics')
d['metrics'] = copy.copy(fd.get('metrics'))
second = fd.get('secondary_metric')
if second not in d['metrics']:
d['metrics'] += [second]
@ -1477,7 +1478,6 @@ class ParallelCoordinatesViz(BaseViz):
def get_data(self):
df = self.get_df()
df = df[[self.form_data.get('series')] + self.form_data.get('metrics')]
return df.to_dict(orient="records")