From 6b64fd15c96da58a5a8119ac6d0d50efb6fc1ef7 Mon Sep 17 00:00:00 2001 From: Lei Yan Date: Mon, 8 May 2017 04:08:56 +0000 Subject: corr_scatter_plot update (use nvd3) --- wqflask/wqflask/correlation/corr_scatter_plot.py | 1 + .../wqflask/static/new/css/corr_scatter_plot2.css | 19 ++++++ .../new/javascript/draw_corr_scatterplot-2.js | 74 ++++++++++++++++++++++ wqflask/wqflask/templates/corr_scatterplot.html | 57 ++++++++++++++--- 4 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 wqflask/wqflask/static/new/css/corr_scatter_plot2.css create mode 100644 wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2.js (limited to 'wqflask') diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py index 96afef1e..6a92c501 100644 --- a/wqflask/wqflask/correlation/corr_scatter_plot.py +++ b/wqflask/wqflask/correlation/corr_scatter_plot.py @@ -89,3 +89,4 @@ class CorrScatterPlot(object): line_color = line_color, line_width = line_width ) + self.jsdata = self.js_data diff --git a/wqflask/wqflask/static/new/css/corr_scatter_plot2.css b/wqflask/wqflask/static/new/css/corr_scatter_plot2.css new file mode 100644 index 00000000..92e777c2 --- /dev/null +++ b/wqflask/wqflask/static/new/css/corr_scatter_plot2.css @@ -0,0 +1,19 @@ +.nvd3 .nv-axis.nv-x text { + font-size: 16px; + font-weight: normal; + fill: black; +} + +.nvd3 .nv-axis.nv-y text { + font-size: 16px; + font-weight: normal; + fill: black; +} + +.nv-y .tick.zero line { + stroke: black; +} + +.nv-y .nv-axis g path.domain { + stroke: black; +} diff --git a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2.js b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2.js new file mode 100644 index 00000000..7a5a86bd --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2.js @@ -0,0 +1,74 @@ +var chart; + +nv.addGraph(function() { + // + chart = nv.models.scatterChart(); + // + chart.showLegend(false); + chart.duration(300); + chart.color(d3.scale.category10().range()); + chart.pointRange([200,0]); + // + // chart.showDistX(true); + // chart.showDistY(true); + chart.xAxis.tickFormat(d3.format('.02f')); + chart.yAxis.tickFormat(d3.format('.02f')); + // chart.showXAxis(false); + // chart.showYAxis(false); + chart.xAxis.axisLabel(js_data.trait_1); + chart.yAxis.axisLabel(js_data.trait_2); + // + xmin = d3.min(js_data.data[0]); + xmax = d3.max(js_data.data[0]); + xrange = xmax - xmin; + ymin = d3.min(js_data.data[1]); + ymax = d3.max(js_data.data[1]); + yrange = ymax - ymin; + chart.xDomain([xmin - xrange/10, xmax + xrange/10]); + chart.yDomain([ymin - yrange/10, ymax + yrange/10]); + // + d3.select('#scatterplot2 svg').datum(nv.log(getdata())).call(chart); + nv.utils.windowResize(chart.update); + return chart; +}); + +function getdata () { + var data = []; + data.push({ + values: [], + slope: js_data.slope, + intercept: js_data.intercept + }); + for (j = 0; j < js_data.data[0].length; j++) { + data[0].values.push({ + x: js_data.data[0][j], + y: js_data.data[1][j], + size: 10, + shape: 'circle' + }); + } + return data; +} + +function randomData(groups, points) { + var data = [], + shapes = ['circle'], + random = d3.random.normal(); + for (i = 0; i < groups; i++) { + data.push({ + key: 'Group ' + i, + values: [], + slope: Math.random() - .01, + intercept: Math.random() - .5 + }); + for (j = 0; j < points; j++) { + data[i].values.push({ + x: random(), + y: random(), + size: Math.random(), + shape: shapes[j % shapes.length] + }); + } + } + return data; +} diff --git a/wqflask/wqflask/templates/corr_scatterplot.html b/wqflask/wqflask/templates/corr_scatterplot.html index 810f4ca3..4464025e 100644 --- a/wqflask/wqflask/templates/corr_scatterplot.html +++ b/wqflask/wqflask/templates/corr_scatterplot.html @@ -7,6 +7,8 @@ + + {% endblock %} {% block content %} @@ -47,10 +49,48 @@ --> -
-
+
-
+

Correlation Scatterplot

+ + + + + + + + + +
num overlap {{jsdata.num_overlap}}
slope {{jsdata.slope}}
intercept {{jsdata.intercept}}
r value {{jsdata.r_value}}
p value {{jsdata.p_value}}
+ + + +
+ +
+ +
+ +
{% if trait_1.dataset.type == "ProbeSet" %}
@@ -103,17 +143,18 @@ {% endif %}
+ {% endblock %} {% block js %} - + + - - -{% endblock %} \ No newline at end of file + +{% endblock %} -- cgit v1.2.3