Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,11 @@ export default class Arrow {
start_x -= 10;

let start_y =
this.gantt.config.header_height +
this.gantt.options.bar_height +
(this.gantt.options.padding + this.gantt.options.bar_height) *
this.from_task.task._index +
this.gantt.options.padding / 2;
this.from_task.$bar.getY() + this.gantt.options.bar_height

let end_x = this.to_task.$bar.getX() - 13;
let end_y =
this.gantt.config.header_height +
this.gantt.options.bar_height / 2 +
(this.gantt.options.padding + this.gantt.options.bar_height) *
this.to_task.task._index +
this.gantt.options.padding / 2;
this.to_task.$bar.getY() + this.gantt.options.bar_height / 2;

const from_is_below_to =
this.from_task.task._index > this.to_task.task._index;
Expand Down Expand Up @@ -80,7 +72,7 @@ export default class Arrow {
this.path = `
M ${start_x} ${start_y}
V ${offset}
a ${curve} ${curve} 0 0 ${clockwise} ${curve} ${curve}
a ${curve} ${curve} 0 0 ${clockwise} ${curve} ${curve_y}
L ${end_x} ${end_y}
m -5 -5
l 5 5
Expand Down
62 changes: 60 additions & 2 deletions src/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export default class Bar {
});
}

update_bar_position({ x = null, width = null }) {
update_bar_position({ x = null, y = null, width = null }) {
const bar = this.$bar;

if (x) {
Expand All @@ -433,6 +433,10 @@ export default class Bar {
this.x = x;
this.$date_highlight.style.left = x + 'px';
}
if (y) {
this.update_attr(bar, 'y', y);
this.y = y;
}
if (width > 0) {
this.update_attr(bar, 'width', width);
this.$date_highlight.style.width = width + 'px';
Expand All @@ -441,6 +445,7 @@ export default class Bar {
this.update_label_position();
this.update_handle_position();
this.date_changed();
this.task_index_changed();
this.compute_duration();

if (this.gantt.options.show_expected_progress) {
Expand Down Expand Up @@ -508,6 +513,23 @@ export default class Bar {
]);
}

task_index_changed() {
let changed = false;
const new_index = this.compute_task_index();
const old_index = this.task._index;
if (this.task._index != new_index) {
changed = true;
this.task._index = new_index;
}

if (!changed) return;

this.gantt.trigger_event('task_index_change', [
this.task,
new_index,
]);
}

progress_changed() {
this.task.progress = this.compute_progress();
this.gantt.trigger_event('progress_change', [
Expand Down Expand Up @@ -540,6 +562,19 @@ export default class Bar {
return { new_start_date, new_end_date };
}

compute_task_index() {
const bar = this.$bar;
let new_index =
(
bar.getY()
- this.gantt.config.header_height
- this.gantt.options.padding / 2
) /
(bar.getHeight() + this.gantt.options.padding);

return new_index;
}

compute_progress() {
this.progress_width = this.$bar_progress.getWidth();
this.x = this.$bar_progress.getBBox().x;
Expand Down Expand Up @@ -659,6 +694,7 @@ export default class Bar {
update_expected_progressbar_position() {
if (this.invalid) return;
this.$expected_bar_progress.setAttribute('x', this.$bar.getX());
this.$expected_bar_progress.setAttribute('y', this.$bar.getY());
this.compute_expected_progress();
this.$expected_bar_progress.setAttribute(
'width',
Expand All @@ -671,6 +707,7 @@ export default class Bar {
update_progressbar_position() {
if (this.invalid || this.gantt.options.readonly) return;
this.$bar_progress.setAttribute('x', this.$bar.getX());
this.$bar_progress.setAttribute('y', this.$bar.getY());

this.$bar_progress.setAttribute(
'width',
Expand All @@ -694,8 +731,13 @@ export default class Bar {
img.setAttribute('x', bar.getEndX() + padding);
img_mask.setAttribute('x', bar.getEndX() + padding);
label.setAttribute('x', bar.getEndX() + x_offset_label_img);

img.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
img_mask.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
label.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
} else {
label.setAttribute('x', bar.getEndX() + padding);
label.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
}
} else {
label.classList.remove('big');
Expand All @@ -706,11 +748,16 @@ export default class Bar {
'x',
bar.getX() + barWidth / 2 + x_offset_label_img,
);

img.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
img_mask.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
label.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
} else {
label.setAttribute(
'x',
bar.getX() + barWidth / 2 - labelWidth / 2,
);
label.setAttribute('y', bar.getY() + bar.getHeight()/ 2);
}
}
}
Expand All @@ -721,11 +768,22 @@ export default class Bar {
this.handle_group
.querySelector('.handle.left')
.setAttribute('x', bar.getX());
this.handle_group
.querySelector('.handle.left')
.setAttribute('y', bar.getY() + bar.getHeight() / 4);
this.handle_group
.querySelector('.handle.right')
.setAttribute('x', bar.getEndX());
this.handle_group
.querySelector('.handle.right')
.setAttribute('y', bar.getY() + bar.getHeight() / 4);
const handle = this.group.querySelector('.handle.progress');
handle && handle.setAttribute('cx', this.$bar_progress.getEndX());
handle
&& handle.setAttribute('cx', this.$bar_progress.getEndX())
&& handle.setAttribute(
'cy',
this.$bar_progress.getY() + this.$bar_progress.getHeight() / 2
);
}

update_arrow_position() {
Expand Down
38 changes: 34 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,11 +1088,13 @@ export default class Gantt {
if (e.target.classList.contains('grid-row')) this.unselect_all();
};

let pos = 0;
let posx = 0;
let posy = 0;
$.on(this.$svg, 'mousemove', '.bar-wrapper, .handle', (e) => {
if (
this.bar_being_dragged === false &&
Math.abs((e.offsetX || e.layerX) - pos) > 10
(Math.abs((e.offsetX || e.layerX) - posx) > 10 ||
Math.abs((e.offsetY || e.layerY) - posy) > 10)
)
this.bar_being_dragged = true;
});
Expand Down Expand Up @@ -1127,14 +1129,16 @@ export default class Gantt {
bars = ids.map((id) => this.get_bar(id));

this.bar_being_dragged = false;
pos = x_on_start;
posx = x_on_start;
posy = y_on_start;

bars.forEach((bar) => {
const $bar = bar.$bar;
$bar.ox = $bar.getX();
$bar.oy = $bar.getY();
$bar.owidth = $bar.getWidth();
$bar.finaldx = 0;
$bar.finaldy = 0;
});
});

Expand Down Expand Up @@ -1278,6 +1282,7 @@ export default class Gantt {
$.on(this.$svg, 'mousemove', (e) => {
if (!action_in_progress()) return;
const dx = (e.offsetX || e.layerX) - x_on_start;
const dy = (e.offsetY || e.layerY) - y_on_start;

bars.forEach((bar) => {
const $bar = bar.$bar;
Expand Down Expand Up @@ -1305,7 +1310,16 @@ export default class Gantt {
!this.options.readonly &&
!this.options.readonly_dates
) {
bar.update_bar_position({ x: $bar.ox + $bar.finaldx });
bar.update_bar_position({
x: $bar.ox + $bar.finaldx,
});
if (parent_bar_id === bar.task.id) {
$bar.finaldy = this.get_snap_row_position(dy, $bar.oy);
bar.update_bar_position({
x: $bar.ox + $bar.finaldx,
y: $bar.oy + $bar.finaldy
});
}
}
});
});
Expand Down Expand Up @@ -1335,6 +1349,7 @@ export default class Gantt {

bind_bar_progress() {
let x_on_start = 0;
let y_on_start = 0;
let is_resizing = null;
let bar = null;
let $bar_progress = null;
Expand Down Expand Up @@ -1466,6 +1481,21 @@ export default class Gantt {
return final_pos - ox;
}

get_snap_row_position(dy, oy) {
let snap_height = this.options.bar_height + this.options.padding;
const rem = dy % snap_height;

let final_dy =
dy -
rem +
(rem < snap_height * 2
? 0
: snap_height);
let final_pos = oy + final_dy;

return final_pos - oy;
}

get_ignored_region(pos, drn = 1) {
if (drn === 1) {
return this.config.ignored_positions.filter((val) => {
Expand Down