Merge branch 'new-ui'
This commit is contained in:
commit
86db2221ff
139
dist/frappe-gantt.css
vendored
139
dist/frappe-gantt.css
vendored
@ -66,24 +66,67 @@
|
|||||||
border-top-color: #333;
|
border-top-color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.gantt-container .grid-header {
|
||||||
|
background-color: #ffffff;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
.gantt-container .lower-text,
|
||||||
|
.gantt-container .upper-text {
|
||||||
|
font-size: 14px;
|
||||||
|
text-anchor: middle;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
.gantt-container .lower-text {
|
||||||
|
position: absolute;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
.gantt-container .upper-text {
|
||||||
|
position: absolute;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
.gantt-container .current-upper {
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
|
.gantt-container .side-header {
|
||||||
|
position: fixed;
|
||||||
|
padding: 0 10px;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
.gantt-container .today-button,
|
||||||
|
.gantt-container .viewmode-select {
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid black;
|
||||||
|
color: #111;
|
||||||
|
padding: 4px 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
.gantt-container .viewmode-select {
|
||||||
|
padding: 3px 5px;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
.gantt-container .date-highlight {
|
||||||
|
border: 2px dotted black;
|
||||||
|
border-radius: 12px;
|
||||||
|
z-index: 1;
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0.4;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.gantt {
|
.gantt {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
|
position: absolute;
|
||||||
}
|
}
|
||||||
.gantt .grid-background {
|
.gantt .grid-background {
|
||||||
fill: none;
|
fill: none;
|
||||||
}
|
}
|
||||||
.gantt .grid-header {
|
|
||||||
fill: #ffffff;
|
|
||||||
stroke: #e0e0e0;
|
|
||||||
stroke-width: 1.4;
|
|
||||||
}
|
|
||||||
.gantt .grid-row {
|
.gantt .grid-row {
|
||||||
fill: #ffffff;
|
fill: #ffffff;
|
||||||
}
|
}
|
||||||
.gantt .grid-row:nth-child(even) {
|
|
||||||
fill: #f5f5f5;
|
|
||||||
}
|
|
||||||
.gantt .row-line {
|
.gantt .row-line {
|
||||||
stroke: #ebeff2;
|
stroke: #ebeff2;
|
||||||
}
|
}
|
||||||
@ -104,7 +147,7 @@
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
.gantt .holiday-highlight {
|
.gantt .holiday-highlight {
|
||||||
fill: #EEE;
|
fill: #f3f4f7;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
.gantt .month-highlight {
|
.gantt .month-highlight {
|
||||||
@ -120,39 +163,52 @@
|
|||||||
stroke: #666;
|
stroke: #666;
|
||||||
stroke-width: 1.4;
|
stroke-width: 1.4;
|
||||||
}
|
}
|
||||||
.gantt .bar {
|
.gantt .bar-wrapper .bar {
|
||||||
fill: #b8c2cc;
|
fill: #fff;
|
||||||
stroke: #8d99a6;
|
stroke: #fff;
|
||||||
stroke-width: 0;
|
stroke-width: 0;
|
||||||
transition: stroke-width 0.3s ease;
|
transition: stroke-width 0.3s ease;
|
||||||
}
|
}
|
||||||
.gantt .bar-progress {
|
.gantt .bar-progress {
|
||||||
fill: #acacfa;
|
fill: #dedfe0;
|
||||||
}
|
}
|
||||||
.gantt .bar-expected-progress {
|
.gantt .bar-expected-progress {
|
||||||
fill: #c4c4e9;
|
fill: #c4c4e9;
|
||||||
}
|
}
|
||||||
.gantt .bar-invalid {
|
.gantt .bar-invalid {
|
||||||
fill: transparent;
|
fill: transparent;
|
||||||
stroke: #8d99a6;
|
stroke: #fff;
|
||||||
stroke-width: 1;
|
stroke-width: 1;
|
||||||
stroke-dasharray: 5;
|
stroke-dasharray: 5;
|
||||||
}
|
}
|
||||||
.gantt .bar-invalid ~ .bar-label {
|
.gantt .bar-invalid ~ .bar-label {
|
||||||
fill: #555;
|
fill: #fff;
|
||||||
}
|
}
|
||||||
.gantt .bar-label {
|
.gantt .bar-label {
|
||||||
fill: #fff;
|
fill: #111;
|
||||||
dominant-baseline: central;
|
dominant-baseline: central;
|
||||||
font-size: 12px;
|
font-family: Helvetica;
|
||||||
font-weight: 500;
|
font-size: 14px;
|
||||||
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
.gantt .bar-label.big {
|
.gantt .bar-label.big {
|
||||||
fill: #555;
|
fill: #111;
|
||||||
text-anchor: start;
|
text-anchor: start;
|
||||||
}
|
}
|
||||||
|
.gantt .bar-wrapper.important .bar {
|
||||||
|
fill: #94c4f4;
|
||||||
|
}
|
||||||
|
.gantt .bar-wrapper.important .bar-progress {
|
||||||
|
fill: #2c94ec;
|
||||||
|
}
|
||||||
|
.gantt .bar-wrapper.important .bar-label {
|
||||||
|
fill: #fff;
|
||||||
|
}
|
||||||
|
.gantt .bar-wrapper.important .handle {
|
||||||
|
fill: #94c4f4;
|
||||||
|
}
|
||||||
.gantt .handle {
|
.gantt .handle {
|
||||||
fill: #ddd;
|
fill: #dcdce4;
|
||||||
cursor: ew-resize;
|
cursor: ew-resize;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
@ -162,32 +218,20 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
.gantt .bar-wrapper:hover .bar {
|
.gantt .bar-wrapper.active .handle {
|
||||||
fill: #a9b5c1;
|
|
||||||
}
|
|
||||||
.gantt .bar-wrapper:hover .bar-progress {
|
|
||||||
fill: #9494f9;
|
|
||||||
}
|
|
||||||
.gantt .bar-wrapper:hover .handle {
|
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
.gantt .bar-wrapper.active .bar {
|
.gantt .bar-wrapper .bar {
|
||||||
fill: #a9b5c1;
|
-webkit-filter: drop-shadow(3px 3px 2px rgba(0, 0, 0, 0.7));
|
||||||
|
filter: drop-shadow(0 0 2px rgba(17, 43, 66, 0.16));
|
||||||
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
.gantt .bar-wrapper.active .bar-progress {
|
.gantt .bar-wrapper:hover .bar {
|
||||||
fill: #9494f9;
|
transition: transform 0.3s ease;
|
||||||
}
|
}
|
||||||
.gantt .lower-text,
|
.gantt .bar-wrapper:hover .date-highlight {
|
||||||
.gantt .upper-text {
|
display: block;
|
||||||
font-size: 12px;
|
|
||||||
text-anchor: middle;
|
|
||||||
}
|
|
||||||
.gantt .upper-text {
|
|
||||||
fill: #555;
|
|
||||||
}
|
|
||||||
.gantt .lower-text {
|
|
||||||
fill: #333;
|
|
||||||
}
|
}
|
||||||
.gantt .hide {
|
.gantt .hide {
|
||||||
display: none;
|
display: none;
|
||||||
@ -203,14 +247,21 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
background: rgba(0, 0, 0, 0.8);
|
background: rgb(0, 0, 0);
|
||||||
padding: 0;
|
padding: 0;
|
||||||
color: #959da5;
|
color: #959da5;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
border: 1px solid rgb(0, 0, 0);
|
||||||
|
width: max-content;
|
||||||
|
}
|
||||||
|
.gantt-container .popup-wrapper.hidden {
|
||||||
|
opacity: 0 !important;
|
||||||
}
|
}
|
||||||
.gantt-container .popup-wrapper .title {
|
.gantt-container .popup-wrapper .title {
|
||||||
border-bottom: 3px solid #acacfa;
|
border-bottom: 1px solid #dedfe0;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
text-align: center;
|
||||||
|
color: #fff;
|
||||||
}
|
}
|
||||||
.gantt-container .popup-wrapper .subtitle {
|
.gantt-container .popup-wrapper .subtitle {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
@ -221,5 +272,5 @@
|
|||||||
height: 5px;
|
height: 5px;
|
||||||
margin: 0 0 0 -5px;
|
margin: 0 0 0 -5px;
|
||||||
border: 5px solid transparent;
|
border: 5px solid transparent;
|
||||||
border-top-color: rgba(0, 0, 0, 0.8);
|
border-bottom-color: rgba(0, 0, 0, 0.8);
|
||||||
}
|
}
|
||||||
342
dist/frappe-gantt.js
vendored
342
dist/frappe-gantt.js
vendored
@ -9,6 +9,21 @@ var Gantt = (function () {
|
|||||||
const SECOND = "second";
|
const SECOND = "second";
|
||||||
const MILLISECOND = "millisecond";
|
const MILLISECOND = "millisecond";
|
||||||
|
|
||||||
|
const SHORTENED = {
|
||||||
|
January: "Jan",
|
||||||
|
February: "Feb",
|
||||||
|
March: "Mar",
|
||||||
|
April: "Apr",
|
||||||
|
May: "May",
|
||||||
|
June: "Jun",
|
||||||
|
July: "Jul",
|
||||||
|
August: "Aug",
|
||||||
|
September: "Sep",
|
||||||
|
October: "Oct",
|
||||||
|
November: "Nov",
|
||||||
|
December: "Dec"
|
||||||
|
};
|
||||||
|
|
||||||
var date_utils = {
|
var date_utils = {
|
||||||
parse_duration(duration) {
|
parse_duration(duration) {
|
||||||
const regex = /([0-9])+(y|m|d|h|min|s|ms)/gm;
|
const regex = /([0-9])+(y|m|d|h|min|s|ms)/gm;
|
||||||
@ -101,7 +116,7 @@ var Gantt = (function () {
|
|||||||
SSS: values[6],
|
SSS: values[6],
|
||||||
D: values[2],
|
D: values[2],
|
||||||
MMMM: month_name_capitalized,
|
MMMM: month_name_capitalized,
|
||||||
MMM: month_name_capitalized,
|
MMM: SHORTENED[month_name_capitalized],
|
||||||
};
|
};
|
||||||
|
|
||||||
let str = format_string;
|
let str = format_string;
|
||||||
@ -422,7 +437,7 @@ var Gantt = (function () {
|
|||||||
this.duration *
|
this.duration *
|
||||||
(this.task.progress / 100) || 0;
|
(this.task.progress / 100) || 0;
|
||||||
this.group = createSVG("g", {
|
this.group = createSVG("g", {
|
||||||
class: "bar-wrapper " + (this.task.custom_class || ""),
|
class: "bar-wrapper" + (this.task.custom_class ? " " + this.task.custom_class : "") + (this.task.important ? ' important' : ''),
|
||||||
"data-id": this.task.id,
|
"data-id": this.task.id,
|
||||||
});
|
});
|
||||||
this.bar_group = createSVG("g", {
|
this.bar_group = createSVG("g", {
|
||||||
@ -463,11 +478,11 @@ var Gantt = (function () {
|
|||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
this.draw_bar();
|
this.draw_bar();
|
||||||
|
this.draw_progress_bar();
|
||||||
if (this.gantt.options.show_expected_progress) {
|
if (this.gantt.options.show_expected_progress) {
|
||||||
this.prepare_expected_progress_values();
|
this.prepare_expected_progress_values();
|
||||||
this.draw_expected_progress_bar();
|
this.draw_expected_progress_bar();
|
||||||
}
|
}
|
||||||
this.draw_progress_bar();
|
|
||||||
this.draw_label();
|
this.draw_label();
|
||||||
this.draw_resize_handles();
|
this.draw_resize_handles();
|
||||||
|
|
||||||
@ -528,12 +543,27 @@ var Gantt = (function () {
|
|||||||
class: "bar-progress",
|
class: "bar-progress",
|
||||||
append_to: this.bar_group,
|
append_to: this.bar_group,
|
||||||
});
|
});
|
||||||
|
const x = (date_utils.diff(this.task._start, this.gantt.gantt_start, 'hour') /
|
||||||
|
this.gantt.options.step) *
|
||||||
|
this.gantt.options.column_width;
|
||||||
|
|
||||||
|
let $date_highlight = document.createElement("div");
|
||||||
|
$date_highlight.id = `${this.task.id}-highlight`;
|
||||||
|
$date_highlight.classList.add('date-highlight');
|
||||||
|
$date_highlight.style.height = this.height * 0.8 + 'px';
|
||||||
|
$date_highlight.style.width = this.width + 'px';
|
||||||
|
$date_highlight.style.top = this.gantt.options.header_height - 21 + 'px';
|
||||||
|
$date_highlight.style.left = x + 'px';
|
||||||
|
this.$date_highlight = $date_highlight;
|
||||||
|
this.gantt.$lower_header.appendChild($date_highlight);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
animateSVG(this.$bar_progress, "width", 0, this.progress_width);
|
animateSVG(this.$bar_progress, "width", 0, this.progress_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_label() {
|
draw_label() {
|
||||||
let x_coord = this.x + 5;
|
let x_coord = this.x + this.$bar.getWidth() / 2;
|
||||||
|
|
||||||
if (this.task.thumbnail) {
|
if (this.task.thumbnail) {
|
||||||
x_coord = this.x + this.image_size + 5;
|
x_coord = this.x + this.image_size + 5;
|
||||||
@ -597,7 +627,7 @@ var Gantt = (function () {
|
|||||||
const handle_width = 8;
|
const handle_width = 8;
|
||||||
|
|
||||||
createSVG("rect", {
|
createSVG("rect", {
|
||||||
x: bar.getX() + bar.getWidth() - 9,
|
x: bar.getX() + bar.getWidth() + handle_width - 4,
|
||||||
y: bar.getY() + 1,
|
y: bar.getY() + 1,
|
||||||
width: handle_width,
|
width: handle_width,
|
||||||
height: this.height - 2,
|
height: this.height - 2,
|
||||||
@ -608,7 +638,7 @@ var Gantt = (function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
createSVG("rect", {
|
createSVG("rect", {
|
||||||
x: bar.getX() + 1,
|
x: bar.getX() - handle_width - 4,
|
||||||
y: bar.getY() + 1,
|
y: bar.getY() + 1,
|
||||||
width: handle_width,
|
width: handle_width,
|
||||||
height: this.height - 2,
|
height: this.height - 2,
|
||||||
@ -628,12 +658,12 @@ var Gantt = (function () {
|
|||||||
get_progress_polygon_points() {
|
get_progress_polygon_points() {
|
||||||
const bar_progress = this.$bar_progress;
|
const bar_progress = this.$bar_progress;
|
||||||
return [
|
return [
|
||||||
bar_progress.getEndX() - 5,
|
bar_progress.getEndX() - 6,
|
||||||
bar_progress.getY() + bar_progress.getHeight(),
|
bar_progress.getY() + bar_progress.getHeight() + 8,
|
||||||
bar_progress.getEndX() + 5,
|
bar_progress.getEndX() + 6,
|
||||||
bar_progress.getY() + bar_progress.getHeight(),
|
bar_progress.getY() + bar_progress.getHeight() + 8,
|
||||||
bar_progress.getEndX(),
|
bar_progress.getEndX(),
|
||||||
bar_progress.getY() + bar_progress.getHeight() - 8.66,
|
bar_progress.getY() + bar_progress.getHeight() + 0.5,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,25 +673,17 @@ var Gantt = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_click_event() {
|
setup_click_event() {
|
||||||
let in_action = false;
|
let task_id = this.task.id;
|
||||||
$.on(this.group, "mouseover", (e) => this.gantt.trigger_event("hover", [this.task, e.screenX, e.screenY, e]));
|
$.on(this.group, "mouseover", (e) => {
|
||||||
|
this.gantt.trigger_event("hover", [this.task, e.screenX, e.screenY, e]);
|
||||||
|
document.querySelector(`#${task_id}-highlight`).style.display = 'block';
|
||||||
|
});
|
||||||
|
$.on(this.group, "mouseenter", (e) => this.show_popup(e.offsetX));
|
||||||
|
$.on(this.group, "mouseleave", () => document.querySelector(`#${task_id}-highlight`).style.display = 'none');
|
||||||
|
|
||||||
|
|
||||||
$.on(this.group, "focus " + this.gantt.options.popup_trigger, (e) => {
|
$.on(this.group, "focus " + this.gantt.options.popup_trigger, (e) => {
|
||||||
this.gantt.trigger_event("click", [this.task]);
|
this.gantt.trigger_event("click", [this.task]);
|
||||||
if (this.action_completed) {
|
|
||||||
// just finished a move action, wait for a few seconds
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (in_action) {
|
|
||||||
this.gantt.hide_popup();
|
|
||||||
this.group.classList.remove("active");
|
|
||||||
} else {
|
|
||||||
this.show_popup();
|
|
||||||
this.gantt.unselect_all();
|
|
||||||
this.group.classList.add("active");
|
|
||||||
}
|
|
||||||
|
|
||||||
in_action = !in_action;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$.on(this.group, "dblclick", (e) => {
|
$.on(this.group, "dblclick", (e) => {
|
||||||
@ -674,7 +696,7 @@ var Gantt = (function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
show_popup() {
|
show_popup(x) {
|
||||||
if (this.gantt.bar_being_dragged) return;
|
if (this.gantt.bar_being_dragged) return;
|
||||||
|
|
||||||
const start_date = date_utils.format(
|
const start_date = date_utils.format(
|
||||||
@ -687,9 +709,10 @@ var Gantt = (function () {
|
|||||||
"MMM D",
|
"MMM D",
|
||||||
this.gantt.options.language,
|
this.gantt.options.language,
|
||||||
);
|
);
|
||||||
const subtitle = start_date + " - " + end_date;
|
const subtitle = `${start_date} - ${end_date}<br/>Progress: ${this.task.progress}`;
|
||||||
|
|
||||||
this.gantt.show_popup({
|
this.gantt.show_popup({
|
||||||
|
x,
|
||||||
target_element: this.$bar,
|
target_element: this.$bar,
|
||||||
title: this.task.name,
|
title: this.task.name,
|
||||||
subtitle: subtitle,
|
subtitle: subtitle,
|
||||||
@ -713,9 +736,11 @@ var Gantt = (function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.update_attr(bar, "x", x);
|
this.update_attr(bar, "x", x);
|
||||||
|
this.update_attr(this.$date_highlight, "x", x);
|
||||||
}
|
}
|
||||||
if (width) {
|
if (width) {
|
||||||
this.update_attr(bar, "width", width);
|
this.update_attr(bar, "width", width);
|
||||||
|
this.update_attr(this.$date_highlight, "width", width);
|
||||||
}
|
}
|
||||||
this.update_label_position();
|
this.update_label_position();
|
||||||
this.update_handle_position();
|
this.update_handle_position();
|
||||||
@ -925,10 +950,12 @@ var Gantt = (function () {
|
|||||||
label = this.group.querySelector(".bar-label"),
|
label = this.group.querySelector(".bar-label"),
|
||||||
img = this.group.querySelector('.bar-img');
|
img = this.group.querySelector('.bar-img');
|
||||||
|
|
||||||
|
|
||||||
let padding = 5;
|
let padding = 5;
|
||||||
let x_offset_label_img = this.image_size + 10;
|
let x_offset_label_img = this.image_size + 10;
|
||||||
|
const labelWidth = label.getBBox().width;
|
||||||
if (label.getBBox().width > bar.getWidth()) {
|
const barWidth = bar.getWidth();
|
||||||
|
if (labelWidth > barWidth) {
|
||||||
label.classList.add("big");
|
label.classList.add("big");
|
||||||
if (img) {
|
if (img) {
|
||||||
img.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
img.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
@ -942,9 +969,9 @@ var Gantt = (function () {
|
|||||||
if (img) {
|
if (img) {
|
||||||
img.setAttribute('x', bar.getX() + padding);
|
img.setAttribute('x', bar.getX() + padding);
|
||||||
img_mask.setAttribute('x', bar.getX() + padding);
|
img_mask.setAttribute('x', bar.getX() + padding);
|
||||||
label.setAttribute('x', bar.getX() + x_offset_label_img);
|
label.setAttribute('x', bar.getX() + barWidth / 2 + x_offset_label_img);
|
||||||
} else {
|
} else {
|
||||||
label.setAttribute('x', bar.getX() + padding);
|
label.setAttribute('x', bar.getX() + barWidth / 2 - labelWidth / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -954,10 +981,10 @@ var Gantt = (function () {
|
|||||||
const bar = this.$bar;
|
const bar = this.$bar;
|
||||||
this.handle_group
|
this.handle_group
|
||||||
.querySelector(".handle.left")
|
.querySelector(".handle.left")
|
||||||
.setAttribute("x", bar.getX() + 1);
|
.setAttribute("x", bar.getX() - 12);
|
||||||
this.handle_group
|
this.handle_group
|
||||||
.querySelector(".handle.right")
|
.querySelector(".handle.right")
|
||||||
.setAttribute("x", bar.getEndX() - 9);
|
.setAttribute("x", bar.getEndX() + 4);
|
||||||
const handle = this.group.querySelector(".handle.progress");
|
const handle = this.group.querySelector(".handle.progress");
|
||||||
handle && handle.setAttribute("points", this.get_progress_polygon_points());
|
handle && handle.setAttribute("points", this.get_progress_polygon_points());
|
||||||
}
|
}
|
||||||
@ -996,15 +1023,15 @@ var Gantt = (function () {
|
|||||||
this.gantt.options.header_height +
|
this.gantt.options.header_height +
|
||||||
this.gantt.options.bar_height +
|
this.gantt.options.bar_height +
|
||||||
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
||||||
this.from_task.task._index +
|
this.from_task.task._index +
|
||||||
this.gantt.options.padding;
|
this.gantt.options.padding;
|
||||||
|
|
||||||
const end_x = this.to_task.$bar.getX() - this.gantt.options.padding / 2;
|
const end_x = this.to_task.$bar.getX() - this.gantt.options.padding / 2 - 7;
|
||||||
const end_y =
|
const end_y =
|
||||||
this.gantt.options.header_height +
|
this.gantt.options.header_height +
|
||||||
this.gantt.options.bar_height / 2 +
|
this.gantt.options.bar_height / 2 +
|
||||||
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
||||||
this.to_task.task._index +
|
this.to_task.task._index +
|
||||||
this.gantt.options.padding;
|
this.gantt.options.padding;
|
||||||
|
|
||||||
const from_is_below_to =
|
const from_is_below_to =
|
||||||
@ -1088,9 +1115,6 @@ var Gantt = (function () {
|
|||||||
if (!options.target_element) {
|
if (!options.target_element) {
|
||||||
throw new Error("target_element is required to show popup");
|
throw new Error("target_element is required to show popup");
|
||||||
}
|
}
|
||||||
if (!options.position) {
|
|
||||||
options.position = "left";
|
|
||||||
}
|
|
||||||
const target_element = options.target_element;
|
const target_element = options.target_element;
|
||||||
|
|
||||||
if (this.custom_html) {
|
if (this.custom_html) {
|
||||||
@ -1102,7 +1126,6 @@ var Gantt = (function () {
|
|||||||
// set data
|
// set data
|
||||||
this.title.innerHTML = options.title;
|
this.title.innerHTML = options.title;
|
||||||
this.subtitle.innerHTML = options.subtitle;
|
this.subtitle.innerHTML = options.subtitle;
|
||||||
this.parent.style.width = this.parent.clientWidth + "px";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set position
|
// set position
|
||||||
@ -1113,15 +1136,11 @@ var Gantt = (function () {
|
|||||||
position_meta = options.target_element.getBBox();
|
position_meta = options.target_element.getBBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.position === "left") {
|
this.parent.style.left = options.x - this.parent.clientWidth / 2 + "px";
|
||||||
this.parent.style.left =
|
this.parent.style.top = position_meta.y + position_meta.height + 10 + "px";
|
||||||
position_meta.x + (position_meta.width + 10) + "px";
|
|
||||||
this.parent.style.top = position_meta.y + "px";
|
|
||||||
|
|
||||||
this.pointer.style.transform = "rotateZ(90deg)";
|
this.pointer.style.left = this.parent.clientWidth / 2 + "px";
|
||||||
this.pointer.style.left = "-7px";
|
this.pointer.style.top = "-15px";
|
||||||
this.pointer.style.top = "2px";
|
|
||||||
}
|
|
||||||
|
|
||||||
// show
|
// show
|
||||||
this.parent.style.opacity = 1;
|
this.parent.style.opacity = 1;
|
||||||
@ -1227,7 +1246,9 @@ var Gantt = (function () {
|
|||||||
language: "en",
|
language: "en",
|
||||||
readonly: false,
|
readonly: false,
|
||||||
highlight_weekend: true,
|
highlight_weekend: true,
|
||||||
scroll_today: true
|
scroll_today: true,
|
||||||
|
lines: 'both',
|
||||||
|
auto_move_label: true,
|
||||||
};
|
};
|
||||||
this.options = Object.assign({}, default_options, options);
|
this.options = Object.assign({}, default_options, options);
|
||||||
if (!options.view_mode_padding) options.view_mode_padding = {};
|
if (!options.view_mode_padding) options.view_mode_padding = {};
|
||||||
@ -1259,12 +1280,16 @@ var Gantt = (function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
task._end = date_utils.parse(task.end);
|
task._end = date_utils.parse(task.end);
|
||||||
|
let diff = date_utils.diff(task._end, task._start, "year");
|
||||||
|
if (diff < 0) {
|
||||||
|
throw Error("start of task can't be after end of task: in task #, " + (i + 1))
|
||||||
|
}
|
||||||
// make task invalid if duration too large
|
// make task invalid if duration too large
|
||||||
if (date_utils.diff(task._end, task._start, "year") > 10) {
|
if (date_utils.diff(task._end, task._start, "year") > 10) {
|
||||||
task.end = null;
|
task.end = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cache index
|
// cache index
|
||||||
task._index = i;
|
task._index = i;
|
||||||
|
|
||||||
@ -1470,7 +1495,7 @@ var Gantt = (function () {
|
|||||||
|
|
||||||
setup_layers() {
|
setup_layers() {
|
||||||
this.layers = {};
|
this.layers = {};
|
||||||
const layers = ["grid", "arrow", "progress", "bar", "details", "date"];
|
const layers = ["grid", "arrow", "progress", "bar", "details"];
|
||||||
// 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", {
|
||||||
@ -1501,7 +1526,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.date,
|
append_to: this.$svg,
|
||||||
});
|
});
|
||||||
|
|
||||||
$.attr(this.$svg, {
|
$.attr(this.$svg, {
|
||||||
@ -1528,34 +1553,79 @@ var Gantt = (function () {
|
|||||||
class: "grid-row",
|
class: "grid-row",
|
||||||
append_to: rows_layer,
|
append_to: rows_layer,
|
||||||
});
|
});
|
||||||
|
if (this.options.lines === 'both' || this.options.lines === 'horizontal') {
|
||||||
createSVG("line", {
|
createSVG("line", {
|
||||||
x1: 0,
|
x1: 0,
|
||||||
y1: row_y + row_height,
|
y1: row_y + row_height,
|
||||||
x2: row_width,
|
x2: row_width,
|
||||||
y2: row_y + row_height,
|
y2: row_y + row_height,
|
||||||
class: "row-line",
|
class: "row-line",
|
||||||
append_to: lines_layer,
|
append_to: lines_layer,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
row_y += this.options.bar_height + this.options.padding;
|
row_y += this.options.bar_height + this.options.padding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
make_grid_header() {
|
make_grid_header() {
|
||||||
const header_width = this.dates.length * this.options.column_width;
|
const curHeader = document.querySelector('.grid-header');
|
||||||
const header_height = this.options.header_height + 10;
|
if (curHeader) {
|
||||||
createSVG("rect", {
|
curHeader.remove();
|
||||||
x: 0,
|
}
|
||||||
y: 0,
|
let $header = document.createElement("div");
|
||||||
width: header_width,
|
$header.style.height = this.options.header_height + 10 + "px";
|
||||||
height: header_height,
|
$header.style.width = this.dates.length * this.options.column_width + "px";
|
||||||
class: "grid-header",
|
$header.classList.add('grid-header');
|
||||||
append_to: this.layers.grid,
|
this.$header = $header;
|
||||||
});
|
this.$container.appendChild($header);
|
||||||
|
|
||||||
|
let $upper_header = document.createElement("div");
|
||||||
|
$upper_header.classList.add('upper-header');
|
||||||
|
this.$upper_header = $upper_header;
|
||||||
|
this.$header.appendChild($upper_header);
|
||||||
|
|
||||||
|
let $lower_header = document.createElement("div");
|
||||||
|
$lower_header.classList.add('lower-header');
|
||||||
|
this.$lower_header = $lower_header;
|
||||||
|
this.$header.appendChild($lower_header);
|
||||||
|
|
||||||
|
let $side_header = document.createElement('div');
|
||||||
|
$side_header.classList.add('side-header');
|
||||||
|
|
||||||
|
|
||||||
|
// Create view mode change select
|
||||||
|
const $select = document.createElement("select");
|
||||||
|
$select.classList.add('viewmode-select');
|
||||||
|
|
||||||
|
for (const key in VIEW_MODE) {
|
||||||
|
const $option = document.createElement("option");
|
||||||
|
$option.value = VIEW_MODE[key];
|
||||||
|
$option.textContent = VIEW_MODE[key];
|
||||||
|
$select.appendChild($option);
|
||||||
|
}
|
||||||
|
$select.value = this.options.view_mode;
|
||||||
|
$select.addEventListener("change", (function () {
|
||||||
|
this.change_view_mode($select.value);
|
||||||
|
}).bind(this));
|
||||||
|
$side_header.appendChild($select);
|
||||||
|
|
||||||
|
// Create today button
|
||||||
|
let $today_button = document.createElement('button');
|
||||||
|
$today_button.classList.add('today-button');
|
||||||
|
$today_button.textContent = 'Today';
|
||||||
|
$today_button.onclick = this.scroll_today.bind(this);
|
||||||
|
$side_header.appendChild($today_button);
|
||||||
|
|
||||||
|
this.$header.appendChild($side_header);
|
||||||
|
const { left, y } = $header.getBoundingClientRect();
|
||||||
|
const width = Math.min(this.$header.clientWidth, this.$container.clientWidth);
|
||||||
|
$side_header.style.left = left + this.$container.scrollLeft + width - $side_header.clientWidth + 'px';
|
||||||
|
$side_header.style.top = y + 5 + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
make_grid_ticks() {
|
make_grid_ticks() {
|
||||||
|
if (this.options.lines !== 'both' && this.options.lines !== 'vertical') return
|
||||||
let tick_x = 0;
|
let tick_x = 0;
|
||||||
let tick_y = this.options.header_height + this.options.padding / 2;
|
let tick_y = this.options.header_height + this.options.padding / 2;
|
||||||
let tick_height =
|
let tick_height =
|
||||||
@ -1602,13 +1672,10 @@ var Gantt = (function () {
|
|||||||
const x = (date_utils.diff(d, this.gantt_start, 'hour') /
|
const x = (date_utils.diff(d, this.gantt_start, 'hour') /
|
||||||
this.options.step) *
|
this.options.step) *
|
||||||
this.options.column_width;
|
this.options.column_width;
|
||||||
const height =
|
const height = (this.options.bar_height + this.options.padding) * this.tasks.length;
|
||||||
(this.options.bar_height + this.options.padding) * this.tasks.length +
|
|
||||||
this.options.header_height +
|
|
||||||
this.options.padding / 2;
|
|
||||||
createSVG('rect', {
|
createSVG('rect', {
|
||||||
x,
|
x,
|
||||||
y: 0,
|
y: this.options.header_height + this.options.padding / 2,
|
||||||
width: (this.view_is('Day') ? 1 : 2) * this.options.column_width,
|
width: (this.view_is('Day') ? 1 : 2) * this.options.column_width,
|
||||||
height,
|
height,
|
||||||
class: 'holiday-highlight',
|
class: 'holiday-highlight',
|
||||||
@ -1698,30 +1765,30 @@ var Gantt = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
make_dates() {
|
make_dates() {
|
||||||
for (let date of this.get_dates_to_draw()) {
|
this.upper_texts_x = {};
|
||||||
createSVG("text", {
|
this.get_dates_to_draw().forEach((date, i) => {
|
||||||
x: date.lower_x,
|
let $lower_text = document.createElement('div');
|
||||||
y: date.lower_y,
|
$lower_text.classList.add('lower-text');
|
||||||
innerHTML: date.lower_text,
|
$lower_text.innerText = date.lower_text;
|
||||||
class: "lower-text",
|
this.$lower_header.appendChild($lower_text);
|
||||||
append_to: this.layers.date,
|
$lower_text.style.left = date.lower_x - ($lower_text.clientWidth / 2 ) + 'px';
|
||||||
});
|
$lower_text.style.top = date.lower_y + 'px';
|
||||||
|
|
||||||
if (date.upper_text) {
|
if (date.upper_text) {
|
||||||
const $upper_text = createSVG("text", {
|
this.upper_texts_x[date.upper_text] = date.upper_x;
|
||||||
x: date.upper_x,
|
let $upper_text = document.createElement('div');
|
||||||
y: date.upper_y,
|
$upper_text.classList.add('upper-text');
|
||||||
innerHTML: date.upper_text,
|
$upper_text.style.left = date.upper_x + 'px';
|
||||||
class: "upper-text",
|
$upper_text.style.top = date.upper_y + 'px';
|
||||||
append_to: this.layers.date,
|
$upper_text.innerText = date.upper_text;
|
||||||
});
|
this.$upper_header.appendChild($upper_text);
|
||||||
|
|
||||||
// remove out-of-bound dates
|
// remove out-of-bound dates
|
||||||
if ($upper_text.getBBox().x2 > this.layers.grid.getBBox().width) {
|
if (date.upper_x > this.layers.grid.getBBox().width) {
|
||||||
$upper_text.remove();
|
$upper_text.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get_dates_to_draw() {
|
get_dates_to_draw() {
|
||||||
@ -1734,9 +1801,8 @@ var Gantt = (function () {
|
|||||||
return dates;
|
return dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_date_info(date, last_date_info, i) {
|
get_date_info(date, last_date_info) {
|
||||||
let last_date = last_date_info ? last_date_info.date : date_utils.add(date, 1, "day");
|
let last_date = last_date_info ? last_date_info.date : date_utils.add(date, 1, "day");
|
||||||
|
|
||||||
const date_text = {
|
const date_text = {
|
||||||
Hour_lower: date_utils.format(date, "HH", this.options.language),
|
Hour_lower: date_utils.format(date, "HH", this.options.language),
|
||||||
"Quarter Day_lower": date_utils.format(date, "HH", this.options.language),
|
"Quarter Day_lower": date_utils.format(date, "HH", this.options.language),
|
||||||
@ -1766,7 +1832,7 @@ var Gantt = (function () {
|
|||||||
: date_utils.format(date, "D", this.options.language)
|
: date_utils.format(date, "D", this.options.language)
|
||||||
: "",
|
: "",
|
||||||
Day_upper:
|
Day_upper:
|
||||||
date.getMonth() !== last_date.getMonth()
|
date.getMonth() !== last_date.getMonth() || !last_date_info
|
||||||
? date_utils.format(date, "MMMM", this.options.language)
|
? date_utils.format(date, "MMMM", this.options.language)
|
||||||
: "",
|
: "",
|
||||||
Week_upper:
|
Week_upper:
|
||||||
@ -1787,27 +1853,25 @@ var Gantt = (function () {
|
|||||||
x: last_date_info
|
x: last_date_info
|
||||||
? last_date_info.base_pos_x + last_date_info.column_width
|
? last_date_info.base_pos_x + last_date_info.column_width
|
||||||
: 0,
|
: 0,
|
||||||
lower_y: this.options.header_height,
|
lower_y: this.options.header_height - 15,
|
||||||
upper_y: this.options.header_height - 25,
|
upper_y: this.options.header_height - 40,
|
||||||
};
|
};
|
||||||
|
|
||||||
const x_pos = {
|
const x_pos = {
|
||||||
Hour_lower: this.options.column_width / 2,
|
Hour_lower: column_width / 2,
|
||||||
Hour_upper: this.options.column_width * 12,
|
Hour_upper: column_width * 12,
|
||||||
"Quarter Day_lower": this.options.column_width / 2,
|
"Quarter Day_lower": column_width / 2,
|
||||||
"Quarter Day_upper": this.options.column_width * 2,
|
"Quarter Day_upper": column_width * 2,
|
||||||
"Half Day_lower": this.options.column_width / 2,
|
"Half Day_lower": column_width / 2,
|
||||||
"Half Day_upper": this.options.column_width,
|
"Half Day_upper": column_width,
|
||||||
Day_lower: this.options.column_width / 2,
|
Day_lower: column_width / 2,
|
||||||
Day_upper: (this.options.column_width * 30) / 2,
|
Day_upper: column_width / 2,
|
||||||
Week_lower: 0,
|
Week_lower: column_width / 2,
|
||||||
Week_upper: (this.options.column_width * 4) / 2,
|
Week_upper: (column_width * 4) / 2,
|
||||||
Month_lower: column_width / 2,
|
Month_lower: column_width / 2,
|
||||||
Month_upper: (column_width * 12) / 2,
|
Month_upper: column_width / 2,
|
||||||
Year_lower: this.options.column_width / 2,
|
Year_lower: column_width / 2,
|
||||||
Year_upper: (this.options.column_width * 30) / 2,
|
Year_upper: (column_width * 30) / 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
date,
|
date,
|
||||||
column_width,
|
column_width,
|
||||||
@ -1889,8 +1953,7 @@ var Gantt = (function () {
|
|||||||
(hours_before_first_task / this.options.step) *
|
(hours_before_first_task / this.options.step) *
|
||||||
this.options.column_width -
|
this.options.column_width -
|
||||||
this.options.column_width;
|
this.options.column_width;
|
||||||
|
parent_element.scrollTo({ left: scroll_pos, behavior: 'smooth' });
|
||||||
parent_element.scrollLeft = scroll_pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scroll_today() {
|
scroll_today() {
|
||||||
@ -1928,6 +1991,7 @@ var Gantt = (function () {
|
|||||||
|
|
||||||
$.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (e, element) => {
|
$.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (e, element) => {
|
||||||
const bar_wrapper = $.closest(".bar-wrapper", element);
|
const bar_wrapper = $.closest(".bar-wrapper", element);
|
||||||
|
bars.forEach((bar) => bar.group.classList.remove("active"));
|
||||||
|
|
||||||
if (element.classList.contains("left")) {
|
if (element.classList.contains("left")) {
|
||||||
is_resizing_left = true;
|
is_resizing_left = true;
|
||||||
@ -1938,6 +2002,7 @@ var Gantt = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bar_wrapper.classList.add("active");
|
bar_wrapper.classList.add("active");
|
||||||
|
this.popup.parent.classList.add('hidden');
|
||||||
|
|
||||||
x_on_start = e.offsetX;
|
x_on_start = e.offsetX;
|
||||||
y_on_start = e.offsetY;
|
y_on_start = e.offsetY;
|
||||||
@ -1964,22 +2029,49 @@ var Gantt = (function () {
|
|||||||
let localBars = [];
|
let localBars = [];
|
||||||
const ids = [];
|
const ids = [];
|
||||||
let dx;
|
let dx;
|
||||||
|
|
||||||
this.layers.date.setAttribute('transform', 'translate(0,' + e.currentTarget.scrollTop + ')');
|
|
||||||
if (x_on_scroll_start) {
|
if (x_on_scroll_start) {
|
||||||
dx = e.currentTarget.scrollLeft - x_on_scroll_start;
|
dx = e.currentTarget.scrollLeft - x_on_scroll_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const daysSinceStart = e.currentTarget.scrollLeft / this.options.column_width * this.options.step / 24;
|
||||||
|
let format_str = "D MMM";
|
||||||
|
if (["Year", "Month"].includes(this.options.view_mode)) format_str = 'YYYY';
|
||||||
|
else if (["Day", "Week"].includes(this.options.view_mode)) format_str = 'MMMM';
|
||||||
|
else if (this.view_is('Half Day')) format_str = 'D';
|
||||||
|
else if (this.view_is('Hour')) format_str = "D MMMM";
|
||||||
|
|
||||||
|
|
||||||
|
let currentUpper = date_utils.format(
|
||||||
|
date_utils.add(this.gantt_start, daysSinceStart, 'day'),
|
||||||
|
format_str
|
||||||
|
);
|
||||||
|
const upperTexts = Array.from(document.querySelectorAll('.upper-text'));
|
||||||
|
const $el = upperTexts.find(el => el.textContent === currentUpper);
|
||||||
|
if ($el && !$el.classList.contains('current-upper')) {
|
||||||
|
const $current = document.querySelector('.current-upper');
|
||||||
|
if ($current) {
|
||||||
|
$current.classList.remove('current-upper');
|
||||||
|
$current.style.left = this.upper_texts_x[$current.textContent] + 'px';
|
||||||
|
$current.style.top = this.options.header_height - 40 + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
|
$el.classList.add('current-upper');
|
||||||
|
let dimensions = this.$svg.getBoundingClientRect();
|
||||||
|
$el.style.left = dimensions.x + this.$container.scrollLeft + 10 + 'px';
|
||||||
|
$el.style.top = dimensions.y + this.options.header_height - 40 + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
Array.prototype.forEach.call(elements, function (el, i) {
|
Array.prototype.forEach.call(elements, function (el, i) {
|
||||||
ids.push(el.getAttribute('data-id'));
|
ids.push(el.getAttribute('data-id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dx) {
|
if (dx) {
|
||||||
localBars = ids.map(id => this.get_bar(id));
|
localBars = ids.map(id => this.get_bar(id));
|
||||||
|
if (this.options.auto_move_label) {
|
||||||
localBars.forEach(bar => {
|
localBars.forEach(bar => {
|
||||||
bar.update_label_position_on_horizontal_scroll({ x: dx, sx: e.currentTarget.scrollLeft });
|
bar.update_label_position_on_horizontal_scroll({ x: dx, sx: e.currentTarget.scrollLeft });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
x_on_scroll_start = e.currentTarget.scrollLeft;
|
x_on_scroll_start = e.currentTarget.scrollLeft;
|
||||||
@ -2018,9 +2110,6 @@ var Gantt = (function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("mouseup", (e) => {
|
document.addEventListener("mouseup", (e) => {
|
||||||
if (is_dragging || is_resizing_left || is_resizing_right) {
|
|
||||||
bars.forEach((bar) => bar.group.classList.remove("active"));
|
|
||||||
}
|
|
||||||
|
|
||||||
is_dragging = false;
|
is_dragging = false;
|
||||||
is_resizing_left = false;
|
is_resizing_left = false;
|
||||||
@ -2148,6 +2237,7 @@ var Gantt = (function () {
|
|||||||
[...this.$svg.querySelectorAll(".bar-wrapper")].forEach((el) => {
|
[...this.$svg.querySelectorAll(".bar-wrapper")].forEach((el) => {
|
||||||
el.classList.remove("active");
|
el.classList.remove("active");
|
||||||
});
|
});
|
||||||
|
this.popup.parent.classList.remove('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
view_is(modes) {
|
view_is(modes) {
|
||||||
|
|||||||
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:#000;stroke-width:.5}.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)}
|
.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-container .grid-header{background-color:#fff;position:sticky;top:0;left:0}.gantt-container .lower-text,.gantt-container .upper-text{font-size:14px;text-anchor:middle;color:#666}.gantt-container .lower-text{position:absolute;width:fit-content}.gantt-container .upper-text{position:absolute;width:fit-content}.gantt-container .current-upper{position:fixed}.gantt-container .side-header{position:fixed;padding:0 10px;background:#fff}.gantt-container .today-button,.gantt-container .viewmode-select{background-color:#fff;border:1px solid #000;color:#111;padding:4px 10px;font-size:14px;border-radius:5px}.gantt-container .viewmode-select{padding:3px 5px;margin-right:4px}.gantt-container .date-highlight{border:2px dotted #000;border-radius:12px;z-index:1;position:absolute;opacity:.4;display:none}.gantt{user-select:none;-webkit-user-select:none;position:absolute}.gantt .grid-background{fill:none}.gantt .grid-row{fill:#fff}.gantt .row-line{stroke:#ebeff2}.gantt .tick{stroke:#e0e0e0;stroke-width:.2}.gantt .tick.thick{stroke:#000;stroke-width:.5}.gantt .today-highlight{fill:#f6e796;opacity:.5}.gantt .week-highlight{fill:#f6e796;opacity:.5}.gantt .holiday-highlight{fill:#f3f4f7;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-wrapper .bar{fill:#fff;stroke:#fff;stroke-width:0;transition:stroke-width .3s ease}.gantt .bar-progress{fill:#dedfe0}.gantt .bar-expected-progress{fill:#c4c4e9}.gantt .bar-invalid{fill:rgba(0,0,0,0);stroke:#fff;stroke-width:1;stroke-dasharray:5}.gantt .bar-invalid~.bar-label{fill:#fff}.gantt .bar-label{fill:#111;dominant-baseline:central;font-family:Helvetica;font-size:14px;font-weight:400}.gantt .bar-label.big{fill:#111;text-anchor:start}.gantt .bar-wrapper.important .bar{fill:#94c4f4}.gantt .bar-wrapper.important .bar-progress{fill:#2c94ec}.gantt .bar-wrapper.important .bar-label{fill:#fff}.gantt .bar-wrapper.important .handle{fill:#94c4f4}.gantt .handle{fill:#dcdce4;cursor:ew-resize;opacity:0;visibility:hidden;transition:opacity .3s ease}.gantt .bar-wrapper{cursor:pointer;outline:none}.gantt .bar-wrapper.active .handle{visibility:visible;opacity:1}.gantt .bar-wrapper .bar{-webkit-filter:drop-shadow(3px 3px 2px rgba(0, 0, 0, 0.7));filter:drop-shadow(0 0 2px rgba(17, 43, 66, 0.16));border-radius:3px}.gantt .bar-wrapper:hover .bar{transition:transform .3s ease}.gantt .bar-wrapper:hover .date-highlight{display:block}.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:#000;padding:0;color:#959da5;border-radius:3px;border:1px solid #000;width:max-content}.gantt-container .popup-wrapper.hidden{opacity:0 !important}.gantt-container .popup-wrapper .title{border-bottom:1px solid #dedfe0;padding:10px;text-align:center;color:#fff}.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-bottom-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
67
index.html
67
index.html
@ -34,48 +34,48 @@
|
|||||||
<script>
|
<script>
|
||||||
let tasks = [
|
let tasks = [
|
||||||
{
|
{
|
||||||
start: '2018-10-01',
|
start: '2024-04-01',
|
||||||
end: '2018-10-08',
|
end: '2024-04-08',
|
||||||
name: 'Redesign website',
|
name: 'Redesign website',
|
||||||
id: "Task 0",
|
id: "Task 0",
|
||||||
progress: 80
|
progress: 30
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start: '2018-09-26',
|
start: '2024-03-26',
|
||||||
// Utilizes duration
|
// Utilizes duration
|
||||||
duration: '1m 4d',
|
duration: '6d',
|
||||||
name: 'Write new content',
|
name: 'Write new content',
|
||||||
id: "Task 1",
|
id: "Task 1",
|
||||||
progress: 5,
|
progress: 5,
|
||||||
dependencies: 'Task 0'
|
important: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start: '2018-10-04',
|
start: '2024-04-04',
|
||||||
end: '2018-10-08',
|
end: '2024-04-08',
|
||||||
name: 'Apply new styles',
|
name: 'Apply new styles',
|
||||||
id: "Task 2",
|
id: "Task 2",
|
||||||
progress: 100,
|
progress: 80,
|
||||||
dependencies: 'Task 1'
|
dependencies: 'Task 1'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start: '2018-10-08',
|
start: '2024-04-08',
|
||||||
end: '2018-10-09',
|
end: '2024-04-09',
|
||||||
name: 'Review',
|
name: 'Review',
|
||||||
id: "Task 3",
|
id: "Task 3",
|
||||||
progress: 5,
|
progress: 5,
|
||||||
dependencies: 'Task 2'
|
dependencies: 'Task 2'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start: '2018-10-08',
|
start: '2024-04-08',
|
||||||
end: '2018-10-10',
|
end: '2024-04-10',
|
||||||
name: 'Deploy',
|
name: 'Deploy',
|
||||||
id: "Task 4",
|
id: "Task 4",
|
||||||
progress: 0,
|
progress: 0,
|
||||||
// dependencies: 'Task 2'
|
// dependencies: 'Task 2'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start: '2018-10-11',
|
start: '2024-04-21',
|
||||||
end: '2018-10-11',
|
end: '2024-04-29',
|
||||||
name: 'Go Live!',
|
name: 'Go Live!',
|
||||||
id: "Task 5",
|
id: "Task 5",
|
||||||
progress: 0,
|
progress: 0,
|
||||||
@ -95,27 +95,28 @@
|
|||||||
// tasks = [...tasks, ...Array.from({length: tasks.length * 3}, (_, i) => ({...tasks[i % 3], id: i}))]
|
// tasks = [...tasks, ...Array.from({length: tasks.length * 3}, (_, i) => ({...tasks[i % 3], id: i}))]
|
||||||
|
|
||||||
let gantt_chart = new Gantt(".gantt-target", tasks, {
|
let gantt_chart = new Gantt(".gantt-target", tasks, {
|
||||||
on_click: (task) => {
|
// on_click: (task) => {
|
||||||
console.log("Double Click", task);
|
// console.log("Double Click", task);
|
||||||
},
|
// },
|
||||||
on_double_click: (task) => {
|
// on_double_click: (task) => {
|
||||||
console.log("Double Click", task);
|
// console.log("Double Click", task);
|
||||||
},
|
// },
|
||||||
on_date_change: (task, start, end) => {
|
// on_date_change: (task, start, end) => {
|
||||||
console.log("Date change", task, start, end);
|
// console.log("Date change", task, start, end);
|
||||||
},
|
// },
|
||||||
on_progress_change: (task, progress) => {
|
// on_progress_change: (task, progress) => {
|
||||||
console.log("Progress Change", task, progress);
|
// console.log("Progress Change", task, progress);
|
||||||
},
|
// },
|
||||||
on_view_change: (mode) => {
|
// on_view_change: (mode) => {
|
||||||
console.log("View Change", mode);
|
// console.log("View Change", mode);
|
||||||
},
|
// },
|
||||||
on_hover: (task, x, y) => {
|
// on_hover: (task, x, y) => {
|
||||||
console.log("Hover", x, y);
|
// console.log("Hover", x, y);
|
||||||
},
|
// },
|
||||||
view_mode: "Day",
|
view_mode: "Day",
|
||||||
view_mode_padding: { DAY: "7d" },
|
view_mode_padding: { DAY: "7d" },
|
||||||
language: "en",
|
language: "en",
|
||||||
|
scroll_today: false,
|
||||||
// readonly: true
|
// readonly: true
|
||||||
});
|
});
|
||||||
console.log(gantt_chart);
|
console.log(gantt_chart);
|
||||||
|
|||||||
@ -26,15 +26,15 @@ export default class Arrow {
|
|||||||
this.gantt.options.header_height +
|
this.gantt.options.header_height +
|
||||||
this.gantt.options.bar_height +
|
this.gantt.options.bar_height +
|
||||||
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
||||||
this.from_task.task._index +
|
this.from_task.task._index +
|
||||||
this.gantt.options.padding;
|
this.gantt.options.padding;
|
||||||
|
|
||||||
const end_x = this.to_task.$bar.getX() - this.gantt.options.padding / 2;
|
const end_x = this.to_task.$bar.getX() - this.gantt.options.padding / 2 - 7;
|
||||||
const end_y =
|
const end_y =
|
||||||
this.gantt.options.header_height +
|
this.gantt.options.header_height +
|
||||||
this.gantt.options.bar_height / 2 +
|
this.gantt.options.bar_height / 2 +
|
||||||
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
||||||
this.to_task.task._index +
|
this.to_task.task._index +
|
||||||
this.gantt.options.padding;
|
this.gantt.options.padding;
|
||||||
|
|
||||||
const from_is_below_to =
|
const from_is_below_to =
|
||||||
|
|||||||
81
src/bar.js
81
src/bar.js
@ -34,7 +34,7 @@ export default class Bar {
|
|||||||
this.duration *
|
this.duration *
|
||||||
(this.task.progress / 100) || 0;
|
(this.task.progress / 100) || 0;
|
||||||
this.group = createSVG("g", {
|
this.group = createSVG("g", {
|
||||||
class: "bar-wrapper " + (this.task.custom_class || ""),
|
class: "bar-wrapper" + (this.task.custom_class ? " " + this.task.custom_class : "") + (this.task.important ? ' important' : ''),
|
||||||
"data-id": this.task.id,
|
"data-id": this.task.id,
|
||||||
});
|
});
|
||||||
this.bar_group = createSVG("g", {
|
this.bar_group = createSVG("g", {
|
||||||
@ -75,11 +75,11 @@ export default class Bar {
|
|||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
this.draw_bar();
|
this.draw_bar();
|
||||||
|
this.draw_progress_bar();
|
||||||
if (this.gantt.options.show_expected_progress) {
|
if (this.gantt.options.show_expected_progress) {
|
||||||
this.prepare_expected_progress_values();
|
this.prepare_expected_progress_values();
|
||||||
this.draw_expected_progress_bar();
|
this.draw_expected_progress_bar();
|
||||||
}
|
}
|
||||||
this.draw_progress_bar();
|
|
||||||
this.draw_label();
|
this.draw_label();
|
||||||
this.draw_resize_handles();
|
this.draw_resize_handles();
|
||||||
|
|
||||||
@ -140,12 +140,27 @@ export default class Bar {
|
|||||||
class: "bar-progress",
|
class: "bar-progress",
|
||||||
append_to: this.bar_group,
|
append_to: this.bar_group,
|
||||||
});
|
});
|
||||||
|
const x = (date_utils.diff(this.task._start, this.gantt.gantt_start, 'hour') /
|
||||||
|
this.gantt.options.step) *
|
||||||
|
this.gantt.options.column_width;
|
||||||
|
|
||||||
|
let $date_highlight = document.createElement("div");
|
||||||
|
$date_highlight.id = `${this.task.id}-highlight`
|
||||||
|
$date_highlight.classList.add('date-highlight')
|
||||||
|
$date_highlight.style.height = this.height * 0.8 + 'px'
|
||||||
|
$date_highlight.style.width = this.width + 'px'
|
||||||
|
$date_highlight.style.top = this.gantt.options.header_height - 21 + 'px'
|
||||||
|
$date_highlight.style.left = x + 'px'
|
||||||
|
this.$date_highlight = $date_highlight
|
||||||
|
this.gantt.$lower_header.appendChild($date_highlight)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
animateSVG(this.$bar_progress, "width", 0, this.progress_width);
|
animateSVG(this.$bar_progress, "width", 0, this.progress_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_label() {
|
draw_label() {
|
||||||
let x_coord = this.x + 5;
|
let x_coord = this.x + this.$bar.getWidth() / 2;
|
||||||
|
|
||||||
if (this.task.thumbnail) {
|
if (this.task.thumbnail) {
|
||||||
x_coord = this.x + this.image_size + 5;
|
x_coord = this.x + this.image_size + 5;
|
||||||
@ -209,7 +224,7 @@ export default class Bar {
|
|||||||
const handle_width = 8;
|
const handle_width = 8;
|
||||||
|
|
||||||
createSVG("rect", {
|
createSVG("rect", {
|
||||||
x: bar.getX() + bar.getWidth() - 9,
|
x: bar.getX() + bar.getWidth() + handle_width - 4,
|
||||||
y: bar.getY() + 1,
|
y: bar.getY() + 1,
|
||||||
width: handle_width,
|
width: handle_width,
|
||||||
height: this.height - 2,
|
height: this.height - 2,
|
||||||
@ -220,7 +235,7 @@ export default class Bar {
|
|||||||
});
|
});
|
||||||
|
|
||||||
createSVG("rect", {
|
createSVG("rect", {
|
||||||
x: bar.getX() + 1,
|
x: bar.getX() - handle_width - 4,
|
||||||
y: bar.getY() + 1,
|
y: bar.getY() + 1,
|
||||||
width: handle_width,
|
width: handle_width,
|
||||||
height: this.height - 2,
|
height: this.height - 2,
|
||||||
@ -240,12 +255,12 @@ export default class Bar {
|
|||||||
get_progress_polygon_points() {
|
get_progress_polygon_points() {
|
||||||
const bar_progress = this.$bar_progress;
|
const bar_progress = this.$bar_progress;
|
||||||
return [
|
return [
|
||||||
bar_progress.getEndX() - 5,
|
bar_progress.getEndX() - 6,
|
||||||
bar_progress.getY() + bar_progress.getHeight(),
|
bar_progress.getY() + bar_progress.getHeight() + 8,
|
||||||
bar_progress.getEndX() + 5,
|
bar_progress.getEndX() + 6,
|
||||||
bar_progress.getY() + bar_progress.getHeight(),
|
bar_progress.getY() + bar_progress.getHeight() + 8,
|
||||||
bar_progress.getEndX(),
|
bar_progress.getEndX(),
|
||||||
bar_progress.getY() + bar_progress.getHeight() - 8.66,
|
bar_progress.getY() + bar_progress.getHeight() + 0.5,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,24 +271,17 @@ export default class Bar {
|
|||||||
|
|
||||||
setup_click_event() {
|
setup_click_event() {
|
||||||
let in_action = false;
|
let in_action = false;
|
||||||
$.on(this.group, "mouseover", (e) => this.gantt.trigger_event("hover", [this.task, e.screenX, e.screenY, e]))
|
let task_id = this.task.id;
|
||||||
|
$.on(this.group, "mouseover", (e) => {
|
||||||
|
this.gantt.trigger_event("hover", [this.task, e.screenX, e.screenY, e])
|
||||||
|
document.querySelector(`#${task_id}-highlight`).style.display = 'block'
|
||||||
|
})
|
||||||
|
$.on(this.group, "mouseenter", (e) => this.show_popup(e.offsetX))
|
||||||
|
$.on(this.group, "mouseleave", () => document.querySelector(`#${task_id}-highlight`).style.display = 'none')
|
||||||
|
|
||||||
$.on(this.group, "focus " + this.gantt.options.popup_trigger, (e) => {
|
|
||||||
if (this.action_completed) {
|
|
||||||
// just finished a move action, wait for a few seconds
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!in_action) this.gantt.trigger_event("click", [this.task]);
|
|
||||||
if (in_action) {
|
|
||||||
this.gantt.hide_popup();
|
|
||||||
this.group.classList.remove("active");
|
|
||||||
} else {
|
|
||||||
this.show_popup();
|
|
||||||
this.gantt.unselect_all();
|
|
||||||
this.group.classList.add("active");
|
|
||||||
}
|
|
||||||
|
|
||||||
in_action = !in_action
|
$.on(this.group, "focus " + this.gantt.options.popup_trigger, () => {
|
||||||
|
this.gantt.trigger_event("click", [this.task]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$.on(this.group, "dblclick", (e) => {
|
$.on(this.group, "dblclick", (e) => {
|
||||||
@ -286,7 +294,7 @@ export default class Bar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
show_popup() {
|
show_popup(x) {
|
||||||
if (this.gantt.bar_being_dragged) return;
|
if (this.gantt.bar_being_dragged) return;
|
||||||
|
|
||||||
const start_date = date_utils.format(
|
const start_date = date_utils.format(
|
||||||
@ -299,9 +307,10 @@ export default class Bar {
|
|||||||
"MMM D",
|
"MMM D",
|
||||||
this.gantt.options.language,
|
this.gantt.options.language,
|
||||||
);
|
);
|
||||||
const subtitle = start_date + " - " + end_date;
|
const subtitle = `${start_date} - ${end_date}<br/>Progress: ${this.task.progress}`;
|
||||||
|
|
||||||
this.gantt.show_popup({
|
this.gantt.show_popup({
|
||||||
|
x,
|
||||||
target_element: this.$bar,
|
target_element: this.$bar,
|
||||||
title: this.task.name,
|
title: this.task.name,
|
||||||
subtitle: subtitle,
|
subtitle: subtitle,
|
||||||
@ -325,9 +334,11 @@ export default class Bar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.update_attr(bar, "x", x);
|
this.update_attr(bar, "x", x);
|
||||||
|
this.update_attr(this.$date_highlight, "x", x);
|
||||||
}
|
}
|
||||||
if (width) {
|
if (width) {
|
||||||
this.update_attr(bar, "width", width);
|
this.update_attr(bar, "width", width);
|
||||||
|
this.update_attr(this.$date_highlight, "width", width);
|
||||||
}
|
}
|
||||||
this.update_label_position();
|
this.update_label_position();
|
||||||
this.update_handle_position();
|
this.update_handle_position();
|
||||||
@ -537,10 +548,12 @@ export default class Bar {
|
|||||||
label = this.group.querySelector(".bar-label"),
|
label = this.group.querySelector(".bar-label"),
|
||||||
img = this.group.querySelector('.bar-img');
|
img = this.group.querySelector('.bar-img');
|
||||||
|
|
||||||
|
|
||||||
let padding = 5;
|
let padding = 5;
|
||||||
let x_offset_label_img = this.image_size + 10;
|
let x_offset_label_img = this.image_size + 10;
|
||||||
|
const labelWidth = label.getBBox().width
|
||||||
if (label.getBBox().width > bar.getWidth()) {
|
const barWidth = bar.getWidth()
|
||||||
|
if (labelWidth > barWidth) {
|
||||||
label.classList.add("big");
|
label.classList.add("big");
|
||||||
if (img) {
|
if (img) {
|
||||||
img.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
img.setAttribute('x', bar.getX() + bar.getWidth() + padding);
|
||||||
@ -554,9 +567,9 @@ export default class Bar {
|
|||||||
if (img) {
|
if (img) {
|
||||||
img.setAttribute('x', bar.getX() + padding);
|
img.setAttribute('x', bar.getX() + padding);
|
||||||
img_mask.setAttribute('x', bar.getX() + padding);
|
img_mask.setAttribute('x', bar.getX() + padding);
|
||||||
label.setAttribute('x', bar.getX() + x_offset_label_img);
|
label.setAttribute('x', bar.getX() + barWidth / 2 + x_offset_label_img);
|
||||||
} else {
|
} else {
|
||||||
label.setAttribute('x', bar.getX() + padding);
|
label.setAttribute('x', bar.getX() + barWidth / 2 - labelWidth / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -566,10 +579,10 @@ export default class Bar {
|
|||||||
const bar = this.$bar;
|
const bar = this.$bar;
|
||||||
this.handle_group
|
this.handle_group
|
||||||
.querySelector(".handle.left")
|
.querySelector(".handle.left")
|
||||||
.setAttribute("x", bar.getX() + 1);
|
.setAttribute("x", bar.getX() - 12);
|
||||||
this.handle_group
|
this.handle_group
|
||||||
.querySelector(".handle.right")
|
.querySelector(".handle.right")
|
||||||
.setAttribute("x", bar.getEndX() - 9);
|
.setAttribute("x", bar.getEndX() + 4);
|
||||||
const handle = this.group.querySelector(".handle.progress");
|
const handle = this.group.querySelector(".handle.progress");
|
||||||
handle && handle.setAttribute("points", this.get_progress_polygon_points());
|
handle && handle.setAttribute("points", this.get_progress_polygon_points());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,21 @@ const MINUTE = "minute";
|
|||||||
const SECOND = "second";
|
const SECOND = "second";
|
||||||
const MILLISECOND = "millisecond";
|
const MILLISECOND = "millisecond";
|
||||||
|
|
||||||
|
const SHORTENED = {
|
||||||
|
January: "Jan",
|
||||||
|
February: "Feb",
|
||||||
|
March: "Mar",
|
||||||
|
April: "Apr",
|
||||||
|
May: "May",
|
||||||
|
June: "Jun",
|
||||||
|
July: "Jul",
|
||||||
|
August: "Aug",
|
||||||
|
September: "Sep",
|
||||||
|
October: "Oct",
|
||||||
|
November: "Nov",
|
||||||
|
December: "Dec"
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
parse_duration(duration) {
|
parse_duration(duration) {
|
||||||
const regex = /([0-9])+(y|m|d|h|min|s|ms)/gm;
|
const regex = /([0-9])+(y|m|d|h|min|s|ms)/gm;
|
||||||
@ -98,7 +113,7 @@ export default {
|
|||||||
SSS: values[6],
|
SSS: values[6],
|
||||||
D: values[2],
|
D: values[2],
|
||||||
MMMM: month_name_capitalized,
|
MMMM: month_name_capitalized,
|
||||||
MMM: month_name_capitalized,
|
MMM: SHORTENED[month_name_capitalized],
|
||||||
};
|
};
|
||||||
|
|
||||||
let str = format_string;
|
let str = format_string;
|
||||||
|
|||||||
180
src/gantt.scss
180
src/gantt.scss
@ -1,40 +1,100 @@
|
|||||||
@import "./dark.scss";
|
@import "./dark.scss";
|
||||||
|
|
||||||
$bar-color: #b8c2cc !default;
|
$bar-color: #fff !default;
|
||||||
$bar-stroke: #8d99a6 !default;
|
$bar-color-important: #94c4f4 !default;
|
||||||
|
$bar-stroke: #fff !default;
|
||||||
$border-color: #e0e0e0 !default;
|
$border-color: #e0e0e0 !default;
|
||||||
$light-bg: #f5f5f5 !default;
|
$light-bg: #f5f5f5 !default;
|
||||||
$light-border-color: #ebeff2 !default;
|
$light-border-color: #ebeff2 !default;
|
||||||
$light-yellow: #f6e796 !default;
|
$light-yellow: #f6e796 !default;
|
||||||
$holiday-color: #EEE !default;
|
$holiday-color: #f3f4f7 !default;
|
||||||
$text-muted: #666 !default;
|
$text-muted: #666 !default;
|
||||||
$text-light: #555 !default;
|
$text-light: #fff !default;
|
||||||
$text-color: #333 !default;
|
$text-dark: #111 !default;
|
||||||
$blue: #acacfa !default;
|
$progress-important: #2c94ec !default;
|
||||||
$handle-color: #ddd !default;
|
$progress: #dedfe0 !default;
|
||||||
|
$handle-color: #dcdce4 !default;
|
||||||
|
$handle-color-important: #94c4f4 !default;
|
||||||
$light-blue: #c4c4e9 !default;
|
$light-blue: #c4c4e9 !default;
|
||||||
|
|
||||||
|
.gantt-container {
|
||||||
|
.grid-header {
|
||||||
|
background-color: #ffffff;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lower-text,
|
||||||
|
.upper-text {
|
||||||
|
font-size: 14px;
|
||||||
|
text-anchor: middle;
|
||||||
|
color: $text-muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lower-text {
|
||||||
|
position: absolute;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upper-text {
|
||||||
|
position: absolute;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.current-upper {
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.side-header {
|
||||||
|
position: fixed;
|
||||||
|
padding: 0 10px;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.today-button,
|
||||||
|
.viewmode-select {
|
||||||
|
background-color: $text-light;
|
||||||
|
border: 1px solid black;
|
||||||
|
color: $text-dark;
|
||||||
|
padding: 4px 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewmode-select {
|
||||||
|
padding: 3px 5px;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-highlight {
|
||||||
|
border: 2px dotted black;
|
||||||
|
border-radius: 12px;
|
||||||
|
z-index: 1;
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0.4;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.gantt {
|
.gantt {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
.grid-background {
|
.grid-background {
|
||||||
fill: none;
|
fill: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-header {
|
|
||||||
fill: #ffffff;
|
|
||||||
stroke: $border-color;
|
|
||||||
stroke-width: 1.4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grid-row {
|
.grid-row {
|
||||||
fill: #ffffff;
|
fill: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-row:nth-child(even) {
|
// .grid-row:nth-child(even) {
|
||||||
fill: $light-bg;
|
// fill: $light-bg;
|
||||||
}
|
// }
|
||||||
|
|
||||||
.row-line {
|
.row-line {
|
||||||
stroke: $light-border-color;
|
stroke: $light-border-color;
|
||||||
@ -81,17 +141,21 @@ $light-blue: #c4c4e9 !default;
|
|||||||
stroke-width: 1.4;
|
stroke-width: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar {
|
.bar-wrapper .bar {
|
||||||
fill: $bar-color;
|
fill: $bar-color;
|
||||||
stroke: $bar-stroke;
|
stroke: $bar-stroke;
|
||||||
stroke-width: 0;
|
stroke-width: 0;
|
||||||
transition: stroke-width 0.3s ease;
|
transition: stroke-width 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.bar-progress {
|
.bar-progress {
|
||||||
fill: $blue;
|
fill: $progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.bar-expected-progress {
|
.bar-expected-progress {
|
||||||
fill: $light-blue;
|
fill: $light-blue;
|
||||||
}
|
}
|
||||||
@ -108,18 +172,38 @@ $light-blue: #c4c4e9 !default;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.bar-label {
|
.bar-label {
|
||||||
fill: #fff;
|
fill: $text-dark;
|
||||||
dominant-baseline: central;
|
dominant-baseline: central;
|
||||||
// text-anchor: middle;
|
// text-anchor: middle;
|
||||||
font-size: 12px;
|
font-family: Helvetica;
|
||||||
font-weight: 500;
|
font-size: 14px;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
&.big {
|
&.big {
|
||||||
fill: $text-light;
|
fill: $text-dark;
|
||||||
text-anchor: start;
|
text-anchor: start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bar-wrapper.important {
|
||||||
|
.bar {
|
||||||
|
fill: $bar-color-important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar-progress {
|
||||||
|
fill: $progress-important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar-label {
|
||||||
|
fill: $text-light;
|
||||||
|
}
|
||||||
|
|
||||||
|
.handle {
|
||||||
|
fill: $handle-color-important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.handle {
|
.handle {
|
||||||
fill: $handle-color;
|
fill: $handle-color;
|
||||||
cursor: ew-resize;
|
cursor: ew-resize;
|
||||||
@ -132,45 +216,31 @@ $light-blue: #c4c4e9 !default;
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|
||||||
&:hover {
|
&.active {
|
||||||
.bar {
|
& .handle {
|
||||||
fill: darken($bar-color, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.bar-progress {
|
|
||||||
fill: darken($blue, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.handle {
|
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active {
|
.bar {
|
||||||
|
-webkit-filter: drop-shadow(3px 3px 2px rgba(0, 0, 0, .7));
|
||||||
|
filter: drop-shadow(0 0 2px rgba(17, 43, 66, .16));
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
&:hover {
|
||||||
.bar {
|
.bar {
|
||||||
fill: darken($bar-color, 5);
|
transition: transform 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-progress {
|
.date-highlight {
|
||||||
fill: darken($blue, 5);
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.lower-text,
|
|
||||||
.upper-text {
|
|
||||||
font-size: 12px;
|
|
||||||
text-anchor: middle;
|
|
||||||
}
|
|
||||||
|
|
||||||
.upper-text {
|
|
||||||
fill: $text-light;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lower-text {
|
|
||||||
fill: $text-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hide {
|
.hide {
|
||||||
display: none;
|
display: none;
|
||||||
@ -187,14 +257,22 @@ $light-blue: #c4c4e9 !default;
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
background: rgba(0, 0, 0, 0.8);
|
background: rgba(0, 0, 0);
|
||||||
padding: 0;
|
padding: 0;
|
||||||
color: #959da5;
|
color: #959da5;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
border: 1px solid rgba(0, 0, 0);
|
||||||
|
width: max-content;
|
||||||
|
|
||||||
|
&.hidden {
|
||||||
|
opacity: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
border-bottom: 3px solid $blue;
|
border-bottom: 1px solid $progress;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
text-align: center;
|
||||||
|
color: $text-light;
|
||||||
}
|
}
|
||||||
|
|
||||||
.subtitle {
|
.subtitle {
|
||||||
@ -207,7 +285,7 @@ $light-blue: #c4c4e9 !default;
|
|||||||
height: 5px;
|
height: 5px;
|
||||||
margin: 0 0 0 -5px;
|
margin: 0 0 0 -5px;
|
||||||
border: 5px solid transparent;
|
border: 5px solid transparent;
|
||||||
border-top-color: rgba(0, 0, 0, 0.8);
|
border-bottom-color: rgba(0, 0, 0, 0.8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
224
src/index.js
224
src/index.js
@ -100,7 +100,9 @@ export default class Gantt {
|
|||||||
language: "en",
|
language: "en",
|
||||||
readonly: false,
|
readonly: false,
|
||||||
highlight_weekend: true,
|
highlight_weekend: true,
|
||||||
scroll_today: true
|
scroll_today: true,
|
||||||
|
lines: 'both',
|
||||||
|
auto_move_label: true,
|
||||||
};
|
};
|
||||||
this.options = Object.assign({}, default_options, options);
|
this.options = Object.assign({}, default_options, options);
|
||||||
if (!options.view_mode_padding) options.view_mode_padding = {}
|
if (!options.view_mode_padding) options.view_mode_padding = {}
|
||||||
@ -132,12 +134,16 @@ export default class Gantt {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
task._end = date_utils.parse(task.end);
|
task._end = date_utils.parse(task.end);
|
||||||
|
let diff = date_utils.diff(task._end, task._start, "year");
|
||||||
|
if (diff < 0) {
|
||||||
|
throw Error("start of task can't be after end of task: in task #, " + (i + 1))
|
||||||
|
}
|
||||||
// make task invalid if duration too large
|
// make task invalid if duration too large
|
||||||
if (date_utils.diff(task._end, task._start, "year") > 10) {
|
if (date_utils.diff(task._end, task._start, "year") > 10) {
|
||||||
task.end = null;
|
task.end = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cache index
|
// cache index
|
||||||
task._index = i;
|
task._index = i;
|
||||||
|
|
||||||
@ -343,7 +349,7 @@ export default class Gantt {
|
|||||||
|
|
||||||
setup_layers() {
|
setup_layers() {
|
||||||
this.layers = {};
|
this.layers = {};
|
||||||
const layers = ["grid", "arrow", "progress", "bar", "details", "date"];
|
const layers = ["grid", "arrow", "progress", "bar", "details"];
|
||||||
// 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", {
|
||||||
@ -374,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.date,
|
append_to: this.$svg,
|
||||||
});
|
});
|
||||||
|
|
||||||
$.attr(this.$svg, {
|
$.attr(this.$svg, {
|
||||||
@ -401,34 +407,80 @@ export default class Gantt {
|
|||||||
class: "grid-row",
|
class: "grid-row",
|
||||||
append_to: rows_layer,
|
append_to: rows_layer,
|
||||||
});
|
});
|
||||||
|
if (this.options.lines === 'both' || this.options.lines === 'horizontal') {
|
||||||
createSVG("line", {
|
createSVG("line", {
|
||||||
x1: 0,
|
x1: 0,
|
||||||
y1: row_y + row_height,
|
y1: row_y + row_height,
|
||||||
x2: row_width,
|
x2: row_width,
|
||||||
y2: row_y + row_height,
|
y2: row_y + row_height,
|
||||||
class: "row-line",
|
class: "row-line",
|
||||||
append_to: lines_layer,
|
append_to: lines_layer,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
row_y += this.options.bar_height + this.options.padding;
|
row_y += this.options.bar_height + this.options.padding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
make_grid_header() {
|
make_grid_header() {
|
||||||
const header_width = this.dates.length * this.options.column_width;
|
const curHeader = document.querySelector('.grid-header')
|
||||||
const header_height = this.options.header_height + 10;
|
if (curHeader) {
|
||||||
createSVG("rect", {
|
curHeader.remove()
|
||||||
x: 0,
|
};
|
||||||
y: 0,
|
|
||||||
width: header_width,
|
let $header = document.createElement("div");
|
||||||
height: header_height,
|
$header.style.height = this.options.header_height + 10 + "px";
|
||||||
class: "grid-header",
|
$header.style.width = this.dates.length * this.options.column_width + "px";
|
||||||
append_to: this.layers.grid,
|
$header.classList.add('grid-header')
|
||||||
});
|
this.$header = $header
|
||||||
|
this.$container.appendChild($header)
|
||||||
|
|
||||||
|
let $upper_header = document.createElement("div");
|
||||||
|
$upper_header.classList.add('upper-header')
|
||||||
|
this.$upper_header = $upper_header
|
||||||
|
this.$header.appendChild($upper_header)
|
||||||
|
|
||||||
|
let $lower_header = document.createElement("div");
|
||||||
|
$lower_header.classList.add('lower-header')
|
||||||
|
this.$lower_header = $lower_header
|
||||||
|
this.$header.appendChild($lower_header)
|
||||||
|
|
||||||
|
let $side_header = document.createElement('div')
|
||||||
|
$side_header.classList.add('side-header')
|
||||||
|
|
||||||
|
|
||||||
|
// Create view mode change select
|
||||||
|
const $select = document.createElement("select");
|
||||||
|
$select.classList.add('viewmode-select')
|
||||||
|
|
||||||
|
for (const key in VIEW_MODE) {
|
||||||
|
const $option = document.createElement("option");
|
||||||
|
$option.value = VIEW_MODE[key];
|
||||||
|
$option.textContent = VIEW_MODE[key];
|
||||||
|
$select.appendChild($option);
|
||||||
|
}
|
||||||
|
$select.value = this.options.view_mode
|
||||||
|
$select.addEventListener("change", (function () {
|
||||||
|
this.change_view_mode($select.value)
|
||||||
|
}).bind(this));
|
||||||
|
$side_header.appendChild($select)
|
||||||
|
|
||||||
|
// Create today button
|
||||||
|
let $today_button = document.createElement('button')
|
||||||
|
$today_button.classList.add('today-button')
|
||||||
|
$today_button.textContent = 'Today'
|
||||||
|
$today_button.onclick = this.scroll_today.bind(this)
|
||||||
|
$side_header.appendChild($today_button)
|
||||||
|
|
||||||
|
this.$header.appendChild($side_header)
|
||||||
|
const { left, y } = $header.getBoundingClientRect();
|
||||||
|
const width = Math.min(this.$header.clientWidth, this.$container.clientWidth)
|
||||||
|
$side_header.style.left = left + this.$container.scrollLeft + width - $side_header.clientWidth + 'px';
|
||||||
|
$side_header.style.top = y + 5 + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
make_grid_ticks() {
|
make_grid_ticks() {
|
||||||
|
if (this.options.lines !== 'both' && this.options.lines !== 'vertical') return
|
||||||
let tick_x = 0;
|
let tick_x = 0;
|
||||||
let tick_y = this.options.header_height + this.options.padding / 2;
|
let tick_y = this.options.header_height + this.options.padding / 2;
|
||||||
let tick_height =
|
let tick_height =
|
||||||
@ -475,13 +527,10 @@ export default class Gantt {
|
|||||||
const x = (date_utils.diff(d, this.gantt_start, 'hour') /
|
const x = (date_utils.diff(d, this.gantt_start, 'hour') /
|
||||||
this.options.step) *
|
this.options.step) *
|
||||||
this.options.column_width;
|
this.options.column_width;
|
||||||
const height =
|
const height = (this.options.bar_height + this.options.padding) * this.tasks.length;
|
||||||
(this.options.bar_height + this.options.padding) * this.tasks.length +
|
|
||||||
this.options.header_height +
|
|
||||||
this.options.padding / 2;
|
|
||||||
createSVG('rect', {
|
createSVG('rect', {
|
||||||
x,
|
x,
|
||||||
y: 0,
|
y: this.options.header_height + this.options.padding / 2,
|
||||||
width: (this.view_is('Day') ? 1 : 2) * this.options.column_width,
|
width: (this.view_is('Day') ? 1 : 2) * this.options.column_width,
|
||||||
height,
|
height,
|
||||||
class: 'holiday-highlight',
|
class: 'holiday-highlight',
|
||||||
@ -571,30 +620,30 @@ export default class Gantt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
make_dates() {
|
make_dates() {
|
||||||
for (let date of this.get_dates_to_draw()) {
|
this.upper_texts_x = {}
|
||||||
createSVG("text", {
|
this.get_dates_to_draw().forEach((date, i) => {
|
||||||
x: date.lower_x,
|
let $lower_text = document.createElement('div');
|
||||||
y: date.lower_y,
|
$lower_text.classList.add('lower-text')
|
||||||
innerHTML: date.lower_text,
|
$lower_text.innerText = date.lower_text
|
||||||
class: "lower-text",
|
this.$lower_header.appendChild($lower_text)
|
||||||
append_to: this.layers.date,
|
$lower_text.style.left = date.lower_x - (true ? $lower_text.clientWidth / 2 : 0) + 'px'
|
||||||
});
|
$lower_text.style.top = date.lower_y + 'px'
|
||||||
|
|
||||||
if (date.upper_text) {
|
if (date.upper_text) {
|
||||||
const $upper_text = createSVG("text", {
|
this.upper_texts_x[date.upper_text] = date.upper_x
|
||||||
x: date.upper_x,
|
let $upper_text = document.createElement('div');
|
||||||
y: date.upper_y,
|
$upper_text.classList.add('upper-text')
|
||||||
innerHTML: date.upper_text,
|
$upper_text.style.left = date.upper_x + 'px'
|
||||||
class: "upper-text",
|
$upper_text.style.top = date.upper_y + 'px'
|
||||||
append_to: this.layers.date,
|
$upper_text.innerText = date.upper_text
|
||||||
});
|
this.$upper_header.appendChild($upper_text)
|
||||||
|
|
||||||
// remove out-of-bound dates
|
// remove out-of-bound dates
|
||||||
if ($upper_text.getBBox().x2 > this.layers.grid.getBBox().width) {
|
if (date.upper_x > this.layers.grid.getBBox().width) {
|
||||||
$upper_text.remove();
|
$upper_text.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
get_dates_to_draw() {
|
get_dates_to_draw() {
|
||||||
@ -607,9 +656,8 @@ export default class Gantt {
|
|||||||
return dates;
|
return dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_date_info(date, last_date_info, i) {
|
get_date_info(date, last_date_info) {
|
||||||
let last_date = last_date_info ? last_date_info.date : date_utils.add(date, 1, "day")
|
let last_date = last_date_info ? last_date_info.date : date_utils.add(date, 1, "day")
|
||||||
|
|
||||||
const date_text = {
|
const date_text = {
|
||||||
Hour_lower: date_utils.format(date, "HH", this.options.language),
|
Hour_lower: date_utils.format(date, "HH", this.options.language),
|
||||||
"Quarter Day_lower": date_utils.format(date, "HH", this.options.language),
|
"Quarter Day_lower": date_utils.format(date, "HH", this.options.language),
|
||||||
@ -639,7 +687,7 @@ export default class Gantt {
|
|||||||
: date_utils.format(date, "D", this.options.language)
|
: date_utils.format(date, "D", this.options.language)
|
||||||
: "",
|
: "",
|
||||||
Day_upper:
|
Day_upper:
|
||||||
date.getMonth() !== last_date.getMonth()
|
date.getMonth() !== last_date.getMonth() || !last_date_info
|
||||||
? date_utils.format(date, "MMMM", this.options.language)
|
? date_utils.format(date, "MMMM", this.options.language)
|
||||||
: "",
|
: "",
|
||||||
Week_upper:
|
Week_upper:
|
||||||
@ -660,27 +708,25 @@ export default class Gantt {
|
|||||||
x: last_date_info
|
x: last_date_info
|
||||||
? last_date_info.base_pos_x + last_date_info.column_width
|
? last_date_info.base_pos_x + last_date_info.column_width
|
||||||
: 0,
|
: 0,
|
||||||
lower_y: this.options.header_height,
|
lower_y: this.options.header_height - 15,
|
||||||
upper_y: this.options.header_height - 25,
|
upper_y: this.options.header_height - 40,
|
||||||
};
|
};
|
||||||
|
|
||||||
const x_pos = {
|
const x_pos = {
|
||||||
Hour_lower: this.options.column_width / 2,
|
Hour_lower: column_width / 2,
|
||||||
Hour_upper: this.options.column_width * 12,
|
Hour_upper: column_width * 12,
|
||||||
"Quarter Day_lower": this.options.column_width / 2,
|
"Quarter Day_lower": column_width / 2,
|
||||||
"Quarter Day_upper": this.options.column_width * 2,
|
"Quarter Day_upper": column_width * 2,
|
||||||
"Half Day_lower": this.options.column_width / 2,
|
"Half Day_lower": column_width / 2,
|
||||||
"Half Day_upper": this.options.column_width,
|
"Half Day_upper": column_width,
|
||||||
Day_lower: this.options.column_width / 2,
|
Day_lower: column_width / 2,
|
||||||
Day_upper: (this.options.column_width * 30) / 2,
|
Day_upper: column_width / 2,
|
||||||
Week_lower: 0,
|
Week_lower: column_width / 2,
|
||||||
Week_upper: (this.options.column_width * 4) / 2,
|
Week_upper: (column_width * 4) / 2,
|
||||||
Month_lower: column_width / 2,
|
Month_lower: column_width / 2,
|
||||||
Month_upper: (column_width * 12) / 2,
|
Month_upper: column_width / 2,
|
||||||
Year_lower: this.options.column_width / 2,
|
Year_lower: column_width / 2,
|
||||||
Year_upper: (this.options.column_width * 30) / 2,
|
Year_upper: (column_width * 30) / 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
date,
|
date,
|
||||||
column_width,
|
column_width,
|
||||||
@ -762,8 +808,7 @@ export default class Gantt {
|
|||||||
(hours_before_first_task / this.options.step) *
|
(hours_before_first_task / this.options.step) *
|
||||||
this.options.column_width -
|
this.options.column_width -
|
||||||
this.options.column_width;
|
this.options.column_width;
|
||||||
|
parent_element.scrollTo({ left: scroll_pos, behavior: 'smooth' })
|
||||||
parent_element.scrollLeft = scroll_pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scroll_today() {
|
scroll_today() {
|
||||||
@ -801,6 +846,7 @@ export default class Gantt {
|
|||||||
|
|
||||||
$.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (e, element) => {
|
$.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (e, element) => {
|
||||||
const bar_wrapper = $.closest(".bar-wrapper", element);
|
const bar_wrapper = $.closest(".bar-wrapper", element);
|
||||||
|
bars.forEach((bar) => bar.group.classList.remove("active"));
|
||||||
|
|
||||||
if (element.classList.contains("left")) {
|
if (element.classList.contains("left")) {
|
||||||
is_resizing_left = true;
|
is_resizing_left = true;
|
||||||
@ -811,6 +857,7 @@ export default class Gantt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bar_wrapper.classList.add("active");
|
bar_wrapper.classList.add("active");
|
||||||
|
this.popup.parent.classList.add('hidden')
|
||||||
|
|
||||||
x_on_start = e.offsetX;
|
x_on_start = e.offsetX;
|
||||||
y_on_start = e.offsetY;
|
y_on_start = e.offsetY;
|
||||||
@ -837,22 +884,49 @@ export default class Gantt {
|
|||||||
let localBars = [];
|
let localBars = [];
|
||||||
const ids = [];
|
const ids = [];
|
||||||
let dx;
|
let dx;
|
||||||
|
|
||||||
this.layers.date.setAttribute('transform', 'translate(0,' + e.currentTarget.scrollTop + ')');
|
|
||||||
if (x_on_scroll_start) {
|
if (x_on_scroll_start) {
|
||||||
dx = e.currentTarget.scrollLeft - x_on_scroll_start;
|
dx = e.currentTarget.scrollLeft - x_on_scroll_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const daysSinceStart = e.currentTarget.scrollLeft / this.options.column_width * this.options.step / 24;
|
||||||
|
let format_str = "D MMM"
|
||||||
|
if (["Year", "Month"].includes(this.options.view_mode)) format_str = 'YYYY'
|
||||||
|
else if (["Day", "Week"].includes(this.options.view_mode)) format_str = 'MMMM'
|
||||||
|
else if (this.view_is('Half Day')) format_str = 'D'
|
||||||
|
else if (this.view_is('Hour')) format_str = "D MMMM"
|
||||||
|
|
||||||
|
|
||||||
|
let currentUpper = date_utils.format(
|
||||||
|
date_utils.add(this.gantt_start, daysSinceStart, 'day'),
|
||||||
|
format_str
|
||||||
|
);
|
||||||
|
const upperTexts = Array.from(document.querySelectorAll('.upper-text'));
|
||||||
|
const $el = upperTexts.find(el => el.textContent === currentUpper)
|
||||||
|
if ($el && !$el.classList.contains('current-upper')) {
|
||||||
|
const $current = document.querySelector('.current-upper')
|
||||||
|
if ($current) {
|
||||||
|
$current.classList.remove('current-upper')
|
||||||
|
$current.style.left = this.upper_texts_x[$current.textContent] + 'px';
|
||||||
|
$current.style.top = this.options.header_height - 40 + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
|
$el.classList.add('current-upper')
|
||||||
|
let dimensions = this.$svg.getBoundingClientRect()
|
||||||
|
$el.style.left = dimensions.x + this.$container.scrollLeft + 10 + 'px';
|
||||||
|
$el.style.top = dimensions.y + this.options.header_height - 40 + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
Array.prototype.forEach.call(elements, function (el, i) {
|
Array.prototype.forEach.call(elements, function (el, i) {
|
||||||
ids.push(el.getAttribute('data-id'));
|
ids.push(el.getAttribute('data-id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dx) {
|
if (dx) {
|
||||||
localBars = ids.map(id => this.get_bar(id));
|
localBars = ids.map(id => this.get_bar(id));
|
||||||
|
if (this.options.auto_move_label) {
|
||||||
localBars.forEach(bar => {
|
localBars.forEach(bar => {
|
||||||
bar.update_label_position_on_horizontal_scroll({ x: dx, sx: e.currentTarget.scrollLeft });
|
bar.update_label_position_on_horizontal_scroll({ x: dx, sx: e.currentTarget.scrollLeft });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
x_on_scroll_start = e.currentTarget.scrollLeft;
|
x_on_scroll_start = e.currentTarget.scrollLeft;
|
||||||
@ -891,9 +965,6 @@ export default class Gantt {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("mouseup", (e) => {
|
document.addEventListener("mouseup", (e) => {
|
||||||
if (is_dragging || is_resizing_left || is_resizing_right) {
|
|
||||||
bars.forEach((bar) => bar.group.classList.remove("active"));
|
|
||||||
}
|
|
||||||
|
|
||||||
is_dragging = false;
|
is_dragging = false;
|
||||||
is_resizing_left = false;
|
is_resizing_left = false;
|
||||||
@ -1021,6 +1092,7 @@ export default class Gantt {
|
|||||||
[...this.$svg.querySelectorAll(".bar-wrapper")].forEach((el) => {
|
[...this.$svg.querySelectorAll(".bar-wrapper")].forEach((el) => {
|
||||||
el.classList.remove("active");
|
el.classList.remove("active");
|
||||||
});
|
});
|
||||||
|
this.popup.parent.classList.remove('hidden')
|
||||||
}
|
}
|
||||||
|
|
||||||
view_is(modes) {
|
view_is(modes) {
|
||||||
|
|||||||
16
src/popup.js
16
src/popup.js
@ -23,9 +23,6 @@ export default class Popup {
|
|||||||
if (!options.target_element) {
|
if (!options.target_element) {
|
||||||
throw new Error("target_element is required to show popup");
|
throw new Error("target_element is required to show popup");
|
||||||
}
|
}
|
||||||
if (!options.position) {
|
|
||||||
options.position = "left";
|
|
||||||
}
|
|
||||||
const target_element = options.target_element;
|
const target_element = options.target_element;
|
||||||
|
|
||||||
if (this.custom_html) {
|
if (this.custom_html) {
|
||||||
@ -37,7 +34,6 @@ export default class Popup {
|
|||||||
// set data
|
// set data
|
||||||
this.title.innerHTML = options.title;
|
this.title.innerHTML = options.title;
|
||||||
this.subtitle.innerHTML = options.subtitle;
|
this.subtitle.innerHTML = options.subtitle;
|
||||||
this.parent.style.width = this.parent.clientWidth + "px";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set position
|
// set position
|
||||||
@ -48,15 +44,11 @@ export default class Popup {
|
|||||||
position_meta = options.target_element.getBBox();
|
position_meta = options.target_element.getBBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.position === "left") {
|
this.parent.style.left = options.x - this.parent.clientWidth / 2 + "px";
|
||||||
this.parent.style.left =
|
this.parent.style.top = position_meta.y + position_meta.height + 10 + "px";
|
||||||
position_meta.x + (position_meta.width + 10) + "px";
|
|
||||||
this.parent.style.top = position_meta.y + "px";
|
|
||||||
|
|
||||||
this.pointer.style.transform = "rotateZ(90deg)";
|
this.pointer.style.left = this.parent.clientWidth / 2 + "px";
|
||||||
this.pointer.style.left = "-7px";
|
this.pointer.style.top = "-15px";
|
||||||
this.pointer.style.top = "2px";
|
|
||||||
}
|
|
||||||
|
|
||||||
// show
|
// show
|
||||||
this.parent.style.opacity = 1;
|
this.parent.style.opacity = 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user