making dots selectable
This commit is contained in:
parent
4f4eb0ff11
commit
12ea08b7e5
|
@ -23,6 +23,7 @@
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
#canvas, #map, .label {
|
#canvas, #map, .label {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
|
@ -47,33 +47,72 @@ function setSpeed(speed) {
|
||||||
$('#speed'+speed).addClass('active');
|
$('#speed'+speed).addClass('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
var mouseDragX0, dragTime, mouseDrag = false;
|
var mouseDrag = false;
|
||||||
function sliderDragMove(event) {
|
var sliderDrag = false;
|
||||||
|
var mapDrag = false;
|
||||||
|
var mouseDragX0;
|
||||||
|
var mouseDragY0;
|
||||||
|
var mouseDragX;
|
||||||
|
var mouseDragY;
|
||||||
|
var sliderDragStartTime;
|
||||||
|
|
||||||
|
function sliderDragStart() {
|
||||||
|
mouseDrag = true;
|
||||||
|
sliderDrag = true;
|
||||||
|
sliderDragStartTime = currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapDragStart() {
|
||||||
|
mouseDrag = true;
|
||||||
|
mapDrag = true;
|
||||||
|
mouseDragX = mouseDragX0;
|
||||||
|
mouseDragY = mouseDragY0;
|
||||||
|
clients.forEach(function (c) { c.selected = false; });
|
||||||
|
}
|
||||||
|
|
||||||
|
function mouseDragMove(event) {
|
||||||
if (mouseDrag) {
|
if (mouseDrag) {
|
||||||
currentTime = dragTime + (mouseDragX0 - event.pageX);
|
if (sliderDrag) {
|
||||||
|
currentTime = sliderDragStartTime + (mouseDragX0 - event.pageX);
|
||||||
|
|
||||||
updateFrame();
|
updateFrame();
|
||||||
|
}
|
||||||
|
if (mapDrag) {
|
||||||
|
mouseDragX = event.pageX;
|
||||||
|
mouseDragY = event.pageY;
|
||||||
|
var p = $('#container').offset();
|
||||||
|
var x0 = Math.min(mouseDragX0, mouseDragX) - p.left;
|
||||||
|
var x1 = Math.max(mouseDragX0, mouseDragX) - p.left;
|
||||||
|
var y0 = Math.min(mouseDragY0, mouseDragY) - p.top;
|
||||||
|
var y1 = Math.max(mouseDragY0, mouseDragY) - p.top;
|
||||||
|
clients.forEach(function (c) {
|
||||||
|
c.selected = ((c.x >= x0) && (c.x <= x1) && (c.y >= y0) && (c.y <= y1));
|
||||||
|
});
|
||||||
|
|
||||||
|
renderCanvas();
|
||||||
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
mouseDragX0 = event.pageX;
|
mouseDragX0 = event.pageX;
|
||||||
|
mouseDragY0 = event.pageY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sliderDragStart() {
|
function mouseDragStop() {
|
||||||
mouseDrag = true;
|
|
||||||
dragTime = currentTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sliderDragStop() {
|
|
||||||
mouseDrag = false;
|
mouseDrag = false;
|
||||||
|
sliderDrag = false;
|
||||||
|
mapDrag = false;
|
||||||
|
|
||||||
|
renderCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
context = $('#canvas')[0].getContext('2d');
|
context = $('#canvas')[0].getContext('2d');
|
||||||
clients = [];
|
clients = [];
|
||||||
data.matrix.forEach(function (times, index) {
|
data.matrix.forEach(function (times, index) {
|
||||||
clients[index] = { point:undefined, x:0, y:0, r:0, x0:0, y0:0, r0:0, index:index, lastEvent:0 };
|
clients[index] = { point:undefined, x:0, y:0, r:0, x0:0, y0:0, r0:0, index:index, lastEvent:0, selected:false };
|
||||||
random[index] = Math.random();
|
random[index] = Math.random();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -83,9 +122,11 @@ function init() {
|
||||||
$('#speed3').click(function () { setSpeed(3); });
|
$('#speed3').click(function () { setSpeed(3); });
|
||||||
|
|
||||||
$('#sliderWrapper').mousedown(function () { sliderDragStart(); });
|
$('#sliderWrapper').mousedown(function () { sliderDragStart(); });
|
||||||
$(document).mousemove(function (e) { return sliderDragMove(e); });
|
$('#container').mousedown(function () { mapDragStart(); });
|
||||||
$(document).mouseup(function (e) { sliderDragStop(); });
|
$(document).mousemove(function (e) { return mouseDragMove(e); });
|
||||||
$(document).on('selectstart', function () { return !mouseDrag; });
|
$(document).mouseup(function (e) { mouseDragStop(); });
|
||||||
|
|
||||||
|
$(document).on('selectstart', function (e) { e.preventDefault(); return !mouseDrag; });
|
||||||
|
|
||||||
var index = -1;
|
var index = -1;
|
||||||
for (var time = -60; time <= (4*24+1)*60; time++) {
|
for (var time = -60; time <= (4*24+1)*60; time++) {
|
||||||
|
@ -144,6 +185,11 @@ function update() {
|
||||||
if (mouseDrag) return;
|
if (mouseDrag) return;
|
||||||
|
|
||||||
currentTime += timeStep;
|
currentTime += timeStep;
|
||||||
|
|
||||||
|
updateFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateFrame() {
|
||||||
if (currentTime > maxTime) {
|
if (currentTime > maxTime) {
|
||||||
currentTime = maxTime;
|
currentTime = maxTime;
|
||||||
stopPlay();
|
stopPlay();
|
||||||
|
@ -151,10 +197,6 @@ function update() {
|
||||||
|
|
||||||
if (currentTime < minTime) currentTime = minTime;
|
if (currentTime < minTime) currentTime = minTime;
|
||||||
|
|
||||||
updateFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateFrame() {
|
|
||||||
renderTime();
|
renderTime();
|
||||||
updateData();
|
updateData();
|
||||||
updatePosition();
|
updatePosition();
|
||||||
|
@ -396,7 +438,6 @@ function updatePosition() {
|
||||||
|
|
||||||
function renderCanvas() {
|
function renderCanvas() {
|
||||||
context.clearRect(0, 0, width, height);
|
context.clearRect(0, 0, width, height);
|
||||||
context.fillStyle = '#000';
|
|
||||||
|
|
||||||
clients.forEach(function (client) {
|
clients.forEach(function (client) {
|
||||||
if (client.valid) {
|
if (client.valid) {
|
||||||
|
@ -406,7 +447,7 @@ function renderCanvas() {
|
||||||
|
|
||||||
if ((r > 1) && (!client.settled)) {
|
if ((r > 1) && (!client.settled)) {
|
||||||
var a = Math.min(Math.pow(1/r, 0.7), 1);
|
var a = Math.min(Math.pow(1/r, 0.7), 1);
|
||||||
context.strokeStyle = 'rgba(0,0,0,'+a+')';
|
context.strokeStyle = (client.selected) ? 'rgba(238,0,0,'+a+')' : 'rgba(0,0,0,'+a+')';
|
||||||
context.lineWidth = client.r*2*radius;
|
context.lineWidth = client.r*2*radius;
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(client.xo, client.yo);
|
context.moveTo(client.xo, client.yo);
|
||||||
|
@ -414,6 +455,7 @@ function renderCanvas() {
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
context.fillStyle = (client.selected) ? '#e00' : '#000';
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.arc(client.x, client.y, client.r*radius, 0, 2*Math.PI, false);
|
context.arc(client.x, client.y, client.r*radius, 0, 2*Math.PI, false);
|
||||||
context.fill();
|
context.fill();
|
||||||
|
@ -421,6 +463,24 @@ function renderCanvas() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (mapDrag) {
|
||||||
|
var x = Math.min(mouseDragX0, mouseDragX);
|
||||||
|
var y = Math.min(mouseDragY0, mouseDragY);
|
||||||
|
var w = Math.max(mouseDragX0, mouseDragX) - x;
|
||||||
|
var h = Math.max(mouseDragY0, mouseDragY) - y;
|
||||||
|
var p = $('#container').offset();
|
||||||
|
x -= 0.5 + p.left;
|
||||||
|
y -= 0.5 + p.top;
|
||||||
|
|
||||||
|
context.fillStyle = 'rgba(238,0,0,0.1)';
|
||||||
|
context.strokeStyle = 'rgba(238,0,0,0.5)';
|
||||||
|
context.lineWidth = 1;
|
||||||
|
context.beginPath();
|
||||||
|
context.rect(x, y, w, h);
|
||||||
|
context.fill();
|
||||||
|
context.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
context.fillStyle = 'rgba(255,0,0,0.5)';
|
context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||||
for (var x = 0; x < width/gridSize; x++) {
|
for (var x = 0; x < width/gridSize; x++) {
|
||||||
|
|
Loading…
Reference in New Issue