commit
b7deffd539
215
dist/frappe-gantt.css
vendored
215
dist/frappe-gantt.css
vendored
@ -66,124 +66,194 @@
|
||||
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 {
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
position: absolute;
|
||||
}
|
||||
.gantt .grid-background {
|
||||
fill: none;
|
||||
}
|
||||
.gantt .grid-header {
|
||||
fill: #ffffff;
|
||||
stroke: #e0e0e0;
|
||||
stroke-width: 1.4;
|
||||
}
|
||||
.gantt .grid-row {
|
||||
fill: #ffffff;
|
||||
}
|
||||
.gantt .grid-row:nth-child(even) {
|
||||
fill: #f5f5f5;
|
||||
}
|
||||
.gantt .row-line {
|
||||
stroke: #ebeff2;
|
||||
}
|
||||
.gantt .tick {
|
||||
stroke: #e0e0e0;
|
||||
stroke-width: 0.2;
|
||||
}
|
||||
.gantt .tick.thick {
|
||||
stroke: #EBEEF0;
|
||||
stroke-width: 0.4;
|
||||
}
|
||||
.gantt .today-highlight {
|
||||
fill: #fcf8e3;
|
||||
opacity: 0.5;
|
||||
.gantt .tick.thick {
|
||||
stroke: #e0e0e0;
|
||||
stroke-width: 0.7;
|
||||
}
|
||||
.gantt .week-highlight {
|
||||
fill: #fcf8e3;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.gantt .month-highlight {
|
||||
fill: #fcf8e3;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.gantt .year-highlight {
|
||||
fill: #fcf8e3;
|
||||
opacity: 0.5;
|
||||
.gantt .holiday-highlight {
|
||||
fill: #F9FAFA;
|
||||
}
|
||||
.gantt .arrow {
|
||||
fill: none;
|
||||
stroke: #666;
|
||||
stroke-width: 1.4;
|
||||
stroke: #9FA9B1;
|
||||
stroke-width: 1;
|
||||
}
|
||||
.gantt .bar {
|
||||
fill: #b8c2cc;
|
||||
stroke: #8d99a6;
|
||||
.gantt .bar-wrapper .bar {
|
||||
fill: #fff;
|
||||
stroke: #fff;
|
||||
stroke-width: 0;
|
||||
transition: stroke-width 0.3s ease;
|
||||
}
|
||||
.gantt .bar-progress {
|
||||
fill: #acacfa;
|
||||
fill: #EBEEF0;
|
||||
}
|
||||
.gantt .bar-expected-progress {
|
||||
fill: #c4c4e9;
|
||||
}
|
||||
.gantt .bar-invalid {
|
||||
fill: transparent;
|
||||
stroke: #8d99a6;
|
||||
stroke: #fff;
|
||||
stroke-width: 1;
|
||||
stroke-dasharray: 5;
|
||||
}
|
||||
.gantt .bar-invalid ~ .bar-label {
|
||||
fill: #555;
|
||||
fill: #fff;
|
||||
}
|
||||
.gantt .bar-label {
|
||||
fill: #fff;
|
||||
fill: #111;
|
||||
dominant-baseline: central;
|
||||
text-anchor: middle;
|
||||
font-size: 12px;
|
||||
font-weight: lighter;
|
||||
font-family: Helvetica;
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.gantt .bar-label.big {
|
||||
fill: #555;
|
||||
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: #ddd;
|
||||
fill: #dcdce4;
|
||||
cursor: ew-resize;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
.gantt .handle.progress {
|
||||
fill: #666;
|
||||
}
|
||||
.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 {
|
||||
.gantt .bar-wrapper.active .handle {
|
||||
visibility: visible;
|
||||
opacity: 1;
|
||||
}
|
||||
.gantt .bar-wrapper.active .bar {
|
||||
fill: #a9b5c1;
|
||||
.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.active .bar-progress {
|
||||
fill: #9494f9;
|
||||
.gantt .bar-wrapper:hover .bar {
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
.gantt .lower-text,
|
||||
.gantt .upper-text {
|
||||
font-size: 12px;
|
||||
text-anchor: middle;
|
||||
}
|
||||
.gantt .upper-text {
|
||||
fill: #555;
|
||||
}
|
||||
.gantt .lower-text {
|
||||
fill: #333;
|
||||
.gantt .bar-wrapper:hover .date-highlight {
|
||||
display: block;
|
||||
}
|
||||
.gantt .hide {
|
||||
display: none;
|
||||
@ -193,28 +263,33 @@
|
||||
position: relative;
|
||||
overflow: auto;
|
||||
font-size: 12px;
|
||||
height: 500px;
|
||||
}
|
||||
.gantt-container .popup-wrapper {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
padding: 0;
|
||||
color: #959da5;
|
||||
border-radius: 3px;
|
||||
background: #171B1F;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
width: max-content;
|
||||
}
|
||||
.gantt-container .popup-wrapper.hidden {
|
||||
opacity: 0 !important;
|
||||
}
|
||||
.gantt-container .popup-wrapper .title {
|
||||
border-bottom: 3px solid #acacfa;
|
||||
padding: 10px;
|
||||
margin-bottom: 5px;
|
||||
text-align: -webkit-center;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
}
|
||||
.gantt-container .popup-wrapper .subtitle {
|
||||
padding: 10px;
|
||||
color: #dfe2e5;
|
||||
color: #98A1A9;
|
||||
}
|
||||
.gantt-container .popup-wrapper .pointer {
|
||||
position: absolute;
|
||||
height: 5px;
|
||||
margin: 0 0 0 -5px;
|
||||
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
750
dist/frappe-gantt.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/frappe-gantt.js.map
vendored
2
dist/frappe-gantt.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-gantt.min.css
vendored
2
dist/frappe-gantt.min.css
vendored
@ -1 +1 @@
|
||||
.dark>.gantt-container .gantt .grid-header{fill:#252525;stroke:#616161}.dark>.gantt-container .gantt .grid-row{fill:#252525}.dark>.gantt-container .gantt .grid-row:nth-child(even){fill:#3e3e3e}.dark>.gantt-container .gantt .row-line{stroke:#3e3e3e}.dark>.gantt-container .gantt .tick{stroke:#616161}.dark>.gantt-container .gantt .today-highlight{opacity:.2}.dark>.gantt-container .gantt .arrow{stroke:#eee}.dark>.gantt-container .gantt .bar{fill:#616161;stroke:none}.dark>.gantt-container .gantt .bar-progress{fill:#8a8aff}.dark>.gantt-container .gantt .bar-invalid{fill:rgba(0,0,0,0);stroke:#c6ccd2}.dark>.gantt-container .gantt .bar-invalid~.bar-label{fill:#ececec}.dark>.gantt-container .gantt .bar-label.big{fill:#ececec}.dark>.gantt-container .gantt .bar-wrapper:hover .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper:hover .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .bar-wrapper.active .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper.active .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .upper-text{fill:#a2a2a2}.dark>.gantt-container .gantt .lower-text{fill:#f7f7f7}.dark>.gantt-container .popup-wrapper{background-color:#333}.dark>.gantt-container .popup-wrapper .title{border-color:#a4a4ff}.dark>.gantt-container .popup-wrapper .pointer{border-top-color:#333}.gantt{user-select:none;-webkit-user-select:none}.gantt .grid-background{fill:none}.gantt .grid-header{fill:#fff;stroke:#e0e0e0;stroke-width:1.4}.gantt .grid-row{fill:#fff}.gantt .grid-row:nth-child(even){fill:#f5f5f5}.gantt .row-line{stroke:#ebeff2}.gantt .tick{stroke:#e0e0e0;stroke-width:.2}.gantt .tick.thick{stroke-width:.4}.gantt .today-highlight{fill:#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)}
|
||||
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
136
index.html
136
index.html
@ -32,55 +32,56 @@
|
||||
<div class="gantt-target"></div>
|
||||
</div>
|
||||
<script>
|
||||
var tasks = [
|
||||
let tasks = [
|
||||
{
|
||||
start: '2018-10-01',
|
||||
end: '2018-10-08',
|
||||
start: '2024-04-01',
|
||||
end: '2024-04-01',
|
||||
name: 'Redesign website',
|
||||
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',
|
||||
// end: '2019-10-12',
|
||||
@ -89,22 +90,39 @@
|
||||
// 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) => {
|
||||
console.log(task);
|
||||
console.log("Click", task);
|
||||
},
|
||||
on_date_change: (task, start, end) => {
|
||||
console.log(task, start, end);
|
||||
},
|
||||
on_progress_change: (task, progress) => {
|
||||
console.log(task, progress);
|
||||
},
|
||||
on_view_change: (mode) => {
|
||||
console.log(mode);
|
||||
},
|
||||
view_mode: "Half Day",
|
||||
view_mode_padding: { DAY: "1d" },
|
||||
language: "en",
|
||||
// on_double_click: (task) => {
|
||||
// console.log("Double Click", task);
|
||||
// },
|
||||
// on_date_change: (task, start, end) => {
|
||||
// console.log("Date change", task, start, end);
|
||||
// },
|
||||
// on_progress_change: (task, progress) => {
|
||||
// console.log("Progress Change", task, progress);
|
||||
// },
|
||||
// on_view_change: (mode) => {
|
||||
// console.log("View Change", mode);
|
||||
// },
|
||||
// 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);
|
||||
</script>
|
||||
|
||||
@ -26,15 +26,15 @@ export default class Arrow {
|
||||
this.gantt.options.header_height +
|
||||
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;
|
||||
|
||||
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 =
|
||||
this.gantt.options.header_height +
|
||||
this.gantt.options.bar_height / 2 +
|
||||
(this.gantt.options.padding + this.gantt.options.bar_height) *
|
||||
this.to_task.task._index +
|
||||
this.to_task.task._index +
|
||||
this.gantt.options.padding;
|
||||
|
||||
const from_is_below_to =
|
||||
|
||||
205
src/bar.js
205
src/bar.js
@ -23,6 +23,7 @@ export default class Bar {
|
||||
prepare_values() {
|
||||
this.invalid = this.task.invalid;
|
||||
this.height = this.gantt.options.bar_height;
|
||||
this.image_size = this.height - 5;
|
||||
this.compute_x();
|
||||
this.compute_y();
|
||||
this.compute_duration();
|
||||
@ -33,7 +34,7 @@ export default class Bar {
|
||||
this.duration *
|
||||
(this.task.progress / 100) || 0;
|
||||
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,
|
||||
});
|
||||
this.bar_group = createSVG("g", {
|
||||
@ -74,13 +75,17 @@ export default class Bar {
|
||||
|
||||
draw() {
|
||||
this.draw_bar();
|
||||
this.draw_progress_bar();
|
||||
if (this.gantt.options.show_expected_progress) {
|
||||
this.prepare_expected_progress_values();
|
||||
this.draw_expected_progress_bar();
|
||||
}
|
||||
this.draw_progress_bar();
|
||||
this.draw_label();
|
||||
this.draw_resize_handles();
|
||||
|
||||
if (this.task.thumbnail) {
|
||||
this.draw_thumbnail();
|
||||
}
|
||||
}
|
||||
|
||||
draw_bar() {
|
||||
@ -135,13 +140,34 @@ export default class Bar {
|
||||
class: "bar-progress",
|
||||
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);
|
||||
}
|
||||
|
||||
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", {
|
||||
x: this.x + this.width / 2,
|
||||
x: x_coord,
|
||||
y: this.y + this.height / 2,
|
||||
innerHTML: this.task.name,
|
||||
class: "bar-label",
|
||||
@ -150,15 +176,55 @@ export default class Bar {
|
||||
// labels get BBox in the next tick
|
||||
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() {
|
||||
if (this.invalid) return;
|
||||
if (this.invalid || this.gantt.options.readonly) return;
|
||||
|
||||
const bar = this.$bar;
|
||||
const handle_width = 8;
|
||||
|
||||
createSVG("rect", {
|
||||
x: bar.getX() + bar.getWidth() - 9,
|
||||
x: bar.getX() + bar.getWidth() + handle_width - 4,
|
||||
y: bar.getY() + 1,
|
||||
width: handle_width,
|
||||
height: this.height - 2,
|
||||
@ -169,7 +235,7 @@ export default class Bar {
|
||||
});
|
||||
|
||||
createSVG("rect", {
|
||||
x: bar.getX() + 1,
|
||||
x: bar.getX() - handle_width - 4,
|
||||
y: bar.getY() + 1,
|
||||
width: handle_width,
|
||||
height: this.height - 2,
|
||||
@ -188,13 +254,24 @@ export default class Bar {
|
||||
|
||||
get_progress_polygon_points() {
|
||||
const bar_progress = this.$bar_progress;
|
||||
let icon_width = 10;
|
||||
let icon_height = 15;
|
||||
|
||||
return [
|
||||
bar_progress.getEndX() - 5,
|
||||
bar_progress.getY() + bar_progress.getHeight(),
|
||||
bar_progress.getEndX() + 5,
|
||||
bar_progress.getY() + bar_progress.getHeight(),
|
||||
bar_progress.getEndX() - icon_width / 2,
|
||||
bar_progress.getY() + bar_progress.getHeight() / 2,
|
||||
|
||||
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() {
|
||||
$.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;
|
||||
}
|
||||
let task_id = this.task.id;
|
||||
$.on(this.group, "mouseover", (e) => {
|
||||
this.gantt.trigger_event("hover", [this.task, e.screenX, e.screenY, e])
|
||||
})
|
||||
|
||||
this.show_popup();
|
||||
this.gantt.unselect_all();
|
||||
this.group.classList.add("active");
|
||||
let timeout;
|
||||
$.on(this.group, "mouseenter", (e) => timeout = setTimeout(() => {
|
||||
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) => {
|
||||
@ -221,11 +309,11 @@ export default class Bar {
|
||||
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;
|
||||
|
||||
const start_date = date_utils.format(
|
||||
@ -238,9 +326,10 @@ export default class Bar {
|
||||
"MMM D",
|
||||
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({
|
||||
x,
|
||||
target_element: this.$bar,
|
||||
title: this.task.name,
|
||||
subtitle: subtitle,
|
||||
@ -256,7 +345,7 @@ export default class Bar {
|
||||
return this.gantt.get_bar(dep).$bar.getX();
|
||||
});
|
||||
// child task must not go before parent
|
||||
const valid_x = xs.reduce((prev, curr) => {
|
||||
const valid_x = xs.reduce((_, curr) => {
|
||||
return x >= curr;
|
||||
}, x);
|
||||
if (!valid_x) {
|
||||
@ -264,9 +353,11 @@ export default class Bar {
|
||||
return;
|
||||
}
|
||||
this.update_attr(bar, "x", x);
|
||||
this.$date_highlight.style.left = x + 'px'
|
||||
}
|
||||
if (width) {
|
||||
this.update_attr(bar, "width", width);
|
||||
this.$date_highlight.style.width = width + 'px'
|
||||
}
|
||||
this.update_label_position();
|
||||
this.update_handle_position();
|
||||
@ -279,6 +370,37 @@ export default class Bar {
|
||||
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() {
|
||||
let changed = false;
|
||||
const { new_start_date, new_end_date } = this.compute_start_end_date();
|
||||
@ -431,7 +553,7 @@ export default class Bar {
|
||||
}
|
||||
|
||||
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(
|
||||
"width",
|
||||
@ -440,27 +562,46 @@ export default class Bar {
|
||||
}
|
||||
|
||||
update_label_position() {
|
||||
const img_mask = this.bar_group.querySelector('.img_mask') || '';
|
||||
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.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 {
|
||||
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() {
|
||||
if (this.invalid) return;
|
||||
if (this.invalid || this.gantt.options.readonly) return;
|
||||
const bar = this.$bar;
|
||||
this.handle_group
|
||||
.querySelector(".handle.left")
|
||||
.setAttribute("x", bar.getX() + 1);
|
||||
.setAttribute("x", bar.getX() - 12);
|
||||
this.handle_group
|
||||
.querySelector(".handle.right")
|
||||
.setAttribute("x", bar.getEndX() - 9);
|
||||
.setAttribute("x", bar.getEndX() + 4);
|
||||
const handle = this.group.querySelector(".handle.progress");
|
||||
handle && handle.setAttribute("points", this.get_progress_polygon_points());
|
||||
}
|
||||
@ -474,7 +615,7 @@ export default class Bar {
|
||||
}
|
||||
|
||||
function isFunction(functionToCheck) {
|
||||
var getType = {};
|
||||
let getType = {};
|
||||
return (
|
||||
functionToCheck &&
|
||||
getType.toString.call(functionToCheck) === "[object Function]"
|
||||
|
||||
@ -6,6 +6,21 @@ const MINUTE = "minute";
|
||||
const SECOND = "second";
|
||||
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 {
|
||||
parse_duration(duration) {
|
||||
const regex = /([0-9])+(y|m|d|h|min|s|ms)/gm;
|
||||
@ -36,25 +51,23 @@ export default {
|
||||
if (typeof date === "string") {
|
||||
let date_parts, time_parts;
|
||||
const parts = date.split(" ");
|
||||
|
||||
date_parts = parts[0]
|
||||
.split(date_separator)
|
||||
.map((val) => parseInt(val, 10));
|
||||
time_parts = parts[1] && parts[1].split(time_separator);
|
||||
|
||||
// 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;
|
||||
|
||||
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] = parseFloat(time_parts[3]) * 1000;
|
||||
}
|
||||
vals = vals.concat(time_parts);
|
||||
}
|
||||
|
||||
return new Date(...vals);
|
||||
}
|
||||
},
|
||||
@ -100,7 +113,7 @@ export default {
|
||||
SSS: values[6],
|
||||
D: values[2],
|
||||
MMMM: month_name_capitalized,
|
||||
MMM: month_name_capitalized,
|
||||
MMM: SHORTENED[month_name_capitalized],
|
||||
};
|
||||
|
||||
let str = format_string;
|
||||
@ -110,13 +123,13 @@ export default {
|
||||
.sort((a, b) => b.length - a.length) // big string first
|
||||
.forEach((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.forEach((value, i) => {
|
||||
str = str.replace(`$${i}`, value);
|
||||
str = str.replaceAll(`$${i}`, value);
|
||||
});
|
||||
|
||||
return str;
|
||||
@ -229,7 +242,7 @@ export default {
|
||||
|
||||
// Feb
|
||||
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 28;
|
||||
|
||||
282
src/gantt.scss
282
src/gantt.scss
@ -1,107 +1,232 @@
|
||||
@import "./dark.scss";
|
||||
|
||||
$bar-color: #b8c2cc !default;
|
||||
$bar-stroke: #8d99a6 !default;
|
||||
$border-color: #e0e0e0 !default;
|
||||
$bar-color: #fff !default;
|
||||
$bar-color-important: #94c4f4 !default;
|
||||
$bar-stroke: #fff !default;
|
||||
$dark-stroke-color: #e0e0e0 !default;
|
||||
$stroke-color: #EBEEF0 !default;
|
||||
$light-bg: #f5f5f5 !default;
|
||||
$light-border-color: #ebeff2 !default;
|
||||
$light-yellow: #fcf8e3 !default;
|
||||
$light-yellow: #f6e796 !default;
|
||||
$holiday-color: #F9FAFA !default;
|
||||
$text-muted: #666 !default;
|
||||
$text-light: #555 !default;
|
||||
$text-color: #333 !default;
|
||||
$blue: #acacfa !default;
|
||||
$handle-color: #ddd !default;
|
||||
$text-grey: #98A1A9;
|
||||
$text-light: #fff !default;
|
||||
$text-dark: #111 !default;
|
||||
$progress: #EBEEF0 !default;
|
||||
$handle-color: #dcdce4 !default;
|
||||
$handle-color-important: #94c4f4 !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 {
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
position: absolute;
|
||||
|
||||
.grid-background {
|
||||
fill: none;
|
||||
}
|
||||
.grid-header {
|
||||
fill: #ffffff;
|
||||
stroke: $border-color;
|
||||
stroke-width: 1.4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.grid-row {
|
||||
fill: #ffffff;
|
||||
}
|
||||
.grid-row:nth-child(even) {
|
||||
fill: $light-bg;
|
||||
}
|
||||
|
||||
// .grid-row:nth-child(even) {
|
||||
// fill: $light-bg;
|
||||
// }
|
||||
|
||||
.row-line {
|
||||
stroke: $light-border-color;
|
||||
}
|
||||
|
||||
.tick {
|
||||
stroke: $border-color;
|
||||
stroke-width: 0.2;
|
||||
stroke: $stroke-color;
|
||||
stroke-width: 0.4;
|
||||
|
||||
&.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 {
|
||||
fill: $light-yellow;
|
||||
opacity: 0.5;
|
||||
.holiday-highlight {
|
||||
fill: $holiday-color;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
fill: none;
|
||||
stroke: $text-muted;
|
||||
stroke-width: 1.4;
|
||||
stroke: #9FA9B1;
|
||||
stroke-width: 1;
|
||||
}
|
||||
|
||||
.bar {
|
||||
.bar-wrapper .bar {
|
||||
fill: $bar-color;
|
||||
stroke: $bar-stroke;
|
||||
stroke-width: 0;
|
||||
transition: stroke-width 0.3s ease;
|
||||
}
|
||||
|
||||
.bar-progress {
|
||||
fill: $blue;
|
||||
fill: $progress;
|
||||
}
|
||||
|
||||
.bar-expected-progress {
|
||||
fill: $light-blue;
|
||||
}
|
||||
|
||||
.bar-invalid {
|
||||
fill: transparent;
|
||||
stroke: $bar-stroke;
|
||||
stroke-width: 1;
|
||||
stroke-dasharray: 5;
|
||||
|
||||
& ~ .bar-label {
|
||||
&~.bar-label {
|
||||
fill: $text-light;
|
||||
}
|
||||
}
|
||||
|
||||
.bar-label {
|
||||
fill: #fff;
|
||||
fill: $text-dark;
|
||||
dominant-baseline: central;
|
||||
text-anchor: middle;
|
||||
font-size: 12px;
|
||||
font-weight: lighter;
|
||||
// text-anchor: middle;
|
||||
font-family: Helvetica;
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
|
||||
&.big {
|
||||
fill: $text-light;
|
||||
fill: $text-dark;
|
||||
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 {
|
||||
fill: $handle-color;
|
||||
cursor: ew-resize;
|
||||
@ -110,47 +235,39 @@ $light-blue: #c4c4e9 !default;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.handle.progress {
|
||||
fill: $text-muted;
|
||||
}
|
||||
|
||||
.bar-wrapper {
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
|
||||
&:hover {
|
||||
.bar {
|
||||
fill: darken($bar-color, 5);
|
||||
}
|
||||
|
||||
.bar-progress {
|
||||
fill: darken($blue, 5);
|
||||
}
|
||||
|
||||
.handle {
|
||||
&.active {
|
||||
& .handle {
|
||||
visibility: visible;
|
||||
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 {
|
||||
fill: darken($bar-color, 5);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.bar-progress {
|
||||
fill: darken($blue, 5);
|
||||
.date-highlight {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.lower-text,
|
||||
.upper-text {
|
||||
font-size: 12px;
|
||||
text-anchor: middle;
|
||||
}
|
||||
.upper-text {
|
||||
fill: $text-light;
|
||||
}
|
||||
.lower-text {
|
||||
fill: $text-color;
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none;
|
||||
@ -161,24 +278,31 @@ $light-blue: #c4c4e9 !default;
|
||||
position: relative;
|
||||
overflow: auto;
|
||||
font-size: 12px;
|
||||
height: 500px;
|
||||
|
||||
.popup-wrapper {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
padding: 0;
|
||||
color: #959da5;
|
||||
border-radius: 3px;
|
||||
background: #171B1F;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
width: max-content;
|
||||
|
||||
&.hidden {
|
||||
opacity: 0 !important;
|
||||
}
|
||||
|
||||
|
||||
.title {
|
||||
border-bottom: 3px solid $blue;
|
||||
padding: 10px;
|
||||
margin-bottom: 5px;
|
||||
text-align: -webkit-center;
|
||||
text-align: center;
|
||||
color: $text-light;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
padding: 10px;
|
||||
color: #dfe2e5;
|
||||
color: $text-grey;
|
||||
}
|
||||
|
||||
.pointer {
|
||||
@ -186,7 +310,7 @@ $light-blue: #c4c4e9 !default;
|
||||
height: 5px;
|
||||
margin: 0 0 0 -5px;
|
||||
border: 5px solid transparent;
|
||||
border-top-color: rgba(0, 0, 0, 0.8);
|
||||
border-bottom-color: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
474
src/index.js
474
src/index.js
@ -26,6 +26,30 @@ const VIEW_MODE_PADDING = {
|
||||
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 {
|
||||
constructor(wrapper, tasks, options) {
|
||||
this.setup_wrapper(wrapper);
|
||||
@ -78,28 +102,14 @@ export default class Gantt {
|
||||
this.$container.appendChild(this.$svg);
|
||||
|
||||
// popup wrapper
|
||||
this.popup_wrapper = document.createElement("div");
|
||||
this.popup_wrapper.classList.add("popup-wrapper");
|
||||
this.$container.appendChild(this.popup_wrapper);
|
||||
this.$popup_wrapper = document.createElement("div");
|
||||
this.$popup_wrapper.classList.add("popup-wrapper");
|
||||
this.$container.appendChild(this.$popup_wrapper);
|
||||
}
|
||||
|
||||
setup_options(options) {
|
||||
const default_options = {
|
||||
header_height: 50,
|
||||
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);
|
||||
this.options = { ...DEFAULT_OPTIONS, ...options }
|
||||
if (!options.view_mode_padding) options.view_mode_padding = {}
|
||||
for (let [key, value] of Object.entries(options.view_mode_padding)) {
|
||||
if (typeof value === "string") {
|
||||
// Configure for single value given
|
||||
@ -128,12 +138,16 @@ export default class Gantt {
|
||||
});
|
||||
}
|
||||
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
|
||||
if (date_utils.diff(task._end, task._start, "year") > 10) {
|
||||
task.end = null;
|
||||
}
|
||||
|
||||
|
||||
// cache index
|
||||
task._index = i;
|
||||
|
||||
@ -170,7 +184,7 @@ export default class Gantt {
|
||||
if (task.dependencies) {
|
||||
deps = task.dependencies
|
||||
.split(",")
|
||||
.map((d) => d.trim())
|
||||
.map((d) => d.trim().replaceAll(' ', '_'))
|
||||
.filter((d) => d);
|
||||
}
|
||||
task.dependencies = deps;
|
||||
@ -179,6 +193,10 @@ export default class Gantt {
|
||||
// uids
|
||||
if (!task.id) {
|
||||
task.id = generate_id(task);
|
||||
} else if (typeof task.id === 'string') {
|
||||
task.id = task.id.replaceAll(' ', '_')
|
||||
} else {
|
||||
task.id = `${task.id}`
|
||||
}
|
||||
|
||||
return task;
|
||||
@ -269,8 +287,7 @@ export default class Gantt {
|
||||
const [padding_start, padding_end] = this.options.view_mode_padding[
|
||||
viewKey
|
||||
].map(date_utils.parse_duration);
|
||||
|
||||
this.gantt_start = date_utils.add(
|
||||
gantt_start = date_utils.add(
|
||||
gantt_start,
|
||||
-padding_start.duration,
|
||||
padding_start.scale,
|
||||
@ -286,15 +303,8 @@ export default class Gantt {
|
||||
} else {
|
||||
format_string = "YYYY-MM-DD HH"
|
||||
}
|
||||
|
||||
this.gantt_start = new Date(
|
||||
date_utils.format(
|
||||
date_utils.add(gantt_start, -padding_end.duration, padding_end.scale),
|
||||
format_string
|
||||
)
|
||||
);
|
||||
this.gantt_start = date_utils.parse(date_utils.format(gantt_start, format_string));
|
||||
this.gantt_start.setHours(0, 0, 0, 0)
|
||||
|
||||
this.gantt_end = date_utils.add(
|
||||
gantt_end,
|
||||
padding_end.duration,
|
||||
@ -323,6 +333,7 @@ export default class Gantt {
|
||||
}
|
||||
|
||||
bind_events() {
|
||||
if (this.options.readonly) return
|
||||
this.bind_grid_click();
|
||||
this.bind_bar_events();
|
||||
}
|
||||
@ -333,15 +344,16 @@ export default class Gantt {
|
||||
this.make_grid();
|
||||
this.make_dates();
|
||||
this.make_bars();
|
||||
this.make_grid_extras();
|
||||
this.make_arrows();
|
||||
this.map_arrows_on_bars();
|
||||
this.set_width();
|
||||
this.set_scroll_position();
|
||||
this.set_scroll_position(this.options.scroll_to);
|
||||
}
|
||||
|
||||
setup_layers() {
|
||||
this.layers = {};
|
||||
const layers = ["grid", "date", "arrow", "progress", "bar", "details"];
|
||||
const layers = ["grid", "arrow", "progress", "bar", "details"];
|
||||
// make group layers
|
||||
for (let layer of layers) {
|
||||
this.layers[layer] = createSVG("g", {
|
||||
@ -355,8 +367,11 @@ export default class Gantt {
|
||||
this.make_grid_background();
|
||||
this.make_grid_rows();
|
||||
this.make_grid_header();
|
||||
this.make_grid_ticks();
|
||||
}
|
||||
|
||||
make_grid_extras() {
|
||||
this.make_grid_highlights();
|
||||
this.make_grid_ticks();
|
||||
}
|
||||
|
||||
make_grid_background() {
|
||||
@ -372,7 +387,7 @@ export default class Gantt {
|
||||
width: grid_width,
|
||||
height: grid_height,
|
||||
class: "grid-background",
|
||||
append_to: this.layers.grid,
|
||||
append_to: this.$svg,
|
||||
});
|
||||
|
||||
$.attr(this.$svg, {
|
||||
@ -383,14 +398,13 @@ export default class Gantt {
|
||||
|
||||
make_grid_rows() {
|
||||
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_height = this.options.bar_height + this.options.padding;
|
||||
|
||||
let row_y = this.options.header_height + this.options.padding / 2;
|
||||
|
||||
for (let task of this.tasks) {
|
||||
for (let _ of this.tasks) {
|
||||
createSVG("rect", {
|
||||
x: 0,
|
||||
y: row_y,
|
||||
@ -399,39 +413,110 @@ export default class Gantt {
|
||||
class: "grid-row",
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
make_grid_header() {
|
||||
const header_width = this.dates.length * this.options.column_width;
|
||||
const header_height = this.options.header_height + 10;
|
||||
createSVG("rect", {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: header_width,
|
||||
height: header_height,
|
||||
class: "grid-header",
|
||||
append_to: this.layers.grid,
|
||||
});
|
||||
const curHeader = document.querySelector('.grid-header')
|
||||
|
||||
let $header = document.createElement("div");
|
||||
$header.style.height = this.options.header_height + 10 + "px";
|
||||
$header.style.width = this.dates.length * this.options.column_width + "px";
|
||||
$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)
|
||||
|
||||
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() {
|
||||
if (!['both', 'vertical', 'horizontal'].includes(this.options.lines)) return
|
||||
let tick_x = 0;
|
||||
let tick_y = this.options.header_height + this.options.padding / 2;
|
||||
let tick_height =
|
||||
(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) {
|
||||
let tick_class = "tick";
|
||||
// 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
|
||||
computeGridHighlightDimensions(view_mode) {
|
||||
let xDist = 0;
|
||||
let x = this.options.column_width / 2;
|
||||
|
||||
if (this.view_is(VIEW_MODE.DAY)) {
|
||||
return (
|
||||
(date_utils.diff(date_utils.today(), this.gantt_start, "hour") /
|
||||
this.options.step) *
|
||||
this.options.column_width
|
||||
);
|
||||
let today = date_utils.today()
|
||||
return {
|
||||
x: x +
|
||||
(date_utils.diff(today, this.gantt_start, "hour") / this.options.step) *
|
||||
this.options.column_width,
|
||||
date: today
|
||||
}
|
||||
}
|
||||
|
||||
for (let date of this.dates) {
|
||||
@ -494,15 +601,15 @@ export default class Gantt {
|
||||
break;
|
||||
}
|
||||
if (todayDate >= startDate && todayDate <= endDate) {
|
||||
break;
|
||||
return { x, date: startDate }
|
||||
} else {
|
||||
xDist += this.options.column_width;
|
||||
x += this.options.column_width;
|
||||
}
|
||||
}
|
||||
return xDist;
|
||||
}
|
||||
|
||||
make_grid_highlights() {
|
||||
if (this.options.highlight_weekend) this.highlightWeekends()
|
||||
// highlight today's | week's | month's | year's
|
||||
if (
|
||||
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.YEAR)
|
||||
) {
|
||||
const x = this.computeGridHighlightDimensions(this.options.view_mode);
|
||||
const y = 0;
|
||||
const width = this.options.column_width;
|
||||
const height =
|
||||
(this.options.bar_height + this.options.padding) * this.tasks.length +
|
||||
this.options.header_height +
|
||||
this.options.padding / 2;
|
||||
// Used as we must find the _end_ of session if view is not Day
|
||||
const { x: left, date } = this.computeGridHighlightDimensions(this.options.view_mode)
|
||||
const top = this.options.header_height + this.options.padding / 2;
|
||||
const height = (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 })
|
||||
let $today = document.getElementById(date_utils.format(date).replaceAll(' ', '_'))
|
||||
|
||||
let className = "";
|
||||
switch (this.options.view_mode) {
|
||||
case VIEW_MODE.DAY:
|
||||
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,
|
||||
});
|
||||
$today.classList.add('current-date-highlight')
|
||||
$today.style.top = +$today.style.top.slice(0, -2) - 4 + 'px'
|
||||
$today.style.left = +$today.style.left.slice(0, -2) - 8 + 'px'
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
for (let date of this.get_dates_to_draw()) {
|
||||
createSVG("text", {
|
||||
x: date.lower_x,
|
||||
y: date.lower_y,
|
||||
innerHTML: date.lower_text,
|
||||
class: "lower-text",
|
||||
append_to: this.layers.date,
|
||||
});
|
||||
this.upper_texts_x = {}
|
||||
this.get_dates_to_draw().forEach((date, i) => {
|
||||
let $lower_text = this.create_el({
|
||||
left: date.lower_x,
|
||||
top: date.lower_y,
|
||||
id: date.formatted_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) {
|
||||
const $upper_text = createSVG("text", {
|
||||
x: date.upper_x,
|
||||
y: date.upper_y,
|
||||
innerHTML: date.upper_text,
|
||||
class: "upper-text",
|
||||
append_to: this.layers.date,
|
||||
});
|
||||
this.upper_texts_x[date.upper_text] = date.upper_x
|
||||
let $upper_text = document.createElement('div');
|
||||
$upper_text.classList.add('upper-text')
|
||||
$upper_text.style.left = date.upper_x + 'px'
|
||||
$upper_text.style.top = date.upper_y + 'px'
|
||||
$upper_text.innerText = date.upper_text
|
||||
this.$upper_header.appendChild($upper_text)
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
get_dates_to_draw() {
|
||||
let last_date = null;
|
||||
const dates = this.dates.map((date, i) => {
|
||||
const d = this.get_date_info(date, last_date, i);
|
||||
last_date = date;
|
||||
last_date = d;
|
||||
return d;
|
||||
});
|
||||
return dates;
|
||||
}
|
||||
|
||||
get_date_info(date, last_date, i) {
|
||||
if (!last_date) {
|
||||
last_date = date_utils.add(date, 1, "day");
|
||||
}
|
||||
get_date_info(date, last_date_info) {
|
||||
let last_date = last_date_info ? last_date_info.date : date_utils.add(date, 1, "day")
|
||||
const date_text = {
|
||||
Hour_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)
|
||||
: "",
|
||||
Day_upper:
|
||||
date.getMonth() !== last_date.getMonth()
|
||||
date.getMonth() !== last_date.getMonth() || !last_date_info
|
||||
? date_utils.format(date, "MMMM", this.options.language)
|
||||
: "",
|
||||
Week_upper:
|
||||
@ -630,33 +729,37 @@ export default class Gantt {
|
||||
? 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 = {
|
||||
x: i * this.options.column_width,
|
||||
lower_y: this.options.header_height,
|
||||
upper_y: this.options.header_height - 25,
|
||||
x: last_date_info
|
||||
? last_date_info.base_pos_x + last_date_info.column_width
|
||||
: 0,
|
||||
lower_y: this.options.header_height - 20,
|
||||
upper_y: this.options.header_height - 50,
|
||||
};
|
||||
|
||||
const x_pos = {
|
||||
Hour_lower: this.options.column_width / 2,
|
||||
Hour_upper: this.options.column_width * 12,
|
||||
"Quarter Day_lower": this.options.column_width / 2,
|
||||
"Quarter Day_upper": this.options.column_width * 2,
|
||||
"Half Day_lower": this.options.column_width / 2,
|
||||
"Half Day_upper": this.options.column_width,
|
||||
Day_lower: this.options.column_width / 2,
|
||||
Day_upper: (this.options.column_width * 30) / 2,
|
||||
Week_lower: 0,
|
||||
Week_upper: (this.options.column_width * 4) / 2,
|
||||
Month_lower: this.options.column_width / 2,
|
||||
Month_upper: (this.options.column_width * 12) / 2,
|
||||
Year_lower: this.options.column_width / 2,
|
||||
Year_upper: (this.options.column_width * 30) / 2,
|
||||
Hour_lower: column_width / 2,
|
||||
Hour_upper: column_width * 12,
|
||||
"Quarter Day_lower": column_width / 2,
|
||||
"Quarter Day_upper": column_width * 2,
|
||||
"Half Day_lower": column_width / 2,
|
||||
"Half Day_upper": column_width,
|
||||
Day_lower: column_width / 2,
|
||||
Day_upper: column_width / 2,
|
||||
Week_lower: column_width / 2,
|
||||
Week_upper: (column_width * 4) / 2,
|
||||
Month_lower: column_width / 2,
|
||||
Month_upper: column_width / 2,
|
||||
Year_lower: column_width / 2,
|
||||
Year_upper: (column_width * 30) / 2,
|
||||
};
|
||||
|
||||
return {
|
||||
upper_text: date_text[`${this.options.view_mode}_upper`],
|
||||
lower_text: date_text[`${this.options.view_mode}_lower`],
|
||||
date,
|
||||
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_y: base_pos.upper_y,
|
||||
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;
|
||||
if (!parent_element) return;
|
||||
|
||||
const hours_before_first_task = date_utils.diff(
|
||||
this.get_oldest_starting_date(),
|
||||
date,
|
||||
this.gantt_start,
|
||||
"hour",
|
||||
);
|
||||
) + 24;
|
||||
|
||||
const scroll_pos =
|
||||
(hours_before_first_task / this.options.step) *
|
||||
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() {
|
||||
@ -747,6 +861,7 @@ export default class Gantt {
|
||||
bind_bar_events() {
|
||||
let is_dragging = false;
|
||||
let x_on_start = 0;
|
||||
let x_on_scroll_start = 0;
|
||||
let y_on_start = 0;
|
||||
let is_resizing_left = false;
|
||||
let is_resizing_right = false;
|
||||
@ -760,6 +875,7 @@ export default class Gantt {
|
||||
|
||||
$.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (e, element) => {
|
||||
const bar_wrapper = $.closest(".bar-wrapper", element);
|
||||
bars.forEach((bar) => bar.group.classList.remove("active"));
|
||||
|
||||
if (element.classList.contains("left")) {
|
||||
is_resizing_left = true;
|
||||
@ -770,6 +886,7 @@ export default class Gantt {
|
||||
}
|
||||
|
||||
bar_wrapper.classList.add("active");
|
||||
this.popup.parent.classList.add('hidden')
|
||||
|
||||
x_on_start = e.offsetX;
|
||||
y_on_start = e.offsetY;
|
||||
@ -791,6 +908,58 @@ export default class Gantt {
|
||||
$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) => {
|
||||
if (!action_in_progress()) return;
|
||||
@ -818,16 +987,13 @@ export default class Gantt {
|
||||
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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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_resizing_left = false;
|
||||
@ -894,8 +1060,13 @@ export default class Gantt {
|
||||
$.on(this.$svg, "mouseup", () => {
|
||||
is_resizing = false;
|
||||
if (!($bar_progress && $bar_progress.finaldx)) return;
|
||||
|
||||
$bar_progress.finaldx = 0;
|
||||
bar.progress_changed();
|
||||
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) => {
|
||||
el.classList.remove("active");
|
||||
});
|
||||
this.popup.parent.classList.remove('hidden')
|
||||
}
|
||||
|
||||
view_is(modes) {
|
||||
@ -977,10 +1149,11 @@ export default class Gantt {
|
||||
}
|
||||
|
||||
show_popup(options) {
|
||||
if (this.options.popup === false) return
|
||||
if (!this.popup) {
|
||||
this.popup = new Popup(
|
||||
this.popup_wrapper,
|
||||
this.options.custom_popup_html,
|
||||
this.$popup_wrapper,
|
||||
this.options.popup,
|
||||
);
|
||||
}
|
||||
this.popup.show(options);
|
||||
@ -1018,6 +1191,9 @@ export default class Gantt {
|
||||
*/
|
||||
clear() {
|
||||
this.$svg.innerHTML = "";
|
||||
this.$header?.remove?.()
|
||||
this.$current_highlight?.remove?.()
|
||||
this.popup?.hide?.()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
src/popup.js
16
src/popup.js
@ -23,9 +23,6 @@ export default class Popup {
|
||||
if (!options.target_element) {
|
||||
throw new Error("target_element is required to show popup");
|
||||
}
|
||||
if (!options.position) {
|
||||
options.position = "left";
|
||||
}
|
||||
const target_element = options.target_element;
|
||||
|
||||
if (this.custom_html) {
|
||||
@ -37,7 +34,6 @@ export default class Popup {
|
||||
// set data
|
||||
this.title.innerHTML = options.title;
|
||||
this.subtitle.innerHTML = options.subtitle;
|
||||
this.parent.style.width = this.parent.clientWidth + "px";
|
||||
}
|
||||
|
||||
// set position
|
||||
@ -48,15 +44,11 @@ export default class Popup {
|
||||
position_meta = options.target_element.getBBox();
|
||||
}
|
||||
|
||||
if (options.position === "left") {
|
||||
this.parent.style.left =
|
||||
position_meta.x + (position_meta.width + 10) + "px";
|
||||
this.parent.style.top = position_meta.y + "px";
|
||||
this.parent.style.left = options.x - this.parent.clientWidth / 2 + "px";
|
||||
this.parent.style.top = position_meta.y + position_meta.height + 10 + "px";
|
||||
|
||||
this.pointer.style.transform = "rotateZ(90deg)";
|
||||
this.pointer.style.left = "-7px";
|
||||
this.pointer.style.top = "2px";
|
||||
}
|
||||
this.pointer.style.left = this.parent.clientWidth / 2 + "px";
|
||||
this.pointer.style.top = "-15px";
|
||||
|
||||
// show
|
||||
this.parent.style.opacity = 1;
|
||||
|
||||
@ -12,6 +12,8 @@ export function createSVG(tag, attrs) {
|
||||
parent.appendChild(elem);
|
||||
} else if (attr === "innerHTML") {
|
||||
elem.innerHTML = attrs.innerHTML;
|
||||
} else if (attr === 'clipPath') {
|
||||
elem.setAttribute('clip-path', 'url(#' + attrs[attr] + ')');
|
||||
} else {
|
||||
elem.setAttribute(attr, attrs[attr]);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user