Permalink
Browse files

Merge branch 'master' of https://github.com/hhba/timelines

  • Loading branch information...
2 parents b2cb482 + 4d21d32 commit 69f82ed26b2c80743904a5e2cc7d2e22b874ace9 @vanhalt vanhalt committed Apr 14, 2012
Showing with 119 additions and 0 deletions.
  1. +81 −0 graficador/js/graficador.js
  2. +4 −0 graficador/js/jquery-1.7.2.min.js
  3. +10 −0 graficador/js/raphael-min.js
  4. +24 −0 graficador/test.html
@@ -0,0 +1,81 @@
+/* Data...
+ [
+ [
+ { // segmento1
+ start: [0,0],
+ end: [100,100]
+ attributes: {}
+ },
+ { // segmento2
+ ...
+ }
+ ]
+ ]
+ */
+/*
+ * config = {
+ * width
+ * heigth
+ * kx constante para multiplicar en x
+ * ky constante para multiplicar en y
+ * }
+ */
+function testValues() {
+ function rancolor() {
+ if (Math.random() > 0.5)
+ return 'red';
+ return 'blue';
+ }
+ var ini = 0
+ var ret = [];
+ for (var i=0; i < 10; i++){
+ ret[i] = [];
+ for (var ii=0; ii < 5; ii++) {
+ //var a = (ii == 0) ? 1 : ii;
+ var a = ii;
+ if (ii == 0) {
+ a = ini;
+ ini += 10;
+ }
+ var b = (!i) ? 1 : i;
+ ret[i][ii] = {
+ color: rancolor(),
+ start: [Math.random()*10*b*ii,Math.random()*b*a+ini],
+ end: [Math.random()*10*b*ii, Math.random()*b*a+ini]
+ };
+ }
+ }
+ return ret;
+}
+var Graficador = function(div, config) {
+ this.divId = div;
+ this.config = config || {};
+ this.paper = new Raphael(this.divId, this.config.width, this.config.height);
+};
+
+Graficador.prototype.loadData = function (data) {
+ for (var i=0; i< data.length; i++) {
+ for (var ii = 0; ii < data[i].length ; ii++){
+ var thisStringLine = this.makeStringLine([data[i][ii].start, data[i][ii].end]);
+ var thisLine = this.paper.path(thisStringLine);
+ thisLine.attr({
+ 'stroke':data[i][ii].color,
+ 'color':data[i][ii].color
+ });
+ }
+
+ }
+};
+
+Graficador.prototype.makeRoundStringLine = function(arr) {
+ var string = '';
+}
+Graficador.prototype.makeStringLine = function(arr) {
+ var string = '';
+ for (var i=0; i < arr.length; i++) {
+ string += (i == 0)? 'M' : 'L';
+ string += (arr[i][0]*this.config.kx)+','+(arr[i][1]*this.config.ky);
+ }
+ //string += 'Z';
+ return string;
+};
Oops, something went wrong.
Oops, something went wrong.
View
@@ -0,0 +1,24 @@
+<html>
+<head>
+ <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
+ <script src="js/raphael-min.js"></script>
+ <script src="js/graficador.js"></script>
+ <title>Lindo Graficador =)</title>
+</head>
+<body>
+ <h1>Graficador</h1>
+ <div id="graph" style="width: 1000px; 1000px"></div>
+ <script>
+ (function() {
+ var grafico = new Graficador('graph', {
+ width: 1100,
+ height: 1000,
+ kx: 4,
+ ky: 4
+ });
+
+ grafico.loadData(testValues());
+ })();
+ </script>
+</body>
+</html>

0 comments on commit 69f82ed

Please sign in to comment.