chore: format (add prettier), fix minor bug, build
This commit is contained in:
parent
a0c7cd36bd
commit
f9da6ad42f
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@ -0,0 +1 @@
|
||||
dist
|
||||
1
.prettierrc
Normal file
1
.prettierrc
Normal file
@ -0,0 +1 @@
|
||||
{}
|
||||
23
README.md
23
README.md
@ -16,18 +16,22 @@
|
||||
</p>
|
||||
|
||||
### Install
|
||||
|
||||
```
|
||||
npm install frappe-gantt
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
Include it in your HTML:
|
||||
|
||||
```
|
||||
<script src="frappe-gantt.min.js"></script>
|
||||
<link rel="stylesheet" href="frappe-gantt.css">
|
||||
```
|
||||
|
||||
And start hacking:
|
||||
|
||||
```js
|
||||
var tasks = [
|
||||
{
|
||||
@ -45,20 +49,21 @@ var gantt = new Gantt("#gantt", tasks);
|
||||
```
|
||||
|
||||
You can also pass various options to the Gantt constructor:
|
||||
|
||||
```js
|
||||
var gantt = new Gantt("#gantt", tasks, {
|
||||
header_height: 50,
|
||||
column_width: 30,
|
||||
step: 24,
|
||||
view_modes: ['Quarter Day', 'Half Day', 'Day', 'Week', 'Month'],
|
||||
view_modes: ["Quarter Day", "Half Day", "Day", "Week", "Month"],
|
||||
bar_height: 20,
|
||||
bar_corner_radius: 3,
|
||||
arrow_curve: 5,
|
||||
padding: 18,
|
||||
view_mode: 'Day',
|
||||
date_format: 'YYYY-MM-DD',
|
||||
language: 'en', // or 'es', 'it', 'ru', 'ptBr', 'fr', 'tr', 'zh', 'de', 'hu'
|
||||
custom_popup_html: null
|
||||
view_mode: "Day",
|
||||
date_format: "YYYY-MM-DD",
|
||||
language: "en", // or 'es', 'it', 'ru', 'ptBr', 'fr', 'tr', 'zh', 'de', 'hu'
|
||||
custom_popup_html: null,
|
||||
});
|
||||
```
|
||||
|
||||
@ -69,6 +74,7 @@ You can add `dark` class to the container element to apply dark theme.
|
||||
```
|
||||
|
||||
### Contributing
|
||||
|
||||
If you want to contribute enhancements or fixes:
|
||||
|
||||
1. Clone this repo.
|
||||
@ -78,6 +84,7 @@ If you want to contribute enhancements or fixes:
|
||||
5. Open `index.html` in your browser, make your code changes and test them.
|
||||
|
||||
### Publishing
|
||||
|
||||
If you have publishing rights (Frappe Team), follow these steps to publish a new version.
|
||||
|
||||
Assuming the last commit (or a couple of commits) were enhancements or fixes,
|
||||
@ -85,15 +92,18 @@ Assuming the last commit (or a couple of commits) were enhancements or fixes,
|
||||
1. Run `yarn build`
|
||||
|
||||
This will generate files in the `dist/` folder. These files need to be committed.
|
||||
|
||||
1. Run `yarn publish`
|
||||
1. Type the new version at the prompt
|
||||
|
||||
Depending on the type of change, you can either bump the patch version or the minor version.
|
||||
For e.g.,
|
||||
|
||||
```
|
||||
0.5.0 -> 0.6.0 (minor version bump)
|
||||
0.5.0 -> 0.5.1 (patch version bump)
|
||||
```
|
||||
|
||||
1. Now, there will be a commit named after the version you just entered. Include the generated files in `dist/` folder as part of this commit by running the command:
|
||||
```
|
||||
git add dist
|
||||
@ -103,5 +113,6 @@ Assuming the last commit (or a couple of commits) were enhancements or fixes,
|
||||
|
||||
License: MIT
|
||||
|
||||
------------------
|
||||
---
|
||||
|
||||
Project maintained by [frappe](https://github.com/frappe)
|
||||
|
||||
24
dist/frappe-gantt.css
vendored
24
dist/frappe-gantt.css
vendored
@ -66,6 +66,10 @@
|
||||
border-top-color: #333;
|
||||
}
|
||||
|
||||
.gantt {
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
.gantt .grid-background {
|
||||
fill: none;
|
||||
}
|
||||
@ -94,6 +98,18 @@
|
||||
fill: #fcf8e3;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.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 .arrow {
|
||||
fill: none;
|
||||
stroke: #666;
|
||||
@ -101,10 +117,9 @@
|
||||
}
|
||||
.gantt .bar {
|
||||
fill: #b8c2cc;
|
||||
stroke: #8D99A6;
|
||||
stroke: #8d99a6;
|
||||
stroke-width: 0;
|
||||
transition: stroke-width 0.3s ease;
|
||||
user-select: none;
|
||||
}
|
||||
.gantt .bar-progress {
|
||||
fill: #acacfa;
|
||||
@ -114,7 +129,7 @@
|
||||
}
|
||||
.gantt .bar-invalid {
|
||||
fill: transparent;
|
||||
stroke: #8D99A6;
|
||||
stroke: #8d99a6;
|
||||
stroke-width: 1;
|
||||
stroke-dasharray: 5;
|
||||
}
|
||||
@ -159,7 +174,8 @@
|
||||
.gantt .bar-wrapper.active .bar-progress {
|
||||
fill: #9494f9;
|
||||
}
|
||||
.gantt .lower-text, .gantt .upper-text {
|
||||
.gantt .lower-text,
|
||||
.gantt .upper-text {
|
||||
font-size: 12px;
|
||||
text-anchor: middle;
|
||||
}
|
||||
|
||||
742
dist/frappe-gantt.js
vendored
742
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 .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 .arrow{fill:none;stroke:#666;stroke-width:1.4}.gantt .bar{fill:#b8c2cc;stroke:#8d99a6;stroke-width:0;transition:stroke-width .3s ease;user-select:none}.gantt .bar-progress{fill:#a3a3ff}.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:#8a8aff}.gantt .bar-wrapper:hover .handle{visibility:visible;opacity:1}.gantt .bar-wrapper.active .bar{fill:#a9b5c1}.gantt .bar-wrapper.active .bar-progress{fill:#8a8aff}.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 #a3a3ff;padding:10px}.gantt-container .popup-wrapper .subtitle{padding:10px;color:#dfe2e5}.gantt-container .popup-wrapper .pointer{position:absolute;height:5px;margin:0 0 0 -5px;border:5px solid rgba(0,0,0,0);border-top-color:rgba(0,0,0,.8)}
|
||||
.dark>.gantt-container .gantt .grid-header{fill:#252525;stroke:#616161}.dark>.gantt-container .gantt .grid-row{fill:#252525}.dark>.gantt-container .gantt .grid-row:nth-child(even){fill:#3e3e3e}.dark>.gantt-container .gantt .row-line{stroke:#3e3e3e}.dark>.gantt-container .gantt .tick{stroke:#616161}.dark>.gantt-container .gantt .today-highlight{opacity:.2}.dark>.gantt-container .gantt .arrow{stroke:#eee}.dark>.gantt-container .gantt .bar{fill:#616161;stroke:none}.dark>.gantt-container .gantt .bar-progress{fill:#8a8aff}.dark>.gantt-container .gantt .bar-invalid{fill:rgba(0,0,0,0);stroke:#c6ccd2}.dark>.gantt-container .gantt .bar-invalid~.bar-label{fill:#ececec}.dark>.gantt-container .gantt .bar-label.big{fill:#ececec}.dark>.gantt-container .gantt .bar-wrapper:hover .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper:hover .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .bar-wrapper.active .bar{fill:#6e6e6e}.dark>.gantt-container .gantt .bar-wrapper.active .bar-progress{fill:#a4a4ff}.dark>.gantt-container .gantt .upper-text{fill:#a2a2a2}.dark>.gantt-container .gantt .lower-text{fill:#f7f7f7}.dark>.gantt-container .popup-wrapper{background-color:#333}.dark>.gantt-container .popup-wrapper .title{border-color:#a4a4ff}.dark>.gantt-container .popup-wrapper .pointer{border-top-color:#333}.gantt{user-select:none;-webkit-user-select:none}.gantt .grid-background{fill:none}.gantt .grid-header{fill:#fff;stroke:#e0e0e0;stroke-width:1.4}.gantt .grid-row{fill:#fff}.gantt .grid-row:nth-child(even){fill:#f5f5f5}.gantt .row-line{stroke:#ebeff2}.gantt .tick{stroke:#e0e0e0;stroke-width:.2}.gantt .tick.thick{stroke-width:.4}.gantt .today-highlight{fill:#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)}
|
||||
2
dist/frappe-gantt.min.js
vendored
2
dist/frappe-gantt.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-gantt.min.js.map
vendored
2
dist/frappe-gantt.min.js.map
vendored
File diff suppressed because one or more lines are too long
111
index.html
111
index.html
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="UTF-8" />
|
||||
<title>Simple Gantt</title>
|
||||
<style>
|
||||
body {
|
||||
@ -38,59 +38,59 @@
|
||||
end: '2018-10-08',
|
||||
name: 'Redesign website',
|
||||
id: "Task 0",
|
||||
progress: 20
|
||||
progress: 100
|
||||
},
|
||||
{
|
||||
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',
|
||||
name: 'Long term task',
|
||||
id: "Task 6",
|
||||
progress: 0
|
||||
}
|
||||
]
|
||||
// {
|
||||
// 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',
|
||||
// name: 'Long term task',
|
||||
// id: "Task 6",
|
||||
// progress: 0
|
||||
// }
|
||||
];
|
||||
var gantt_chart = new Gantt(".gantt-target", tasks, {
|
||||
on_click: task => {
|
||||
on_click: (task) => {
|
||||
console.log(task);
|
||||
},
|
||||
on_date_change: (task, start, end) => {
|
||||
@ -102,8 +102,9 @@
|
||||
on_view_change: (mode) => {
|
||||
console.log(mode);
|
||||
},
|
||||
view_mode: 'Month',
|
||||
language: 'en'
|
||||
view_mode: "Half Day",
|
||||
view_mode_padding: { DAY: "1d" },
|
||||
language: "en",
|
||||
});
|
||||
console.log(gantt_chart);
|
||||
</script>
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
"eslint-config-prettier": "^2.9.0",
|
||||
"eslint-plugin-prettier": "^2.6.0",
|
||||
"jest": "^22.2.1",
|
||||
"prettier": "^2.6.2",
|
||||
"prettier": "3.2.5",
|
||||
"rollup": "^2.70.2",
|
||||
"rollup-plugin-sass": "^1.2.12",
|
||||
"rollup-plugin-terser": "^7.0.2"
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import sass from 'rollup-plugin-sass';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import sass from "rollup-plugin-sass";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
|
||||
const dev = {
|
||||
input: 'src/index.js',
|
||||
input: "src/index.js",
|
||||
output: {
|
||||
name: 'Gantt',
|
||||
file: 'dist/frappe-gantt.js',
|
||||
name: "Gantt",
|
||||
file: "dist/frappe-gantt.js",
|
||||
sourcemap: true,
|
||||
format: 'iife',
|
||||
format: "iife",
|
||||
},
|
||||
plugins: [
|
||||
sass({
|
||||
@ -16,18 +16,18 @@ const dev = {
|
||||
],
|
||||
};
|
||||
const prod = {
|
||||
input: 'src/index.js',
|
||||
input: "src/index.js",
|
||||
output: {
|
||||
name: 'Gantt',
|
||||
file: 'dist/frappe-gantt.min.js',
|
||||
name: "Gantt",
|
||||
file: "dist/frappe-gantt.min.js",
|
||||
sourcemap: true,
|
||||
format: 'iife',
|
||||
format: "iife",
|
||||
},
|
||||
plugins: [
|
||||
sass({
|
||||
output: true,
|
||||
options: {
|
||||
outputStyle: 'compressed',
|
||||
outputStyle: "compressed",
|
||||
},
|
||||
}),
|
||||
terser(),
|
||||
|
||||
14
src/arrow.js
14
src/arrow.js
@ -1,4 +1,4 @@
|
||||
import { createSVG } from './svg_utils';
|
||||
import { createSVG } from "./svg_utils";
|
||||
|
||||
export default class Arrow {
|
||||
constructor(gantt, from_task, to_task) {
|
||||
@ -61,9 +61,7 @@ export default class Arrow {
|
||||
) {
|
||||
const down_1 = this.gantt.options.padding / 2 - curve;
|
||||
const down_2 =
|
||||
this.to_task.$bar.getY() +
|
||||
this.to_task.$bar.getHeight() / 2 -
|
||||
curve_y;
|
||||
this.to_task.$bar.getY() + this.to_task.$bar.getHeight() / 2 - curve_y;
|
||||
const left = this.to_task.$bar.getX() - this.gantt.options.padding;
|
||||
|
||||
this.path = `
|
||||
@ -82,15 +80,15 @@ export default class Arrow {
|
||||
}
|
||||
|
||||
draw() {
|
||||
this.element = createSVG('path', {
|
||||
this.element = createSVG("path", {
|
||||
d: this.path,
|
||||
'data-from': this.from_task.task.id,
|
||||
'data-to': this.to_task.task.id,
|
||||
"data-from": this.from_task.task.id,
|
||||
"data-to": this.to_task.task.id,
|
||||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
this.calculate_path();
|
||||
this.element.setAttribute('d', this.path);
|
||||
this.element.setAttribute("d", this.path);
|
||||
}
|
||||
}
|
||||
|
||||
173
src/bar.js
173
src/bar.js
@ -1,5 +1,5 @@
|
||||
import date_utils from './date_utils';
|
||||
import { $, createSVG, animateSVG } from './svg_utils';
|
||||
import date_utils from "./date_utils";
|
||||
import { $, createSVG, animateSVG } from "./svg_utils";
|
||||
|
||||
export default class Bar {
|
||||
constructor(gantt, task) {
|
||||
@ -32,32 +32,32 @@ export default class Bar {
|
||||
this.gantt.options.column_width *
|
||||
this.duration *
|
||||
(this.task.progress / 100) || 0;
|
||||
this.group = createSVG('g', {
|
||||
class: 'bar-wrapper ' + (this.task.custom_class || ''),
|
||||
'data-id': this.task.id,
|
||||
this.group = createSVG("g", {
|
||||
class: "bar-wrapper " + (this.task.custom_class || ""),
|
||||
"data-id": this.task.id,
|
||||
});
|
||||
this.bar_group = createSVG('g', {
|
||||
class: 'bar-group',
|
||||
this.bar_group = createSVG("g", {
|
||||
class: "bar-group",
|
||||
append_to: this.group,
|
||||
});
|
||||
this.handle_group = createSVG('g', {
|
||||
class: 'handle-group',
|
||||
this.handle_group = createSVG("g", {
|
||||
class: "handle-group",
|
||||
append_to: this.group,
|
||||
});
|
||||
}
|
||||
|
||||
prepare_helpers() {
|
||||
SVGElement.prototype.getX = function () {
|
||||
return +this.getAttribute('x');
|
||||
return +this.getAttribute("x");
|
||||
};
|
||||
SVGElement.prototype.getY = function () {
|
||||
return +this.getAttribute('y');
|
||||
return +this.getAttribute("y");
|
||||
};
|
||||
SVGElement.prototype.getWidth = function () {
|
||||
return +this.getAttribute('width');
|
||||
return +this.getAttribute("width");
|
||||
};
|
||||
SVGElement.prototype.getHeight = function () {
|
||||
return +this.getAttribute('height');
|
||||
return +this.getAttribute("height");
|
||||
};
|
||||
SVGElement.prototype.getEndX = function () {
|
||||
return this.getX() + this.getWidth();
|
||||
@ -84,62 +84,67 @@ export default class Bar {
|
||||
}
|
||||
|
||||
draw_bar() {
|
||||
this.$bar = createSVG('rect', {
|
||||
this.$bar = createSVG("rect", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
rx: this.corner_radius,
|
||||
ry: this.corner_radius,
|
||||
class: 'bar',
|
||||
class: "bar",
|
||||
append_to: this.bar_group,
|
||||
});
|
||||
|
||||
animateSVG(this.$bar, 'width', 0, this.width);
|
||||
animateSVG(this.$bar, "width", 0, this.width);
|
||||
|
||||
if (this.invalid) {
|
||||
this.$bar.classList.add('bar-invalid');
|
||||
this.$bar.classList.add("bar-invalid");
|
||||
}
|
||||
}
|
||||
|
||||
draw_expected_progress_bar() {
|
||||
if (this.invalid) return;
|
||||
this.$expected_bar_progress = createSVG('rect', {
|
||||
this.$expected_bar_progress = createSVG("rect", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: this.expected_progress_width,
|
||||
height: this.height,
|
||||
rx: this.corner_radius,
|
||||
ry: this.corner_radius,
|
||||
class: 'bar-expected-progress',
|
||||
class: "bar-expected-progress",
|
||||
append_to: this.bar_group,
|
||||
});
|
||||
|
||||
animateSVG(this.$expected_bar_progress, 'width', 0, this.expected_progress_width);
|
||||
animateSVG(
|
||||
this.$expected_bar_progress,
|
||||
"width",
|
||||
0,
|
||||
this.expected_progress_width,
|
||||
);
|
||||
}
|
||||
|
||||
draw_progress_bar() {
|
||||
if (this.invalid) return;
|
||||
this.$bar_progress = createSVG('rect', {
|
||||
this.$bar_progress = createSVG("rect", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: this.progress_width,
|
||||
height: this.height,
|
||||
rx: this.corner_radius,
|
||||
ry: this.corner_radius,
|
||||
class: 'bar-progress',
|
||||
class: "bar-progress",
|
||||
append_to: this.bar_group,
|
||||
});
|
||||
|
||||
animateSVG(this.$bar_progress, 'width', 0, this.progress_width);
|
||||
animateSVG(this.$bar_progress, "width", 0, this.progress_width);
|
||||
}
|
||||
|
||||
draw_label() {
|
||||
createSVG('text', {
|
||||
createSVG("text", {
|
||||
x: this.x + this.width / 2,
|
||||
y: this.y + this.height / 2,
|
||||
innerHTML: this.task.name,
|
||||
class: 'bar-label',
|
||||
class: "bar-label",
|
||||
append_to: this.bar_group,
|
||||
});
|
||||
// labels get BBox in the next tick
|
||||
@ -152,36 +157,34 @@ export default class Bar {
|
||||
const bar = this.$bar;
|
||||
const handle_width = 8;
|
||||
|
||||
createSVG('rect', {
|
||||
createSVG("rect", {
|
||||
x: bar.getX() + bar.getWidth() - 9,
|
||||
y: bar.getY() + 1,
|
||||
width: handle_width,
|
||||
height: this.height - 2,
|
||||
rx: this.corner_radius,
|
||||
ry: this.corner_radius,
|
||||
class: 'handle right',
|
||||
class: "handle right",
|
||||
append_to: this.handle_group,
|
||||
});
|
||||
|
||||
createSVG('rect', {
|
||||
createSVG("rect", {
|
||||
x: bar.getX() + 1,
|
||||
y: bar.getY() + 1,
|
||||
width: handle_width,
|
||||
height: this.height - 2,
|
||||
rx: this.corner_radius,
|
||||
ry: this.corner_radius,
|
||||
class: 'handle left',
|
||||
class: "handle left",
|
||||
append_to: this.handle_group,
|
||||
});
|
||||
|
||||
if (this.task.progress < 100) {
|
||||
this.$handle_progress = createSVG('polygon', {
|
||||
points: this.get_progress_polygon_points().join(','),
|
||||
class: 'handle progress',
|
||||
this.$handle_progress = createSVG("polygon", {
|
||||
points: this.get_progress_polygon_points().join(","),
|
||||
class: "handle progress",
|
||||
append_to: this.handle_group,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get_progress_polygon_points() {
|
||||
const bar_progress = this.$bar_progress;
|
||||
@ -201,7 +204,7 @@ export default class Bar {
|
||||
}
|
||||
|
||||
setup_click_event() {
|
||||
$.on(this.group, 'focus ' + this.gantt.options.popup_trigger, (e) => {
|
||||
$.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;
|
||||
@ -209,16 +212,16 @@ export default class Bar {
|
||||
|
||||
this.show_popup();
|
||||
this.gantt.unselect_all();
|
||||
this.group.classList.add('active');
|
||||
this.group.classList.add("active");
|
||||
});
|
||||
|
||||
$.on(this.group, 'dblclick', (e) => {
|
||||
$.on(this.group, "dblclick", (e) => {
|
||||
if (this.action_completed) {
|
||||
// just finished a move action, wait for a few seconds
|
||||
return;
|
||||
}
|
||||
|
||||
this.gantt.trigger_event('click', [this.task]);
|
||||
this.gantt.trigger_event("click", [this.task]);
|
||||
});
|
||||
}
|
||||
|
||||
@ -227,15 +230,15 @@ export default class Bar {
|
||||
|
||||
const start_date = date_utils.format(
|
||||
this.task._start,
|
||||
'MMM D',
|
||||
this.gantt.options.language
|
||||
"MMM D",
|
||||
this.gantt.options.language,
|
||||
);
|
||||
const end_date = date_utils.format(
|
||||
date_utils.add(this.task._end, -1, 'second'),
|
||||
'MMM D',
|
||||
this.gantt.options.language
|
||||
date_utils.add(this.task._end, -1, "second"),
|
||||
"MMM D",
|
||||
this.gantt.options.language,
|
||||
);
|
||||
const subtitle = start_date + ' - ' + end_date;
|
||||
const subtitle = start_date + " - " + end_date;
|
||||
|
||||
this.gantt.show_popup({
|
||||
target_element: this.$bar,
|
||||
@ -260,10 +263,10 @@ export default class Bar {
|
||||
width = null;
|
||||
return;
|
||||
}
|
||||
this.update_attr(bar, 'x', x);
|
||||
this.update_attr(bar, "x", x);
|
||||
}
|
||||
if (width) {
|
||||
this.update_attr(bar, 'width', width);
|
||||
this.update_attr(bar, "width", width);
|
||||
}
|
||||
this.update_label_position();
|
||||
this.update_handle_position();
|
||||
@ -292,17 +295,17 @@ export default class Bar {
|
||||
|
||||
if (!changed) return;
|
||||
|
||||
this.gantt.trigger_event('date_change', [
|
||||
this.gantt.trigger_event("date_change", [
|
||||
this.task,
|
||||
new_start_date,
|
||||
date_utils.add(new_end_date, -1, 'second'),
|
||||
date_utils.add(new_end_date, -1, "second"),
|
||||
]);
|
||||
}
|
||||
|
||||
progress_changed() {
|
||||
const new_progress = this.compute_progress();
|
||||
this.task.progress = new_progress;
|
||||
this.gantt.trigger_event('progress_change', [this.task, new_progress]);
|
||||
this.gantt.trigger_event("progress_change", [this.task, new_progress]);
|
||||
}
|
||||
|
||||
set_action_completed() {
|
||||
@ -316,13 +319,13 @@ export default class Bar {
|
||||
const new_start_date = date_utils.add(
|
||||
this.gantt.gantt_start,
|
||||
x_in_units * this.gantt.options.step,
|
||||
'hour'
|
||||
"hour",
|
||||
);
|
||||
const width_in_units = bar.getWidth() / this.gantt.options.column_width;
|
||||
const new_end_date = date_utils.add(
|
||||
new_start_date,
|
||||
width_in_units * this.gantt.options.step,
|
||||
'hour'
|
||||
"hour",
|
||||
);
|
||||
|
||||
return { new_start_date, new_end_date };
|
||||
@ -335,8 +338,15 @@ export default class Bar {
|
||||
}
|
||||
|
||||
compute_expected_progress() {
|
||||
this.expected_progress = date_utils.diff(date_utils.today(), this.task._start, 'hour') / this.gantt.options.step;
|
||||
this.expected_progress = ((this.expected_progress < this.duration) ? this.expected_progress : this.duration) * 100 / this.duration;
|
||||
this.expected_progress =
|
||||
date_utils.diff(date_utils.today(), this.task._start, "hour") /
|
||||
this.gantt.options.step;
|
||||
this.expected_progress =
|
||||
((this.expected_progress < this.duration
|
||||
? this.expected_progress
|
||||
: this.duration) *
|
||||
100) /
|
||||
this.duration;
|
||||
}
|
||||
|
||||
compute_x() {
|
||||
@ -344,26 +354,26 @@ export default class Bar {
|
||||
const task_start = this.task._start;
|
||||
const gantt_start = this.gantt.gantt_start;
|
||||
|
||||
const diff = date_utils.diff(task_start, gantt_start, 'hour');
|
||||
const diff = date_utils.diff(task_start, gantt_start, "hour");
|
||||
let x = (diff / step) * column_width;
|
||||
|
||||
if (this.gantt.view_is('Month')) {
|
||||
const diff = date_utils.diff(task_start, gantt_start, 'day');
|
||||
if (this.gantt.view_is("Month")) {
|
||||
const diff = date_utils.diff(task_start, gantt_start, "day");
|
||||
x = (diff * column_width) / 30;
|
||||
}
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
compute_y() {
|
||||
this.y = (
|
||||
this.y =
|
||||
this.gantt.options.header_height +
|
||||
this.gantt.options.padding +
|
||||
this.task._index * (this.height + this.gantt.options.padding)
|
||||
);
|
||||
this.task._index * (this.height + this.gantt.options.padding);
|
||||
}
|
||||
|
||||
compute_duration() {
|
||||
this.duration = date_utils.diff(this.task._end, this.task._start, 'hour') /
|
||||
this.duration =
|
||||
date_utils.diff(this.task._end, this.task._start, "hour") /
|
||||
this.gantt.options.step;
|
||||
}
|
||||
|
||||
@ -372,7 +382,7 @@ export default class Bar {
|
||||
rem,
|
||||
position;
|
||||
|
||||
if (this.gantt.view_is('Week')) {
|
||||
if (this.gantt.view_is("Week")) {
|
||||
rem = dx % (this.gantt.options.column_width / 7);
|
||||
position =
|
||||
odx -
|
||||
@ -380,7 +390,7 @@ export default class Bar {
|
||||
(rem < this.gantt.options.column_width / 14
|
||||
? 0
|
||||
: this.gantt.options.column_width / 7);
|
||||
} else if (this.gantt.view_is('Month')) {
|
||||
} else if (this.gantt.view_is("Month")) {
|
||||
rem = dx % (this.gantt.options.column_width / 30);
|
||||
position =
|
||||
odx -
|
||||
@ -410,33 +420,35 @@ export default class Bar {
|
||||
|
||||
update_expected_progressbar_position() {
|
||||
if (this.invalid) return;
|
||||
this.$expected_bar_progress.setAttribute('x', this.$bar.getX());
|
||||
this.$expected_bar_progress.setAttribute("x", this.$bar.getX());
|
||||
this.compute_expected_progress();
|
||||
this.$expected_bar_progress.setAttribute(
|
||||
'width',
|
||||
this.gantt.options.column_width * this.duration * (this.expected_progress / 100) || 0
|
||||
"width",
|
||||
this.gantt.options.column_width *
|
||||
this.duration *
|
||||
(this.expected_progress / 100) || 0,
|
||||
);
|
||||
}
|
||||
|
||||
update_progressbar_position() {
|
||||
if (this.invalid) return;
|
||||
this.$bar_progress.setAttribute('x', this.$bar.getX());
|
||||
this.$bar_progress.setAttribute("x", this.$bar.getX());
|
||||
this.$bar_progress.setAttribute(
|
||||
'width',
|
||||
this.$bar.getWidth() * (this.task.progress / 100)
|
||||
"width",
|
||||
this.$bar.getWidth() * (this.task.progress / 100),
|
||||
);
|
||||
}
|
||||
|
||||
update_label_position() {
|
||||
const bar = this.$bar,
|
||||
label = this.group.querySelector('.bar-label');
|
||||
label = this.group.querySelector(".bar-label");
|
||||
|
||||
if (label.getBBox().width > bar.getWidth()) {
|
||||
label.classList.add('big');
|
||||
label.setAttribute('x', bar.getX() + bar.getWidth() + 5);
|
||||
label.classList.add("big");
|
||||
label.setAttribute("x", bar.getX() + bar.getWidth() + 5);
|
||||
} else {
|
||||
label.classList.remove('big');
|
||||
label.setAttribute('x', bar.getX() + bar.getWidth() / 2);
|
||||
label.classList.remove("big");
|
||||
label.setAttribute("x", bar.getX() + bar.getWidth() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,14 +456,13 @@ export default class Bar {
|
||||
if (this.invalid) return;
|
||||
const bar = this.$bar;
|
||||
this.handle_group
|
||||
.querySelector('.handle.left')
|
||||
.setAttribute('x', bar.getX() + 1);
|
||||
.querySelector(".handle.left")
|
||||
.setAttribute("x", bar.getX() + 1);
|
||||
this.handle_group
|
||||
.querySelector('.handle.right')
|
||||
.setAttribute('x', bar.getEndX() - 9);
|
||||
const handle = this.group.querySelector('.handle.progress');
|
||||
handle &&
|
||||
handle.setAttribute('points', this.get_progress_polygon_points());
|
||||
.querySelector(".handle.right")
|
||||
.setAttribute("x", bar.getEndX() - 9);
|
||||
const handle = this.group.querySelector(".handle.progress");
|
||||
handle && handle.setAttribute("points", this.get_progress_polygon_points());
|
||||
}
|
||||
|
||||
update_arrow_position() {
|
||||
@ -466,6 +477,6 @@ function isFunction(functionToCheck) {
|
||||
var getType = {};
|
||||
return (
|
||||
functionToCheck &&
|
||||
getType.toString.call(functionToCheck) === '[object Function]'
|
||||
getType.toString.call(functionToCheck) === "[object Function]"
|
||||
);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ $blue-dark: #8a8aff;
|
||||
background-color: #333;
|
||||
|
||||
.title {
|
||||
border-color: lighten($blue-dark, 5);;
|
||||
border-color: lighten($blue-dark, 5);
|
||||
}
|
||||
.pointer {
|
||||
border-top-color: #333;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
const YEAR = 'year';
|
||||
const MONTH = 'month';
|
||||
const DAY = 'day';
|
||||
const HOUR = 'hour';
|
||||
const MINUTE = 'minute';
|
||||
const SECOND = 'second';
|
||||
const MILLISECOND = 'millisecond';
|
||||
const YEAR = "year";
|
||||
const MONTH = "month";
|
||||
const DAY = "day";
|
||||
const HOUR = "hour";
|
||||
const MINUTE = "minute";
|
||||
const SECOND = "second";
|
||||
const MILLISECOND = "millisecond";
|
||||
|
||||
export default {
|
||||
parse_duration(duration) {
|
||||
@ -29,13 +29,13 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
parse(date, date_separator = '-', time_separator = /[.:]/) {
|
||||
parse(date, date_separator = "-", time_separator = /[.:]/) {
|
||||
if (date instanceof Date) {
|
||||
return date;
|
||||
}
|
||||
if (typeof date === 'string') {
|
||||
if (typeof date === "string") {
|
||||
let date_parts, time_parts;
|
||||
const parts = date.split(' ');
|
||||
const parts = date.split(" ");
|
||||
|
||||
date_parts = parts[0]
|
||||
.split(date_separator)
|
||||
@ -49,7 +49,7 @@ export default {
|
||||
|
||||
if (time_parts && time_parts.length) {
|
||||
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;
|
||||
}
|
||||
vals = vals.concat(time_parts);
|
||||
@ -61,7 +61,7 @@ export default {
|
||||
|
||||
to_string(date, with_time = false) {
|
||||
if (!(date instanceof Date)) {
|
||||
throw new TypeError('Invalid argument type');
|
||||
throw new TypeError("Invalid argument type");
|
||||
}
|
||||
const vals = this.get_date_values(date).map((val, i) => {
|
||||
if (i === 1) {
|
||||
@ -70,26 +70,26 @@ export default {
|
||||
}
|
||||
|
||||
if (i === 6) {
|
||||
return padStart(val + '', 3, '0');
|
||||
return padStart(val + "", 3, "0");
|
||||
}
|
||||
|
||||
return padStart(val + '', 2, '0');
|
||||
return padStart(val + "", 2, "0");
|
||||
});
|
||||
const date_string = `${vals[0]}-${vals[1]}-${vals[2]}`;
|
||||
const time_string = `${vals[3]}:${vals[4]}:${vals[5]}.${vals[6]}`;
|
||||
|
||||
return date_string + (with_time ? ' ' + time_string : '');
|
||||
return date_string + (with_time ? " " + time_string : "");
|
||||
},
|
||||
|
||||
format(date, format_string = 'YYYY-MM-DD HH:mm:ss.SSS', lang = 'en') {
|
||||
format(date, format_string = "YYYY-MM-DD HH:mm:ss.SSS", lang = "en") {
|
||||
const dateTimeFormat = new Intl.DateTimeFormat(lang, {
|
||||
month: 'long'
|
||||
month: "long",
|
||||
});
|
||||
const month_name = dateTimeFormat.format(date);
|
||||
const month_name_capitalized =
|
||||
month_name.charAt(0).toUpperCase() + month_name.slice(1);
|
||||
|
||||
const values = this.get_date_values(date).map(d => padStart(d, 2, 0));
|
||||
const values = this.get_date_values(date).map((d) => padStart(d, 2, 0));
|
||||
const format_map = {
|
||||
YYYY: values[0],
|
||||
MM: padStart(+values[1] + 1, 2, 0),
|
||||
@ -133,8 +133,8 @@ export default {
|
||||
months = days / 30;
|
||||
years = months / 12;
|
||||
|
||||
if (!scale.endsWith('s')) {
|
||||
scale += 's';
|
||||
if (!scale.endsWith("s")) {
|
||||
scale += "s";
|
||||
}
|
||||
|
||||
return Math.floor(
|
||||
@ -146,7 +146,7 @@ export default {
|
||||
days,
|
||||
months,
|
||||
years,
|
||||
}[scale]
|
||||
}[scale],
|
||||
);
|
||||
},
|
||||
|
||||
@ -238,9 +238,9 @@ export default {
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
|
||||
function padStart(str, targetLength, padString) {
|
||||
str = str + '';
|
||||
str = str + "";
|
||||
targetLength = targetLength >> 0;
|
||||
padString = String(typeof padString !== 'undefined' ? padString : ' ');
|
||||
padString = String(typeof padString !== "undefined" ? padString : " ");
|
||||
if (str.length > targetLength) {
|
||||
return String(str);
|
||||
} else {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
@import "./dark.scss";
|
||||
|
||||
$bar-color: #b8c2cc !default;
|
||||
$bar-stroke: #8D99A6 !default;
|
||||
$bar-stroke: #8d99a6 !default;
|
||||
$border-color: #e0e0e0 !default;
|
||||
$light-bg: #f5f5f5 !default;
|
||||
$light-border-color: #ebeff2 !default;
|
||||
@ -71,7 +71,7 @@ $light-blue: #c4c4e9 !default;
|
||||
fill: $bar-color;
|
||||
stroke: $bar-stroke;
|
||||
stroke-width: 0;
|
||||
transition: stroke-width .3s ease;
|
||||
transition: stroke-width 0.3s ease;
|
||||
}
|
||||
.bar-progress {
|
||||
fill: $blue;
|
||||
@ -107,7 +107,7 @@ $light-blue: #c4c4e9 !default;
|
||||
cursor: ew-resize;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity .3s ease;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.bar-wrapper {
|
||||
@ -140,7 +140,8 @@ $light-blue: #c4c4e9 !default;
|
||||
}
|
||||
}
|
||||
|
||||
.lower-text, .upper-text {
|
||||
.lower-text,
|
||||
.upper-text {
|
||||
font-size: 12px;
|
||||
text-anchor: middle;
|
||||
}
|
||||
|
||||
371
src/index.js
371
src/index.js
@ -1,30 +1,29 @@
|
||||
import date_utils from './date_utils';
|
||||
import { $, createSVG } from './svg_utils';
|
||||
import Bar from './bar';
|
||||
import Arrow from './arrow';
|
||||
import Popup from './popup';
|
||||
import date_utils from "./date_utils";
|
||||
import { $, createSVG } from "./svg_utils";
|
||||
import Bar from "./bar";
|
||||
import Arrow from "./arrow";
|
||||
import Popup from "./popup";
|
||||
|
||||
import './gantt.scss';
|
||||
import "./gantt.scss";
|
||||
|
||||
const VIEW_MODE = {
|
||||
HOUR: 'Hour',
|
||||
QUARTER_DAY: 'Quarter Day',
|
||||
HALF_DAY: 'Half Day',
|
||||
DAY: 'Day',
|
||||
WEEK: 'Week',
|
||||
MONTH: 'Month',
|
||||
YEAR: 'Year',
|
||||
HOUR: "Hour",
|
||||
QUARTER_DAY: "Quarter Day",
|
||||
HALF_DAY: "Half Day",
|
||||
DAY: "Day",
|
||||
WEEK: "Week",
|
||||
MONTH: "Month",
|
||||
YEAR: "Year",
|
||||
};
|
||||
|
||||
|
||||
const VIEW_MODE_PADDING = {
|
||||
HOUR: ['7d', '7d'],
|
||||
QUARTER_DAY: ['7d', '7d'],
|
||||
HALF_DAY: ['7d', '7d'],
|
||||
DAY: ['1m', '1m'],
|
||||
WEEK: ['1m', '1m'],
|
||||
MONTH: ['1m', '1m'],
|
||||
YEAR: ['2y', '2y'],
|
||||
HOUR: ["7d", "7d"],
|
||||
QUARTER_DAY: ["7d", "7d"],
|
||||
HALF_DAY: ["7d", "7d"],
|
||||
DAY: ["1m", "1m"],
|
||||
WEEK: ["1m", "1m"],
|
||||
MONTH: ["1m", "1m"],
|
||||
YEAR: ["2y", "2y"],
|
||||
};
|
||||
|
||||
export default class Gantt {
|
||||
@ -41,46 +40,46 @@ export default class Gantt {
|
||||
let svg_element, wrapper_element;
|
||||
|
||||
// CSS Selector is passed
|
||||
if (typeof element === 'string') {
|
||||
if (typeof element === "string") {
|
||||
element = document.querySelector(element);
|
||||
}
|
||||
|
||||
// get the SVGElement
|
||||
if (element instanceof HTMLElement) {
|
||||
wrapper_element = element;
|
||||
svg_element = element.querySelector('svg');
|
||||
svg_element = element.querySelector("svg");
|
||||
} else if (element instanceof SVGElement) {
|
||||
svg_element = element;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
'Frappé Gantt only supports usage of a string CSS selector,' +
|
||||
" HTML DOM element or SVG DOM element for the 'element' parameter"
|
||||
"Frappé Gantt only supports usage of a string CSS selector," +
|
||||
" HTML DOM element or SVG DOM element for the 'element' parameter",
|
||||
);
|
||||
}
|
||||
|
||||
// svg element
|
||||
if (!svg_element) {
|
||||
// create it
|
||||
this.$svg = createSVG('svg', {
|
||||
this.$svg = createSVG("svg", {
|
||||
append_to: wrapper_element,
|
||||
class: 'gantt',
|
||||
class: "gantt",
|
||||
});
|
||||
} else {
|
||||
this.$svg = svg_element;
|
||||
this.$svg.classList.add('gantt');
|
||||
this.$svg.classList.add("gantt");
|
||||
}
|
||||
|
||||
// wrapper element
|
||||
this.$container = document.createElement('div');
|
||||
this.$container.classList.add('gantt-container');
|
||||
this.$container = document.createElement("div");
|
||||
this.$container.classList.add("gantt-container");
|
||||
|
||||
const parent_element = this.$svg.parentElement;
|
||||
parent_element.appendChild(this.$container);
|
||||
this.$container.appendChild(this.$svg);
|
||||
|
||||
// popup wrapper
|
||||
this.popup_wrapper = document.createElement('div');
|
||||
this.popup_wrapper.classList.add('popup-wrapper');
|
||||
this.popup_wrapper = document.createElement("div");
|
||||
this.popup_wrapper.classList.add("popup-wrapper");
|
||||
this.$container.appendChild(this.popup_wrapper);
|
||||
}
|
||||
|
||||
@ -94,22 +93,25 @@ export default class Gantt {
|
||||
bar_corner_radius: 3,
|
||||
arrow_curve: 5,
|
||||
padding: 18,
|
||||
view_mode: 'Day',
|
||||
date_format: 'YYYY-MM-DD',
|
||||
popup_trigger: 'click',
|
||||
view_mode: "Day",
|
||||
date_format: "YYYY-MM-DD",
|
||||
popup_trigger: "click",
|
||||
custom_popup_html: null,
|
||||
language: 'en',
|
||||
language: "en",
|
||||
};
|
||||
this.options = Object.assign({}, default_options, options);
|
||||
for (let [key, value] of Object.entries(options.view_mode_padding)) {
|
||||
if (typeof value === 'string') {
|
||||
if (typeof value === "string") {
|
||||
// Configure for single value given
|
||||
options.view_mode_padding[key] = [value, value]
|
||||
options.view_mode_padding[key] = [value, value];
|
||||
}
|
||||
}
|
||||
|
||||
console.log(options.view_mode_padding)
|
||||
this.options.view_mode_padding = { ...VIEW_MODE_PADDING, ...options.view_mode_padding }
|
||||
console.log(options.view_mode_padding);
|
||||
this.options.view_mode_padding = {
|
||||
...VIEW_MODE_PADDING,
|
||||
...options.view_mode_padding,
|
||||
};
|
||||
}
|
||||
|
||||
setup_tasks(tasks) {
|
||||
@ -121,15 +123,15 @@ export default class Gantt {
|
||||
task.end = task._start;
|
||||
let durations = task.duration.split(" ");
|
||||
|
||||
durations.forEach(tmpDuration => {
|
||||
durations.forEach((tmpDuration) => {
|
||||
let { duration, scale } = date_utils.parse_duration(tmpDuration);
|
||||
task.end = date_utils.add(task.end, duration, scale);
|
||||
})
|
||||
});
|
||||
}
|
||||
task._end = date_utils.parse(task.end);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -140,22 +142,22 @@ export default class Gantt {
|
||||
if (!task.start && !task.end) {
|
||||
const today = date_utils.today();
|
||||
task._start = today;
|
||||
task._end = date_utils.add(today, 2, 'day');
|
||||
task._end = date_utils.add(today, 2, "day");
|
||||
}
|
||||
|
||||
if (!task.start && task.end) {
|
||||
task._start = date_utils.add(task._end, -2, 'day');
|
||||
task._start = date_utils.add(task._end, -2, "day");
|
||||
}
|
||||
|
||||
if (task.start && !task.end) {
|
||||
task._end = date_utils.add(task._start, 2, 'day');
|
||||
task._end = date_utils.add(task._start, 2, "day");
|
||||
}
|
||||
|
||||
// if hours is not set, assume the last day is full day
|
||||
// e.g: 2018-09-09 becomes 2018-09-09 23:59:59
|
||||
const task_end_values = date_utils.get_date_values(task._end);
|
||||
if (task_end_values.slice(3).every((d) => d === 0)) {
|
||||
task._end = date_utils.add(task._end, 24, 'hour');
|
||||
task._end = date_utils.add(task._end, 24, "hour");
|
||||
}
|
||||
|
||||
// invalid flag
|
||||
@ -164,11 +166,11 @@ export default class Gantt {
|
||||
}
|
||||
|
||||
// dependencies
|
||||
if (typeof task.dependencies === 'string' || !task.dependencies) {
|
||||
if (typeof task.dependencies === "string" || !task.dependencies) {
|
||||
let deps = [];
|
||||
if (task.dependencies) {
|
||||
deps = task.dependencies
|
||||
.split(',')
|
||||
.split(",")
|
||||
.map((d) => d.trim())
|
||||
.filter((d) => d);
|
||||
}
|
||||
@ -206,7 +208,7 @@ export default class Gantt {
|
||||
this.setup_dates();
|
||||
this.render();
|
||||
// fire viewmode_change event
|
||||
this.trigger_event('view_change', [mode]);
|
||||
this.trigger_event("view_change", [mode]);
|
||||
}
|
||||
|
||||
update_view_scale(view_mode) {
|
||||
@ -253,18 +255,28 @@ export default class Gantt {
|
||||
}
|
||||
}
|
||||
|
||||
let gantt_start = date_utils.start_of(this.gantt_start, 'day');
|
||||
let gantt_end = date_utils.start_of(this.gantt_end, 'day');
|
||||
let gantt_start = date_utils.start_of(this.gantt_start, "day");
|
||||
let gantt_end = date_utils.start_of(this.gantt_end, "day");
|
||||
// add date padding on both sides
|
||||
let viewKey;
|
||||
for (let [key, value] of Object.entries(VIEW_MODE)) {
|
||||
if (value === this.options.view_mode) {
|
||||
viewKey = key
|
||||
viewKey = key;
|
||||
}
|
||||
}
|
||||
const [padding_start, padding_end] = this.options.view_mode_padding[viewKey].map(date_utils.parse_duration);
|
||||
this.gantt_start = date_utils.add(gantt_start, -padding_start.duration, padding_start.scale);
|
||||
this.gantt_end = date_utils.add(gantt_end, padding_end.duration, padding_end.scale);
|
||||
const [padding_start, padding_end] = this.options.view_mode_padding[
|
||||
viewKey
|
||||
].map(date_utils.parse_duration);
|
||||
this.gantt_start = date_utils.add(
|
||||
gantt_start,
|
||||
-padding_start.duration,
|
||||
padding_start.scale,
|
||||
);
|
||||
this.gantt_end = date_utils.add(
|
||||
gantt_end,
|
||||
padding_end.duration,
|
||||
padding_end.scale,
|
||||
);
|
||||
}
|
||||
|
||||
setup_date_values() {
|
||||
@ -276,15 +288,11 @@ export default class Gantt {
|
||||
cur_date = date_utils.clone(this.gantt_start);
|
||||
} else {
|
||||
if (this.view_is(VIEW_MODE.YEAR)) {
|
||||
cur_date = date_utils.add(cur_date, 1, 'year');
|
||||
cur_date = date_utils.add(cur_date, 1, "year");
|
||||
} else if (this.view_is(VIEW_MODE.MONTH)) {
|
||||
cur_date = date_utils.add(cur_date, 1, 'month');
|
||||
cur_date = date_utils.add(cur_date, 1, "month");
|
||||
} else {
|
||||
cur_date = date_utils.add(
|
||||
cur_date,
|
||||
this.options.step,
|
||||
'hour'
|
||||
);
|
||||
cur_date = date_utils.add(cur_date, this.options.step, "hour");
|
||||
}
|
||||
}
|
||||
this.dates.push(cur_date);
|
||||
@ -310,10 +318,10 @@ export default class Gantt {
|
||||
|
||||
setup_layers() {
|
||||
this.layers = {};
|
||||
const layers = ['grid', 'date', 'arrow', 'progress', 'bar', 'details'];
|
||||
const layers = ["grid", "date", "arrow", "progress", "bar", "details"];
|
||||
// make group layers
|
||||
for (let layer of layers) {
|
||||
this.layers[layer] = createSVG('g', {
|
||||
this.layers[layer] = createSVG("g", {
|
||||
class: layer,
|
||||
append_to: this.$svg,
|
||||
});
|
||||
@ -333,27 +341,26 @@ export default class Gantt {
|
||||
const grid_height =
|
||||
this.options.header_height +
|
||||
this.options.padding +
|
||||
(this.options.bar_height + this.options.padding) *
|
||||
this.tasks.length;
|
||||
(this.options.bar_height + this.options.padding) * this.tasks.length;
|
||||
|
||||
createSVG('rect', {
|
||||
createSVG("rect", {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: grid_width,
|
||||
height: grid_height,
|
||||
class: 'grid-background',
|
||||
class: "grid-background",
|
||||
append_to: this.layers.grid,
|
||||
});
|
||||
|
||||
$.attr(this.$svg, {
|
||||
height: grid_height + this.options.padding + 100,
|
||||
width: '100%',
|
||||
width: "100%",
|
||||
});
|
||||
}
|
||||
|
||||
make_grid_rows() {
|
||||
const rows_layer = createSVG('g', { append_to: this.layers.grid });
|
||||
const lines_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_height = this.options.bar_height + this.options.padding;
|
||||
@ -361,21 +368,21 @@ export default class Gantt {
|
||||
let row_y = this.options.header_height + this.options.padding / 2;
|
||||
|
||||
for (let task of this.tasks) {
|
||||
createSVG('rect', {
|
||||
createSVG("rect", {
|
||||
x: 0,
|
||||
y: row_y,
|
||||
width: row_width,
|
||||
height: row_height,
|
||||
class: 'grid-row',
|
||||
class: "grid-row",
|
||||
append_to: rows_layer,
|
||||
});
|
||||
|
||||
createSVG('line', {
|
||||
createSVG("line", {
|
||||
x1: 0,
|
||||
y1: row_y + row_height,
|
||||
x2: row_width,
|
||||
y2: row_y + row_height,
|
||||
class: 'row-line',
|
||||
class: "row-line",
|
||||
append_to: lines_layer,
|
||||
});
|
||||
|
||||
@ -386,12 +393,12 @@ export default class Gantt {
|
||||
make_grid_header() {
|
||||
const header_width = this.dates.length * this.options.column_width;
|
||||
const header_height = this.options.header_height + 10;
|
||||
createSVG('rect', {
|
||||
createSVG("rect", {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: header_width,
|
||||
height: header_height,
|
||||
class: 'grid-header',
|
||||
class: "grid-header",
|
||||
append_to: this.layers.grid,
|
||||
});
|
||||
}
|
||||
@ -400,14 +407,13 @@ export default class Gantt {
|
||||
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;
|
||||
(this.options.bar_height + this.options.padding) * this.tasks.length;
|
||||
|
||||
for (let date of this.dates) {
|
||||
let tick_class = 'tick';
|
||||
let tick_class = "tick";
|
||||
// thick tick for monday
|
||||
if (this.view_is(VIEW_MODE.DAY) && date.getDate() === 1) {
|
||||
tick_class += ' thick';
|
||||
tick_class += " thick";
|
||||
}
|
||||
// thick tick for first week
|
||||
if (
|
||||
@ -415,14 +421,14 @@ export default class Gantt {
|
||||
date.getDate() >= 1 &&
|
||||
date.getDate() < 8
|
||||
) {
|
||||
tick_class += ' thick';
|
||||
tick_class += " thick";
|
||||
}
|
||||
// thick ticks for quarters
|
||||
if (this.view_is(VIEW_MODE.MONTH) && date.getMonth() % 3 === 0) {
|
||||
tick_class += ' thick';
|
||||
tick_class += " thick";
|
||||
}
|
||||
|
||||
createSVG('path', {
|
||||
createSVG("path", {
|
||||
d: `M ${tick_x} ${tick_y} v ${tick_height}`,
|
||||
class: tick_class,
|
||||
append_to: this.layers.grid,
|
||||
@ -430,9 +436,7 @@ export default class Gantt {
|
||||
|
||||
if (this.view_is(VIEW_MODE.MONTH)) {
|
||||
tick_x +=
|
||||
(date_utils.get_days_in_month(date) *
|
||||
this.options.column_width) /
|
||||
30;
|
||||
(date_utils.get_days_in_month(date) * this.options.column_width) / 30;
|
||||
} else {
|
||||
tick_x += this.options.column_width;
|
||||
}
|
||||
@ -444,9 +448,11 @@ export default class Gantt {
|
||||
let xDist = 0;
|
||||
|
||||
if (this.view_is(VIEW_MODE.DAY)) {
|
||||
return (date_utils.diff(date_utils.today(), this.gantt_start, 'hour') /
|
||||
return (
|
||||
(date_utils.diff(date_utils.today(), this.gantt_start, "hour") /
|
||||
this.options.step) *
|
||||
this.options.column_width;
|
||||
this.options.column_width
|
||||
);
|
||||
}
|
||||
|
||||
for (let date of this.dates) {
|
||||
@ -475,33 +481,36 @@ export default class Gantt {
|
||||
|
||||
make_grid_highlights() {
|
||||
// highlight today's | week's | month's | year's
|
||||
if (this.view_is(VIEW_MODE.DAY) || this.view_is(VIEW_MODE.WEEK) || this.view_is(VIEW_MODE.MONTH) || this.view_is(VIEW_MODE.YEAR)) {
|
||||
|
||||
if (
|
||||
this.view_is(VIEW_MODE.DAY) ||
|
||||
this.view_is(VIEW_MODE.WEEK) ||
|
||||
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.bar_height + this.options.padding) * this.tasks.length +
|
||||
this.options.header_height +
|
||||
this.options.padding / 2;
|
||||
|
||||
let className = '';
|
||||
let className = "";
|
||||
switch (this.options.view_mode) {
|
||||
case VIEW_MODE.DAY:
|
||||
className = 'today-highlight'
|
||||
className = "today-highlight";
|
||||
break;
|
||||
case VIEW_MODE.WEEK:
|
||||
className = 'week-highlight'
|
||||
className = "week-highlight";
|
||||
break;
|
||||
case VIEW_MODE.MONTH:
|
||||
className = 'month-highlight'
|
||||
className = "month-highlight";
|
||||
break;
|
||||
case VIEW_MODE.YEAR:
|
||||
className = 'year-highlight'
|
||||
className = "year-highlight";
|
||||
break;
|
||||
}
|
||||
createSVG('rect', {
|
||||
createSVG("rect", {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
@ -514,27 +523,25 @@ export default class Gantt {
|
||||
|
||||
make_dates() {
|
||||
for (let date of this.get_dates_to_draw()) {
|
||||
createSVG('text', {
|
||||
createSVG("text", {
|
||||
x: date.lower_x,
|
||||
y: date.lower_y,
|
||||
innerHTML: date.lower_text,
|
||||
class: 'lower-text',
|
||||
class: "lower-text",
|
||||
append_to: this.layers.date,
|
||||
});
|
||||
|
||||
if (date.upper_text) {
|
||||
const $upper_text = createSVG('text', {
|
||||
const $upper_text = createSVG("text", {
|
||||
x: date.upper_x,
|
||||
y: date.upper_y,
|
||||
innerHTML: date.upper_text,
|
||||
class: 'upper-text',
|
||||
class: "upper-text",
|
||||
append_to: this.layers.date,
|
||||
});
|
||||
|
||||
// remove out-of-bound dates
|
||||
if (
|
||||
$upper_text.getBBox().x2 > this.layers.grid.getBBox().width
|
||||
) {
|
||||
if ($upper_text.getBBox().x2 > this.layers.grid.getBBox().width) {
|
||||
$upper_text.remove();
|
||||
}
|
||||
}
|
||||
@ -553,68 +560,52 @@ export default class Gantt {
|
||||
|
||||
get_date_info(date, last_date, i) {
|
||||
if (!last_date) {
|
||||
last_date = date_utils.add(date, 1, 'day');
|
||||
last_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
|
||||
),
|
||||
'Half Day_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),
|
||||
"Half Day_lower": date_utils.format(date, "HH", this.options.language),
|
||||
Day_lower:
|
||||
date.getDate() !== last_date.getDate()
|
||||
? date_utils.format(date, 'D', this.options.language)
|
||||
: '',
|
||||
? date_utils.format(date, "D", this.options.language)
|
||||
: "",
|
||||
Week_lower:
|
||||
date.getMonth() !== last_date.getMonth()
|
||||
? date_utils.format(date, 'D MMM', this.options.language)
|
||||
: date_utils.format(date, 'D', this.options.language),
|
||||
Month_lower: date_utils.format(date, 'MMMM', this.options.language),
|
||||
Year_lower: date_utils.format(date, 'YYYY', this.options.language),
|
||||
? date_utils.format(date, "D MMM", this.options.language)
|
||||
: date_utils.format(date, "D", this.options.language),
|
||||
Month_lower: date_utils.format(date, "MMMM", this.options.language),
|
||||
Year_lower: date_utils.format(date, "YYYY", this.options.language),
|
||||
Hour_upper:
|
||||
date.getDate() !== last_date.getDate()
|
||||
? date_utils.format(date, 'D MMMM', this.options.language)
|
||||
: '',
|
||||
'Quarter Day_upper':
|
||||
? date_utils.format(date, "D MMMM", this.options.language)
|
||||
: "",
|
||||
"Quarter Day_upper":
|
||||
date.getDate() !== last_date.getDate()
|
||||
? date_utils.format(date, 'D MMM', this.options.language)
|
||||
: '',
|
||||
'Half Day_upper':
|
||||
? date_utils.format(date, "D MMM", this.options.language)
|
||||
: "",
|
||||
"Half Day_upper":
|
||||
date.getDate() !== last_date.getDate()
|
||||
? date.getMonth() !== last_date.getMonth()
|
||||
? date_utils.format(
|
||||
date,
|
||||
'D MMM',
|
||||
this.options.language
|
||||
)
|
||||
: date_utils.format(date, 'D', this.options.language)
|
||||
: '',
|
||||
? date_utils.format(date, "D MMM", this.options.language)
|
||||
: date_utils.format(date, "D", this.options.language)
|
||||
: "",
|
||||
Day_upper:
|
||||
date.getMonth() !== last_date.getMonth()
|
||||
? date_utils.format(date, 'MMMM', this.options.language)
|
||||
: '',
|
||||
? date_utils.format(date, "MMMM", this.options.language)
|
||||
: "",
|
||||
Week_upper:
|
||||
date.getMonth() !== last_date.getMonth()
|
||||
? date_utils.format(date, 'MMMM', this.options.language)
|
||||
: '',
|
||||
? date_utils.format(date, "MMMM", this.options.language)
|
||||
: "",
|
||||
Month_upper:
|
||||
date.getFullYear() !== last_date.getFullYear()
|
||||
? date_utils.format(date, 'YYYY', this.options.language)
|
||||
: '',
|
||||
? date_utils.format(date, "YYYY", this.options.language)
|
||||
: "",
|
||||
Year_upper:
|
||||
date.getFullYear() !== last_date.getFullYear()
|
||||
? date_utils.format(date, 'YYYY', this.options.language)
|
||||
: '',
|
||||
? date_utils.format(date, "YYYY", this.options.language)
|
||||
: "",
|
||||
};
|
||||
|
||||
const base_pos = {
|
||||
@ -626,10 +617,10 @@ export default class Gantt {
|
||||
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,
|
||||
"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,
|
||||
@ -669,7 +660,7 @@ export default class Gantt {
|
||||
const arrow = new Arrow(
|
||||
this,
|
||||
this.bars[dependency._index], // from_task
|
||||
this.bars[task._index] // to_task
|
||||
this.bars[task._index], // to_task
|
||||
);
|
||||
this.layers.arrow.appendChild(arrow.element);
|
||||
return arrow;
|
||||
@ -693,10 +684,10 @@ export default class Gantt {
|
||||
set_width() {
|
||||
const cur_width = this.$svg.getBoundingClientRect().width;
|
||||
const actual_width = this.$svg
|
||||
.querySelector('.grid .grid-row')
|
||||
.getAttribute('width');
|
||||
.querySelector(".grid .grid-row")
|
||||
.getAttribute("width");
|
||||
if (cur_width < actual_width) {
|
||||
this.$svg.setAttribute('width', actual_width);
|
||||
this.$svg.setAttribute("width", actual_width);
|
||||
}
|
||||
}
|
||||
|
||||
@ -707,7 +698,7 @@ export default class Gantt {
|
||||
const hours_before_first_task = date_utils.diff(
|
||||
this.get_oldest_starting_date(),
|
||||
this.gantt_start,
|
||||
'hour'
|
||||
"hour",
|
||||
);
|
||||
|
||||
const scroll_pos =
|
||||
@ -722,11 +713,11 @@ export default class Gantt {
|
||||
$.on(
|
||||
this.$svg,
|
||||
this.options.popup_trigger,
|
||||
'.grid-row, .grid-header',
|
||||
".grid-row, .grid-header",
|
||||
() => {
|
||||
this.unselect_all();
|
||||
this.hide_popup();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -744,23 +735,23 @@ export default class Gantt {
|
||||
return is_dragging || is_resizing_left || is_resizing_right;
|
||||
}
|
||||
|
||||
$.on(this.$svg, 'mousedown', '.bar-wrapper, .handle', (e, element) => {
|
||||
const bar_wrapper = $.closest('.bar-wrapper', element);
|
||||
$.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (e, element) => {
|
||||
const bar_wrapper = $.closest(".bar-wrapper", element);
|
||||
|
||||
if (element.classList.contains('left')) {
|
||||
if (element.classList.contains("left")) {
|
||||
is_resizing_left = true;
|
||||
} else if (element.classList.contains('right')) {
|
||||
} else if (element.classList.contains("right")) {
|
||||
is_resizing_right = true;
|
||||
} else if (element.classList.contains('bar-wrapper')) {
|
||||
} else if (element.classList.contains("bar-wrapper")) {
|
||||
is_dragging = true;
|
||||
}
|
||||
|
||||
bar_wrapper.classList.add('active');
|
||||
bar_wrapper.classList.add("active");
|
||||
|
||||
x_on_start = e.offsetX;
|
||||
y_on_start = e.offsetY;
|
||||
|
||||
parent_bar_id = bar_wrapper.getAttribute('data-id');
|
||||
parent_bar_id = bar_wrapper.getAttribute("data-id");
|
||||
const ids = [
|
||||
parent_bar_id,
|
||||
...this.get_all_dependent_tasks(parent_bar_id),
|
||||
@ -778,7 +769,7 @@ export default class Gantt {
|
||||
});
|
||||
});
|
||||
|
||||
$.on(this.$svg, 'mousemove', (e) => {
|
||||
$.on(this.$svg, "mousemove", (e) => {
|
||||
if (!action_in_progress()) return;
|
||||
const dx = e.offsetX - x_on_start;
|
||||
const dy = e.offsetY - y_on_start;
|
||||
@ -810,9 +801,9 @@ export default class Gantt {
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('mouseup', (e) => {
|
||||
document.addEventListener("mouseup", (e) => {
|
||||
if (is_dragging || is_resizing_left || is_resizing_right) {
|
||||
bars.forEach((bar) => bar.group.classList.remove('active'));
|
||||
bars.forEach((bar) => bar.group.classList.remove("active"));
|
||||
}
|
||||
|
||||
is_dragging = false;
|
||||
@ -820,7 +811,7 @@ export default class Gantt {
|
||||
is_resizing_right = false;
|
||||
});
|
||||
|
||||
$.on(this.$svg, 'mouseup', (e) => {
|
||||
$.on(this.$svg, "mouseup", (e) => {
|
||||
this.bar_being_dragged = null;
|
||||
bars.forEach((bar) => {
|
||||
const $bar = bar.$bar;
|
||||
@ -841,13 +832,13 @@ export default class Gantt {
|
||||
let $bar_progress = null;
|
||||
let $bar = null;
|
||||
|
||||
$.on(this.$svg, 'mousedown', '.handle.progress', (e, handle) => {
|
||||
$.on(this.$svg, "mousedown", ".handle.progress", (e, handle) => {
|
||||
is_resizing = true;
|
||||
x_on_start = e.offsetX;
|
||||
y_on_start = e.offsetY;
|
||||
|
||||
const $bar_wrapper = $.closest('.bar-wrapper', handle);
|
||||
const id = $bar_wrapper.getAttribute('data-id');
|
||||
const $bar_wrapper = $.closest(".bar-wrapper", handle);
|
||||
const id = $bar_wrapper.getAttribute("data-id");
|
||||
bar = this.get_bar(id);
|
||||
|
||||
$bar_progress = bar.$bar_progress;
|
||||
@ -859,7 +850,7 @@ export default class Gantt {
|
||||
$bar_progress.max_dx = $bar.getWidth() - $bar_progress.getWidth();
|
||||
});
|
||||
|
||||
$.on(this.$svg, 'mousemove', (e) => {
|
||||
$.on(this.$svg, "mousemove", (e) => {
|
||||
if (!is_resizing) return;
|
||||
let dx = e.offsetX - x_on_start;
|
||||
let dy = e.offsetY - y_on_start;
|
||||
@ -872,12 +863,12 @@ export default class Gantt {
|
||||
}
|
||||
|
||||
const $handle = bar.$handle_progress;
|
||||
$.attr($bar_progress, 'width', $bar_progress.owidth + dx);
|
||||
$.attr($handle, 'points', bar.get_progress_polygon_points());
|
||||
$.attr($bar_progress, "width", $bar_progress.owidth + dx);
|
||||
$.attr($handle, "points", bar.get_progress_polygon_points());
|
||||
$bar_progress.finaldx = dx;
|
||||
});
|
||||
|
||||
$.on(this.$svg, 'mouseup', () => {
|
||||
$.on(this.$svg, "mouseup", () => {
|
||||
is_resizing = false;
|
||||
if (!($bar_progress && $bar_progress.finaldx)) return;
|
||||
bar.progress_changed();
|
||||
@ -927,21 +918,19 @@ export default class Gantt {
|
||||
position =
|
||||
odx -
|
||||
rem +
|
||||
(rem < this.options.column_width / 2
|
||||
? 0
|
||||
: this.options.column_width);
|
||||
(rem < this.options.column_width / 2 ? 0 : this.options.column_width);
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
unselect_all() {
|
||||
[...this.$svg.querySelectorAll('.bar-wrapper')].forEach((el) => {
|
||||
el.classList.remove('active');
|
||||
[...this.$svg.querySelectorAll(".bar-wrapper")].forEach((el) => {
|
||||
el.classList.remove("active");
|
||||
});
|
||||
}
|
||||
|
||||
view_is(modes) {
|
||||
if (typeof modes === 'string') {
|
||||
if (typeof modes === "string") {
|
||||
return this.options.view_mode === modes;
|
||||
}
|
||||
|
||||
@ -968,7 +957,7 @@ export default class Gantt {
|
||||
if (!this.popup) {
|
||||
this.popup = new Popup(
|
||||
this.popup_wrapper,
|
||||
this.options.custom_popup_html
|
||||
this.options.custom_popup_html,
|
||||
);
|
||||
}
|
||||
this.popup.show(options);
|
||||
@ -979,8 +968,8 @@ export default class Gantt {
|
||||
}
|
||||
|
||||
trigger_event(event, args) {
|
||||
if (this.options['on_' + event]) {
|
||||
this.options['on_' + event].apply(null, args);
|
||||
if (this.options["on_" + event]) {
|
||||
this.options["on_" + event].apply(null, args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -994,7 +983,7 @@ export default class Gantt {
|
||||
return this.tasks
|
||||
.map((task) => task._start)
|
||||
.reduce((prev_date, cur_date) =>
|
||||
cur_date <= prev_date ? cur_date : prev_date
|
||||
cur_date <= prev_date ? cur_date : prev_date,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1004,12 +993,12 @@ export default class Gantt {
|
||||
* @memberof Gantt
|
||||
*/
|
||||
clear() {
|
||||
this.$svg.innerHTML = '';
|
||||
this.$svg.innerHTML = "";
|
||||
}
|
||||
}
|
||||
|
||||
Gantt.VIEW_MODE = VIEW_MODE;
|
||||
|
||||
function generate_id(task) {
|
||||
return task.name + '_' + Math.random().toString(36).slice(2, 12);
|
||||
return task.name + "_" + Math.random().toString(36).slice(2, 12);
|
||||
}
|
||||
|
||||
26
src/popup.js
26
src/popup.js
@ -14,17 +14,17 @@ export default class Popup {
|
||||
|
||||
this.hide();
|
||||
|
||||
this.title = this.parent.querySelector('.title');
|
||||
this.subtitle = this.parent.querySelector('.subtitle');
|
||||
this.pointer = this.parent.querySelector('.pointer');
|
||||
this.title = this.parent.querySelector(".title");
|
||||
this.subtitle = this.parent.querySelector(".subtitle");
|
||||
this.pointer = this.parent.querySelector(".pointer");
|
||||
}
|
||||
|
||||
show(options) {
|
||||
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';
|
||||
options.position = "left";
|
||||
}
|
||||
const target_element = options.target_element;
|
||||
|
||||
@ -32,12 +32,12 @@ export default class Popup {
|
||||
let html = this.custom_html(options.task);
|
||||
html += '<div class="pointer"></div>';
|
||||
this.parent.innerHTML = html;
|
||||
this.pointer = this.parent.querySelector('.pointer');
|
||||
this.pointer = this.parent.querySelector(".pointer");
|
||||
} else {
|
||||
// set data
|
||||
this.title.innerHTML = options.title;
|
||||
this.subtitle.innerHTML = options.subtitle;
|
||||
this.parent.style.width = this.parent.clientWidth + 'px';
|
||||
this.parent.style.width = this.parent.clientWidth + "px";
|
||||
}
|
||||
|
||||
// set position
|
||||
@ -48,14 +48,14 @@ export default class Popup {
|
||||
position_meta = options.target_element.getBBox();
|
||||
}
|
||||
|
||||
if (options.position === 'left') {
|
||||
if (options.position === "left") {
|
||||
this.parent.style.left =
|
||||
position_meta.x + (position_meta.width + 10) + 'px';
|
||||
this.parent.style.top = position_meta.y + '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 = '-7px';
|
||||
this.pointer.style.top = '2px';
|
||||
this.pointer.style.transform = "rotateZ(90deg)";
|
||||
this.pointer.style.left = "-7px";
|
||||
this.pointer.style.top = "2px";
|
||||
}
|
||||
|
||||
// show
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
export function $(expr, con) {
|
||||
return typeof expr === 'string'
|
||||
return typeof expr === "string"
|
||||
? (con || document).querySelector(expr)
|
||||
: expr || null;
|
||||
}
|
||||
|
||||
export function createSVG(tag, attrs) {
|
||||
const elem = document.createElementNS('http://www.w3.org/2000/svg', tag);
|
||||
const elem = document.createElementNS("http://www.w3.org/2000/svg", tag);
|
||||
for (let attr in attrs) {
|
||||
if (attr === 'append_to') {
|
||||
if (attr === "append_to") {
|
||||
const parent = attrs.append_to;
|
||||
parent.appendChild(elem);
|
||||
} else if (attr === 'innerHTML') {
|
||||
} else if (attr === "innerHTML") {
|
||||
elem.innerHTML = attrs.innerHTML;
|
||||
} else {
|
||||
elem.setAttribute(attr, attrs[attr]);
|
||||
@ -25,9 +25,9 @@ export function animateSVG(svgElement, attr, from, to) {
|
||||
if (animatedSvgElement === svgElement) {
|
||||
// triggered 2nd time programmatically
|
||||
// trigger artificial click event
|
||||
const event = document.createEvent('HTMLEvents');
|
||||
event.initEvent('click', true, true);
|
||||
event.eventName = 'click';
|
||||
const event = document.createEvent("HTMLEvents");
|
||||
event.initEvent("click", true, true);
|
||||
event.eventName = "click";
|
||||
animatedSvgElement.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
@ -37,31 +37,31 @@ function getAnimationElement(
|
||||
attr,
|
||||
from,
|
||||
to,
|
||||
dur = '0.4s',
|
||||
begin = '0.1s'
|
||||
dur = "0.4s",
|
||||
begin = "0.1s",
|
||||
) {
|
||||
const animEl = svgElement.querySelector('animate');
|
||||
const animEl = svgElement.querySelector("animate");
|
||||
if (animEl) {
|
||||
$.attr(animEl, {
|
||||
attributeName: attr,
|
||||
from,
|
||||
to,
|
||||
dur,
|
||||
begin: 'click + ' + begin, // artificial click
|
||||
begin: "click + " + begin, // artificial click
|
||||
});
|
||||
return svgElement;
|
||||
}
|
||||
|
||||
const animateElement = createSVG('animate', {
|
||||
const animateElement = createSVG("animate", {
|
||||
attributeName: attr,
|
||||
from,
|
||||
to,
|
||||
dur,
|
||||
begin,
|
||||
calcMode: 'spline',
|
||||
values: from + ';' + to,
|
||||
keyTimes: '0; 1',
|
||||
keySplines: cubic_bezier('ease-out'),
|
||||
calcMode: "spline",
|
||||
values: from + ";" + to,
|
||||
keyTimes: "0; 1",
|
||||
keySplines: cubic_bezier("ease-out"),
|
||||
});
|
||||
svgElement.appendChild(animateElement);
|
||||
|
||||
@ -70,11 +70,11 @@ function getAnimationElement(
|
||||
|
||||
function cubic_bezier(name) {
|
||||
return {
|
||||
ease: '.25 .1 .25 1',
|
||||
linear: '0 0 1 1',
|
||||
'ease-in': '.42 0 1 1',
|
||||
'ease-out': '0 0 .58 1',
|
||||
'ease-in-out': '.42 0 .58 1',
|
||||
ease: ".25 .1 .25 1",
|
||||
linear: "0 0 1 1",
|
||||
"ease-in": ".42 0 1 1",
|
||||
"ease-out": "0 0 .58 1",
|
||||
"ease-in-out": ".42 0 .58 1",
|
||||
}[name];
|
||||
}
|
||||
|
||||
@ -118,11 +118,11 @@ $.closest = (selector, element) => {
|
||||
};
|
||||
|
||||
$.attr = (element, attr, value) => {
|
||||
if (!value && typeof attr === 'string') {
|
||||
if (!value && typeof attr === "string") {
|
||||
return element.getAttribute(attr);
|
||||
}
|
||||
|
||||
if (typeof attr === 'object') {
|
||||
if (typeof attr === "object") {
|
||||
for (let key in attr) {
|
||||
$.attr(element, key, attr[key]);
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import date_utils from '../src/date_utils';
|
||||
import date_utils from "../src/date_utils";
|
||||
|
||||
test('Parse: parses string date', () => {
|
||||
const date = date_utils.parse('2017-09-09');
|
||||
test("Parse: parses string date", () => {
|
||||
const date = date_utils.parse("2017-09-09");
|
||||
|
||||
expect(date.getDate()).toBe(9);
|
||||
expect(date.getMonth()).toBe(8);
|
||||
expect(date.getFullYear()).toBe(2017);
|
||||
});
|
||||
|
||||
test('Parse: parses string datetime', () => {
|
||||
const date = date_utils.parse('2017-08-27 16:08:34');
|
||||
test("Parse: parses string datetime", () => {
|
||||
const date = date_utils.parse("2017-08-27 16:08:34");
|
||||
|
||||
expect(date.getFullYear()).toBe(2017);
|
||||
expect(date.getMonth()).toBe(7);
|
||||
@ -19,8 +19,8 @@ test('Parse: parses string datetime', () => {
|
||||
expect(date.getSeconds()).toBe(34);
|
||||
});
|
||||
|
||||
test('Parse: parses string datetime', () => {
|
||||
const date = date_utils.parse('2016-02-29 16:08:34.3');
|
||||
test("Parse: parses string datetime", () => {
|
||||
const date = date_utils.parse("2016-02-29 16:08:34.3");
|
||||
|
||||
expect(date.getFullYear()).toBe(2016);
|
||||
expect(date.getMonth()).toBe(1);
|
||||
@ -31,8 +31,8 @@ test('Parse: parses string datetime', () => {
|
||||
expect(date.getMilliseconds()).toBe(300);
|
||||
});
|
||||
|
||||
test('Parse: parses string datetime', () => {
|
||||
const date = date_utils.parse('2015-07-01 00:00:59.200');
|
||||
test("Parse: parses string datetime", () => {
|
||||
const date = date_utils.parse("2015-07-01 00:00:59.200");
|
||||
|
||||
expect(date.getFullYear()).toBe(2015);
|
||||
expect(date.getMonth()).toBe(6);
|
||||
@ -43,82 +43,82 @@ test('Parse: parses string datetime', () => {
|
||||
expect(date.getMilliseconds()).toBe(200);
|
||||
});
|
||||
|
||||
test('Format: converts date object to string', () => {
|
||||
const date = new Date('2017-09-18');
|
||||
expect(date_utils.to_string(date)).toBe('2017-09-18');
|
||||
test("Format: converts date object to string", () => {
|
||||
const date = new Date("2017-09-18");
|
||||
expect(date_utils.to_string(date)).toBe("2017-09-18");
|
||||
});
|
||||
|
||||
test('Format: converts date object to string', () => {
|
||||
const date = new Date('2016-02-29 16:08:34.3');
|
||||
expect(date_utils.to_string(date, true)).toBe('2016-02-29 16:08:34.300');
|
||||
test("Format: converts date object to string", () => {
|
||||
const date = new Date("2016-02-29 16:08:34.3");
|
||||
expect(date_utils.to_string(date, true)).toBe("2016-02-29 16:08:34.300");
|
||||
});
|
||||
|
||||
test('Format: converts date object to string', () => {
|
||||
const date = new Date('2016-02-29 16:08:34.3');
|
||||
expect(date_utils.to_string(date, true)).toBe('2016-02-29 16:08:34.300');
|
||||
test("Format: converts date object to string", () => {
|
||||
const date = new Date("2016-02-29 16:08:34.3");
|
||||
expect(date_utils.to_string(date, true)).toBe("2016-02-29 16:08:34.300");
|
||||
});
|
||||
|
||||
test('Parse: returns Date Object as is', () => {
|
||||
test("Parse: returns Date Object as is", () => {
|
||||
const d = new Date();
|
||||
const date = date_utils.parse(d);
|
||||
|
||||
expect(d).toBe(date);
|
||||
});
|
||||
|
||||
test('Diff: returns diff between 2 date objects', () => {
|
||||
const a = date_utils.parse('2017-09-08');
|
||||
const b = date_utils.parse('2017-06-07');
|
||||
test("Diff: returns diff between 2 date objects", () => {
|
||||
const a = date_utils.parse("2017-09-08");
|
||||
const b = date_utils.parse("2017-06-07");
|
||||
|
||||
expect(date_utils.diff(a, b, 'day')).toBe(93);
|
||||
expect(date_utils.diff(a, b, 'month')).toBe(3);
|
||||
expect(date_utils.diff(a, b, 'year')).toBe(0);
|
||||
expect(date_utils.diff(a, b, "day")).toBe(93);
|
||||
expect(date_utils.diff(a, b, "month")).toBe(3);
|
||||
expect(date_utils.diff(a, b, "year")).toBe(0);
|
||||
});
|
||||
|
||||
test('StartOf', () => {
|
||||
const date = date_utils.parse('2017-08-12 15:07:34.012');
|
||||
test("StartOf", () => {
|
||||
const date = date_utils.parse("2017-08-12 15:07:34.012");
|
||||
|
||||
const start_of_millisecond = date_utils.start_of(date, 'millisecond');
|
||||
const start_of_millisecond = date_utils.start_of(date, "millisecond");
|
||||
expect(date_utils.to_string(start_of_millisecond, true)).toBe(
|
||||
'2017-08-12 15:07:34.012'
|
||||
"2017-08-12 15:07:34.012",
|
||||
);
|
||||
|
||||
const start_of_second = date_utils.start_of(date, 'second');
|
||||
const start_of_second = date_utils.start_of(date, "second");
|
||||
expect(date_utils.to_string(start_of_second, true)).toBe(
|
||||
'2017-08-12 15:07:34.000'
|
||||
"2017-08-12 15:07:34.000",
|
||||
);
|
||||
|
||||
const start_of_minute = date_utils.start_of(date, 'minute');
|
||||
const start_of_minute = date_utils.start_of(date, "minute");
|
||||
expect(date_utils.to_string(start_of_minute, true)).toBe(
|
||||
'2017-08-12 15:07:00.000'
|
||||
"2017-08-12 15:07:00.000",
|
||||
);
|
||||
|
||||
const start_of_hour = date_utils.start_of(date, 'hour');
|
||||
const start_of_hour = date_utils.start_of(date, "hour");
|
||||
expect(date_utils.to_string(start_of_hour, true)).toBe(
|
||||
'2017-08-12 15:00:00.000'
|
||||
"2017-08-12 15:00:00.000",
|
||||
);
|
||||
|
||||
const start_of_day = date_utils.start_of(date, 'day');
|
||||
const start_of_day = date_utils.start_of(date, "day");
|
||||
expect(date_utils.to_string(start_of_day, true)).toBe(
|
||||
'2017-08-12 00:00:00.000'
|
||||
"2017-08-12 00:00:00.000",
|
||||
);
|
||||
|
||||
const start_of_month = date_utils.start_of(date, 'month');
|
||||
const start_of_month = date_utils.start_of(date, "month");
|
||||
expect(date_utils.to_string(start_of_month, true)).toBe(
|
||||
'2017-08-01 00:00:00.000'
|
||||
"2017-08-01 00:00:00.000",
|
||||
);
|
||||
|
||||
const start_of_year = date_utils.start_of(date, 'year');
|
||||
const start_of_year = date_utils.start_of(date, "year");
|
||||
expect(date_utils.to_string(start_of_year, true)).toBe(
|
||||
'2017-01-01 00:00:00.000'
|
||||
"2017-01-01 00:00:00.000",
|
||||
);
|
||||
});
|
||||
|
||||
test('format', () => {
|
||||
const date = date_utils.parse('2017-08-12 15:07:23');
|
||||
expect(date_utils.format(date, 'YYYY-MM-DD')).toBe('2017-08-12');
|
||||
test("format", () => {
|
||||
const date = date_utils.parse("2017-08-12 15:07:23");
|
||||
expect(date_utils.format(date, "YYYY-MM-DD")).toBe("2017-08-12");
|
||||
});
|
||||
|
||||
test('format', () => {
|
||||
const date = date_utils.parse('2016-02-29 16:08:34.3');
|
||||
expect(date_utils.format(date)).toBe('2016-02-29 16:08:34.300');
|
||||
test("format", () => {
|
||||
const date = date_utils.parse("2016-02-29 16:08:34.3");
|
||||
expect(date_utils.format(date)).toBe("2016-02-29 16:08:34.300");
|
||||
});
|
||||
|
||||
@ -2907,10 +2907,10 @@ preserve@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
|
||||
|
||||
prettier@^2.6.2:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
|
||||
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==
|
||||
prettier@3.2.5:
|
||||
version "3.2.5"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
|
||||
integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==
|
||||
|
||||
pretty-format@^22.1.0:
|
||||
version "22.1.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user