";
+ return s;
+ }
+ });
rect.call(tip);
@@ -123,32 +130,36 @@ function heatmapVis(slice) {
var yscale_skip = 2;
var xAxis = d3.svg.axis()
- .scale(xRbScale)
- .tickValues(xRbScale.domain().filter(
- function(d, i) { return !(i % (parseInt(fd.xscale_interval))); }))
- .orient("bottom");
+ .scale(xRbScale)
+ .tickValues(xRbScale.domain().filter(
+ function(d, i) {
+ return !(i % (parseInt(fd.xscale_interval)));
+ }))
+ .orient("bottom");
var yAxis = d3.svg.axis()
- .scale(yRbScale)
- .tickValues(yRbScale.domain().filter(
- function(d, i) { return !(i % (parseInt(fd.yscale_interval))); }))
- .orient("left");
+ .scale(yRbScale)
+ .tickValues(yRbScale.domain().filter(
+ function(d, i) {
+ return !(i % (parseInt(fd.yscale_interval)));
+ }))
+ .orient("left");
svg.append("g")
- .attr("class", "x axis")
- .attr("transform", "translate(" + margins.l + "," + (margins.t + hmHeight) + ")")
- .call(xAxis)
- .selectAll("text")
- .style("text-anchor", "end")
- .attr("transform", "rotate(-45)")
- .style("font-weight", "bold");
+ .attr("class", "x axis")
+ .attr("transform", "translate(" + margins.l + "," + (margins.t + hmHeight) + ")")
+ .call(xAxis)
+ .selectAll("text")
+ .style("text-anchor", "end")
+ .attr("transform", "rotate(-45)")
+ .style("font-weight", "bold");
svg.append("g")
- .attr("class", "y axis")
- .attr("transform", "translate(" + margins.l + ", 0)")
- .call(yAxis);
+ .attr("class", "y axis")
+ .attr("transform", "translate(" + margins.l + ", 0)")
+ .call(yAxis);
- rect.on('mousemove', tip.show);
- rect.on('mouseout', tip.hide);
+ rect.on('mousemove', tip.show);
+ rect.on('mouseout', tip.hide);
var context = canvas.node().getContext("2d");
context.imageSmoothingEnabled = false;
@@ -163,28 +174,28 @@ function heatmapVis(slice) {
var image = context.createImageData(heatmapDim[0], heatmapDim[1]);
var pixs = {};
$.each(data, function(i, d) {
- var c = d3.rgb(color(d.perc));
- var x = xScale(d.x);
- var y = yScale(d.y);
- pixs[x + (y*xScale.domain().length)] = c;
- if (matrix[x] === undefined)
- matrix[x] = {}
- if (matrix[x][y] === undefined)
- matrix[x][y] = d;
+ var c = d3.rgb(color(d.perc));
+ var x = xScale(d.x);
+ var y = yScale(d.y);
+ pixs[x + (y * xScale.domain().length)] = c;
+ if (matrix[x] === undefined)
+ matrix[x] = {};
+ if (matrix[x][y] === undefined)
+ matrix[x][y] = d;
});
var p = -1;
- for(var i = 0; i < heatmapDim[0] * heatmapDim[1]; i++){
- var c = pixs[i];
- var alpha = 255;
- if (c === undefined){
- c = d3.rgb('#F00');
- alpha = 0;
- }
- image.data[++p] = c.r;
- image.data[++p] = c.g;
- image.data[++p] = c.b;
- image.data[++p] = alpha;
+ for (var i = 0; i < heatmapDim[0] * heatmapDim[1]; i++) {
+ var c = pixs[i];
+ var alpha = 255;
+ if (c === undefined) {
+ c = d3.rgb('#F00');
+ alpha = 0;
+ }
+ image.data[++p] = c.r;
+ image.data[++p] = c.g;
+ image.data[++p] = c.b;
+ image.data[++p] = alpha;
}
context.putImageData(image, 0, 0);
imageObj.src = canvas.node().toDataURL();
diff --git a/panoramix/assets/visualizations/iframe.js b/panoramix/assets/visualizations/iframe.js
index 546c28230f4a5..f2faae8f690a8 100644
--- a/panoramix/assets/visualizations/iframe.js
+++ b/panoramix/assets/visualizations/iframe.js
@@ -3,7 +3,7 @@ var $ = window.$ || require('jquery');
function iframeWidget(slice) {
function refresh() {
- $('#code').attr('rows', '15')
+ $('#code').attr('rows', '15');
$.getJSON(slice.jsonEndpoint(), function(payload) {
slice.container.html('
');
var iframe = slice.container.find('iframe');
@@ -14,7 +14,7 @@ function iframeWidget(slice) {
.fail(function(xhr) {
slice.error(xhr.responseText);
});
- };
+ }
return {
render: refresh,
@@ -22,4 +22,4 @@ function iframeWidget(slice) {
};
}
-module.exports = iframeWidget
+module.exports = iframeWidget;
diff --git a/panoramix/assets/visualizations/markup.js b/panoramix/assets/visualizations/markup.js
index 4fe808b4e4d3e..3c31ce5a14ef8 100644
--- a/panoramix/assets/visualizations/markup.js
+++ b/panoramix/assets/visualizations/markup.js
@@ -12,7 +12,7 @@ function markupWidget(slice) {
.fail(function(xhr) {
slice.error(xhr.responseText);
});
- };
+ }
return {
render: refresh,
diff --git a/panoramix/assets/visualizations/nvd3_vis.js b/panoramix/assets/visualizations/nvd3_vis.js
index 1ee5ef09853bf..14a4191c2db10 100644
--- a/panoramix/assets/visualizations/nvd3_vis.js
+++ b/panoramix/assets/visualizations/nvd3_vis.js
@@ -1,5 +1,5 @@
// JS
-var $ = window.$ || require('jquery');
+var $ = window.$ || require('jquery');
var px = window.px || require('../javascripts/modules/panoramix.js');
require('nvd3');
@@ -7,198 +7,189 @@ require('nvd3');
require('../node_modules/nvd3/build/nv.d3.min.css');
function nvd3Vis(slice) {
- var chart = undefined;
+ var chart;
var data = {};
var render = function() {
$.getJSON(slice.jsonEndpoint(), function(payload) {
- var fd = payload.form_data;
- var viz_type = fd.viz_type;
+ var fd = payload.form_data;
+ var viz_type = fd.viz_type;
+
+ var f = d3.format('.3s');
+ var colorKey = 'key';
+
+ nv.addGraph(function() {
+ switch (viz_type) {
+
+ case 'line':
+ if (fd.show_brush) {
+ chart = nv.models.lineWithFocusChart();
+ chart.lines2.xScale(d3.time.scale.utc());
+ chart.x2Axis
+ .showMaxMin(fd.x_axis_showminmax)
+ .staggerLabels(true);
+ } else {
+ chart = nv.models.lineChart();
+ }
+ // To alter the tooltip header
+ // chart.interactiveLayer.tooltip.headerFormatter(function(){return '';});
+ chart.xScale(d3.time.scale.utc());
+ chart.interpolate(fd.line_interpolation);
+ chart.xAxis
+ .showMaxMin(fd.x_axis_showminmax)
+ .staggerLabels(true);
+ break;
+
+ case 'bar':
+ chart = nv.models.multiBarChart()
+ .showControls(true)
+ .groupSpacing(0.1);
+
+ chart.xAxis
+ .showMaxMin(false)
+ .staggerLabels(true);
+
+ chart.stacked(fd.bar_stacked);
+ break;
+
+ case 'dist_bar':
+ chart = nv.models.multiBarChart()
+ .showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode.
+ .reduceXTicks(false)
+ .rotateLabels(45)
+ .groupSpacing(0.1); //Distance between each group of bars.
+
+ chart.xAxis
+ .showMaxMin(false);
+
+ chart.stacked(fd.bar_stacked);
+ break;
+
+ case 'pie':
+ chart = nv.models.pieChart();
+ colorKey = 'x';
+ chart.valueFormat(f);
+ if (fd.donut) {
+ chart.donut(true);
+ chart.labelsOutside(true);
+ }
+ chart.labelsOutside(true);
+ chart.cornerRadius(true);
+ break;
+
+ case 'column':
+ chart = nv.models.multiBarChart()
+ .reduceXTicks(false)
+ .rotateLabels(45);
+ break;
+
+ case 'compare':
+ chart = nv.models.cumulativeLineChart();
+ chart.xScale(d3.time.scale.utc());
+ chart.xAxis
+ .showMaxMin(false)
+ .staggerLabels(true);
+ break;
+
+ case 'bubble':
+ var row = function(col1, col2) {
+ return "
" + col1 + " | " + col2 + " |
";
+ };
+ chart = nv.models.scatterChart();
+ chart.showDistX(true);
+ chart.showDistY(true);
+ chart.tooltip.contentGenerator(function(obj) {
+ var p = obj.point;
+ var s = "
";
+ s += '' + p[fd.entity] + ' (' + p.group + ') |
';
+ s += row(fd.x, f(p.x));
+ s += row(fd.y, f(p.y));
+ s += row(fd.size, f(p.size));
+ s += "
";
+ return s;
+ });
+ chart.pointRange([5, fd.max_bubble_size * fd.max_bubble_size]);
+ break;
+
+ case 'area':
+ chart = nv.models.stackedAreaChart();
+ chart.style(fd.stacked_style);
+ chart.xScale(d3.time.scale.utc());
+ chart.xAxis
+ .showMaxMin(false)
+ .staggerLabels(true);
+ break;
+
+ default:
+ console.error("unrecognized visualization for nvd3", viz_type);
+ }
- var f = d3.format('.3s');
- var colorKey = 'key';
+ if ("showLegend" in chart && typeof fd.show_legend !== 'undefined') {
+ chart.showLegend(fd.show_legend);
+ }
- nv.addGraph(function() {
- switch (viz_type) {
+ var height = slice.height();
- case 'line':
- if (fd.show_brush) {
- chart = nv.models.lineWithFocusChart();
- chart.lines2.xScale(d3.time.scale.utc());
- chart.x2Axis
- .showMaxMin(fd.x_axis_showminmax)
- .staggerLabels(false);
- } else {
- chart = nv.models.lineChart()
- }
- // To alter the tooltip header
- // chart.interactiveLayer.tooltip.headerFormatter(function(){return '';});
- chart.xScale(d3.time.scale.utc());
- chart.interpolate(fd.line_interpolation);
- chart.xAxis
- .showMaxMin(fd.x_axis_showminmax)
- .staggerLabels(true);
- break;
-
- case 'bar':
- chart = nv.models.multiBarChart()
- .showControls(true)
- .groupSpacing(0.1);
-
- chart.xAxis
- .showMaxMin(false)
- .staggerLabels(true);
-
- chart.stacked(fd.bar_stacked);
- break;
-
- case 'dist_bar':
- chart = nv.models.multiBarChart()
- .showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode.
- .reduceXTicks(false)
- .rotateLabels(45)
- .groupSpacing(0.1); //Distance between each group of bars.
-
- chart.xAxis
- .showMaxMin(false);
-
- chart.stacked(fd.bar_stacked);
- break;
-
- case 'pie':
- chart = nv.models.pieChart()
- colorKey = 'x';
- chart.valueFormat(f);
- if (fd.donut) {
- chart.donut(true);
- chart.labelsOutside(true);
- }
- chart.labelsOutside(true);
- chart.cornerRadius(true);
- break;
-
- case 'column':
- chart = nv.models.multiBarChart()
- .reduceXTicks(false)
- .rotateLabels(45);
- break;
-
- case 'compare':
- chart = nv.models.cumulativeLineChart();
- chart.xScale(d3.time.scale.utc());
- chart.xAxis
- .showMaxMin(false)
- .staggerLabels(true);
- break;
-
- case 'bubble':
- var row = function(col1, col2) {
- return "
" + col1 + " | " + col2 + " |
";
- };
- chart = nv.models.scatterChart();
- chart.showDistX(true);
- chart.showDistY(true);
- chart.tooltip.contentGenerator(function (obj) {
- var p = obj.point;
- var s = "
";
- s += '' + p[fd.entity] + ' (' + p.group + ') |
';
- s += row(fd.x, f(p.x));
- s += row(fd.y, f(p.y));
- s += row(fd.size, f(p.size));
- s += "
";
- return s;
- });
- chart.pointRange([5, fd.max_bubble_size * fd.max_bubble_size]);
- break;
-
- case 'area':
- chart = nv.models.stackedAreaChart();
- chart.style(fd.stacked_style);
- chart.xScale(d3.time.scale.utc());
- chart.xAxis
- .showMaxMin(false)
- .staggerLabels(true);
- break;
-
- default:
- console.error("unrecognized visualization for nvd3", viz_type);
- }
-
- if ("showLegend" in chart && typeof fd.show_legend !== 'undefined') {
- chart.showLegend(fd.show_legend);
- }
-
- var height = slice.height();
-
- if(chart.hasOwnProperty("x2Axis")) {
- height += 30;
- }
- chart.height(height);
- slice.container.css('height', height + 'px');
-
- if ((viz_type === "line" || viz_type === "area") && fd.rich_tooltip) {
- chart.useInteractiveGuideline(true);
- }
- if (fd.y_axis_zero) {
- chart.forceY([0, 1]);
- }
- else if (fd.y_log_scale) {
- chart.yScale(d3.scale.log());
- }
- if (fd.x_log_scale) {
- chart.xScale(d3.scale.log());
- }
- if (viz_type === 'bubble') {
- chart.xAxis.tickFormat(d3.format('.3s'));
- }
- else if (fd.x_axis_format == 'smart_date') {
- chart.xAxis.tickFormat(px.formatDate);
- if(chart.hasOwnProperty("x2Axis")) {
- chart.x2Axis.tickFormat(px.formatDate);
+ if (chart.hasOwnProperty("x2Axis")) {
+ height += 30;
}
- }
- else if (fd.x_axis_format !== undefined) {
- var tf = px.timeFormatFactory(fd.x_axis_format);
- chart.xAxis.tickFormat(tf);
- if(chart.hasOwnProperty("x2Axis")) {
- chart.x2Axis.tickFormat(tf);
+ chart.height(height);
+ slice.container.css('height', height + 'px');
+
+ if ((viz_type === "line" || viz_type === "area") && fd.rich_tooltip) {
+ chart.useInteractiveGuideline(true);
}
- }
- if (chart.yAxis !== undefined) {
- chart.yAxis.tickFormat(d3.format('.3s'));
- }
-
- if (fd.contribution || fd.num_period_compare || viz_type == 'compare') {
- chart.yAxis.tickFormat(d3.format('.3p'));
- if (chart.y2Axis != undefined) {
- chart.y2Axis.tickFormat(d3.format('.3p'));
+ if (fd.y_axis_zero) {
+ chart.forceY([0, 1]);
+ } else if (fd.y_log_scale) {
+ chart.yScale(d3.scale.log());
+ }
+ if (fd.x_log_scale) {
+ chart.xScale(d3.scale.log());
}
- } else if (fd.y_axis_format) {
- chart.yAxis.tickFormat(d3.format(fd.y_axis_format));
+ if (viz_type === 'bubble') {
+ chart.xAxis.tickFormat(d3.format('.3s'));
+ } else if (fd.x_axis_format == 'smart_date') {
+ chart.xAxis.tickFormat(px.formatDate);
+ } else if (fd.x_axis_format !== undefined) {
+ chart.xAxis.tickFormat(px.timeFormatFactory(fd.x_axis_format));
+ }
+ if (chart.yAxis !== undefined) {
+ chart.yAxis.tickFormat(d3.format('.3s'));
+ }
+
+ if (fd.contribution || fd.num_period_compare || viz_type == 'compare') {
+ chart.yAxis.tickFormat(d3.format('.3p'));
+ if (chart.y2Axis !== undefined) {
+ chart.y2Axis.tickFormat(d3.format('.3p'));
+ }
+ } else if (fd.y_axis_format) {
+ chart.yAxis.tickFormat(d3.format(fd.y_axis_format));
- if (chart.y2Axis != undefined) {
- chart.y2Axis.tickFormat(d3.format(fd.y_axis_format));
+ if (chart.y2Axis !== undefined) {
+ chart.y2Axis.tickFormat(d3.format(fd.y_axis_format));
+ }
}
- }
- chart.color(function(d, i){
- return px.color.category21(d[colorKey]);
- });
+ chart.color(function(d, i) {
+ return px.color.category21(d[colorKey]);
+ });
- d3.select(slice.selector).append("svg")
- .datum(payload.data)
- .transition().duration(500)
- .attr('height', height)
- .call(chart);
+ d3.select(slice.selector).html('');
+ d3.select(slice.selector).append("svg")
+ .datum(payload.data)
+ .transition().duration(500)
+ .attr('height', height)
+ .call(chart);
- return chart;
- });
+ return chart;
+ });
- slice.done(payload);
- })
- .fail(function(xhr) {
- slice.error(xhr.responseText);
- });
+ slice.done(payload);
+ })
+ .fail(function(xhr) {
+ slice.error(xhr.responseText);
+ });
};
var update = function() {
@@ -211,6 +202,6 @@ function nvd3Vis(slice) {
render: render,
resize: update,
};
-};
+}
module.exports = nvd3Vis;
diff --git a/panoramix/assets/visualizations/parallel_coordinates.js b/panoramix/assets/visualizations/parallel_coordinates.js
index fa80224bd1c8e..575db6d3c168f 100644
--- a/panoramix/assets/visualizations/parallel_coordinates.js
+++ b/panoramix/assets/visualizations/parallel_coordinates.js
@@ -1,7 +1,7 @@
// JS
var d3 = window.d3 || require('d3');
d3.parcoords = require('../vendor/parallel_coordinates/d3.parcoords.js');
-d3.divgrid = require('../vendor/parallel_coordinates/divgrid.js');
+d3.divgrid = require('../vendor/parallel_coordinates/divgrid.js');
// CSS
require('../vendor/parallel_coordinates/d3.parcoords.css');
@@ -9,20 +9,22 @@ require('../vendor/parallel_coordinates/d3.parcoords.css');
function parallelCoordVis(slice) {
function refresh() {
- $('#code').attr('rows', '15')
- $.getJSON(slice.jsonEndpoint(), function(payload) {
+ $('#code').attr('rows', '15');
+ $.getJSON(slice.jsonEndpoint(), function(payload) {
var data = payload.data;
var fd = payload.form_data;
- var ext = d3.extent(data, function(d){
+ var ext = d3.extent(data, function(d) {
return d[fd.secondary_metric];
});
- ext = [ext[0], (ext[1]-ext[0])/2,ext[1]];
+ ext = [ext[0], (ext[1] - ext[0]) / 2, ext[1]];
var cScale = d3.scale.linear()
.domain(ext)
.range(['red', 'grey', 'blue'])
.interpolate(d3.interpolateLab);
- var color = function(d){return cScale(d[fd.secondary_metric])};
+ var color = function(d) {
+ return cScale(d[fd.secondary_metric]);
+ };
var container = d3.select(slice.selector);
var eff_height = fd.show_datatable ? (slice.height() / 2) : slice.height();
@@ -48,23 +50,27 @@ function parallelCoordVis(slice) {
// create data table, row hover highlighting
var grid = d3.divgrid();
container.append("div")
- .datum(data.slice(0,10))
+ .datum(data.slice(0, 10))
.attr('id', "grid")
.call(grid)
.classed("parcoords", true)
.selectAll(".row")
.on({
- "mouseover": function(d) { parcoords.highlight([d]) },
+ "mouseover": function(d) {
+ parcoords.highlight([d]);
+ },
"mouseout": parcoords.unhighlight
});
// update data table on brush event
parcoords.on("brush", function(d) {
d3.select("#grid")
- .datum(d.slice(0,10))
+ .datum(d.slice(0, 10))
.call(grid)
.selectAll(".row")
.on({
- "mouseover": function(d) { parcoords.highlight([d]) },
+ "mouseover": function(d) {
+ parcoords.highlight([d]);
+ },
"mouseout": parcoords.unhighlight
});
});
@@ -72,14 +78,14 @@ function parallelCoordVis(slice) {
slice.done();
})
.fail(function(xhr) {
- slice.error(xhr.responseText);
- });
- };
+ slice.error(xhr.responseText);
+ });
+ }
return {
render: refresh,
resize: refresh,
};
-};
+}
module.exports = parallelCoordVis;
diff --git a/panoramix/assets/visualizations/pivot_table.js b/panoramix/assets/visualizations/pivot_table.js
index 398815faa3b21..dc74253d60eb5 100644
--- a/panoramix/assets/visualizations/pivot_table.js
+++ b/panoramix/assets/visualizations/pivot_table.js
@@ -1,28 +1,27 @@
-
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
require('datatables');
require('./pivot_table.css');
-require('../node_modules/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css')
+require('../node_modules/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
module.exports = function(slice) {
var container = slice.container;
var form_data = slice.data.form_data;
function refresh() {
- $.getJSON(slice.jsonEndpoint(), function(json){
+ $.getJSON(slice.jsonEndpoint(), function(json) {
container.html(json.data);
- if (form_data.groupby.length == 1){
+ if (form_data.groupby.length == 1) {
var table = container.find('table').DataTable({
paging: false,
searching: false,
});
- table.column('-1').order( 'desc' ).draw();
+ table.column('-1').order('desc').draw();
}
slice.done(json);
- }).fail(function(xhr){
- slice.error(xhr.responseText);
+ }).fail(function(xhr) {
+ slice.error(xhr.responseText);
});
}
return {
diff --git a/panoramix/assets/visualizations/sankey.js b/panoramix/assets/visualizations/sankey.js
index dc6cd76b972e1..aeaccd57992e1 100644
--- a/panoramix/assets/visualizations/sankey.js
+++ b/panoramix/assets/visualizations/sankey.js
@@ -9,96 +9,133 @@ function sankeyVis(slice) {
var div = d3.select(slice.selector);
var render = function() {
- var margin = {top: 5, right: 5, bottom: 5, left: 5};
- var width = slice.width() - margin.left - margin.right;
- var height = slice.height() - margin.top - margin.bottom;
+ var margin = {
+ top: 5,
+ right: 5,
+ bottom: 5,
+ left: 5
+ };
+ var width = slice.width() - margin.left - margin.right;
+ var height = slice.height() - margin.top - margin.bottom;
- var formatNumber = d3.format(",.0f"),
- format = function(d) { return formatNumber(d) + " TWh"; };
+ var formatNumber = d3.format(",.0f"),
+ format = function(d) {
+ return formatNumber(d) + " TWh";
+ };
- var svg = div.append("svg")
- .attr("width", width + margin.left + margin.right)
- .attr("height", height + margin.top + margin.bottom)
- .append("g")
- .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
+ var svg = div.append("svg")
+ .attr("width", width + margin.left + margin.right)
+ .attr("height", height + margin.top + margin.bottom)
+ .append("g")
+ .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
- var sankey = d3.sankey()
- .nodeWidth(15)
- .nodePadding(10)
- .size([width, height]);
+ var sankey = d3.sankey()
+ .nodeWidth(15)
+ .nodePadding(10)
+ .size([width, height]);
- var path = sankey.link();
+ var path = sankey.link();
- d3.json(slice.jsonEndpoint(), function(error, json) {
- if (error != null){
- slice.error(error.responseText);
- return '';
- }
- var links = json.data;
- var nodes = {};
- // Compute the distinct nodes from the links.
- links.forEach(function(link) {
- link.source = nodes[link.source] ||
- (nodes[link.source] = {name: link.source});
- link.target = nodes[link.target] ||
- (nodes[link.target] = {name: link.target});
- link.value = +link.value;
- });
- nodes = d3.values(nodes);
+ d3.json(slice.jsonEndpoint(), function(error, json) {
+ if (error !== null) {
+ slice.error(error.responseText);
+ return '';
+ }
+ var links = json.data;
+ var nodes = {};
+ // Compute the distinct nodes from the links.
+ links.forEach(function(link) {
+ link.source = nodes[link.source] ||
+ (nodes[link.source] = {
+ name: link.source
+ });
+ link.target = nodes[link.target] ||
+ (nodes[link.target] = {
+ name: link.target
+ });
+ link.value = +link.value;
+ });
+ nodes = d3.values(nodes);
- sankey
- .nodes(nodes)
- .links(links)
- .layout(32);
+ sankey
+ .nodes(nodes)
+ .links(links)
+ .layout(32);
- var link = svg.append("g").selectAll(".link")
- .data(links)
- .enter().append("path")
- .attr("class", "link")
- .attr("d", path)
- .style("stroke-width", function(d) { return Math.max(1, d.dy); })
- .sort(function(a, b) { return b.dy - a.dy; });
+ var link = svg.append("g").selectAll(".link")
+ .data(links)
+ .enter().append("path")
+ .attr("class", "link")
+ .attr("d", path)
+ .style("stroke-width", function(d) {
+ return Math.max(1, d.dy);
+ })
+ .sort(function(a, b) {
+ return b.dy - a.dy;
+ });
- link.append("title")
- .text(function(d) { return d.source.name + " → " + d.target.name + "\n" + format(d.value); });
+ link.append("title")
+ .text(function(d) {
+ return d.source.name + " → " + d.target.name + "\n" + format(d.value);
+ });
- var node = svg.append("g").selectAll(".node")
- .data(nodes)
- .enter().append("g")
- .attr("class", "node")
- .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
- .call(d3.behavior.drag()
- .origin(function(d) { return d; })
- .on("dragstart", function() { this.parentNode.appendChild(this); })
- .on("drag", dragmove));
+ var node = svg.append("g").selectAll(".node")
+ .data(nodes)
+ .enter().append("g")
+ .attr("class", "node")
+ .attr("transform", function(d) {
+ return "translate(" + d.x + "," + d.y + ")";
+ })
+ .call(d3.behavior.drag()
+ .origin(function(d) {
+ return d;
+ })
+ .on("dragstart", function() {
+ this.parentNode.appendChild(this);
+ })
+ .on("drag", dragmove));
- node.append("rect")
- .attr("height", function(d) { return d.dy; })
- .attr("width", sankey.nodeWidth())
- .style("fill", function(d) { return d.color = px.color.category21(d.name.replace(/ .*/, "")); })
- .style("stroke", function(d) { return d3.rgb(d.color).darker(2); })
- .append("title")
- .text(function(d) { return d.name + "\n" + format(d.value); });
+ node.append("rect")
+ .attr("height", function(d) {
+ return d.dy;
+ })
+ .attr("width", sankey.nodeWidth())
+ .style("fill", function(d) {
+ return d.color = px.color.category21(d.name.replace(/ .*/, ""));
+ })
+ .style("stroke", function(d) {
+ return d3.rgb(d.color).darker(2);
+ })
+ .append("title")
+ .text(function(d) {
+ return d.name + "\n" + format(d.value);
+ });
- node.append("text")
- .attr("x", -6)
- .attr("y", function(d) { return d.dy / 2; })
- .attr("dy", ".35em")
- .attr("text-anchor", "end")
- .attr("transform", null)
- .text(function(d) { return d.name; })
- .filter(function(d) { return d.x < width / 2; })
- .attr("x", 6 + sankey.nodeWidth())
- .attr("text-anchor", "start");
+ node.append("text")
+ .attr("x", -6)
+ .attr("y", function(d) {
+ return d.dy / 2;
+ })
+ .attr("dy", ".35em")
+ .attr("text-anchor", "end")
+ .attr("transform", null)
+ .text(function(d) {
+ return d.name;
+ })
+ .filter(function(d) {
+ return d.x < width / 2;
+ })
+ .attr("x", 6 + sankey.nodeWidth())
+ .attr("text-anchor", "start");
- function dragmove(d) {
- d3.select(this).attr("transform", "translate(" + d.x + "," + (d.y = Math.max(0, Math.min(height - d.dy, d3.event.y))) + ")");
- sankey.relayout();
- link.attr("d", path);
- }
- slice.done(json);
- });
- }
+ function dragmove(d) {
+ d3.select(this).attr("transform", "translate(" + d.x + "," + (d.y = Math.max(0, Math.min(height - d.dy, d3.event.y))) + ")");
+ sankey.relayout();
+ link.attr("d", path);
+ }
+ slice.done(json);
+ });
+ };
return {
render: render,
resize: render,
diff --git a/panoramix/assets/visualizations/sunburst.js b/panoramix/assets/visualizations/sunburst.js
index e9435478e050a..07940662e3f8d 100644
--- a/panoramix/assets/visualizations/sunburst.js
+++ b/panoramix/assets/visualizations/sunburst.js
@@ -1,8 +1,7 @@
require('./sunburst.css');
-/*
- Modified from http://bl.ocks.org/kerryrodden/7090426
- */
+// Modified from http://bl.ocks.org/kerryrodden/7090426
+
function sunburstVis(slice) {
var container = d3.select(slice.selector);
var render = function() {
@@ -27,18 +26,28 @@ function sunburstVis(slice) {
var partition = d3.layout.partition()
.size([2 * Math.PI, radius * radius])
- .value(function(d) { return d.m1; });
+ .value(function(d) {
+ return d.m1;
+ });
var arc = d3.svg.arc()
- .startAngle(function(d) { return d.x; })
- .endAngle(function(d) { return d.x + d.dx; })
- .innerRadius(function(d) { return Math.sqrt(d.y); })
- .outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });
+ .startAngle(function(d) {
+ return d.x;
+ })
+ .endAngle(function(d) {
+ return d.x + d.dx;
+ })
+ .innerRadius(function(d) {
+ return Math.sqrt(d.y);
+ })
+ .outerRadius(function(d) {
+ return Math.sqrt(d.y + d.dy);
+ });
var ext;
- d3.json(slice.jsonEndpoint(), function(error, json){
+ d3.json(slice.jsonEndpoint(), function(error, json) {
- if (error != null){
+ if (error !== null) {
slice.error(error.responseText);
return '';
}
@@ -62,23 +71,29 @@ function sunburstVis(slice) {
.filter(function(d) {
return (d.dx > 0.005); // 0.005 radians = 0.29 degrees
});
- ext = d3.extent(nodes, function(d){return d.m2 / d.m1;});
+ ext = d3.extent(nodes, function(d) {
+ return d.m2 / d.m1;
+ });
var colorScale = d3.scale.linear()
- .domain([ext[0], ext[0] + ((ext[1] - ext[0]) / 2), ext[1]])
- .range(["#00D1C1", "white","#FFB400"]);
+ .domain([ext[0], ext[0] + ((ext[1] - ext[0]) / 2), ext[1]])
+ .range(["#00D1C1", "white", "#FFB400"]);
var path = arcs.data([json]).selectAll("path")
- .data(nodes)
+ .data(nodes)
.enter().append("svg:path")
- .attr("display", function(d) { return d.depth ? null : "none"; })
- .attr("d", arc)
- .attr("fill-rule", "evenodd")
- .style("stroke", "grey")
- .style("stroke-width", "1px")
- .style("fill", function(d) { return colorScale(d.m2/d.m1); })
- .style("opacity", 1)
- .on("mouseenter", mouseenter);
+ .attr("display", function(d) {
+ return d.depth ? null : "none";
+ })
+ .attr("d", arc)
+ .attr("fill-rule", "evenodd")
+ .style("stroke", "grey")
+ .style("stroke-width", "1px")
+ .style("fill", function(d) {
+ return colorScale(d.m2 / d.m1);
+ })
+ .style("opacity", 1)
+ .on("mouseenter", mouseenter);
// Add the mouseleave handler to the bounding circle.
@@ -86,7 +101,7 @@ function sunburstVis(slice) {
// Get total size of the tree = value of root node from partition.
totalSize = path.node().__data__.value;
- };
+ }
var f = d3.format(".3s");
var fp = d3.format(".3p");
@@ -110,9 +125,10 @@ function sunburstVis(slice) {
.classed("middle", true)
.style("font-size", "15px")
.attr("y", "50")
- .text("m2/m1: " + fp(d.m2/d.m1));
+ .text("m2/m1: " + fp(d.m2 / d.m1));
var sequenceArray = getAncestors(d);
+
function breadcrumbPoints(d, i) {
var points = [];
points.push("0,0");
@@ -129,10 +145,10 @@ function sunburstVis(slice) {
// Update the breadcrumb trail to show the current sequence and percentage.
function updateBreadcrumbs(nodeArray, percentageString) {
var l = [];
- for(var i=0; i
')
+ var s = l.join(' > ');
gMiddleText.append("text")
.text(s)
.classed("middle", true)
@@ -142,8 +158,8 @@ function sunburstVis(slice) {
// Fade all the segments.
arcs.selectAll("path")
- .style("stroke-width", "1px")
- .style("opacity", 0.3);
+ .style("stroke-width", "1px")
+ .style("opacity", 0.3);
// Then highlight only those that are an ancestor of the current segment.
arcs.selectAll("path")
@@ -193,25 +209,28 @@ function sunburstVis(slice) {
}
function buildHierarchy(rows) {
- var root = {"name": "root", "children": []};
+ var root = {
+ "name": "root",
+ "children": []
+ };
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
- var m1 = +row[row.length-2];
- var m2 = +row[row.length-1];
- var parts = row.slice(0, row.length-2);
+ var m1 = +row[row.length - 2];
+ var m2 = +row[row.length - 1];
+ var parts = row.slice(0, row.length - 2);
if (isNaN(m1)) { // e.g. if this is a header row
continue;
}
var currentNode = root;
for (var j = 0; j < parts.length; j++) {
- var children = currentNode["children"];
+ var children = currentNode.children;
var nodeName = parts[j];
var childNode;
if (j + 1 < parts.length) {
// Not yet at the end of the sequence; move down the tree.
var foundChild = false;
for (var k = 0; k < children.length; k++) {
- if (children[k]["name"] == nodeName) {
+ if (children[k].name == nodeName) {
childNode = children[k];
foundChild = true;
break;
@@ -219,40 +238,48 @@ function sunburstVis(slice) {
}
// If we don't already have a child node for this branch, create it.
if (!foundChild) {
- childNode = {"name": nodeName, "children": []};
+ childNode = {
+ "name": nodeName,
+ "children": []
+ };
children.push(childNode);
}
currentNode = childNode;
} else {
// Reached the end of the sequence; create a leaf node.
- childNode = {"name": nodeName, "m1": m1, 'm2': m2};
+ childNode = {
+ "name": nodeName,
+ "m1": m1,
+ 'm2': m2
+ };
children.push(childNode);
}
}
}
- function recurse(node){
- if (node.children){
+
+ function recurse(node) {
+ if (node.children) {
var sums;
var m1 = 0;
var m2 = 0;
- for (var i=0; i=0};
+ return {
+ col: c,
+ val: row[c],
+ isMetric: metrics.indexOf(c) >= 0
+ };
});
- }).enter()
- .append('td')
- .style('background-image', function(d){
- if (d.isMetric){
+ }).enter()
+ .append('td')
+ .style('background-image', function(d) {
+ if (d.isMetric) {
var perc = Math.round((d.val / maxes[d.col]) * 100);
return "linear-gradient(to right, lightgrey, lightgrey " + perc + "%, rgba(0,0,0,0) " + perc + "%";
}
- })
- .attr('title', function(d){
- if (!isNaN(d.val))
- return fC(d.val);
- })
- .attr('data-sort', function(d){
+ })
+ .attr('title', function(d) {
+ if (!isNaN(d.val))
+ return fC(d.val);
+ })
+ .attr('data-sort', function(d) {
if (d.isMetric)
return d.val;
- })
- .on("click", function(d){
- if(!d.isMetric){
+ })
+ .on("click", function(d) {
+ if (!d.isMetric) {
var td = d3.select(this);
- if (td.classed('filtered')){
- slice.clearFilter(d.col, [d.val]);
- table.selectAll('.filtered').classed('filtered', false);
+ if (td.classed('filtered')) {
+ slice.removeFilter(d.col, [d.val]);
+ d3.select(this).classed('filtered', false);
} else {
- table.selectAll('.filtered').classed('filtered', false);
d3.select(this).classed('filtered', true);
- slice.addFilter([[d.col, [d.val]]]);
+ slice.addFilter(d.col, [d.val]);
}
}
- })
- .style("cursor", function(d){
- if(!d.isMetric){
- return 'pointer';
- }
- })
- .html(function(d){
+ })
+ .style("cursor", function(d) {
+ if (!d.isMetric) {
+ return 'pointer';
+ }
+ })
+ .html(function(d) {
if (d.isMetric)
return f(d.val);
else
return d.val;
- });
+ });
var datatable = slice.container.find('.dataTable').DataTable({
paging: false,
searching: form_data.include_search,
@@ -93,19 +99,19 @@ function tableVis(slice) {
// Sorting table by main column
if (form_data.metrics.length > 0) {
var main_metric = form_data.metrics[0];
- datatable.column(data.columns.indexOf(main_metric)).order( 'desc' ).draw();
+ datatable.column(data.columns.indexOf(main_metric)).order('desc').draw();
}
slice.done(json);
slice.container.parents('.widget').find('.tooltip').remove();
- }).fail(function(xhr){
+ }).fail(function(xhr) {
slice.error(xhr.responseText);
});
}
return {
render: refresh,
- resize: function(){},
+ resize: function() {},
};
-};
+}
module.exports = tableVis;
diff --git a/panoramix/assets/visualizations/word_cloud.js b/panoramix/assets/visualizations/word_cloud.js
index 257f7947a0da6..7a000693bdad4 100644
--- a/panoramix/assets/visualizations/word_cloud.js
+++ b/panoramix/assets/visualizations/word_cloud.js
@@ -3,11 +3,11 @@ var d3 = window.d3 || require('d3');
var cloudLayout = require('d3-cloud');
function wordCloudChart(slice) {
- var slice = slice;
var chart = d3.select(slice.selector);
+
function refresh() {
d3.json(slice.jsonEndpoint(), function(error, json) {
- if (error != null){
+ if (error !== null) {
slice.error(error.responseText);
return '';
}
@@ -17,20 +17,27 @@ function wordCloudChart(slice) {
json.form_data.size_to,
];
var rotation = json.form_data.rotation;
+ var f_rotation;
if (rotation == "square") {
- var f_rotation = function() { return ~~(Math.random() * 2) * 90; };
- }
- else if (rotation == "flat") {
- var f_rotation = function() { return 0 };
- }
- else {
- var f_rotation = function() { return (~~(Math.random() * 6) - 3) * 30; };
+ f_rotation = function() {
+ return ~~(Math.random() * 2) * 90;
+ };
+ } else if (rotation == "flat") {
+ f_rotation = function() {
+ return 0;
+ };
+ } else {
+ f_rotation = function() {
+ return (~~(Math.random() * 6) - 3) * 30;
+ };
}
var size = [slice.width(), slice.height()];
var scale = d3.scale.linear()
.range(range)
- .domain(d3.extent(data, function(d) { return d.size; }));
+ .domain(d3.extent(data, function(d) {
+ return d.size;
+ }));
var layout = cloudLayout()
.size(size)
@@ -38,7 +45,9 @@ function wordCloudChart(slice) {
.padding(5)
.rotate(f_rotation)
.font("serif")
- .fontSize(function(d) { return scale(d.size); })
+ .fontSize(function(d) {
+ return scale(d.size);
+ })
.on("end", draw);
layout.start();
@@ -47,21 +56,27 @@ function wordCloudChart(slice) {
chart.selectAll("*").remove();
chart.append("svg")
- .attr("width", layout.size()[0])
- .attr("height", layout.size()[1])
+ .attr("width", layout.size()[0])
+ .attr("height", layout.size()[1])
.append("g")
- .attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
+ .attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
.selectAll("text")
- .data(words)
- .enter().append("text")
- .style("font-size", function(d) { return d.size + "px"; })
- .style("font-family", "Impact")
- .style("fill", function(d, i) {return px.color.category21(d.text); })
- .attr("text-anchor", "middle")
- .attr("transform", function(d) {
- return "translate(" + [d.x, d.y] + ") rotate(" + d.rotate + ")";
- })
- .text(function(d) { return d.text; });
+ .data(words)
+ .enter().append("text")
+ .style("font-size", function(d) {
+ return d.size + "px";
+ })
+ .style("font-family", "Impact")
+ .style("fill", function(d, i) {
+ return px.color.category21(d.text);
+ })
+ .attr("text-anchor", "middle")
+ .attr("transform", function(d) {
+ return "translate(" + [d.x, d.y] + ") rotate(" + d.rotate + ")";
+ })
+ .text(function(d) {
+ return d.text;
+ });
}
slice.done(data);
});
diff --git a/panoramix/assets/visualizations/world_map.js b/panoramix/assets/visualizations/world_map.js
index 155039337815d..986653f0f24ce 100644
--- a/panoramix/assets/visualizations/world_map.js
+++ b/panoramix/assets/visualizations/world_map.js
@@ -13,31 +13,35 @@ function worldMapChart(slice) {
container.css('height', slice.height());
- d3.json(slice.jsonEndpoint(), function(error, json){
+ d3.json(slice.jsonEndpoint(), function(error, json) {
var fd = json.form_data;
- if (error != null){
+ if (error !== null) {
slice.error(error.responseText);
return '';
}
- var ext = d3.extent(json.data, function(d){return d.m1});
- var extRadius = d3.extent(json.data, function(d){return d.m2});
+ var ext = d3.extent(json.data, function(d) {
+ return d.m1;
+ });
+ var extRadius = d3.extent(json.data, function(d) {
+ return d.m2;
+ });
var radiusScale = d3.scale.linear()
.domain([extRadius[0], extRadius[1]])
.range([1, fd.max_bubble_size]);
- json.data.forEach(function(d){
- d.radius = radiusScale(d.m2);
- });
+ json.data.forEach(function(d) {
+ d.radius = radiusScale(d.m2);
+ });
var colorScale = d3.scale.linear()
.domain([ext[0], ext[1]])
.range(["#FFF", "black"]);
var d = {};
- for (var i=0; i' + data.name + '
'+ f(data.m1) + '';
},
},
bubblesConfig: {
@@ -70,7 +74,7 @@ function worldMapChart(slice) {
popupOnHover: true,
radius: null,
popupTemplate: function(geo, data) {
- return '
';
},
fillOpacity: 0.5,
animate: true,
@@ -95,7 +99,7 @@ function worldMapChart(slice) {
slice.done(json);
});
- }
+ };
return {
render: render,
diff --git a/panoramix/templates/panoramix/featured.html b/panoramix/templates/panoramix/featured.html
index 86e71a60ec735..29a646b704a1f 100644
--- a/panoramix/templates/panoramix/featured.html
+++ b/panoramix/templates/panoramix/featured.html
@@ -24,7 +24,7 @@