From 28a128b242af78941b7511e8f84ca5d61a19997c Mon Sep 17 00:00:00 2001
From: Lei Yan
Date: Wed, 23 Aug 2017 15:26:26 +0000
Subject: Update corr scatterplot
---
wqflask/wqflask/correlation/corr_scatter_plot.py | 15 ++
.../new/javascript/draw_corr_scatterplot-2_sr.js | 133 ++++++++++++
wqflask/wqflask/templates/corr_scatterplot.html | 239 ++++++++++++++-------
3 files changed, 315 insertions(+), 72 deletions(-)
create mode 100644 wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2_sr.js
(limited to 'wqflask')
diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py
index 6a92c501..a08cd759 100644
--- a/wqflask/wqflask/correlation/corr_scatter_plot.py
+++ b/wqflask/wqflask/correlation/corr_scatter_plot.py
@@ -67,9 +67,17 @@ class CorrScatterPlot(object):
x = np.array(vals_1)
y = np.array(vals_2)
slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
+
+ rx = stats.rankdata(x)
+ ry = stats.rankdata(y)
+ self.rdata = []
+ self.rdata.append(rx.tolist())
+ self.rdata.append(ry.tolist())
+ srslope, srintercept, srr_value, srp_value, srstd_err = stats.linregress(rx, ry)
self.js_data = dict(
data = self.data,
+ rdata = self.rdata,
indIDs = self.indIDs,
trait_1 = self.trait_1.dataset.name + ": " + str(self.trait_1.name),
trait_2 = self.trait_2.dataset.name + ": " + str(self.trait_2.name),
@@ -78,10 +86,17 @@ class CorrScatterPlot(object):
num_overlap = num_overlap,
vals_1 = vals_1,
vals_2 = vals_2,
+
slope = slope,
intercept = intercept,
r_value = r_value,
p_value = p_value,
+
+ srslope = srslope,
+ srintercept = srintercept,
+ srr_value = srr_value,
+ srp_value = srp_value,
+
width = width,
height = height,
circle_color = circle_color,
diff --git a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2_sr.js b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2_sr.js
new file mode 100644
index 00000000..08ddc825
--- /dev/null
+++ b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot-2_sr.js
@@ -0,0 +1,133 @@
+var srchart;
+
+function srdrawg () {
+ //
+ srchart = nv.models.scatterChart();
+ //
+ srchart.showLegend(false);
+ srchart.duration(300);
+ srchart.color(d3.scale.category10().range());
+ srchart.pointRange([0, 400]);
+ srchart.pointDomain([0, 10]);
+ //
+ srchart.xAxis.axisLabel(js_data.trait_1);
+ srchart.xAxis.axisLabelDistance(11);
+ srchart.yAxis.axisLabel(js_data.trait_2);
+ srchart.yAxis.axisLabelDistance(11);
+ //
+ xmin = d3.min(js_data.rdata[0]);
+ xmax = d3.max(js_data.rdata[0]);
+ xrange = xmax - xmin;
+ ymin = d3.min(js_data.rdata[1]);
+ ymax = d3.max(js_data.rdata[1]);
+ yrange = ymax - ymin;
+ srchart.xDomain([xmin - xrange/10, xmax + xrange/10]);
+ srchart.yDomain([ymin - yrange/10, ymax + yrange/10]);
+ srchart.xAxis.tickFormat(d3.format(srcheckformat(xrange)));
+ srchart.yAxis.tickFormat(d3.format(srcheckformat(yrange)));
+ //
+ srchart.tooltip.contentGenerator(function (obj) {
+ // return '(' + obj.point.x + ', ' + obj.point.y + ')';
+ return '' + obj.point.name + '';
+ });
+}
+
+function srgetdata(size, shape) {
+ var data = [];
+ data.push({
+ values: [],
+ slope: js_data.srslope,
+ intercept: js_data.srintercept
+ });
+ for (j = 0; j < js_data.rdata[0].length; j++) {
+ data[0].values.push({
+ x: js_data.rdata[0][j],
+ y: js_data.rdata[1][j],
+ name: js_data.indIDs[j],
+ size: size,
+ shape: shape
+ });
+ }
+ return data;
+}
+
+function srcheckformat(range) {
+ cell = range / 10.0;
+ if (cell >= 1) {
+ return ",r";
+ } else {
+ cell = -Math.log(cell);
+ n = cell.toString().split(".")[0].length;
+ return ",.0" + n + "f";
+ }
+}
+
+function srchartupdate() {
+ //
+ var axisxcolor = $("#axisxcolor").val();
+ $(".nvd3 .nv-axis.nv-x text").css("fill", axisxcolor);
+ //
+ var axisycolor = $("#axisycolor").val();
+ $(".nvd3 .nv-axis.nv-y text").css("fill", axisycolor);
+ //
+ var axisxfont = $("#axisxfont").val();
+ $(".nvd3 .nv-axis.nv-x text").css("font-size", axisxfont);
+ //
+ var axisyfont = $("#axisyfont").val();
+ $(".nvd3 .nv-axis.nv-y text").css("font-size", axisyfont);
+ //
+ var domainxcolor = $("#domainxcolor").val();
+ $(".nv-x .nv-axis g path.domain").css("stroke", domainxcolor);
+ //
+ var domainycolor = $("#domainycolor").val();
+ $(".nv-y .nv-axis g path.domain").css("stroke", domainycolor);
+ //
+ var domainxwidth = $("#domainxwidth").val();
+ $(".nv-x .nv-axis g path.domain").css("stroke-width", domainxwidth);
+ //
+ var domainywidth = $("#domainywidth").val();
+ $(".nv-y .nv-axis g path.domain").css("stroke-width", domainywidth);
+ //
+ var clinecolor = $("#clinecolor").val();
+ $("line.nv-regLine").css("stroke", clinecolor);
+ //
+ var clinewidth = $("#clinewidth").val();
+ $("line.nv-regLine").css("stroke-width", clinewidth);
+}
+
+function srchartupdatewh() {
+ //
+ var width = $("#srwidth").val();
+ $("#srscatterplot2 svg").css("width", width);
+ //
+ var height = $("#srheight").val();
+ $("#srscatterplot2 svg").css("height", height);
+ //
+ window.dispatchEvent(new Event('resize'));
+}
+
+function srchartupdatedata() {
+ //
+ var size = $("#srmarksize").val();
+ var shape = $("#srmarkshape").val();
+ //
+ d3.select('#srscatterplot2 svg').datum(nv.log(srgetdata(size, shape))).call(srchart);
+ nv.utils.windowResize(srchart.update);
+}
+
+srdrawg();
+srchartupdate();
+srchartupdatewh();
+srchartupdatedata();
+
+$(".srchartupdate").change(function () {
+ srchartupdate();
+});
+
+$(".srchartupdatewh").change(function () {
+ srchartupdatewh();
+});
+
+$(".srchartupdatedata").change(function () {
+ srchartupdatedata();
+});
diff --git a/wqflask/wqflask/templates/corr_scatterplot.html b/wqflask/wqflask/templates/corr_scatterplot.html
index 47b83018..fc9925e7 100644
--- a/wqflask/wqflask/templates/corr_scatterplot.html
+++ b/wqflask/wqflask/templates/corr_scatterplot.html
@@ -17,12 +17,65 @@
Correlation Scatterplot
+
+
+ {% if trait_1.dataset.type == "ProbeSet" %}
+
+
+ [{{trait_1.symbol}} on {{trait_1.location_repr}} Mb]
+ {{trait_1.description_display}}
+
+ {% elif trait_1.dataset.type == "Publish" %}
+
+
+ {% endif %}
+
+
+
+ {% if trait_2.dataset.type == "ProbeSet" %}
+
+
+ [{{trait_2.symbol}} on {{trait_2.location_repr}} Mb]
+ {{trait_2.description_display}}
+
+ {% elif trait_2.dataset.type == "Publish" %}
+
+
+ {% endif %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{% endblock %}
{% block js %}
@@ -179,4 +273,5 @@
+
{% endblock %}
--
cgit v1.2.3