[redistricter] 2 new revisions pushed by brian.olson on 2012-02-12 01:43 GMT

0 views
Skip to first unread message

redist...@googlecode.com

unread,
Feb 11, 2012, 8:44:04 PM2/11/12
to redistrict...@googlegroups.com
2 new revisions:

Revision: 7fa76a8d6d5f
Author: Brian Olson <brian...@gmail.com>
Date: Sat Feb 11 17:42:31 2012
Log: add multiplotting for scatter plot
http://code.google.com/p/redistricter/source/detail?r=7fa76a8d6d5f

Revision: 41b8cdf6755b
Author: Brian Olson <brian...@gmail.com>
Date: Sat Feb 11 17:42:40 2012
Log: add hgignore
http://code.google.com/p/redistricter/source/detail?r=41b8cdf6755b

==============================================================================
Revision: 7fa76a8d6d5f
Author: Brian Olson <brian...@gmail.com>
Date: Sat Feb 11 17:42:31 2012
Log: add multiplotting for scatter plot
http://code.google.com/p/redistricter/source/detail?r=7fa76a8d6d5f

Modified:
/plotlib.js

=======================================
--- /plotlib.js Thu Feb 9 23:39:18 2012
+++ /plotlib.js Sat Feb 11 17:42:31 2012
@@ -4,12 +4,15 @@

function PlotCommon() {};

-PlotCommon.prototype.setup = function(canvas, xy, opt) {
+PlotCommon.prototype.setupxy = function(xy) {
+ if (!this.firstdatas) {
this.minx = xy[0];
this.miny = xy[1];
this.maxx = xy[0];
this.maxy = xy[1];
this.lasty = xy[1];
+ this.firstdatas = true;
+ }
for (var i = 2; i < xy.length; i += 2) {
if (xy[i] < this.minx) {
this.minx = xy[i];
@@ -25,6 +28,16 @@
}
this.lasty = xy[i+1];
}
+}
+
+PlotCommon.prototype.setup = function(canvas, xy, opt) {
+ if (opt.data) {
+ for (var di = 0, ds; ds = opt.data[di]; di++) {
+ this.setupxy(ds.xy);
+ }
+ } else {
+ this.setupxy(xy);
+ }
this.ctx = canvas.getContext('2d');
this.miny_str = new String(this.miny);
this.miny_width = this.ctx.measureText(this.miny_str).width;
@@ -98,13 +111,26 @@
// TODO: something smart about how if lasty is close to miny or maxy,
adjust text baselines so they don't clobber each other
this.ctx.fillText(new String(this.lasty), this.px(this.maxx),
this.py(this.lasty));
}
+ if (opt.data) {
+ this.ctx.textAlign = 'left';
+ this.ctx.textBaseline = 'top';
+ var lx = this.px(this.maxx);
+ var ly = this.py(this.maxy);
+ for (var di = 0, ds; ds = opt.data[di]; di++) {
+ if (!ds.name) {continue;}
+ this.ctx.strokeStyle = ds.strokeStyle || '#000';
+ this.ctx.fillStyle = ds.fillStyle || '#000';
+ ly += 10;
+ this.ctx.fillText(ds.name, lx, ly);
+ }
+ }
}

function LinePlot() {};
LinePlot.prototype = new PlotCommon;

LinePlot.prototype.plot = function(canvas, xy, opt) {
- this.setup(canvas, xy);
+ this.setup(canvas, xy, opt);
this.ctx.clearRect(0,0, canvas.width, canvas.height);
this.ctx.strokeStyle = '#000';
this.ctx.beginPath();
@@ -124,15 +150,31 @@
function ScatterPlot() {};
ScatterPlot.prototype = new PlotCommon;

+/**
+accepts data either in xy = [x,y, x,y, ...] or opt['data'] =
[{'fillStyle':'#123', 'xy':[x,y, x,y, ...]}, ... ]
+*/
ScatterPlot.prototype.plot = function(canvas, xy, opt) {
- this.setup(canvas, xy);
+ this.setup(canvas, xy, opt);
this.ctx.clearRect(0,0, canvas.width, canvas.height);
- this.ctx.strokeStyle = '#000';
- this.ctx.fillStyle = '#000';
+ if (opt.data) {
+ for (var di = 0, ds; ds = opt.data[di]; di++) {
+ this.ctx.strokeStyle = ds.strokeStyle || '#000';
+ this.ctx.fillStyle = ds.fillStyle || '#000';
+ xy = ds.xy;
+ for (var i = 0; i < xy.length; i += 2) {
+ this.ctx.fillRect(this.px(xy[i])-1, this.py(xy[i+1])-1, 3, 3);
+ }
+ }
+ } else {
+ this.ctx.strokeStyle = '#000';
+ this.ctx.fillStyle = '#000';
for (var i = 0; i < xy.length; i += 2) {
this.ctx.fillRect(this.px(xy[i])-1, this.py(xy[i+1])-1, 3, 3);
}
- this.axisLabels();
+ }
+ this.ctx.strokeStyle = '#000';
+ this.ctx.fillStyle = '#000';
+ this.axisLabels(opt);
}
function scatterplot(canvas, xy, opt) {
var sp = new ScatterPlot();

==============================================================================
Revision: 41b8cdf6755b
Author: Brian Olson <brian...@gmail.com>
Date: Sat Feb 11 17:42:40 2012
Log: add hgignore
http://code.google.com/p/redistricter/source/detail?r=41b8cdf6755b

Added:
/.hgignore

=======================================
--- /dev/null
+++ /.hgignore Sat Feb 11 17:42:40 2012
@@ -0,0 +1,11 @@
+syntax: glob
+*.o
+*.d
+*.pyc
+analyze
+districter2
+drend
+linkfixup
+redata.pb.cc
+redata.pb.h
+*~

Reply all
Reply to author
Forward
0 new messages