fixed hold and drag
This commit is contained in:
parent
77af1bb8fb
commit
6169f11053
@ -34,11 +34,11 @@
|
|||||||
start: "2016-10-0"+i,
|
start: "2016-10-0"+i,
|
||||||
end: "2016-10-2"+i,
|
end: "2016-10-2"+i,
|
||||||
name: "Task "+i,
|
name: "Task "+i,
|
||||||
id: i,
|
id: "Task"+i,
|
||||||
progress: i*10
|
progress: i*10
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tasks[0].dependencies = '2, 3';
|
tasks[0].dependencies = 'Task2, Task3';
|
||||||
|
|
||||||
var gantt_chart = gantt("#gantt", tasks, {
|
var gantt_chart = gantt("#gantt", tasks, {
|
||||||
date_format: "YYYY-MM-DD",
|
date_format: "YYYY-MM-DD",
|
||||||
|
|||||||
39
lib/gantt.js
39
lib/gantt.js
@ -615,6 +615,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
function make_arrows() {
|
function make_arrows() {
|
||||||
|
self._arrows = [];
|
||||||
var _iteratorNormalCompletion8 = true;
|
var _iteratorNormalCompletion8 = true;
|
||||||
var _didIteratorError8 = false;
|
var _didIteratorError8 = false;
|
||||||
var _iteratorError8 = undefined;
|
var _iteratorError8 = undefined;
|
||||||
@ -623,7 +624,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
var _loop = function _loop() {
|
var _loop = function _loop() {
|
||||||
var task = _step8.value;
|
var task = _step8.value;
|
||||||
|
|
||||||
self._arrows = task.dependencies.map(function (dep) {
|
var arrows = [];
|
||||||
|
arrows = task.dependencies.map(function (dep) {
|
||||||
var dependency = get_task(dep);
|
var dependency = get_task(dep);
|
||||||
if (!dependency) return;
|
if (!dependency) return;
|
||||||
|
|
||||||
@ -634,6 +636,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
self.element_groups.arrow.add(arrow.element);
|
self.element_groups.arrow.add(arrow.element);
|
||||||
return arrow; // eslint-disable-line
|
return arrow; // eslint-disable-line
|
||||||
});
|
});
|
||||||
|
self._arrows = self._arrows.concat(arrows);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var _iterator8 = self.tasks[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
for (var _iterator8 = self.tasks[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
||||||
@ -748,13 +751,13 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
self.view_is = view_is;
|
self.view_is = view_is;
|
||||||
|
|
||||||
function get_task(id) {
|
function get_task(id) {
|
||||||
self.tasks.find(function (task) {
|
return self.tasks.find(function (task) {
|
||||||
return task.id === id;
|
return task.id === id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_bar(id) {
|
function get_bar(id) {
|
||||||
self._bars.find(function (bar) {
|
return self._bars.find(function (bar) {
|
||||||
return bar.task.id === id;
|
return bar.task.id === id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1321,12 +1324,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
left.drag(onmove_left, onstart, onstop_left);
|
left.drag(onmove_left, onstart, onstop_left);
|
||||||
right.drag(onmove_right, onstart, onstop_right);
|
right.drag(onmove_right, onstart, onstop_right);
|
||||||
|
|
||||||
function onstart() {
|
|
||||||
onstart();
|
|
||||||
this.ox = this.getX();
|
|
||||||
this.oy = this.getY();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onmove_right(dx, dy) {
|
function onmove_right(dx, dy) {
|
||||||
onmove_handle_right(dx, dy);
|
onmove_handle_right(dx, dy);
|
||||||
}
|
}
|
||||||
@ -1351,25 +1348,15 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
function bind_drag() {
|
function bind_drag() {
|
||||||
self.bar_group.drag(onmove, onstart, onstop);
|
self.bar_group.drag(onmove, onstart, onstop);
|
||||||
|
|
||||||
function onmove(dx, dy) {
|
|
||||||
onmove(dx, dy);
|
|
||||||
}
|
|
||||||
function onstop() {
|
|
||||||
onstop();
|
|
||||||
}
|
|
||||||
function onstart() {
|
|
||||||
onstart();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bind_resize_progress() {
|
function bind_resize_progress() {
|
||||||
var bar = self.$bar,
|
var bar = self.$bar,
|
||||||
bar_progress = self.$bar_progress,
|
bar_progress = self.$bar_progress,
|
||||||
handle = self.group.select('.handle.progress');
|
handle = self.group.select('.handle.progress');
|
||||||
handle && handle.drag(onmove, onstart, onstop);
|
handle && handle.drag(on_move, on_start, on_stop);
|
||||||
|
|
||||||
function onmove(dx, dy) {
|
function on_move(dx, dy) {
|
||||||
if (dx > bar_progress.max_dx) {
|
if (dx > bar_progress.max_dx) {
|
||||||
dx = bar_progress.max_dx;
|
dx = bar_progress.max_dx;
|
||||||
}
|
}
|
||||||
@ -1381,12 +1368,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
handle.transform('t{dx},0');
|
handle.transform('t{dx},0');
|
||||||
bar_progress.finaldx = dx;
|
bar_progress.finaldx = dx;
|
||||||
}
|
}
|
||||||
function onstop() {
|
function on_stop() {
|
||||||
if (!bar_progress.finaldx) return;
|
if (!bar_progress.finaldx) return;
|
||||||
progress_changed();
|
progress_changed();
|
||||||
set_action_completed();
|
set_action_completed();
|
||||||
}
|
}
|
||||||
function onstart() {
|
function on_start() {
|
||||||
bar_progress.finaldx = 0;
|
bar_progress.finaldx = 0;
|
||||||
bar_progress.owidth = bar_progress.getWidth();
|
bar_progress.owidth = bar_progress.getWidth();
|
||||||
bar_progress.min_dx = -bar_progress.getWidth();
|
bar_progress.min_dx = -bar_progress.getWidth();
|
||||||
@ -1728,7 +1715,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
end_x: self.end_x,
|
end_x: self.end_x,
|
||||||
end_y: self.end_y,
|
end_y: self.end_y,
|
||||||
down_1: gt.config.padding / 2 - self.curve,
|
down_1: gt.config.padding / 2 - self.curve,
|
||||||
down_2: to_task.$bar.getY() + to_task.$bar.get('height') / 2 - self.curve_y,
|
down_2: to_task.$bar.getY() + to_task.$bar.getHeight() / 2 - self.curve_y,
|
||||||
left: to_task.$bar.getX() - gt.config.padding,
|
left: to_task.$bar.getX() - gt.config.padding,
|
||||||
offset: self.offset,
|
offset: self.offset,
|
||||||
curve: self.curve,
|
curve: self.curve,
|
||||||
@ -1739,12 +1726,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
self.element = self.gantt.canvas.path(self.path).attr('data-from', self.from_task.task.id).attr('data-to', self.to_task.task.id);
|
self.element = gt.canvas.path(self.path).attr('data-from', self.from_task.task.id).attr('data-to', self.to_task.task.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
// eslint-disable-line
|
// eslint-disable-line
|
||||||
self.prepare();
|
prepare();
|
||||||
self.element.attr('d', self.path);
|
self.element.attr('d', self.path);
|
||||||
}
|
}
|
||||||
self.update = update;
|
self.update = update;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -77,7 +77,7 @@ export default function Arrow(gt, from_task, to_task) {
|
|||||||
end_x: self.end_x,
|
end_x: self.end_x,
|
||||||
end_y: self.end_y,
|
end_y: self.end_y,
|
||||||
down_1: gt.config.padding / 2 - self.curve,
|
down_1: gt.config.padding / 2 - self.curve,
|
||||||
down_2: to_task.$bar.getY() + to_task.$bar.get('height') / 2 - self.curve_y,
|
down_2: to_task.$bar.getY() + to_task.$bar.getHeight() / 2 - self.curve_y,
|
||||||
left: to_task.$bar.getX() - gt.config.padding,
|
left: to_task.$bar.getX() - gt.config.padding,
|
||||||
offset: self.offset,
|
offset: self.offset,
|
||||||
curve: self.curve,
|
curve: self.curve,
|
||||||
@ -88,13 +88,13 @@ export default function Arrow(gt, from_task, to_task) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
self.element = self.gantt.canvas.path(self.path)
|
self.element = gt.canvas.path(self.path)
|
||||||
.attr('data-from', self.from_task.task.id)
|
.attr('data-from', self.from_task.task.id)
|
||||||
.attr('data-to', self.to_task.task.id);
|
.attr('data-to', self.to_task.task.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() { // eslint-disable-line
|
function update() { // eslint-disable-line
|
||||||
self.prepare();
|
prepare();
|
||||||
self.element.attr('d', self.path);
|
self.element.attr('d', self.path);
|
||||||
}
|
}
|
||||||
self.update = update;
|
self.update = update;
|
||||||
|
|||||||
24
src/Bar.js
24
src/Bar.js
@ -225,12 +225,6 @@ export default function Bar(gt, task) {
|
|||||||
left.drag(onmove_left, onstart, onstop_left);
|
left.drag(onmove_left, onstart, onstop_left);
|
||||||
right.drag(onmove_right, onstart, onstop_right);
|
right.drag(onmove_right, onstart, onstop_right);
|
||||||
|
|
||||||
function onstart() {
|
|
||||||
onstart();
|
|
||||||
this.ox = this.getX();
|
|
||||||
this.oy = this.getY();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onmove_right(dx, dy) {
|
function onmove_right(dx, dy) {
|
||||||
onmove_handle_right(dx, dy);
|
onmove_handle_right(dx, dy);
|
||||||
}
|
}
|
||||||
@ -255,25 +249,15 @@ export default function Bar(gt, task) {
|
|||||||
|
|
||||||
function bind_drag() {
|
function bind_drag() {
|
||||||
self.bar_group.drag(onmove, onstart, onstop);
|
self.bar_group.drag(onmove, onstart, onstop);
|
||||||
|
|
||||||
function onmove(dx, dy) {
|
|
||||||
onmove(dx, dy);
|
|
||||||
}
|
|
||||||
function onstop() {
|
|
||||||
onstop();
|
|
||||||
}
|
|
||||||
function onstart() {
|
|
||||||
onstart();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bind_resize_progress() {
|
function bind_resize_progress() {
|
||||||
const bar = self.$bar,
|
const bar = self.$bar,
|
||||||
bar_progress = self.$bar_progress,
|
bar_progress = self.$bar_progress,
|
||||||
handle = self.group.select('.handle.progress');
|
handle = self.group.select('.handle.progress');
|
||||||
handle && handle.drag(onmove, onstart, onstop);
|
handle && handle.drag(on_move, on_start, on_stop);
|
||||||
|
|
||||||
function onmove(dx, dy) {
|
function on_move(dx, dy) {
|
||||||
if (dx > bar_progress.max_dx) {
|
if (dx > bar_progress.max_dx) {
|
||||||
dx = bar_progress.max_dx;
|
dx = bar_progress.max_dx;
|
||||||
}
|
}
|
||||||
@ -285,12 +269,12 @@ export default function Bar(gt, task) {
|
|||||||
handle.transform(`t{dx},0`);
|
handle.transform(`t{dx},0`);
|
||||||
bar_progress.finaldx = dx;
|
bar_progress.finaldx = dx;
|
||||||
}
|
}
|
||||||
function onstop() {
|
function on_stop() {
|
||||||
if (!bar_progress.finaldx) return;
|
if (!bar_progress.finaldx) return;
|
||||||
progress_changed();
|
progress_changed();
|
||||||
set_action_completed();
|
set_action_completed();
|
||||||
}
|
}
|
||||||
function onstart() {
|
function on_start() {
|
||||||
bar_progress.finaldx = 0;
|
bar_progress.finaldx = 0;
|
||||||
bar_progress.owidth = bar_progress.getWidth();
|
bar_progress.owidth = bar_progress.getWidth();
|
||||||
bar_progress.min_dx = -bar_progress.getWidth();
|
bar_progress.min_dx = -bar_progress.getWidth();
|
||||||
|
|||||||
15
src/Gantt.js
15
src/Gantt.js
@ -433,9 +433,10 @@ export default function Gantt(element, tasks, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function make_arrows() {
|
function make_arrows() {
|
||||||
|
self._arrows = [];
|
||||||
for(let task of self.tasks) {
|
for(let task of self.tasks) {
|
||||||
self._arrows = task.dependencies.map(dep => {
|
let arrows = [];
|
||||||
|
arrows = task.dependencies.map(dep => {
|
||||||
const dependency = get_task(dep);
|
const dependency = get_task(dep);
|
||||||
if(!dependency) return;
|
if(!dependency) return;
|
||||||
|
|
||||||
@ -447,6 +448,7 @@ export default function Gantt(element, tasks, config) {
|
|||||||
self.element_groups.arrow.add(arrow.element);
|
self.element_groups.arrow.add(arrow.element);
|
||||||
return arrow; // eslint-disable-line
|
return arrow; // eslint-disable-line
|
||||||
});
|
});
|
||||||
|
self._arrows = self._arrows.concat(arrows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,11 +462,10 @@ export default function Gantt(element, tasks, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function map_arrows_on_bars() {
|
function map_arrows_on_bars() {
|
||||||
|
|
||||||
for(let bar of self._bars) {
|
for(let bar of self._bars) {
|
||||||
bar.arrows = self._arrows.filter(arrow => {
|
bar.arrows = self._arrows.filter(arrow => {
|
||||||
return arrow.from_task.task.id === bar.task.id ||
|
return (arrow.from_task.task.id === bar.task.id) ||
|
||||||
arrow.to_task.task.id === bar.task.id;
|
(arrow.to_task.task.id === bar.task.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -498,13 +499,13 @@ export default function Gantt(element, tasks, config) {
|
|||||||
self.view_is = view_is;
|
self.view_is = view_is;
|
||||||
|
|
||||||
function get_task(id) {
|
function get_task(id) {
|
||||||
self.tasks.find((task) => {
|
return self.tasks.find((task) => {
|
||||||
return task.id === id;
|
return task.id === id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_bar(id) {
|
function get_bar(id) {
|
||||||
self._bars.find((bar) => {
|
return self._bars.find((bar) => {
|
||||||
return bar.task.id === id;
|
return bar.task.id === id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user