From 6a28ad3f4e295f8401555c4fd51c946ea01a90c6 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 21 Dec 2015 07:58:20 -0800 Subject: [PATCH] Adding standalone mode --- TODO.md | 2 + panoramix/static/panoramix.css | 2 +- panoramix/static/panoramix.js | 358 +++++++++--------- .../static/widgets/viz_directed_force.css | 3 - .../static/widgets/viz_directed_force.js | 3 +- panoramix/templates/panoramix/dashboard.html | 4 +- panoramix/templates/panoramix/explore.html | 33 +- panoramix/templates/panoramix/standalone.html | 29 ++ panoramix/templates/panoramix/viz.html | 18 +- .../templates/panoramix/viz_standalone.html | 13 - panoramix/viz.py | 4 + 11 files changed, 246 insertions(+), 223 deletions(-) create mode 100644 panoramix/templates/panoramix/standalone.html delete mode 100644 panoramix/templates/panoramix/viz_standalone.html diff --git a/TODO.md b/TODO.md index 3690658f22..a808804501 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,8 @@ # TODO List of TODO items for Panoramix +* fix directed + ## Improvments * dashboard controller + filters * Color hash in JS diff --git a/panoramix/static/panoramix.css b/panoramix/static/panoramix.css index d671d23e32..de48069c14 100644 --- a/panoramix/static/panoramix.css +++ b/panoramix/static/panoramix.css @@ -136,7 +136,7 @@ legend { .datasource .tooltip-inner { max-width: 350px; } -.datasource img.loading { +img.loading { width: 30px; } diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js index 5b6ab45f30..71b121d858 100644 --- a/panoramix/static/panoramix.js +++ b/panoramix/static/panoramix.js @@ -1,6 +1,7 @@ var px = (function() { var visualizations = []; + var dashboard = undefined; var Slice = function(data, dashboard){ var timer; @@ -73,10 +74,14 @@ var px = (function() { container.hide(); container.html(''); timer = setInterval(stopwatch, 10); - viz.render(this); + viz.render(); }, resize: function() { - viz.resize(this); + token.find("img.loading").show(); + container.hide(); + container.html(''); + viz.render(); + viz.resize(); }, addFilter: function(col, vals) { if(dashboard !== undefined) @@ -92,10 +97,11 @@ var px = (function() { return slice; } - var Dashboard = function(){ + var Dashboard = function(id){ var dash = { slices: [], filters: {}, + id: id, addFilter: function(slice_id, field, values) { this.filters[slice_id] = [field, values]; this.refreshExcept(slice_id); @@ -111,6 +117,13 @@ var px = (function() { delete this.filters[slice_id]; this.refreshExcept(slice_id); }, + getSlice: function(slice_id) { + for(var i=0; i div").each(function() { - $(this).attr("id", function() {return "flt_" + i;}) - $(this).find("#flt_col_0") - .attr("id", function() {return "flt_col_" + i;}) - .attr("name", function() {return "flt_col_" + i;}); - $(this).find("#flt_op_0") - .attr("id", function() {return "flt_op_" + i;}) - .attr("name", function() {return "flt_op_" + i;}); - $(this).find("#flt_eq_0") - .attr("id", function() {return "flt_eq_" + i;}) - .attr("name", function() {return "flt_eq_" + i;}); - i++; - }); - $("#query").submit(); - } - - $("#plus").click(add_filter); - $("#btn_save").click(function () { - var slice_name = prompt("Name your slice!"); - if (slice_name != "" && slice_name != null) { - $("#slice_name").val(slice_name); - $("#action").val("save"); - druidify(); - } - }); - $("#btn_overwrite").click(function () { - var flag = confirm("Overwrite slice [" + $("#slice_name").val() + "] !?"); - if (flag) { - $("#action").val("overwrite"); - druidify(); - } - }); - add_filter(); - $(".druidify").click(druidify); - - function create_choices(term, data) { - var filtered = $(data).filter(function() { - return this.text.localeCompare(term) === 0; - }); - if (filtered.length === 0) { - return {id: term, text: term}; - } - } - function initSelectionToValue(element, callback) { - callback({id: element.val(), text: element.val()}); - } - function list_data(arr) { - var obj = []; - for (var i=0; i'); - $("input[name='" + name +"']") - .select2({ - createSearchChoice: create_choices, - initSelection: initSelectionToValue, - multiple: false, - data: l, - }); - $(this).remove(); - }); -} - -function initDashboardView(dashboard_id) { - var gridster = $(".gridster ul").gridster({ - widget_margins: [5, 5], - widget_base_dimensions: [100, 100], - draggable: { - handle: '.drag', - }, - resize: { - enabled: true, - stop: function(e, ui, element) { - var slice = $(element).data('slice'); - slice.resize(); } - }, - serialize_params: function(_w, wgd) { - return { - slice_id: $(_w).attr('slice_id'), - col: wgd.col, - row: wgd.row, - size_x: wgd.size_x, - size_y: wgd.size_y - }; - }, - }).data('gridster'); - $("div.gridster").css('visibility', 'visible'); - $("#savedash").click(function() { - var data = { - positions: gridster.serialize(), - css: $("#dash_css").val() - }; - $.ajax({ - type: "POST", - url: '/panoramix/save_dash/' + dashboard_id + '/', - data: {'data': JSON.stringify(data)}, - success: function() {alert("Saved!")}, - error: function() {alert("Error :(")}, + } + set_filters(); + + function add_filter(i) { + cp = $("#flt0").clone(); + $(cp).appendTo("#filters"); + $(cp).show(); + if (i != undefined){ + $(cp).find("#flt_eq_0").val(getParam("flt_eq_" + i)); + $(cp).find("#flt_op_0").val(getParam("flt_op_" + i)); + $(cp).find("#flt_col_0").val(getParam("flt_col_" + i)); + } + $(cp).find('select').select2(); + $(cp).find('.remove').click(function() { + $(this).parent().parent().remove(); + }); + } + + function druidify(){ + var i = 1; + // Assigning the right id to form elements in filters + $("#filters > div").each(function() { + $(this).attr("id", function() {return "flt_" + i;}) + $(this).find("#flt_col_0") + .attr("id", function() {return "flt_col_" + i;}) + .attr("name", function() {return "flt_col_" + i;}); + $(this).find("#flt_op_0") + .attr("id", function() {return "flt_op_" + i;}) + .attr("name", function() {return "flt_op_" + i;}); + $(this).find("#flt_eq_0") + .attr("id", function() {return "flt_eq_" + i;}) + .attr("name", function() {return "flt_eq_" + i;}); + i++; + }); + $("#query").submit(); + } + + $("#plus").click(add_filter); + $("#btn_save").click(function () { + var slice_name = prompt("Name your slice!"); + if (slice_name != "" && slice_name != null) { + $("#slice_name").val(slice_name); + $("#action").val("save"); + druidify(); + } }); - }); - $("a.closeslice").click(function() { - var li = $(this).parents("li"); - gridster.remove_widget(li); - }); - $("table.slice_header").mouseover(function() { - $(this).find("td.icons nobr").show(); - }); - $("table.slice_header").mouseout(function() { - $(this).find("td.icons nobr").hide(); - }); - $("#dash_css").on("keyup", function(){ - css = $(this).val(); - $("#user_style").html(css); - }); + $("#btn_overwrite").click(function () { + var flag = confirm("Overwrite slice [" + $("#slice_name").val() + "] !?"); + if (flag) { + $("#action").val("overwrite"); + druidify(); + } + }); + add_filter(); + $(".druidify").click(druidify); - // this sets the z-index for left side boxes higher - $('li.slice').each(function() { - current_row = $(this).attr('data-col'); - $( this ).css('z-index', 100 - current_row); - }); + function create_choices(term, data) { + var filtered = $(data).filter(function() { + return this.text.localeCompare(term) === 0; + }); + if (filtered.length === 0) { + return {id: term, text: term}; + } + } + function initSelectionToValue(element, callback) { + callback({id: element.val(), text: element.val()}); + } + function list_data(arr) { + var obj = []; + for (var i=0; i'); + $("input[name='" + name +"']") + .select2({ + createSearchChoice: create_choices, + initSelection: initSelectionToValue, + multiple: false, + data: l, + }); + $(this).remove(); + }); + } - // this makes the whole chart fit within the dashboard div - $("div.chart").each(function() { - $(this).css('height', '95%'); - }); + function initDashboardView() { + var gridster = $(".gridster ul").gridster({ + widget_margins: [5, 5], + widget_base_dimensions: [100, 100], + draggable: { + handle: '.drag', + }, + resize: { + enabled: true, + stop: function(e, ui, element) { + var slice_data = $(element).data('slice'); + dashboard.getSlice(slice_data.slice_id).resize(); + } + }, + serialize_params: function(_w, wgd) { + return { + slice_id: $(_w).attr('slice_id'), + col: wgd.col, + row: wgd.row, + size_x: wgd.size_x, + size_y: wgd.size_y + }; + }, + }).data('gridster'); + console.log(gridster); + $("div.gridster").css('visibility', 'visible'); + $("#savedash").click(function() { + var data = { + positions: gridster.serialize(), + css: $("#dash_css").val() + }; + $.ajax({ + type: "POST", + url: '/panoramix/save_dash/' + dashboard.id + '/', + data: {'data': JSON.stringify(data)}, + success: function() {alert("Saved!")}, + error: function() {alert("Error :(")}, + }); + }); + $("a.closeslice").click(function() { + var li = $(this).parents("li"); + gridster.remove_widget(li); + }); + $("table.slice_header").mouseover(function() { + $(this).find("td.icons nobr").show(); + }); + $("table.slice_header").mouseout(function() { + $(this).find("td.icons nobr").hide(); + }); + $("#dash_css").on("keyup", function(){ + css = $(this).val(); + $("#user_style").html(css); + }); + // this sets the z-index for left side boxes higher + $('li.slice').each(function() { + current_row = $(this).attr('data-col'); + $( this ).css('z-index', 100 - current_row); + }); -} + // this makes the whole chart fit within the dashboard div + $("div.chart").each(function() { + $(this).css('height', '95%'); + }); + } // Export public functions return { @@ -323,4 +336,3 @@ function initDashboardView(dashboard_id) { initDashboardView: initDashboardView, } })(); - diff --git a/panoramix/static/widgets/viz_directed_force.css b/panoramix/static/widgets/viz_directed_force.css index 3787a274a8..170eccba19 100644 --- a/panoramix/static/widgets/viz_directed_force.css +++ b/panoramix/static/widgets/viz_directed_force.css @@ -3,9 +3,6 @@ stroke: #000; stroke-width: 1.5px; } -.directed_force #chart { - height: 100%; -} .directed_force circle { fill: #ccc; diff --git a/panoramix/static/widgets/viz_directed_force.js b/panoramix/static/widgets/viz_directed_force.js index f4d74f1caa..5d95d61c55 100644 --- a/panoramix/static/widgets/viz_directed_force.js +++ b/panoramix/static/widgets/viz_directed_force.js @@ -3,11 +3,10 @@ Modified from http://bl.ocks.org/d3noob/5141278 */ function viz_directed_force(slice) { - var div = d3.select(slice.selector); var width = slice.container.width(); var height = slice.container.height() - 25; - var radius = Math.min(width, height) / 2; var link_length = slice.data.form_data['link_length']; + var div = d3.select(slice.selector); if (link_length === undefined){ link_length = 200; } diff --git a/panoramix/templates/panoramix/dashboard.html b/panoramix/templates/panoramix/dashboard.html index a69b5ce558..9853a92b63 100644 --- a/panoramix/templates/panoramix/dashboard.html +++ b/panoramix/templates/panoramix/dashboard.html @@ -122,8 +122,8 @@ body { {% endblock %} diff --git a/panoramix/templates/panoramix/explore.html b/panoramix/templates/panoramix/explore.html index 301060f8bd..842d5ab95e 100644 --- a/panoramix/templates/panoramix/explore.html +++ b/panoramix/templates/panoramix/explore.html @@ -36,13 +36,16 @@ query 0 sec -
- - - - .csv - .json -
+ + .csv + + + + .json + + + +
@@ -133,23 +136,14 @@
- {% block messages %} - {% endblock %} - {% include 'appbuilder/flash.html' %} + {% block messages %}{% endblock %} + {% include 'appbuilder/flash.html' %}
loading - {% block viz_html %} - {% if viz.error_msg %} -
{{ viz.error_msg }}
- {% endif %} - {% if viz.warning_msg %} -
{{ viz.warning_msg }}
- {% endif %} - {% endblock %}
@@ -243,6 +237,9 @@ $('#csv').click(function () { window.location = '{{ viz.csv_endpoint | safe }}'; }); + $('#standalone').click(function () { + window.location = '{{ viz.standalone_endpoint | safe }}'; + }); $("#viz_type").change(function() {$("#query").submit();}); collapsed_fieldsets = get_collapsed_fieldsets(); for(var i=0; i < collapsed_fieldsets.length; i++){ diff --git a/panoramix/templates/panoramix/standalone.html b/panoramix/templates/panoramix/standalone.html new file mode 100644 index 0000000000..bc2faa9dff --- /dev/null +++ b/panoramix/templates/panoramix/standalone.html @@ -0,0 +1,29 @@ + + + + + {% block head_css %} + + + {% endblock %} + + +
+ loading +
+
+ + + {% block tail %}{% endblock %} + + diff --git a/panoramix/templates/panoramix/viz.html b/panoramix/templates/panoramix/viz.html index d8eabb78b4..b9d6eeee47 100644 --- a/panoramix/templates/panoramix/viz.html +++ b/panoramix/templates/panoramix/viz.html @@ -2,7 +2,7 @@ {{ viz.get_json() }} {% else %} {% if viz.request.args.get("standalone") == "true" %} - {% extends 'panoramix/viz_standalone.html' %} + {% extends 'panoramix/standalone.html' %} {% else %} {% extends 'panoramix/explore.html' %} {% endif %} @@ -10,20 +10,16 @@ {% block head_css %} {{super()}} - {% if viz.request.args.get("skip_libs") != "true" %} - {% for css in viz.css_files %} - - {% endfor %} - {% endif %} + {% for css in viz.css_files %} + + {% endfor %} {% endblock %} {% block tail %} {{super()}} - {% if viz.request.args.get("skip_libs") != "true" %} - {% for js in viz.js_files %} - - {% endfor %} - {% endif %} + {% for js in viz.js_files %} + + {% endfor %} {% endblock %} {% endif %} diff --git a/panoramix/templates/panoramix/viz_standalone.html b/panoramix/templates/panoramix/viz_standalone.html deleted file mode 100644 index 51edffff9a..0000000000 --- a/panoramix/templates/panoramix/viz_standalone.html +++ /dev/null @@ -1,13 +0,0 @@ - - - {% if viz.request.args.get("skip_libs") != "true" %} - {% block head %} - - {% endblock %} - {% endif %} - {% block tail %}{% endblock %} - - - {% block viz_html %}{% endblock %} - - diff --git a/panoramix/viz.py b/panoramix/viz.py index 09f43adab7..44886f3665 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -222,6 +222,10 @@ class BaseViz(object): def csv_endpoint(self): return self.get_url(csv="true") + @property + def standalone_endpoint(self): + return self.get_url(standalone="true") + @property def data(self): content = {