feat: fixed header, thumbnail, movable label;
bug of bar task id fixed
This commit is contained in:
parent
b8bad72109
commit
9401b35139
4
dist/frappe-gantt.css
vendored
4
dist/frappe-gantt.css
vendored
@ -143,9 +143,8 @@
|
|||||||
.gantt .bar-label {
|
.gantt .bar-label {
|
||||||
fill: #fff;
|
fill: #fff;
|
||||||
dominant-baseline: central;
|
dominant-baseline: central;
|
||||||
text-anchor: middle;
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: lighter;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
.gantt .bar-label.big {
|
.gantt .bar-label.big {
|
||||||
fill: #555;
|
fill: #555;
|
||||||
@ -197,6 +196,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
height: 500px;
|
||||||
}
|
}
|
||||||
.gantt-container .popup-wrapper {
|
.gantt-container .popup-wrapper {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
155
dist/frappe-gantt.js
vendored
155
dist/frappe-gantt.js
vendored
@ -269,6 +269,8 @@ var Gantt = (function () {
|
|||||||
parent.appendChild(elem);
|
parent.appendChild(elem);
|
||||||
} else if (attr === "innerHTML") {
|
} else if (attr === "innerHTML") {
|
||||||
elem.innerHTML = attrs.innerHTML;
|
elem.innerHTML = attrs.innerHTML;
|
||||||
|
} else if (attr === 'clipPath') {
|
||||||
|
elem.setAttribute('clip-path', 'url(#' + attrs[attr] + ')');
|
||||||
} else {
|
} else {
|
||||||
elem.setAttribute(attr, attrs[attr]);
|
elem.setAttribute(attr, attrs[attr]);
|
||||||
}
|
}
|
||||||
@ -411,6 +413,7 @@ var Gantt = (function () {
|
|||||||
prepare_values() {
|
prepare_values() {
|
||||||
this.invalid = this.task.invalid;
|
this.invalid = this.task.invalid;
|
||||||
this.height = this.gantt.options.bar_height;
|
this.height = this.gantt.options.bar_height;
|
||||||
|
this.image_size = this.height - 5;
|
||||||
this.compute_x();
|
this.compute_x();
|
||||||
this.compute_y();
|
this.compute_y();
|
||||||
this.compute_duration();
|
this.compute_duration();
|
||||||
@ -469,6 +472,10 @@ var Gantt = (function () {
|
|||||||
this.draw_progress_bar();
|
this.draw_progress_bar();
|
||||||
this.draw_label();
|
this.draw_label();
|
||||||
this.draw_resize_handles();
|
this.draw_resize_handles();
|
||||||
|
|
||||||
|
if (this.task.thumbnail) {
|
||||||
|
this.draw_thumbnail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_bar() {
|
draw_bar() {
|
||||||
@ -528,8 +535,14 @@ var Gantt = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw_label() {
|
draw_label() {
|
||||||
|
let x_coord = this.x + 5;
|
||||||
|
|
||||||
|
if (this.task.thumbnail) {
|
||||||
|
x_coord = this.x + this.image_size + 5;
|
||||||
|
}
|
||||||
|
|
||||||
createSVG("text", {
|
createSVG("text", {
|
||||||
x: this.x + this.width / 2,
|
x: x_coord,
|
||||||
y: this.y + this.height / 2,
|
y: this.y + this.height / 2,
|
||||||
innerHTML: this.task.name,
|
innerHTML: this.task.name,
|
||||||
class: "bar-label",
|
class: "bar-label",
|
||||||
@ -538,6 +551,46 @@ var Gantt = (function () {
|
|||||||
// labels get BBox in the next tick
|
// labels get BBox in the next tick
|
||||||
requestAnimationFrame(() => this.update_label_position());
|
requestAnimationFrame(() => this.update_label_position());
|
||||||
}
|
}
|
||||||
|
draw_thumbnail() {
|
||||||
|
let x_offset = 10, y_offset = 2;
|
||||||
|
let defs, clipPath;
|
||||||
|
|
||||||
|
defs = createSVG('defs', {
|
||||||
|
append_to: this.bar_group
|
||||||
|
});
|
||||||
|
|
||||||
|
createSVG('rect', {
|
||||||
|
id: 'rect_' + this.task.id,
|
||||||
|
x: this.x + x_offset,
|
||||||
|
y: this.y + y_offset,
|
||||||
|
width: this.image_size,
|
||||||
|
height: this.image_size,
|
||||||
|
rx: '15',
|
||||||
|
class: 'img_mask',
|
||||||
|
append_to: defs
|
||||||
|
});
|
||||||
|
|
||||||
|
clipPath = createSVG('clipPath', {
|
||||||
|
id: 'clip_' + this.task.id,
|
||||||
|
append_to: defs
|
||||||
|
});
|
||||||
|
|
||||||
|
createSVG('use', {
|
||||||
|
href: '#rect_' + this.task.id,
|
||||||
|
append_to: clipPath
|
||||||
|
});
|
||||||
|
|
||||||
|
createSVG('image', {
|
||||||
|
x: this.x + x_offset,
|
||||||
|
y: this.y + y_offset,
|
||||||
|
width: this.image_size,
|
||||||
|
height: this.image_size,
|
||||||
|
class: 'bar-img',
|
||||||
|
href: this.task.thumbnail,
|
||||||
|
clipPath: 'clip_' + this.task.id,
|
||||||
|
append_to: this.bar_group
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
draw_resize_handles() {
|
draw_resize_handles() {
|
||||||
if (this.invalid || this.gantt.options.readonly) return;
|
if (this.invalid || this.gantt.options.readonly) return;
|
||||||
@ -667,6 +720,37 @@ var Gantt = (function () {
|
|||||||
this.update_arrow_position();
|
this.update_arrow_position();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_label_position_on_horizontal_scroll({ x, sx }) {
|
||||||
|
const container = document.querySelector('.gantt-container');
|
||||||
|
const label = this.group.querySelector('.bar-label');
|
||||||
|
const img = this.group.querySelector('.bar-img') || '';
|
||||||
|
const img_mask = this.bar_group.querySelector('.img_mask') || '';
|
||||||
|
|
||||||
|
let barWidthLimit = this.$bar.getX() + this.$bar.getWidth();
|
||||||
|
let newLabelX = label.getX() + x;
|
||||||
|
let newImgX = img && img.getX() + x || 0;
|
||||||
|
let imgWidth = img && img.getBBox().width + 7 || 7;
|
||||||
|
let labelEndX = newLabelX + label.getBBox().width + 7;
|
||||||
|
let viewportCentral = sx + container.clientWidth / 2;
|
||||||
|
|
||||||
|
if (label.classList.contains('big')) return;
|
||||||
|
|
||||||
|
if (labelEndX < barWidthLimit && x > 0 && labelEndX < viewportCentral) {
|
||||||
|
label.setAttribute('x', newLabelX);
|
||||||
|
if (img) {
|
||||||
|
img.setAttribute('x', newImgX);
|
||||||
|
img_mask.setAttribute('x', newImgX);
|
||||||
|
}
|
||||||
|
} else if ((newLabelX - imgWidth) > this.$bar.getX() && x < 0 && labelEndX > viewportCentral) {
|
||||||
|
label.setAttribute('x', newLabelX);
|
||||||
|
if (img) {
|
||||||
|
img.setAttribute('x', newImgX);
|
||||||
|
img_mask.setAttribute('x', newImgX);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
date_changed() {
|
date_changed() {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
const { new_start_date, new_end_date } = this.compute_start_end_date();
|
const { new_start_date, new_end_date } = this.compute_start_end_date();
|
||||||
@ -819,7 +903,7 @@ var Gantt = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_progressbar_position() {
|
update_progressbar_position() {
|
||||||
if (this.invalid) return;
|
if (this.invalid || this.gantt.options.readonly) return;
|
||||||
this.$bar_progress.setAttribute("x", this.$bar.getX());
|
this.$bar_progress.setAttribute("x", this.$bar.getX());
|
||||||
this.$bar_progress.setAttribute(
|
this.$bar_progress.setAttribute(
|
||||||
"width",
|
"width",
|
||||||
@ -828,20 +912,37 @@ var Gantt = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_label_position() {
|
update_label_position() {
|
||||||
|
const img_mask = this.bar_group.querySelector('.img_mask') || '';
|
||||||
const bar = this.$bar,
|
const bar = this.$bar,
|
||||||
label = this.group.querySelector(".bar-label");
|
label = this.group.querySelector(".bar-label"),
|
||||||
|
img = this.group.querySelector('.bar-img');
|
||||||
|
|
||||||
|
let padding = 5;
|
||||||
|
let x_offset_label_img = this.image_size + 10;
|
||||||
|
|
||||||
if (label.getBBox().width > bar.getWidth()) {
|
if (label.getBBox().width > bar.getWidth()) {
|
||||||
label.classList.add("big");
|
label.classList.add("big");
|
||||||
label.setAttribute("x", bar.getX() + bar.getWidth() + 5);
|
if (img) {
|
||||||
|
img.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
|
img_mask.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
|
label.setAttribute('x', bar.getX() + bar.getWidth() + x_offset_label_img);
|
||||||
|
} else {
|
||||||
|
label.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
label.classList.remove("big");
|
label.classList.remove("big");
|
||||||
label.setAttribute("x", bar.getX() + bar.getWidth() / 2);
|
if (img) {
|
||||||
|
img.setAttribute('x', bar.getX() + padding);
|
||||||
|
img_mask.setAttribute('x', bar.getX() + padding);
|
||||||
|
label.setAttribute('x', bar.getX() + x_offset_label_img);
|
||||||
|
} else {
|
||||||
|
label.setAttribute('x', bar.getX() + padding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_handle_position() {
|
update_handle_position() {
|
||||||
if (this.invalid) return;
|
if (this.invalid || this.gantt.options.readonly) return;
|
||||||
const bar = this.$bar;
|
const bar = this.$bar;
|
||||||
this.handle_group
|
this.handle_group
|
||||||
.querySelector(".handle.left")
|
.querySelector(".handle.left")
|
||||||
@ -1107,7 +1208,7 @@ var Gantt = (function () {
|
|||||||
column_width: 30,
|
column_width: 30,
|
||||||
step: 24,
|
step: 24,
|
||||||
view_modes: [...Object.values(VIEW_MODE)],
|
view_modes: [...Object.values(VIEW_MODE)],
|
||||||
bar_height: 20,
|
bar_height: 30,
|
||||||
bar_corner_radius: 3,
|
bar_corner_radius: 3,
|
||||||
arrow_curve: 5,
|
arrow_curve: 5,
|
||||||
padding: 18,
|
padding: 18,
|
||||||
@ -1200,6 +1301,10 @@ var Gantt = (function () {
|
|||||||
// uids
|
// uids
|
||||||
if (!task.id) {
|
if (!task.id) {
|
||||||
task.id = generate_id(task);
|
task.id = generate_id(task);
|
||||||
|
} else if (typeof task.id === 'string') {
|
||||||
|
task.id = task.id.replace(' ', '_');
|
||||||
|
} else {
|
||||||
|
task.id = `${task.id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
@ -1363,7 +1468,7 @@ var Gantt = (function () {
|
|||||||
|
|
||||||
setup_layers() {
|
setup_layers() {
|
||||||
this.layers = {};
|
this.layers = {};
|
||||||
const layers = ["grid", "date", "arrow", "progress", "bar", "details"];
|
const layers = ["grid", "arrow", "progress", "bar", "details", "date"];
|
||||||
// make group layers
|
// make group layers
|
||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
this.layers[layer] = createSVG("g", {
|
this.layers[layer] = createSVG("g", {
|
||||||
@ -1394,7 +1499,7 @@ var Gantt = (function () {
|
|||||||
width: grid_width,
|
width: grid_width,
|
||||||
height: grid_height,
|
height: grid_height,
|
||||||
class: "grid-background",
|
class: "grid-background",
|
||||||
append_to: this.layers.grid,
|
append_to: this.layers.date,
|
||||||
});
|
});
|
||||||
|
|
||||||
$.attr(this.$svg, {
|
$.attr(this.$svg, {
|
||||||
@ -1792,6 +1897,7 @@ var Gantt = (function () {
|
|||||||
bind_bar_events() {
|
bind_bar_events() {
|
||||||
let is_dragging = false;
|
let is_dragging = false;
|
||||||
let x_on_start = 0;
|
let x_on_start = 0;
|
||||||
|
let x_on_scroll_start = 0;
|
||||||
let y_on_start = 0;
|
let y_on_start = 0;
|
||||||
let is_resizing_left = false;
|
let is_resizing_left = false;
|
||||||
let is_resizing_right = false;
|
let is_resizing_right = false;
|
||||||
@ -1836,6 +1942,31 @@ var Gantt = (function () {
|
|||||||
$bar.finaldx = 0;
|
$bar.finaldx = 0;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$.on(this.$container, 'scroll', e => {
|
||||||
|
let elements = document.querySelectorAll('.bar-wrapper');
|
||||||
|
let localBars = [];
|
||||||
|
const ids = [];
|
||||||
|
let dx;
|
||||||
|
|
||||||
|
this.layers.date.setAttribute('transform', 'translate(0,' + e.currentTarget.scrollTop + ')');
|
||||||
|
if (x_on_scroll_start) {
|
||||||
|
dx = e.currentTarget.scrollLeft - x_on_scroll_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.prototype.forEach.call(elements, function (el, i) {
|
||||||
|
ids.push(el.getAttribute('data-id'));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (dx) {
|
||||||
|
localBars = ids.map(id => this.get_bar(id));
|
||||||
|
|
||||||
|
localBars.forEach(bar => {
|
||||||
|
bar.update_label_position_on_horizontal_scroll({ x: dx, sx: e.currentTarget.scrollLeft });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
x_on_scroll_start = e.currentTarget.scrollLeft;
|
||||||
|
});
|
||||||
|
|
||||||
$.on(this.$svg, "mousemove", (e) => {
|
$.on(this.$svg, "mousemove", (e) => {
|
||||||
if (!action_in_progress()) return;
|
if (!action_in_progress()) return;
|
||||||
@ -1863,7 +1994,7 @@ var Gantt = (function () {
|
|||||||
width: $bar.owidth + $bar.finaldx,
|
width: $bar.owidth + $bar.finaldx,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (is_dragging) {
|
} else if (is_dragging && !this.options.readonly) {
|
||||||
bar.update_bar_position({ x: $bar.ox + $bar.finaldx });
|
bar.update_bar_position({ x: $bar.ox + $bar.finaldx });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -2011,13 +2142,13 @@ var Gantt = (function () {
|
|||||||
|
|
||||||
get_task(id) {
|
get_task(id) {
|
||||||
return this.tasks.find((task) => {
|
return this.tasks.find((task) => {
|
||||||
return task.id === id;
|
return task.id == id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get_bar(id) {
|
get_bar(id) {
|
||||||
return this.bars.find((bar) => {
|
return this.bars.find((bar) => {
|
||||||
return bar.task.id === id;
|
return bar.task.id == id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
dist/frappe-gantt.js.map
vendored
2
dist/frappe-gantt.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-gantt.min.css
vendored
2
dist/frappe-gantt.min.css
vendored
@ -1 +1 @@
|
|||||||
.dark>.gantt-container .gantt .grid-header{fill:#252525;stroke:#616161}.dark>.gantt-container .gantt .grid-row{fill:#252525}.dark>.gantt-container .gantt .grid-row:nth-child(even){fill:#3e3e3e}.dark>.gantt-container .gantt .row-line{stroke:#3e3e3e}.dark>.gantt-container .gantt .tick{stroke:#616161}.dark>.gantt-container .gantt .today-highlight{opacity:.2}.dark>.gantt-container .gantt .arrow{stroke:#eee}.dark>.gantt-container .gantt .bar{fill:#616161;stroke:none}.dark>.gantt-container .gantt .bar-progress{fill:#8a8aff}.dark>.gantt-container .gantt .bar-invalid{fill:rgba(0,0,0,0);stroke:#c6ccd2}.dark>.gantt-container .gantt .bar-invalid~.bar-label{fill:#ececec}.dark>.gantt-container .gantt .bar-label.big{fill:#ececec}.dark>.gantt-container .gantt .bar-wrapper:hover .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper:hover .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .bar-wrapper.active .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper.active .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .upper-text{fill:#a2a2a2}.dark>.gantt-container .gantt .lower-text{fill:#f7f7f7}.dark>.gantt-container .popup-wrapper{background-color:#333}.dark>.gantt-container .popup-wrapper .title{border-color:#a4a4ff}.dark>.gantt-container .popup-wrapper .pointer{border-top-color:#333}.gantt{user-select:none;-webkit-user-select:none}.gantt .grid-background{fill:none}.gantt .grid-header{fill:#fff;stroke:#e0e0e0;stroke-width:1.4}.gantt .grid-row{fill:#fff}.gantt .grid-row:nth-child(even){fill:#f5f5f5}.gantt .row-line{stroke:#ebeff2}.gantt .tick{stroke:#e0e0e0;stroke-width:.2}.gantt .tick.thick{stroke-width:.4}.gantt .today-highlight{fill:#f6e796;opacity:.5}.gantt .week-highlight{fill:#f6e796;opacity:.5}.gantt .holiday-highlight{fill:#eee;opacity:.5}.gantt .month-highlight{fill:#f6e796;opacity:.5}.gantt .year-highlight{fill:#f6e796;opacity:.5}.gantt .arrow{fill:none;stroke:#666;stroke-width:1.4}.gantt .bar{fill:#b8c2cc;stroke:#8d99a6;stroke-width:0;transition:stroke-width .3s ease}.gantt .bar-progress{fill:#acacfa}.gantt .bar-expected-progress{fill:#c4c4e9}.gantt .bar-invalid{fill:rgba(0,0,0,0);stroke:#8d99a6;stroke-width:1;stroke-dasharray:5}.gantt .bar-invalid~.bar-label{fill:#555}.gantt .bar-label{fill:#fff;dominant-baseline:central;text-anchor:middle;font-size:12px;font-weight:lighter}.gantt .bar-label.big{fill:#555;text-anchor:start}.gantt .handle{fill:#ddd;cursor:ew-resize;opacity:0;visibility:hidden;transition:opacity .3s ease}.gantt .bar-wrapper{cursor:pointer;outline:none}.gantt .bar-wrapper:hover .bar{fill:#a9b5c1}.gantt .bar-wrapper:hover .bar-progress{fill:#9494f9}.gantt .bar-wrapper:hover .handle{visibility:visible;opacity:1}.gantt .bar-wrapper.active .bar{fill:#a9b5c1}.gantt .bar-wrapper.active .bar-progress{fill:#9494f9}.gantt .lower-text,.gantt .upper-text{font-size:12px;text-anchor:middle}.gantt .upper-text{fill:#555}.gantt .lower-text{fill:#333}.gantt .hide{display:none}.gantt-container{position:relative;overflow:auto;font-size:12px}.gantt-container .popup-wrapper{position:absolute;top:0;left:0;background:rgba(0,0,0,.8);padding:0;color:#959da5;border-radius:3px}.gantt-container .popup-wrapper .title{border-bottom:3px solid #acacfa;padding:10px}.gantt-container .popup-wrapper .subtitle{padding:10px;color:#dfe2e5}.gantt-container .popup-wrapper .pointer{position:absolute;height:5px;margin:0 0 0 -5px;border:5px solid rgba(0,0,0,0);border-top-color:rgba(0,0,0,.8)}
|
.dark>.gantt-container .gantt .grid-header{fill:#252525;stroke:#616161}.dark>.gantt-container .gantt .grid-row{fill:#252525}.dark>.gantt-container .gantt .grid-row:nth-child(even){fill:#3e3e3e}.dark>.gantt-container .gantt .row-line{stroke:#3e3e3e}.dark>.gantt-container .gantt .tick{stroke:#616161}.dark>.gantt-container .gantt .today-highlight{opacity:.2}.dark>.gantt-container .gantt .arrow{stroke:#eee}.dark>.gantt-container .gantt .bar{fill:#616161;stroke:none}.dark>.gantt-container .gantt .bar-progress{fill:#8a8aff}.dark>.gantt-container .gantt .bar-invalid{fill:rgba(0,0,0,0);stroke:#c6ccd2}.dark>.gantt-container .gantt .bar-invalid~.bar-label{fill:#ececec}.dark>.gantt-container .gantt .bar-label.big{fill:#ececec}.dark>.gantt-container .gantt .bar-wrapper:hover .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper:hover .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .bar-wrapper.active .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper.active .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .upper-text{fill:#a2a2a2}.dark>.gantt-container .gantt .lower-text{fill:#f7f7f7}.dark>.gantt-container .popup-wrapper{background-color:#333}.dark>.gantt-container .popup-wrapper .title{border-color:#a4a4ff}.dark>.gantt-container .popup-wrapper .pointer{border-top-color:#333}.gantt{user-select:none;-webkit-user-select:none}.gantt .grid-background{fill:none}.gantt .grid-header{fill:#fff;stroke:#e0e0e0;stroke-width:1.4}.gantt .grid-row{fill:#fff}.gantt .grid-row:nth-child(even){fill:#f5f5f5}.gantt .row-line{stroke:#ebeff2}.gantt .tick{stroke:#e0e0e0;stroke-width:.2}.gantt .tick.thick{stroke-width:.4}.gantt .today-highlight{fill:#f6e796;opacity:.5}.gantt .week-highlight{fill:#f6e796;opacity:.5}.gantt .holiday-highlight{fill:#eee;opacity:.5}.gantt .month-highlight{fill:#f6e796;opacity:.5}.gantt .year-highlight{fill:#f6e796;opacity:.5}.gantt .arrow{fill:none;stroke:#666;stroke-width:1.4}.gantt .bar{fill:#b8c2cc;stroke:#8d99a6;stroke-width:0;transition:stroke-width .3s ease}.gantt .bar-progress{fill:#acacfa}.gantt .bar-expected-progress{fill:#c4c4e9}.gantt .bar-invalid{fill:rgba(0,0,0,0);stroke:#8d99a6;stroke-width:1;stroke-dasharray:5}.gantt .bar-invalid~.bar-label{fill:#555}.gantt .bar-label{fill:#fff;dominant-baseline:central;font-size:12px;font-weight:500}.gantt .bar-label.big{fill:#555;text-anchor:start}.gantt .handle{fill:#ddd;cursor:ew-resize;opacity:0;visibility:hidden;transition:opacity .3s ease}.gantt .bar-wrapper{cursor:pointer;outline:none}.gantt .bar-wrapper:hover .bar{fill:#a9b5c1}.gantt .bar-wrapper:hover .bar-progress{fill:#9494f9}.gantt .bar-wrapper:hover .handle{visibility:visible;opacity:1}.gantt .bar-wrapper.active .bar{fill:#a9b5c1}.gantt .bar-wrapper.active .bar-progress{fill:#9494f9}.gantt .lower-text,.gantt .upper-text{font-size:12px;text-anchor:middle}.gantt .upper-text{fill:#555}.gantt .lower-text{fill:#333}.gantt .hide{display:none}.gantt-container{position:relative;overflow:auto;font-size:12px;height:500px}.gantt-container .popup-wrapper{position:absolute;top:0;left:0;background:rgba(0,0,0,.8);padding:0;color:#959da5;border-radius:3px}.gantt-container .popup-wrapper .title{border-bottom:3px solid #acacfa;padding:10px}.gantt-container .popup-wrapper .subtitle{padding:10px;color:#dfe2e5}.gantt-container .popup-wrapper .pointer{position:absolute;height:5px;margin:0 0 0 -5px;border:5px solid rgba(0,0,0,0);border-top-color:rgba(0,0,0,.8)}
|
||||||
2
dist/frappe-gantt.min.js
vendored
2
dist/frappe-gantt.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-gantt.min.js.map
vendored
2
dist/frappe-gantt.min.js.map
vendored
File diff suppressed because one or more lines are too long
111
src/bar.js
111
src/bar.js
@ -23,6 +23,7 @@ export default class Bar {
|
|||||||
prepare_values() {
|
prepare_values() {
|
||||||
this.invalid = this.task.invalid;
|
this.invalid = this.task.invalid;
|
||||||
this.height = this.gantt.options.bar_height;
|
this.height = this.gantt.options.bar_height;
|
||||||
|
this.image_size = this.height - 5;
|
||||||
this.compute_x();
|
this.compute_x();
|
||||||
this.compute_y();
|
this.compute_y();
|
||||||
this.compute_duration();
|
this.compute_duration();
|
||||||
@ -81,6 +82,10 @@ export default class Bar {
|
|||||||
this.draw_progress_bar();
|
this.draw_progress_bar();
|
||||||
this.draw_label();
|
this.draw_label();
|
||||||
this.draw_resize_handles();
|
this.draw_resize_handles();
|
||||||
|
|
||||||
|
if (this.task.thumbnail) {
|
||||||
|
this.draw_thumbnail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_bar() {
|
draw_bar() {
|
||||||
@ -140,8 +145,14 @@ export default class Bar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw_label() {
|
draw_label() {
|
||||||
|
let x_coord = this.x + 5;
|
||||||
|
|
||||||
|
if (this.task.thumbnail) {
|
||||||
|
x_coord = this.x + this.image_size + 5;
|
||||||
|
}
|
||||||
|
|
||||||
createSVG("text", {
|
createSVG("text", {
|
||||||
x: this.x + this.width / 2,
|
x: x_coord,
|
||||||
y: this.y + this.height / 2,
|
y: this.y + this.height / 2,
|
||||||
innerHTML: this.task.name,
|
innerHTML: this.task.name,
|
||||||
class: "bar-label",
|
class: "bar-label",
|
||||||
@ -150,6 +161,46 @@ export default class Bar {
|
|||||||
// labels get BBox in the next tick
|
// labels get BBox in the next tick
|
||||||
requestAnimationFrame(() => this.update_label_position());
|
requestAnimationFrame(() => this.update_label_position());
|
||||||
}
|
}
|
||||||
|
draw_thumbnail() {
|
||||||
|
let x_offset = 10, y_offset = 2;
|
||||||
|
let defs, clipPath;
|
||||||
|
|
||||||
|
defs = createSVG('defs', {
|
||||||
|
append_to: this.bar_group
|
||||||
|
});
|
||||||
|
|
||||||
|
createSVG('rect', {
|
||||||
|
id: 'rect_' + this.task.id,
|
||||||
|
x: this.x + x_offset,
|
||||||
|
y: this.y + y_offset,
|
||||||
|
width: this.image_size,
|
||||||
|
height: this.image_size,
|
||||||
|
rx: '15',
|
||||||
|
class: 'img_mask',
|
||||||
|
append_to: defs
|
||||||
|
});
|
||||||
|
|
||||||
|
clipPath = createSVG('clipPath', {
|
||||||
|
id: 'clip_' + this.task.id,
|
||||||
|
append_to: defs
|
||||||
|
});
|
||||||
|
|
||||||
|
createSVG('use', {
|
||||||
|
href: '#rect_' + this.task.id,
|
||||||
|
append_to: clipPath
|
||||||
|
});
|
||||||
|
|
||||||
|
createSVG('image', {
|
||||||
|
x: this.x + x_offset,
|
||||||
|
y: this.y + y_offset,
|
||||||
|
width: this.image_size,
|
||||||
|
height: this.image_size,
|
||||||
|
class: 'bar-img',
|
||||||
|
href: this.task.thumbnail,
|
||||||
|
clipPath: 'clip_' + this.task.id,
|
||||||
|
append_to: this.bar_group
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
draw_resize_handles() {
|
draw_resize_handles() {
|
||||||
if (this.invalid || this.gantt.options.readonly) return;
|
if (this.invalid || this.gantt.options.readonly) return;
|
||||||
@ -279,6 +330,37 @@ export default class Bar {
|
|||||||
this.update_arrow_position();
|
this.update_arrow_position();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_label_position_on_horizontal_scroll({ x, sx }) {
|
||||||
|
const container = document.querySelector('.gantt-container');
|
||||||
|
const label = this.group.querySelector('.bar-label');
|
||||||
|
const img = this.group.querySelector('.bar-img') || '';
|
||||||
|
const img_mask = this.bar_group.querySelector('.img_mask') || '';
|
||||||
|
|
||||||
|
let barWidthLimit = this.$bar.getX() + this.$bar.getWidth();
|
||||||
|
let newLabelX = label.getX() + x;
|
||||||
|
let newImgX = img && img.getX() + x || 0;
|
||||||
|
let imgWidth = img && img.getBBox().width + 7 || 7;
|
||||||
|
let labelEndX = newLabelX + label.getBBox().width + 7;
|
||||||
|
let viewportCentral = sx + container.clientWidth / 2;
|
||||||
|
|
||||||
|
if (label.classList.contains('big')) return;
|
||||||
|
|
||||||
|
if (labelEndX < barWidthLimit && x > 0 && labelEndX < viewportCentral) {
|
||||||
|
label.setAttribute('x', newLabelX);
|
||||||
|
if (img) {
|
||||||
|
img.setAttribute('x', newImgX);
|
||||||
|
img_mask.setAttribute('x', newImgX);
|
||||||
|
}
|
||||||
|
} else if ((newLabelX - imgWidth) > this.$bar.getX() && x < 0 && labelEndX > viewportCentral) {
|
||||||
|
label.setAttribute('x', newLabelX);
|
||||||
|
if (img) {
|
||||||
|
img.setAttribute('x', newImgX);
|
||||||
|
img_mask.setAttribute('x', newImgX);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
date_changed() {
|
date_changed() {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
const { new_start_date, new_end_date } = this.compute_start_end_date();
|
const { new_start_date, new_end_date } = this.compute_start_end_date();
|
||||||
@ -431,7 +513,7 @@ export default class Bar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_progressbar_position() {
|
update_progressbar_position() {
|
||||||
if (this.invalid) return;
|
if (this.invalid || this.gantt.options.readonly) return;
|
||||||
this.$bar_progress.setAttribute("x", this.$bar.getX());
|
this.$bar_progress.setAttribute("x", this.$bar.getX());
|
||||||
this.$bar_progress.setAttribute(
|
this.$bar_progress.setAttribute(
|
||||||
"width",
|
"width",
|
||||||
@ -440,20 +522,37 @@ export default class Bar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_label_position() {
|
update_label_position() {
|
||||||
|
const img_mask = this.bar_group.querySelector('.img_mask') || '';
|
||||||
const bar = this.$bar,
|
const bar = this.$bar,
|
||||||
label = this.group.querySelector(".bar-label");
|
label = this.group.querySelector(".bar-label"),
|
||||||
|
img = this.group.querySelector('.bar-img');
|
||||||
|
|
||||||
|
let padding = 5;
|
||||||
|
let x_offset_label_img = this.image_size + 10;
|
||||||
|
|
||||||
if (label.getBBox().width > bar.getWidth()) {
|
if (label.getBBox().width > bar.getWidth()) {
|
||||||
label.classList.add("big");
|
label.classList.add("big");
|
||||||
label.setAttribute("x", bar.getX() + bar.getWidth() + 5);
|
if (img) {
|
||||||
|
img.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
|
img_mask.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
|
label.setAttribute('x', bar.getX() + bar.getWidth() + x_offset_label_img);
|
||||||
|
} else {
|
||||||
|
label.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
label.classList.remove("big");
|
label.classList.remove("big");
|
||||||
label.setAttribute("x", bar.getX() + bar.getWidth() / 2);
|
if (img) {
|
||||||
|
img.setAttribute('x', bar.getX() + padding);
|
||||||
|
img_mask.setAttribute('x', bar.getX() + padding);
|
||||||
|
label.setAttribute('x', bar.getX() + x_offset_label_img);
|
||||||
|
} else {
|
||||||
|
label.setAttribute('x', bar.getX() + padding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_handle_position() {
|
update_handle_position() {
|
||||||
if (this.invalid) return;
|
if (this.invalid || this.gantt.options.readonly) return;
|
||||||
const bar = this.$bar;
|
const bar = this.$bar;
|
||||||
this.handle_group
|
this.handle_group
|
||||||
.querySelector(".handle.left")
|
.querySelector(".handle.left")
|
||||||
|
|||||||
@ -109,9 +109,9 @@ $light-blue: #c4c4e9 !default;
|
|||||||
.bar-label {
|
.bar-label {
|
||||||
fill: #fff;
|
fill: #fff;
|
||||||
dominant-baseline: central;
|
dominant-baseline: central;
|
||||||
text-anchor: middle;
|
// text-anchor: middle;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: lighter;
|
font-weight: 500;
|
||||||
|
|
||||||
&.big {
|
&.big {
|
||||||
fill: $text-light;
|
fill: $text-light;
|
||||||
@ -180,6 +180,7 @@ $light-blue: #c4c4e9 !default;
|
|||||||
position: relative;
|
position: relative;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
height: 500px;
|
||||||
|
|
||||||
.popup-wrapper {
|
.popup-wrapper {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
42
src/index.js
42
src/index.js
@ -89,7 +89,7 @@ export default class Gantt {
|
|||||||
column_width: 30,
|
column_width: 30,
|
||||||
step: 24,
|
step: 24,
|
||||||
view_modes: [...Object.values(VIEW_MODE)],
|
view_modes: [...Object.values(VIEW_MODE)],
|
||||||
bar_height: 20,
|
bar_height: 30,
|
||||||
bar_corner_radius: 3,
|
bar_corner_radius: 3,
|
||||||
arrow_curve: 5,
|
arrow_curve: 5,
|
||||||
padding: 18,
|
padding: 18,
|
||||||
@ -182,6 +182,10 @@ export default class Gantt {
|
|||||||
// uids
|
// uids
|
||||||
if (!task.id) {
|
if (!task.id) {
|
||||||
task.id = generate_id(task);
|
task.id = generate_id(task);
|
||||||
|
} else if (typeof task.id === 'string') {
|
||||||
|
task.id = task.id.replace(' ', '_')
|
||||||
|
} else {
|
||||||
|
task.id = `${task.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
@ -345,7 +349,7 @@ export default class Gantt {
|
|||||||
|
|
||||||
setup_layers() {
|
setup_layers() {
|
||||||
this.layers = {};
|
this.layers = {};
|
||||||
const layers = ["grid", "date", "arrow", "progress", "bar", "details"];
|
const layers = ["grid", "arrow", "progress", "bar", "details", "date"];
|
||||||
// make group layers
|
// make group layers
|
||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
this.layers[layer] = createSVG("g", {
|
this.layers[layer] = createSVG("g", {
|
||||||
@ -376,7 +380,7 @@ export default class Gantt {
|
|||||||
width: grid_width,
|
width: grid_width,
|
||||||
height: grid_height,
|
height: grid_height,
|
||||||
class: "grid-background",
|
class: "grid-background",
|
||||||
append_to: this.layers.grid,
|
append_to: this.layers.date,
|
||||||
});
|
});
|
||||||
|
|
||||||
$.attr(this.$svg, {
|
$.attr(this.$svg, {
|
||||||
@ -774,6 +778,7 @@ export default class Gantt {
|
|||||||
bind_bar_events() {
|
bind_bar_events() {
|
||||||
let is_dragging = false;
|
let is_dragging = false;
|
||||||
let x_on_start = 0;
|
let x_on_start = 0;
|
||||||
|
let x_on_scroll_start = 0;
|
||||||
let y_on_start = 0;
|
let y_on_start = 0;
|
||||||
let is_resizing_left = false;
|
let is_resizing_left = false;
|
||||||
let is_resizing_right = false;
|
let is_resizing_right = false;
|
||||||
@ -818,6 +823,31 @@ export default class Gantt {
|
|||||||
$bar.finaldx = 0;
|
$bar.finaldx = 0;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$.on(this.$container, 'scroll', e => {
|
||||||
|
let elements = document.querySelectorAll('.bar-wrapper');
|
||||||
|
let localBars = [];
|
||||||
|
const ids = [];
|
||||||
|
let dx;
|
||||||
|
|
||||||
|
this.layers.date.setAttribute('transform', 'translate(0,' + e.currentTarget.scrollTop + ')');
|
||||||
|
if (x_on_scroll_start) {
|
||||||
|
dx = e.currentTarget.scrollLeft - x_on_scroll_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.prototype.forEach.call(elements, function (el, i) {
|
||||||
|
ids.push(el.getAttribute('data-id'));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (dx) {
|
||||||
|
localBars = ids.map(id => this.get_bar(id));
|
||||||
|
|
||||||
|
localBars.forEach(bar => {
|
||||||
|
bar.update_label_position_on_horizontal_scroll({ x: dx, sx: e.currentTarget.scrollLeft });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
x_on_scroll_start = e.currentTarget.scrollLeft;
|
||||||
|
});
|
||||||
|
|
||||||
$.on(this.$svg, "mousemove", (e) => {
|
$.on(this.$svg, "mousemove", (e) => {
|
||||||
if (!action_in_progress()) return;
|
if (!action_in_progress()) return;
|
||||||
@ -845,7 +875,7 @@ export default class Gantt {
|
|||||||
width: $bar.owidth + $bar.finaldx,
|
width: $bar.owidth + $bar.finaldx,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (is_dragging) {
|
} else if (is_dragging && !this.options.readonly) {
|
||||||
bar.update_bar_position({ x: $bar.ox + $bar.finaldx });
|
bar.update_bar_position({ x: $bar.ox + $bar.finaldx });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -993,13 +1023,13 @@ export default class Gantt {
|
|||||||
|
|
||||||
get_task(id) {
|
get_task(id) {
|
||||||
return this.tasks.find((task) => {
|
return this.tasks.find((task) => {
|
||||||
return task.id === id;
|
return task.id == id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get_bar(id) {
|
get_bar(id) {
|
||||||
return this.bars.find((bar) => {
|
return this.bars.find((bar) => {
|
||||||
return bar.task.id === id;
|
return bar.task.id == id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@ export function createSVG(tag, attrs) {
|
|||||||
parent.appendChild(elem);
|
parent.appendChild(elem);
|
||||||
} else if (attr === "innerHTML") {
|
} else if (attr === "innerHTML") {
|
||||||
elem.innerHTML = attrs.innerHTML;
|
elem.innerHTML = attrs.innerHTML;
|
||||||
|
} else if (attr === 'clipPath') {
|
||||||
|
elem.setAttribute('clip-path', 'url(#' + attrs[attr] + ')');
|
||||||
} else {
|
} else {
|
||||||
elem.setAttribute(attr, attrs[attr]);
|
elem.setAttribute(attr, attrs[attr]);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user