Skip to content

Commit

Permalink
Consistent colors rendered client side
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jan 24, 2016
1 parent e6920f8 commit a3c2ee0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
4 changes: 3 additions & 1 deletion panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ var px = (function() {
var parser = document.createElement('a');
parser.href = data.json_endpoint;
if (dashboard !== undefined){
qrystr = parser.search + "&extra_filters=" + JSON.stringify(dashboard.filters);
var flts = encodeURIComponent(JSON.stringify(dashboard.filters));
qrystr = parser.search + "&extra_filters=" + flts;
}
else if ($('#query').length == 0){
qrystr = parser.search;
Expand Down Expand Up @@ -489,5 +490,6 @@ var px = (function() {
timeFormatFactory: timeFormatFactory,
colorBnb: colorBnb,
bnbColors: bnbColors,
color: colorBnb(),
}
})();
6 changes: 5 additions & 1 deletion panoramix/static/widgets/viz_nvd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function viz_nvd3(slice) {
var fd = payload.form_data;
var viz_type = fd.viz_type;
var f = d3.format('.3s');
var colorKey = 'key';
nv.addGraph(function() {
if (viz_type === 'line') {
if (fd.show_brush) {
Expand Down Expand Up @@ -48,6 +49,7 @@ function viz_nvd3(slice) {

} else if (viz_type === 'pie') {
chart = nv.models.pieChart()
colorKey = 'x';
chart.showLegend(fd.show_legend);
chart.valueFormat(f);
if (fd.donut) {
Expand Down Expand Up @@ -144,7 +146,9 @@ function viz_nvd3(slice) {
}
}

chart.duration(0);
chart.color(function(d, i){
return px.color(d[colorKey]);
});
d3.select(slice.selector).append("svg")
.datum(payload.data)
.transition().duration(500)
Expand Down
5 changes: 2 additions & 3 deletions panoramix/static/widgets/viz_wordcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ px.registerViz('word_cloud', function(slice) {
scale = d3.scale.linear()
.range(range)
.domain(d3.extent(data, function(d) { return d.size; }));
var fill = px.colorBnb();
var layout = d3.layout.cloud()
.size(size)
.words(data)
Expand All @@ -47,10 +46,10 @@ px.registerViz('word_cloud', function(slice) {
.attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
.selectAll("text")
.data(words)
.enter().append("text")
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.style("fill", function(d, i) {return px.color(d.text); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ") rotate(" + d.rotate + ")";
Expand Down
9 changes: 0 additions & 9 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,9 @@ def get_json_data(self):
for row in df.to_dict(orient='records'):
series[row['group']].append(row)
chart_data = []
cf = utils.ColorFactory()
for k, v in series.items():
chart_data.append({
'key': k,
"color": cf.get(str(k)),
'values': v })
return dumps(chart_data)

Expand Down Expand Up @@ -692,7 +690,6 @@ def to_series(self, df, classed='', title_suffix=''):
series = df.to_dict('series')

chart_data = []
cf = utils.ColorFactory()
for name in df.T.index.tolist():
ys = series[name]
if df[name].dtype.kind not in "biufc":
Expand All @@ -706,13 +703,11 @@ def to_series(self, df, classed='', title_suffix=''):
series_title = ", ".join(name)
else:
series_title = ", ".join(name[1:])
color = cf.get(series_title)
if title_suffix:
series_title += title_suffix

d = {
"key": series_title,
"color": color,
"classed": classed,
"values": [
{'x': ds, 'y': ys[ds]}
Expand Down Expand Up @@ -812,8 +807,6 @@ def get_json_data(self):
df = self.get_df()
df = df.reset_index()
df.columns = ['x', 'y']
cf = utils.ColorFactory()
df['color'] = map(cf.get, df.x)
return dumps(df.to_dict(orient="records"))


Expand Down Expand Up @@ -845,7 +838,6 @@ def get_json_data(self):
df = self.get_df()
series = df.to_dict('series')
chart_data = []
cf = utils.ColorFactory()
for name, ys in series.items():
if df[name].dtype.kind not in "biufc":
continue
Expand All @@ -858,7 +850,6 @@ def get_json_data(self):
series_title = ", ".join(name[1:])
d = {
"key": series_title,
"color": cf.get(series_title),
"values": [
{'x': ds, 'y': ys[i]}
for i, ds in enumerate(df.timestamp)]
Expand Down

0 comments on commit a3c2ee0

Please sign in to comment.