diff --git a/index.html b/index.html
index 15f3ac4..35a6095 100644
--- a/index.html
+++ b/index.html
@@ -23,6 +23,7 @@
+
@@ -71,7 +72,7 @@
Visualiza tu timeline aca
@@ -80,7 +81,7 @@
Visualiza tu timeline aca
-
+
@@ -136,14 +137,20 @@ Visualiza tu timeline aca
var optimizer = new TAOptimizer(p, params);
var redraw = function(o) {
- //console.log("Redraw called!");
+ console.log("Redraw called!");
var grafico = new Graficador('graph', {
- width: 1100,
- height: 1000,
- kx: 4,
- ky: 4
- });
- grafico.loadData(o.solution);
+ width: 1100,//px
+ height: 1000,//px
+ 'margin-top': 50,//px
+ 'margin-right': 50,//px
+ 'margin-bottom': 50,//px
+ 'margin-left': 50,//px
+ textoffset: 5, // -textoffset px
+ kx: 50,
+ ky: 10
+ });
+ console.log(o.solution)
+ grafico.loadData(o.solution );
}
optimizer.callback = redraw
diff --git a/javascripts/graficador.js b/javascripts/graficador.js
index 4c9633a..a1fe139 100644
--- a/javascripts/graficador.js
+++ b/javascripts/graficador.js
@@ -120,6 +120,7 @@ function testValues() {
var Graficador = function(div, config) {
this.divId = div;
this.config = config || {};
+ $(this.divId).empty();
this.paper = new Raphael(this.divId, this.config.width, this.config.height);
};
@@ -132,6 +133,7 @@ Graficador.prototype.defaultLine = {
};
Graficador.prototype.loadData = function (data) {
+ this.paper.clear();
for (var i=0; i< data.length; i++) {
this.writeText(data[i]);
var linesAndData = this.joinLine(data[i].segments);
@@ -188,6 +190,28 @@ Graficador.prototype.joinLine = function(segments) {
return [ret, attr];
};
+Graficador.prototype.makeRoundStringLine = function(arr) {
+ function midPoint(Ax, Ay, Bx, By) {
+ var Zx = (Ax-Bx)/2 + Bx;
+ var Zy = (Ay-By)/2 + By;
+ return [Zx, Zy];
+ }
+ var string = '';
+ for (var i=0; i < arr.length; i++) {
+ string += (i == 0)? 'M' : 'L';
+
+ Z = midPoint(point[X], point[Y], next[X], next[Y]);
+ path_string += " "+Z[X]+","+Z[Y];
+ path_string += "Q"+next[X]+","+next[Y];
+
+ string += (arr[i][0]*this.config.kx+this.config['margin-left'])+','+(arr[i][1]*this.config.ky+this.config['margin-top']);
+
+
+
+
+ }
+};
+
Graficador.prototype.makeStringLine = function(arr) {
var string = '';
for (var i=0; i < arr.length; i++) {
@@ -205,10 +229,10 @@ Graficador.prototype.writeText = function(tHash) {
tHash.name
),
opts = {};
- for (key in this.defaultText)
- opts[key] = this.defaultText[key];
+ for (key in this.defaultText)
+ opts[key] = this.defaultText[key];
for (key in (tHash.attributes || {} )){
- if (['fill', 'fill-opacity', 'font', 'font-family', 'font-size', 'font-weight', 'stroke', 'text-anchor'].indexOf(key))
+ if (['fill', 'fill-opacity', 'font', 'font-family', 'font-size', 'font-weight', 'stroke', 'text-anchor'].indexOf(key) > -1)
opts[key] = tHash.attributes[key];
}
thisText.attr(opts);
diff --git a/javascripts/preprocess.js b/javascripts/preprocess.js
index b82cd72..8ec13a9 100644
--- a/javascripts/preprocess.js
+++ b/javascripts/preprocess.js
@@ -15,7 +15,7 @@ function preprocessData(data) {
var eventList = {};
for (d in data) {
if (!eventList[data[d].character]) {
- eventList[data[d].character] = [];
+ eventList[data[d].character] = {};
}
eventList[data[d].character].name = data[d].character;
if (!eventList[data[d].character].position) {
@@ -49,13 +49,14 @@ function mergeSegments(events, places_position){
pos_y = places_position[positions[position]['group']];
pos_x = positions[position]['orderBox'];
var current = [pos_x, pos_y]
- character_time['segments'].push({'start': current});
+ character_time['segments'].push({'start': current, "attributes":{"color": "#bbffbb"}});
if(prev != null) {
- positions[position - 1]['end'] = current;
+ character_time['segments'][character_time['segments'].length - 2]['end'] = current;
}
prev = current;
}
character_time['name'] = character['name'];
+ character_time['segments'].pop();
result.push(character_time);
}
return result;
diff --git a/javascripts/timelineproblem.js b/javascripts/timelineproblem.js
index 52d5d36..5053c8f 100644
--- a/javascripts/timelineproblem.js
+++ b/javascripts/timelineproblem.js
@@ -82,16 +82,11 @@
delta = (Math.random() - 0.5) * (0.2 * 100.0 / this.numGroups);
numOperations = 2;
op = Math.round(Math.random() * numOperations);
- if (op === 0) {
- from = this.groupNames[i];
- to = this.groupNames[j];
- prevPos = this.groupPosition[to];
- this.groupPosition[to] = this.groupPosition[from];
- this.groupPosition[from] = prevPos;
- } else if (op === 1) {
- from = this.groupNames[i];
- this.groupPosition[from] += delta;
- }
+ from = this.groupNames[i];
+ to = this.groupNames[j];
+ prevPos = this.groupPosition[to];
+ this.groupPosition[to] = this.groupPosition[from];
+ this.groupPosition[from] = prevPos;
this.solution = mergeSegments(this.problem.eventList, this.groupPosition);
return this.solution;
};
diff --git a/src/timelineproblem.coffee b/src/timelineproblem.coffee
index ae949fa..8672537 100644
--- a/src/timelineproblem.coffee
+++ b/src/timelineproblem.coffee
@@ -85,15 +85,21 @@ class TimeLineProblem extends ProblemInstance
# Determine what to do
numOperations = 2
op = Math.round( Math.random() * numOperations )
- if op == 0
- from = @groupNames[i]
- to = @groupNames[j]
- prevPos = @groupPosition[to]
- @groupPosition[to] = @groupPosition[from]
- @groupPosition[from] = prevPos
- else if op == 1
- from = @groupNames[i]
- @groupPosition[from] += delta
+ from = @groupNames[i]
+ to = @groupNames[j]
+ prevPos = @groupPosition[to]
+ @groupPosition[to] = @groupPosition[from]
+ @groupPosition[from] = prevPos
+
+ #if op == 0
+ # from = @groupNames[i]
+ # to = @groupNames[j]
+ # prevPos = @groupPosition[to]
+ # @groupPosition[to] = @groupPosition[from]
+ # @groupPosition[from] = prevPos
+ #else if op == 1
+ # from = @groupNames[i]
+ # @groupPosition[from] += delta
@solution = mergeSegments(@problem.eventList, @groupPosition)
return @solution