Skip to content

Commit

Permalink
anim functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhalt committed Apr 14, 2012
2 parents 55ac750 + f65a198 commit 7d65f1d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 34 deletions.
25 changes: 16 additions & 9 deletions index.html
Expand Up @@ -23,6 +23,7 @@
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<script src='javascripts/raphael-min.js' type='text/javascript'></script>
<script src='javascripts/get_data.js' type='text/javascript'></script>
<script src='javascripts/preprocess.js' type="text/javascript"></script>
<script src='JSOptimizer/js/taoptimizer.js' type="text/javascript"></script>
Expand Down Expand Up @@ -71,7 +72,7 @@ <h1>Visualiza tu timeline aca</h1>
<div class="clearfix">
<label>url del gdoc (spreadsheet please)</label>
<div class="input">
<input type="text" class="input-xxlarge" name="url" id='url' value='https://spreadsheets.google.com/feeds/cells/0Av8QEY2w-qTYdE1EX0R3a04zaEVwY0ltVU1oSkxKSWc/od5/public/basic?alt=json-in-script&callback=parseRequest' />
<input type="text" class="input-xxlarge" name="url" id='url' value='https://spreadsheets.google.com/feeds/cells/0Aj6IH4grpvxcdGpBNHBrelNJS0NhNjBDblFlbkVrWkE/od6/public/basic?alt=json-in-script&callback=parseRequest' />
</div>
</div>
<p>
Expand All @@ -80,7 +81,7 @@ <h1>Visualiza tu timeline aca</h1>
</a>
</p>
</div>
<div id='graph'></div>
<div id='graph' style='width:1000px; height:1000px;'></div>

</form>

Expand Down Expand Up @@ -136,14 +137,20 @@ <h1>Visualiza tu timeline aca</h1>
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
Expand Down
30 changes: 27 additions & 3 deletions javascripts/graficador.js
Expand Up @@ -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);
};

Expand All @@ -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);
Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions javascripts/preprocess.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 5 additions & 10 deletions javascripts/timelineproblem.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions src/timelineproblem.coffee
Expand Up @@ -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
Expand Down

0 comments on commit 7d65f1d

Please sign in to comment.