Merge pull request #393 from safwansamsudeen/master

Rewrite Framework
This commit is contained in:
Faris Ansari 2024-04-30 16:52:07 +05:30 committed by GitHub
commit b7deffd539
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 1505 additions and 618 deletions

215
dist/frappe-gantt.css vendored
View File

@ -66,124 +66,194 @@
border-top-color: #333; border-top-color: #333;
} }
.gantt-container {
line-height: 14.5px;
}
.gantt-container .grid-header {
background-color: #ffffff;
position: sticky;
top: 0;
left: 0;
z-index: 10;
}
.gantt-container .lower-text,
.gantt-container .upper-text {
text-anchor: middle;
color: #111;
}
.gantt-container .upper-header {
height: 40px;
}
.gantt-container .lower-header {
height: 30px;
}
.gantt-container .lower-text {
font-size: 14px;
position: absolute;
width: fit-content;
}
.gantt-container .upper-text {
position: absolute;
width: fit-content;
font-weight: 500;
font-size: 16px;
}
.gantt-container .current-upper {
position: fixed;
}
.gantt-container .side-header {
position: fixed;
padding: 0 10px;
margin-right: 10px;
background: white;
line-height: 20px;
font-weight: 400;
}
.gantt-container .today-button,
.gantt-container .viewmode-select {
background: #F4F5F6;
text-align: -webkit-center;
text-align: center;
height: 25px;
border-radius: 8px;
border: none;
color: #111;
padding: 4px 10px;
border-radius: 8px;
height: 25px;
}
.gantt-container .viewmode-select {
outline: none !important;
padding: 4px 8px;
margin-right: 4px;
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: "";
}
.gantt-container .date-highlight {
background-color: #EBEEF0;
border-radius: 12px;
position: absolute;
display: none;
}
.gantt-container .current-highlight {
position: absolute;
background: #2c94ec;
width: 1px;
}
.gantt-container .current-date-highlight {
background: #2c94ec;
color: #fff;
padding: 4px 8px;
border-radius: 200px;
}
.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;
} }
.gantt .tick { .gantt .tick {
stroke: #e0e0e0; stroke: #EBEEF0;
stroke-width: 0.2;
}
.gantt .tick.thick {
stroke-width: 0.4; stroke-width: 0.4;
} }
.gantt .today-highlight { .gantt .tick.thick {
fill: #fcf8e3; stroke: #e0e0e0;
opacity: 0.5; stroke-width: 0.7;
} }
.gantt .week-highlight { .gantt .holiday-highlight {
fill: #fcf8e3; fill: #F9FAFA;
opacity: 0.5;
}
.gantt .month-highlight {
fill: #fcf8e3;
opacity: 0.5;
}
.gantt .year-highlight {
fill: #fcf8e3;
opacity: 0.5;
} }
.gantt .arrow { .gantt .arrow {
fill: none; fill: none;
stroke: #666; stroke: #9FA9B1;
stroke-width: 1.4; stroke-width: 1;
} }
.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: #EBEEF0;
} }
.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;
text-anchor: middle; font-family: Helvetica;
font-size: 12px; font-size: 13px;
font-weight: lighter; 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 .bar-wrapper.important .handle.progress {
fill: #fff;
}
.gantt .handle { .gantt .handle {
fill: #ddd; fill: #dcdce4;
cursor: ew-resize; cursor: ew-resize;
opacity: 0; opacity: 0;
visibility: hidden; visibility: hidden;
transition: opacity 0.3s ease; transition: opacity 0.3s ease;
} }
.gantt .handle.progress {
fill: #666;
}
.gantt .bar-wrapper { .gantt .bar-wrapper {
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;
@ -193,28 +263,33 @@
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;
top: 0; top: 0;
left: 0; left: 0;
background: rgba(0, 0, 0, 0.8); background: #171B1F;
padding: 0; padding: 10px;
color: #959da5; border-radius: 5px;
border-radius: 3px; 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; margin-bottom: 5px;
padding: 10px; text-align: -webkit-center;
text-align: center;
color: #fff;
} }
.gantt-container .popup-wrapper .subtitle { .gantt-container .popup-wrapper .subtitle {
padding: 10px; color: #98A1A9;
color: #dfe2e5;
} }
.gantt-container .popup-wrapper .pointer { .gantt-container .popup-wrapper .pointer {
position: absolute; position: absolute;
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);
} }

750
dist/frappe-gantt.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -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:#fcf8e3;opacity:.5}.gantt .week-highlight{fill:#fcf8e3;opacity:.5}.gantt .month-highlight{fill:#fcf8e3;opacity:.5}.gantt .year-highlight{fill:#fcf8e3;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-container{line-height:14.5px}.gantt-container .grid-header{background-color:#fff;position:sticky;top:0;left:0;z-index:10}.gantt-container .lower-text,.gantt-container .upper-text{text-anchor:middle;color:#111}.gantt-container .upper-header{height:40px}.gantt-container .lower-header{height:30px}.gantt-container .lower-text{font-size:14px;position:absolute;width:fit-content}.gantt-container .upper-text{position:absolute;width:fit-content;font-weight:500;font-size:16px}.gantt-container .current-upper{position:fixed}.gantt-container .side-header{position:fixed;padding:0 10px;margin-right:10px;background:#fff;line-height:20px;font-weight:400}.gantt-container .today-button,.gantt-container .viewmode-select{background:#f4f5f6;text-align:-webkit-center;text-align:center;height:25px;border-radius:8px;border:none;color:#111;padding:4px 10px;border-radius:8px;height:25px}.gantt-container .viewmode-select{outline:none !important;padding:4px 8px;margin-right:4px;-webkit-appearance:none;-moz-appearance:none;text-indent:1px;text-overflow:""}.gantt-container .date-highlight{background-color:#ebeef0;border-radius:12px;position:absolute;display:none}.gantt-container .current-highlight{position:absolute;background:#2c94ec;width:1px}.gantt-container .current-date-highlight{background:#2c94ec;color:#fff;padding:4px 8px;border-radius:200px}.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:#ebeef0;stroke-width:.4}.gantt .tick.thick{stroke:#e0e0e0;stroke-width:.7}.gantt .holiday-highlight{fill:#f9fafa}.gantt .arrow{fill:none;stroke:#9fa9b1;stroke-width:1}.gantt .bar-wrapper .bar{fill:#fff;stroke:#fff;stroke-width:0;transition:stroke-width .3s ease}.gantt .bar-progress{fill:#ebeef0}.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:13px;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 .bar-wrapper.important .handle.progress{fill:#fff}.gantt .handle{fill:#dcdce4;cursor:ew-resize;opacity:0;visibility:hidden;transition:opacity .3s ease}.gantt .handle.progress{fill:#666}.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:#171b1f;padding:10px;border-radius:5px;width:max-content}.gantt-container .popup-wrapper.hidden{opacity:0 !important}.gantt-container .popup-wrapper .title{margin-bottom:5px;text-align:-webkit-center;text-align:center;color:#fff}.gantt-container .popup-wrapper .subtitle{color:#98a1a9}.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)}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -32,55 +32,56 @@
<div class="gantt-target"></div> <div class="gantt-target"></div>
</div> </div>
<script> <script>
var tasks = [ let tasks = [
{ {
start: '2018-10-01', start: '2024-04-01',
end: '2018-10-08', end: '2024-04-01',
name: 'Redesign website', name: 'Redesign website',
id: "Task 0", id: "Task 0",
progress: 100 progress: 30
},
{
start: '2024-03-26',
// Utilizes duration
duration: '6d',
name: 'Write new content',
id: "Task 1",
progress: 5,
important: true
},
{
start: '2024-04-04',
end: '2024-04-08',
name: 'Apply new styles',
id: "Task 2",
progress: 80,
dependencies: 'Task 1'
},
{
start: '2024-04-08',
end: '2024-04-09',
name: 'Review',
id: "Task 3",
progress: 5,
dependencies: 'Task 2'
},
{
start: '2024-04-08',
end: '2024-04-10',
name: 'Deploy',
id: "Task 4",
progress: 0,
// dependencies: 'Task 2'
},
{
start: '2024-04-21',
end: '2024-04-29',
name: 'Go Live!',
id: "Task 5",
progress: 0,
dependencies: 'Task 2',
custom_class: 'bar-milestone'
}, },
// {
// start: '2018-10-03',
// duration: '1m 4d',
// name: 'Write new content',
// id: "Task 1",
// progress: 5,
// dependencies: 'Task 0'
// },
// {
// start: '2018-10-04',
// end: '2018-10-08',
// name: 'Apply new styles',
// id: "Task 2",
// progress: 10,
// dependencies: 'Task 1'
// },
// {
// start: '2018-10-08',
// end: '2018-10-09',
// name: 'Review',
// id: "Task 3",
// progress: 5,
// dependencies: 'Task 2'
// },
// {
// start: '2018-10-08',
// end: '2018-10-10',
// name: 'Deploy',
// id: "Task 4",
// progress: 0,
// dependencies: 'Task 2'
// },
// {
// start: '2018-10-11',
// end: '2018-10-11',
// name: 'Go Live!',
// id: "Task 5",
// progress: 0,
// dependencies: 'Task 4',
// custom_class: 'bar-milestone'
// },
// { // {
// start: '2014-01-05', // start: '2014-01-05',
// end: '2019-10-12', // end: '2019-10-12',
@ -89,22 +90,39 @@
// progress: 0 // progress: 0
// } // }
]; ];
var gantt_chart = new Gantt(".gantt-target", tasks, {
// Uncomment to test fixed header
tasks = [...tasks, ...Array.from({length: tasks.length * 3}, (_, i) => ({...tasks[i % 3], id: i}))]
let gantt_chart = new Gantt(".gantt-target", tasks, {
on_click: (task) => { on_click: (task) => {
console.log(task); console.log("Click", task);
}, },
on_date_change: (task, start, end) => { // on_double_click: (task) => {
console.log(task, start, end); // console.log("Double Click", task);
}, // },
on_progress_change: (task, progress) => { // on_date_change: (task, start, end) => {
console.log(task, progress); // console.log("Date change", task, start, end);
}, // },
on_view_change: (mode) => { // on_progress_change: (task, progress) => {
console.log(mode); // console.log("Progress Change", task, progress);
}, // },
view_mode: "Half Day", // on_view_change: (mode) => {
view_mode_padding: { DAY: "1d" }, // console.log("View Change", mode);
language: "en", // },
// on_hover: (task, x, y) => {
// console.log("Hover", x, y);
// },
view_mode: "Day",
view_mode_padding: { DAY: "3d" },
popup: false,
// scroll_to: 'today',
// view_mode_select: true,
// today_button: false,
// readonly: true,
// lines: 'vertical',
// lower_text: (date) => date.getDay(),
// upper_text: (date, view_mode, def) => def,
}); });
console.log(gantt_chart); console.log(gantt_chart);
</script> </script>

View File

@ -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 =

View File

@ -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();
@ -33,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", {
@ -74,13 +75,17 @@ 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();
if (this.task.thumbnail) {
this.draw_thumbnail();
}
} }
draw_bar() { draw_bar() {
@ -135,13 +140,34 @@ 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 - 25 + 'px'
$date_highlight.style.left = x + 'px'
this.$date_highlight = $date_highlight
this.gantt.$lower_header.prepend($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 + this.$bar.getWidth() / 2;
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,15 +176,55 @@ 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) return; if (this.invalid || this.gantt.options.readonly) return;
const bar = this.$bar; const bar = this.$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,
@ -169,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,
@ -188,13 +254,24 @@ export default class Bar {
get_progress_polygon_points() { get_progress_polygon_points() {
const bar_progress = this.$bar_progress; const bar_progress = this.$bar_progress;
let icon_width = 10;
let icon_height = 15;
return [ return [
bar_progress.getEndX() - 5, bar_progress.getEndX() - icon_width / 2,
bar_progress.getY() + bar_progress.getHeight(), bar_progress.getY() + bar_progress.getHeight() / 2,
bar_progress.getEndX() + 5,
bar_progress.getY() + bar_progress.getHeight(),
bar_progress.getEndX(), bar_progress.getEndX(),
bar_progress.getY() + bar_progress.getHeight() - 8.66, bar_progress.getY() + bar_progress.getHeight() / 2 - icon_height / 2,
bar_progress.getEndX() + icon_width / 2,
bar_progress.getY() + bar_progress.getHeight() / 2,
bar_progress.getEndX(),
bar_progress.getY() + bar_progress.getHeight() / 2 + icon_height / 2,
bar_progress.getEndX() - icon_width / 2,
bar_progress.getY() + bar_progress.getHeight() / 2,
]; ];
} }
@ -204,15 +281,26 @@ export default class Bar {
} }
setup_click_event() { setup_click_event() {
$.on(this.group, "focus " + this.gantt.options.popup_trigger, (e) => { let task_id = this.task.id;
if (this.action_completed) { $.on(this.group, "mouseover", (e) => {
// just finished a move action, wait for a few seconds this.gantt.trigger_event("hover", [this.task, e.screenX, e.screenY, e])
return; })
}
this.show_popup(); let timeout;
this.gantt.unselect_all(); $.on(this.group, "mouseenter", (e) => timeout = setTimeout(() => {
this.group.classList.add("active"); this.show_popup(e.offsetX)
document.querySelector(`#${task_id}-highlight`).style.display = 'block'
}, 200))
$.on(this.group, "mouseleave", () => {
clearTimeout(timeout)
this.gantt.popup?.hide?.()
document.querySelector(`#${task_id}-highlight`).style.display = 'none'
})
$.on(this.group, this.gantt.options.popup_trigger, () => {
this.gantt.trigger_event("click", [this.task]);
}); });
$.on(this.group, "dblclick", (e) => { $.on(this.group, "dblclick", (e) => {
@ -221,11 +309,11 @@ export default class Bar {
return; return;
} }
this.gantt.trigger_event("click", [this.task]); this.gantt.trigger_event("double_click", [this.task]);
}); });
} }
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(
@ -238,9 +326,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,
@ -256,7 +345,7 @@ export default class Bar {
return this.gantt.get_bar(dep).$bar.getX(); return this.gantt.get_bar(dep).$bar.getX();
}); });
// child task must not go before parent // child task must not go before parent
const valid_x = xs.reduce((prev, curr) => { const valid_x = xs.reduce((_, curr) => {
return x >= curr; return x >= curr;
}, x); }, x);
if (!valid_x) { if (!valid_x) {
@ -264,9 +353,11 @@ export default class Bar {
return; return;
} }
this.update_attr(bar, "x", x); this.update_attr(bar, "x", x);
this.$date_highlight.style.left = x + 'px'
} }
if (width) { if (width) {
this.update_attr(bar, "width", width); this.update_attr(bar, "width", width);
this.$date_highlight.style.width = width + 'px'
} }
this.update_label_position(); this.update_label_position();
this.update_handle_position(); this.update_handle_position();
@ -279,6 +370,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 +553,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,27 +562,46 @@ 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');
if (label.getBBox().width > bar.getWidth()) {
let padding = 5;
let x_offset_label_img = this.image_size + 10;
const labelWidth = label.getBBox().width
const barWidth = bar.getWidth()
if (labelWidth > barWidth) {
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() + barWidth / 2 + x_offset_label_img);
} else {
label.setAttribute('x', bar.getX() + barWidth / 2 - labelWidth / 2);
}
} }
} }
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")
.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());
} }
@ -474,7 +615,7 @@ export default class Bar {
} }
function isFunction(functionToCheck) { function isFunction(functionToCheck) {
var getType = {}; let getType = {};
return ( return (
functionToCheck && functionToCheck &&
getType.toString.call(functionToCheck) === "[object Function]" getType.toString.call(functionToCheck) === "[object Function]"

View File

@ -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;
@ -36,25 +51,23 @@ export default {
if (typeof date === "string") { if (typeof date === "string") {
let date_parts, time_parts; let date_parts, time_parts;
const parts = date.split(" "); const parts = date.split(" ");
date_parts = parts[0] date_parts = parts[0]
.split(date_separator) .split(date_separator)
.map((val) => parseInt(val, 10)); .map((val) => parseInt(val, 10));
time_parts = parts[1] && parts[1].split(time_separator); time_parts = parts[1] && parts[1].split(time_separator);
// month is 0 indexed // month is 0 indexed
date_parts[1] = date_parts[1] - 1; date_parts[1] = date_parts[1] ? date_parts[1] - 1 : 0;
let vals = date_parts; let vals = date_parts;
if (time_parts && time_parts.length) { if (time_parts && time_parts.length) {
if (time_parts.length == 4) { if (time_parts.length === 4) {
time_parts[3] = "0." + time_parts[3]; time_parts[3] = "0." + time_parts[3];
time_parts[3] = parseFloat(time_parts[3]) * 1000; time_parts[3] = parseFloat(time_parts[3]) * 1000;
} }
vals = vals.concat(time_parts); vals = vals.concat(time_parts);
} }
return new Date(...vals); return new Date(...vals);
} }
}, },
@ -100,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;
@ -110,13 +123,13 @@ export default {
.sort((a, b) => b.length - a.length) // big string first .sort((a, b) => b.length - a.length) // big string first
.forEach((key) => { .forEach((key) => {
if (str.includes(key)) { if (str.includes(key)) {
str = str.replace(key, `$${formatted_values.length}`); str = str.replaceAll(key, `$${formatted_values.length}`);
formatted_values.push(format_map[key]); formatted_values.push(format_map[key]);
} }
}); });
formatted_values.forEach((value, i) => { formatted_values.forEach((value, i) => {
str = str.replace(`$${i}`, value); str = str.replaceAll(`$${i}`, value);
}); });
return str; return str;
@ -229,7 +242,7 @@ export default {
// Feb // Feb
const year = date.getFullYear(); const year = date.getFullYear();
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { if ((year % 4 === 0 && year % 100 != 0) || year % 400 === 0) {
return 29; return 29;
} }
return 28; return 28;

View File

@ -1,107 +1,232 @@
@import "./dark.scss"; @import "./dark.scss";
$bar-color: #b8c2cc !default; $bar-color: #fff !default;
$bar-stroke: #8d99a6 !default; $bar-color-important: #94c4f4 !default;
$border-color: #e0e0e0 !default; $bar-stroke: #fff !default;
$dark-stroke-color: #e0e0e0 !default;
$stroke-color: #EBEEF0 !default;
$light-bg: #f5f5f5 !default; $light-bg: #f5f5f5 !default;
$light-border-color: #ebeff2 !default; $light-border-color: #ebeff2 !default;
$light-yellow: #fcf8e3 !default; $light-yellow: #f6e796 !default;
$holiday-color: #F9FAFA !default;
$text-muted: #666 !default; $text-muted: #666 !default;
$text-light: #555 !default; $text-grey: #98A1A9;
$text-color: #333 !default; $text-light: #fff !default;
$blue: #acacfa !default; $text-dark: #111 !default;
$handle-color: #ddd !default; $progress: #EBEEF0 !default;
$handle-color: #dcdce4 !default;
$handle-color-important: #94c4f4 !default;
$light-blue: #c4c4e9 !default; $light-blue: #c4c4e9 !default;
$middle-blue: #62B2F9 !default;
$dark-blue: #2c94ec !default;
.gantt-container {
line-height: 14.5px;
.grid-header {
background-color: #ffffff;
position: sticky;
top: 0;
left: 0;
z-index: 10;
}
.lower-text,
.upper-text {
text-anchor: middle;
color: $text-dark;
}
.upper-header {
height: 40px;
}
.lower-header {
height: 30px;
}
.lower-text {
font-size: 14px;
position: absolute;
width: fit-content;
}
.upper-text {
position: absolute;
width: fit-content;
font-weight: 500;
font-size: 16px;
}
.current-upper {
position: fixed;
}
.side-header {
position: fixed;
padding: 0 10px;
margin-right: 10px;
background: white;
line-height: 20px;
font-weight: 400;
}
.today-button,
.viewmode-select {
background: #F4F5F6;
text-align: -webkit-center;
text-align: center;
height: 25px;
border-radius: 8px;
border: none;
color: $text-dark;
padding: 4px 10px;
border-radius: 8px;
height: 25px;
}
.viewmode-select {
outline: none !important;
padding: 4px 8px;
margin-right: 4px;
// Hide select icon
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: '';
}
.date-highlight {
background-color: $progress;
border-radius: 12px;
position: absolute;
display: none;
}
.current-highlight {
position: absolute;
background: $dark-blue;
width: 1px;
}
.current-date-highlight {
background: $dark-blue;
color: $text-light;
padding: 4px 8px;
border-radius: 200px;
}
}
.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) {
fill: $light-bg; // .grid-row:nth-child(even) {
} // fill: $light-bg;
// }
.row-line { .row-line {
stroke: $light-border-color; stroke: $light-border-color;
} }
.tick { .tick {
stroke: $border-color; stroke: $stroke-color;
stroke-width: 0.2; stroke-width: 0.4;
&.thick { &.thick {
stroke-width: 0.4; stroke: $dark-stroke-color;
stroke-width: 0.7;
} }
} }
.today-highlight {
fill: $light-yellow;
opacity: 0.5;
}
.week-highlight {
fill: $light-yellow;
opacity: 0.5;
}
.month-highlight {
fill: $light-yellow;
opacity: 0.5;
}
.year-highlight { .holiday-highlight {
fill: $light-yellow; fill: $holiday-color;
opacity: 0.5;
} }
.arrow { .arrow {
fill: none; fill: none;
stroke: $text-muted; stroke: #9FA9B1;
stroke-width: 1.4; stroke-width: 1;
} }
.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;
} }
.bar-invalid { .bar-invalid {
fill: transparent; fill: transparent;
stroke: $bar-stroke; stroke: $bar-stroke;
stroke-width: 1; stroke-width: 1;
stroke-dasharray: 5; stroke-dasharray: 5;
& ~ .bar-label { &~.bar-label {
fill: $text-light; fill: $text-light;
} }
} }
.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: lighter; font-size: 13px;
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: $dark-blue;
}
.bar-label {
fill: $text-light;
}
.handle {
fill: $handle-color-important;
}
.handle.progress {
fill: $text-light;
}
}
.handle { .handle {
fill: $handle-color; fill: $handle-color;
cursor: ew-resize; cursor: ew-resize;
@ -110,47 +235,39 @@ $light-blue: #c4c4e9 !default;
transition: opacity 0.3s ease; transition: opacity 0.3s ease;
} }
.handle.progress {
fill: $text-muted;
}
.bar-wrapper { .bar-wrapper {
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;
@ -161,24 +278,31 @@ $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;
top: 0; top: 0;
left: 0; left: 0;
background: rgba(0, 0, 0, 0.8); background: #171B1F;
padding: 0; padding: 10px;
color: #959da5; border-radius: 5px;
border-radius: 3px; width: max-content;
&.hidden {
opacity: 0 !important;
}
.title { .title {
border-bottom: 3px solid $blue; margin-bottom: 5px;
padding: 10px; text-align: -webkit-center;
text-align: center;
color: $text-light;
} }
.subtitle { .subtitle {
padding: 10px; color: $text-grey;
color: #dfe2e5;
} }
.pointer { .pointer {
@ -186,7 +310,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);
} }
} }
} }

View File

@ -26,6 +26,30 @@ const VIEW_MODE_PADDING = {
YEAR: ["2y", "2y"], YEAR: ["2y", "2y"],
}; };
const DEFAULT_OPTIONS = {
header_height: 65,
column_width: 30,
step: 24,
view_modes: [...Object.values(VIEW_MODE)],
bar_height: 30,
bar_corner_radius: 3,
arrow_curve: 5,
padding: 18,
view_mode: "Day",
date_format: "YYYY-MM-DD",
popup_trigger: "click",
show_expected_progress: false,
popup: null,
language: "en",
readonly: false,
highlight_weekend: true,
scroll_to: 'start',
lines: 'both',
auto_move_label: true,
today_button: true,
view_mode_select: false,
};
export default class Gantt { export default class Gantt {
constructor(wrapper, tasks, options) { constructor(wrapper, tasks, options) {
this.setup_wrapper(wrapper); this.setup_wrapper(wrapper);
@ -78,28 +102,14 @@ export default class Gantt {
this.$container.appendChild(this.$svg); this.$container.appendChild(this.$svg);
// popup wrapper // popup wrapper
this.popup_wrapper = document.createElement("div"); this.$popup_wrapper = document.createElement("div");
this.popup_wrapper.classList.add("popup-wrapper"); this.$popup_wrapper.classList.add("popup-wrapper");
this.$container.appendChild(this.popup_wrapper); this.$container.appendChild(this.$popup_wrapper);
} }
setup_options(options) { setup_options(options) {
const default_options = { this.options = { ...DEFAULT_OPTIONS, ...options }
header_height: 50, if (!options.view_mode_padding) options.view_mode_padding = {}
column_width: 30,
step: 24,
view_modes: [...Object.values(VIEW_MODE)],
bar_height: 20,
bar_corner_radius: 3,
arrow_curve: 5,
padding: 18,
view_mode: "Day",
date_format: "YYYY-MM-DD",
popup_trigger: "click",
custom_popup_html: null,
language: "en",
};
this.options = Object.assign({}, default_options, options);
for (let [key, value] of Object.entries(options.view_mode_padding)) { for (let [key, value] of Object.entries(options.view_mode_padding)) {
if (typeof value === "string") { if (typeof value === "string") {
// Configure for single value given // Configure for single value given
@ -128,12 +138,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;
@ -170,7 +184,7 @@ export default class Gantt {
if (task.dependencies) { if (task.dependencies) {
deps = task.dependencies deps = task.dependencies
.split(",") .split(",")
.map((d) => d.trim()) .map((d) => d.trim().replaceAll(' ', '_'))
.filter((d) => d); .filter((d) => d);
} }
task.dependencies = deps; task.dependencies = deps;
@ -179,6 +193,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.replaceAll(' ', '_')
} else {
task.id = `${task.id}`
} }
return task; return task;
@ -269,8 +287,7 @@ export default class Gantt {
const [padding_start, padding_end] = this.options.view_mode_padding[ const [padding_start, padding_end] = this.options.view_mode_padding[
viewKey viewKey
].map(date_utils.parse_duration); ].map(date_utils.parse_duration);
gantt_start = date_utils.add(
this.gantt_start = date_utils.add(
gantt_start, gantt_start,
-padding_start.duration, -padding_start.duration,
padding_start.scale, padding_start.scale,
@ -286,15 +303,8 @@ export default class Gantt {
} else { } else {
format_string = "YYYY-MM-DD HH" format_string = "YYYY-MM-DD HH"
} }
this.gantt_start = date_utils.parse(date_utils.format(gantt_start, format_string));
this.gantt_start = new Date(
date_utils.format(
date_utils.add(gantt_start, -padding_end.duration, padding_end.scale),
format_string
)
);
this.gantt_start.setHours(0, 0, 0, 0) this.gantt_start.setHours(0, 0, 0, 0)
this.gantt_end = date_utils.add( this.gantt_end = date_utils.add(
gantt_end, gantt_end,
padding_end.duration, padding_end.duration,
@ -323,6 +333,7 @@ export default class Gantt {
} }
bind_events() { bind_events() {
if (this.options.readonly) return
this.bind_grid_click(); this.bind_grid_click();
this.bind_bar_events(); this.bind_bar_events();
} }
@ -333,15 +344,16 @@ export default class Gantt {
this.make_grid(); this.make_grid();
this.make_dates(); this.make_dates();
this.make_bars(); this.make_bars();
this.make_grid_extras();
this.make_arrows(); this.make_arrows();
this.map_arrows_on_bars(); this.map_arrows_on_bars();
this.set_width(); this.set_width();
this.set_scroll_position(); this.set_scroll_position(this.options.scroll_to);
} }
setup_layers() { setup_layers() {
this.layers = {}; this.layers = {};
const layers = ["grid", "date", "arrow", "progress", "bar", "details"]; 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", {
@ -355,8 +367,11 @@ export default class Gantt {
this.make_grid_background(); this.make_grid_background();
this.make_grid_rows(); this.make_grid_rows();
this.make_grid_header(); this.make_grid_header();
this.make_grid_ticks(); }
make_grid_extras() {
this.make_grid_highlights(); this.make_grid_highlights();
this.make_grid_ticks();
} }
make_grid_background() { make_grid_background() {
@ -372,7 +387,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.$svg,
}); });
$.attr(this.$svg, { $.attr(this.$svg, {
@ -383,14 +398,13 @@ export default class Gantt {
make_grid_rows() { make_grid_rows() {
const rows_layer = createSVG("g", { append_to: this.layers.grid }); const rows_layer = createSVG("g", { append_to: this.layers.grid });
const lines_layer = createSVG("g", { append_to: this.layers.grid });
const row_width = this.dates.length * this.options.column_width; const row_width = this.dates.length * this.options.column_width;
const row_height = this.options.bar_height + this.options.padding; const row_height = this.options.bar_height + this.options.padding;
let row_y = this.options.header_height + this.options.padding / 2; let row_y = this.options.header_height + this.options.padding / 2;
for (let task of this.tasks) { for (let _ of this.tasks) {
createSVG("rect", { createSVG("rect", {
x: 0, x: 0,
y: row_y, y: row_y,
@ -399,39 +413,110 @@ 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", { }
x1: 0,
y1: row_y + row_height,
x2: row_width,
y2: row_y + row_height,
class: "row-line",
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;
createSVG("rect", { let $header = document.createElement("div");
x: 0, $header.style.height = this.options.header_height + 10 + "px";
y: 0, $header.style.width = this.dates.length * this.options.column_width + "px";
width: header_width, $header.classList.add('grid-header')
height: header_height, this.$header = $header
class: "grid-header", this.$container.appendChild($header)
append_to: this.layers.grid,
}); 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)
this.make_side_header()
}
make_side_header() {
let $side_header = document.createElement('div')
$side_header.classList.add('side-header')
// Create view mode change select
if (this.options.view_mode_select) {
const $select = document.createElement("select");
$select.classList.add('viewmode-select')
const $el = document.createElement("option");
$el.selected = true
$el.disabled = true
$el.textContent = 'Mode'
$select.appendChild($el)
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
if (this.options.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 } = this.$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 + 10 + 'px';
} }
make_grid_ticks() { make_grid_ticks() {
if (!['both', 'vertical', 'horizontal'].includes(this.options.lines)) 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 =
(this.options.bar_height + this.options.padding) * this.tasks.length; (this.options.bar_height + this.options.padding) * this.tasks.length;
let $lines_layer = createSVG("g", { class: 'lines_layer', append_to: this.layers.grid });
let row_y = this.options.header_height + this.options.padding / 2;
const row_width = this.dates.length * this.options.column_width;
const row_height = this.options.bar_height + this.options.padding;
if (this.options.lines !== 'vertical') {
for (let _ of this.tasks) {
createSVG("line", {
x1: 0,
y1: row_y + row_height,
x2: row_width,
y2: row_y + row_height,
class: "row-line",
append_to: $lines_layer,
});
row_y += row_height;
}
}
if (this.options.lines === 'horizontal') return;
for (let date of this.dates) { for (let date of this.dates) {
let tick_class = "tick"; let tick_class = "tick";
// thick tick for monday // thick tick for monday
@ -466,16 +551,38 @@ export default class Gantt {
} }
} }
highlightWeekends() {
if (!this.view_is('Day') && !this.view_is('Half Day')) return
for (let d = new Date(this.gantt_start); d <= this.gantt_end; d.setDate(d.getDate() + 1)) {
if (d.getDay() === 0 || d.getDay() === 6) {
const x = (date_utils.diff(d, this.gantt_start, 'hour') /
this.options.step) *
this.options.column_width;
const height = (this.options.bar_height + this.options.padding) * this.tasks.length;
createSVG('rect', {
x,
y: this.options.header_height + this.options.padding / 2,
width: (this.view_is('Day') ? 1 : 2) * this.options.column_width,
height,
class: 'holiday-highlight',
append_to: this.layers.grid,
});
}
}
}
//compute the horizontal x distance //compute the horizontal x distance
computeGridHighlightDimensions(view_mode) { computeGridHighlightDimensions(view_mode) {
let xDist = 0; let x = this.options.column_width / 2;
if (this.view_is(VIEW_MODE.DAY)) { if (this.view_is(VIEW_MODE.DAY)) {
return ( let today = date_utils.today()
(date_utils.diff(date_utils.today(), this.gantt_start, "hour") / return {
this.options.step) * x: x +
this.options.column_width (date_utils.diff(today, this.gantt_start, "hour") / this.options.step) *
); this.options.column_width,
date: today
}
} }
for (let date of this.dates) { for (let date of this.dates) {
@ -494,15 +601,15 @@ export default class Gantt {
break; break;
} }
if (todayDate >= startDate && todayDate <= endDate) { if (todayDate >= startDate && todayDate <= endDate) {
break; return { x, date: startDate }
} else { } else {
xDist += this.options.column_width; x += this.options.column_width;
} }
} }
return xDist;
} }
make_grid_highlights() { make_grid_highlights() {
if (this.options.highlight_weekend) this.highlightWeekends()
// highlight today's | week's | month's | year's // highlight today's | week's | month's | year's
if ( if (
this.view_is(VIEW_MODE.DAY) || this.view_is(VIEW_MODE.DAY) ||
@ -510,81 +617,73 @@ export default class Gantt {
this.view_is(VIEW_MODE.MONTH) || this.view_is(VIEW_MODE.MONTH) ||
this.view_is(VIEW_MODE.YEAR) this.view_is(VIEW_MODE.YEAR)
) { ) {
const x = this.computeGridHighlightDimensions(this.options.view_mode); // Used as we must find the _end_ of session if view is not Day
const y = 0; const { x: left, date } = this.computeGridHighlightDimensions(this.options.view_mode)
const width = this.options.column_width; const top = this.options.header_height + this.options.padding / 2;
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.$current_highlight = this.create_el({ top, left, height, classes: 'current-highlight', append_to: this.$container })
this.options.header_height + let $today = document.getElementById(date_utils.format(date).replaceAll(' ', '_'))
this.options.padding / 2;
let className = ""; $today.classList.add('current-date-highlight')
switch (this.options.view_mode) { $today.style.top = +$today.style.top.slice(0, -2) - 4 + 'px'
case VIEW_MODE.DAY: $today.style.left = +$today.style.left.slice(0, -2) - 8 + 'px'
className = "today-highlight";
break;
case VIEW_MODE.WEEK:
className = "week-highlight";
break;
case VIEW_MODE.MONTH:
className = "month-highlight";
break;
case VIEW_MODE.YEAR:
className = "year-highlight";
break;
}
createSVG("rect", {
x,
y,
width,
height,
class: className,
append_to: this.layers.grid,
});
} }
} }
create_el({ left, top, width, height, id, classes, append_to }) {
let $el = document.createElement("div");
$el.classList.add(classes)
$el.style.top = top + 'px'
$el.style.left = left + 'px'
if (id) $el.id = id
if (width) $el.style.width = height + 'px'
if (height) $el.style.height = height + 'px'
append_to.appendChild($el)
return $el
}
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 = this.create_el({
y: date.lower_y, left: date.lower_x,
innerHTML: date.lower_text, top: date.lower_y,
class: "lower-text", id: date.formatted_date,
append_to: this.layers.date, classes: 'lower-text',
}); append_to: this.$lower_header
})
$lower_text.innerText = date.lower_text
$lower_text.style.left = +$lower_text.style.left.slice(0, -2) - $lower_text.clientWidth / 2 + '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() {
let last_date = null; let last_date = null;
const dates = this.dates.map((date, i) => { const dates = this.dates.map((date, i) => {
const d = this.get_date_info(date, last_date, i); const d = this.get_date_info(date, last_date, i);
last_date = date; last_date = d;
return d; return d;
}); });
return dates; return dates;
} }
get_date_info(date, last_date, i) { get_date_info(date, last_date_info) {
if (!last_date) { let last_date = last_date_info ? last_date_info.date : date_utils.add(date, 1, "day")
last_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),
@ -614,7 +713,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:
@ -630,33 +729,37 @@ export default class Gantt {
? date_utils.format(date, "YYYY", this.options.language) ? date_utils.format(date, "YYYY", this.options.language)
: "", : "",
}; };
let column_width = this.view_is(VIEW_MODE.MONTH) ? (date_utils.get_days_in_month(date) * this.options.column_width) / 30 : this.options.column_width;
const base_pos = { const base_pos = {
x: i * this.options.column_width, x: last_date_info
lower_y: this.options.header_height, ? last_date_info.base_pos_x + last_date_info.column_width
upper_y: this.options.header_height - 25, : 0,
lower_y: this.options.header_height - 20,
upper_y: this.options.header_height - 50,
}; };
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: this.options.column_width / 2, Month_lower: column_width / 2,
Month_upper: (this.options.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 {
upper_text: date_text[`${this.options.view_mode}_upper`], date,
lower_text: date_text[`${this.options.view_mode}_lower`], formatted_date: date_utils.format(date).replaceAll(' ', '_'),
column_width,
base_pos_x: base_pos.x,
upper_text: this.options.lower_text ? this.options.upper_text(date, this.options.view_mode, date_text[`${this.options.view_mode}_upper`]) : date_text[`${this.options.view_mode}_upper`],
lower_text: this.options.lower_text ? this.options.lower_text(date, this.options.view_mode, date_text[`${this.options.view_mode}_lower`]) : date_text[`${this.options.view_mode}_lower`],
upper_x: base_pos.x + x_pos[`${this.options.view_mode}_upper`], upper_x: base_pos.x + x_pos[`${this.options.view_mode}_upper`],
upper_y: base_pos.upper_y, upper_y: base_pos.upper_y,
lower_x: base_pos.x + x_pos[`${this.options.view_mode}_lower`], lower_x: base_pos.x + x_pos[`${this.options.view_mode}_lower`],
@ -714,22 +817,33 @@ export default class Gantt {
} }
} }
set_scroll_position() { set_scroll_position(date) {
if (!date || date === 'start') {
date = this.gantt_start
} else if (date === 'today') {
return this.scroll_today()
} else if (typeof date === 'string') {
date = date_utils.parse(date)
}
const parent_element = this.$svg.parentElement; const parent_element = this.$svg.parentElement;
if (!parent_element) return; if (!parent_element) return;
const hours_before_first_task = date_utils.diff( const hours_before_first_task = date_utils.diff(
this.get_oldest_starting_date(), date,
this.gantt_start, this.gantt_start,
"hour", "hour",
); ) + 24;
const scroll_pos = const scroll_pos =
(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() {
this.set_scroll_position(new Date())
} }
bind_grid_click() { bind_grid_click() {
@ -747,6 +861,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;
@ -760,6 +875,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;
@ -770,6 +886,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;
@ -791,6 +908,58 @@ 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;
if (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 - 50 + '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 - 50 + 'px';
}
Array.prototype.forEach.call(elements, function (el, i) {
ids.push(el.getAttribute('data-id'));
});
if (dx) {
localBars = ids.map(id => this.get_bar(id));
if (this.options.auto_move_label) {
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;
@ -818,16 +987,13 @@ 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 });
} }
}); });
}); });
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;
@ -894,8 +1060,13 @@ export default class Gantt {
$.on(this.$svg, "mouseup", () => { $.on(this.$svg, "mouseup", () => {
is_resizing = false; is_resizing = false;
if (!($bar_progress && $bar_progress.finaldx)) return; if (!($bar_progress && $bar_progress.finaldx)) return;
$bar_progress.finaldx = 0;
bar.progress_changed(); bar.progress_changed();
bar.set_action_completed(); bar.set_action_completed();
bar = null;
$bar_progress = null;
$bar = null;
}); });
} }
@ -950,6 +1121,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) {
@ -977,10 +1149,11 @@ export default class Gantt {
} }
show_popup(options) { show_popup(options) {
if (this.options.popup === false) return
if (!this.popup) { if (!this.popup) {
this.popup = new Popup( this.popup = new Popup(
this.popup_wrapper, this.$popup_wrapper,
this.options.custom_popup_html, this.options.popup,
); );
} }
this.popup.show(options); this.popup.show(options);
@ -1018,6 +1191,9 @@ export default class Gantt {
*/ */
clear() { clear() {
this.$svg.innerHTML = ""; this.$svg.innerHTML = "";
this.$header?.remove?.()
this.$current_highlight?.remove?.()
this.popup?.hide?.()
} }
} }

View File

@ -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;

View File

@ -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]);
} }