Skip to content

Commit

Permalink
Merge pull request apache#6 in DATA-PLATFORM/caravel from dev to master
Browse files Browse the repository at this point in the history
* commit 'ffc86fb7209084b8d0e78edbc9c4fe3b7f37ca7b':
  fix csv button
  stop and remove pm2 entry during run_prod.sh
  Fix bar value markers
  Fix annotatinos for stacked bar chart
  • Loading branch information
the-dcruz committed Oct 24, 2016
2 parents 37ad1b2 + ffc86fb commit 15c7d17
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
47 changes: 27 additions & 20 deletions caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const nv = require('nvd3');
require('../node_modules/nvd3/build/nv.d3.min.css');
require('./nvd3_vis.css');

const minBarWidth = 15;
const animationTime = 1000;

const addTotalBarValues = function (containerId, chart, data, stacked) {
Expand Down Expand Up @@ -43,10 +42,11 @@ const addTotalBarValues = function (containerId, chart, data, stacked) {
const xPos = parseFloat(rectObj.attr('x'));
const rectWidth = parseFloat(rectObj.attr('width'));
const t = groupLabels.append('text')
.attr('x', xPos) // rough position first, fine tune later
.attr('y', yPos - 5)
.attr('x', xPos + 5) // rough position first, fine tune later
.attr('y', yPos)
.style('font-size', '10px')
.text(format(stacked ? totalStackedValues[index] : d.y))
.attr('transform', transformAttr)
.attr('transform', transformAttr + 'rotate(-45,' + xPos + ',' + yPos +')')
.attr('class', 'bar-chart-label');
const labelWidth = t.node().getBBox().width;
t.attr('x', xPos + rectWidth / 2 - labelWidth / 2); // fine tune
Expand Down Expand Up @@ -239,11 +239,15 @@ function nvd3Vis(slice) {

const barchartWidth = function () {
let bars;
let minBarWidth = 0;
if (fd.bar_stacked) {
bars = d3.max(payload.data, function (d) { return d.values.length; });
} else {
bars = d3.sum(payload.data, function (d) { return d.values.length; });
}
if (fd.show_bar_value) {
minBarWidth = 10;
}
if (bars * minBarWidth > width) {
return bars * minBarWidth;
}
Expand Down Expand Up @@ -299,25 +303,28 @@ function nvd3Vis(slice) {
chart.stacked(stacked);

if (fd.enable_annotations) {
const chartData = payload.data[0].values;
const latestDataDate = chartData[chartData.length - 1].x;

const dateValues = {};
chartData.forEach(function (barData) {
dateValues[barData.x] = true;
});

let yMax = 0;
payload.annotations.forEach(function (annotation) {
const annotationTimestamp = annotation.timestamp;
if (!(annotationTimestamp in dateValues)) {
if (annotationTimestamp > latestDataDate) {
chartData.push({ x: annotationTimestamp, y: 0 });

payload.data.forEach(function (data) {
const chartData = data.values;
const latestDataDate = chartData[chartData.length - 1].x;

const dateValues = {};
chartData.forEach(function (barData) {
dateValues[barData.x] = true;
});

payload.annotations.forEach(function (annotation) {
const annotationTimestamp = annotation.timestamp;
if (!(annotationTimestamp in dateValues)) {
if (annotationTimestamp > latestDataDate) {
chartData.push({x: annotationTimestamp, y: 0});
}
}
}

yMax = yMax > annotation.value ?
yMax : annotation.value;
yMax = yMax > annotation.value ?
yMax : annotation.value;
});
});
chart.forceY([0, yMax]);

Expand Down
2 changes: 1 addition & 1 deletion caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def json_dumps(self, obj):
def data(self):
"""This is the data object serialized to the js layer"""
content = {
'csv_end*point': self.csv_endpoint,
'csv_endpoint': self.csv_endpoint,
'form_data': self.form_data,
'json_endpoint': self.json_endpoint,
'standalone_endpoint': self.standalone_endpoint,
Expand Down
2 changes: 2 additions & 0 deletions run_prod.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/bash
/root/node_modules/pm2/bin/pm2 stop caravel
/root/node_modules/pm2/bin/pm2 delete caravel

python setup.py develop

Expand Down

0 comments on commit 15c7d17

Please sign in to comment.