adore-gantt 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,179 @@
1
+ <div align="center" markdown="1">
2
+ <img src=".github/gantt-logo.jpg" width="80">
3
+ <h1>Frappe Gantt</h1>
4
+
5
+ **A modern, configurable, Gantt library for the web.**
6
+
7
+ </div>
8
+
9
+ ![Hero Image](.github/hero-image.png)
10
+
11
+ ## Frappe Gantt
12
+
13
+ Gantt charts are bar charts that visually illustrate a project's tasks, schedule, and dependencies. With Frappe Gantt, you can build beautiful, customizable, Gantt charts with ease.
14
+
15
+ You can use it anywhere from hobby projects to tracking the goals of your team at the worksplace.
16
+
17
+ [ERPNext](https://erpnext.com/) uses Frappe Gantt.
18
+
19
+ ### Motivation
20
+
21
+ We needed a Gantt View for ERPNext. Surprisingly, we couldn't find a visually appealing Gantt library that was open source - so we decided to build it. Initially, the design was heavily inspired by Google Gantt and DHTMLX.
22
+
23
+ ### Key Features
24
+
25
+ - **Customizable Views**: customize the timeline based on various time periods - day, hour, or year, you have it. You can also create your own views.
26
+ - **Ignore Periods**: exclude weekends and other holidays from your tasks' progress calculation.
27
+ - **Configure Anything**: spacing, edit access, labels, you can control it all. Change both the style and functionality to meet your needs.
28
+ - **Multi-lingual Support**: suitable for companies with an international base.
29
+
30
+ ## Usage
31
+
32
+ Install with:
33
+
34
+ ```bash
35
+ npm install frappe-gantt
36
+ ```
37
+
38
+ Include it in your HTML:
39
+
40
+ ```html
41
+ <script src="frappe-gantt.umd.js"></script>
42
+ <link rel="stylesheet" href="frappe-gantt.css" />
43
+ ```
44
+
45
+ Or from the CDN:
46
+
47
+ ```html
48
+ <script src="https://cdn.jsdelivr.net/npm/frappe-gantt/dist/frappe-gantt.umd.js"></script>
49
+ <link
50
+ rel="stylesheet"
51
+ href="https://cdn.jsdelivr.net/npm/frappe-gantt/dist/frappe-gantt.css"
52
+ />
53
+ ```
54
+
55
+ Start using Gantt:
56
+
57
+ ```js
58
+ let tasks = [
59
+ {
60
+ id: '1',
61
+ name: 'Redesign website',
62
+ start: '2016-12-28',
63
+ end: '2016-12-31',
64
+ progress: 20
65
+ },
66
+ ...
67
+ ]
68
+ let gantt = new Gantt("#gantt", tasks);
69
+
70
+ // Use .refresh to update the chart
71
+ gantt.tasks.append(...)
72
+ gantt.tasks.refresh()
73
+ ```
74
+
75
+ ### Configuration
76
+
77
+ Frappe Gantt offers a wide range of options to customize your chart.
78
+
79
+ | **Option** | **Description** | **Possible Values** | **Default** |
80
+ | ------------------------ | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
81
+ | `arrow_curve` | Curve radius of arrows connecting dependencies. | Any positive integer. | `5` |
82
+ | `auto_move_label` | Move task labels when user scrolls horizontally. | `true`, `false` | `false` |
83
+ | `bar_corner_radius` | Radius of the task bar corners (in pixels). | Any positive integer. | `3` |
84
+ | `bar_height` | Height of task bars (in pixels). | Any positive integer. | `30` |
85
+ | `container_height` | Height of the container. | `auto` - dynamic container height to fit all tasks - _or_ any positive integer (for pixels). | `auto` |
86
+ | `column_width` | Width of each column in the timeline. | Any positive integer. | 45 |
87
+ | `date_format` | Format for displaying dates. | Any valid JS date format string. | `YYYY-MM-DD` |
88
+ | `upper_header_height` | Height of the upper header in the timeline (in pixels). | Any positive integer. | `45` |
89
+ | `lower_header_height` | Height of the lower header in the timeline (in pixels). | Any positive integer. | `30` |
90
+ | `snap_at` | Snap tasks at particular intervel while resizing or dragging. | Any _interval_ (see below) | `1d` |
91
+ | `infinite_padding` | Whether to extend timeline infinitely when user scrolls. | `true`, `false` | `true` |
92
+ | `holidays` | Highlighted holidays on the timeline. | Object mapping CSS colors to holiday types. Types can either be a) 'weekend', or b) array of _strings_ or _date objects_ or _objects_ in the format `{date: ..., label: ...}` | `{ 'var(--g-weekend-highlight-color)': 'weekend' }` |
93
+ | `is_weekend` | Determines whether a day is a weekend | Function | `(d) => d.getDay() === 0 \|\| d.getDay() === 6` |
94
+ | `ignore` | Ignored areas in the rendering | `weekend` _or_ Array of strings or date objects (`weekend` can be present to the array also). | `[]` |
95
+ | `language` | Language for localization. | ISO 639-1 codes like `en`, `fr`, `es`. | `en` |
96
+ | `lines` | Determines which grid lines to display. | `none` for no lines, `vertical` for only vertical lines, `horizontal` for only horizontal lines, `both` for complete grid. | `both` |
97
+ | `move_dependencies` | Whether moving a task automatically moves its dependencies. | `true`, `false` | `true` |
98
+ | `padding` | Padding around task bars (in pixels). | Any positive integer. | `18` |
99
+ | `popup_on` | Event to trigger the popup display. | `click` _or_ `hover` | `click` |
100
+ | `readonly_progress` | Disables editing task progress. | `true`, `false` | `false` |
101
+ | `readonly_dates` | Disables editing task dates. | `true`, `false` | `false` |
102
+ | `readonly` | Disables all editing features. | `true`, `false` | `false` |
103
+ | `scroll_to` | Determines the starting point when chart is rendered. | `today`, `start`, `end`, or a date string. | `today` |
104
+ | `show_expected_progress` | Shows expected progress for tasks. | `true`, `false` | `false` |
105
+ | `today_button` | Adds a button to navigate to today’s date. | `true`, `false` | `true` |
106
+ | `view_mode` | The initial view mode of the Gantt chart. | `Day`, `Week`, `Month`, `Year`. | `Day` |
107
+ | `view_mode_select` | Allows selecting the view mode from a dropdown. | `true`, `false` | `false` |
108
+
109
+ Apart from these ones, two options - `popup` and `view_modes` (plural, not singular) - are available. They have "sub"-APIs, and thus are listed separately.
110
+
111
+ #### View Mode Configuration
112
+
113
+ The `view_modes` option determines all the available view modes for the chart. It should be an array of objects.
114
+
115
+ Each object can have the following properties:
116
+
117
+ - `name` (string) - the name of view mode.
118
+ - `padding` (interval) - the time above.
119
+ - `step` - the interval of each column
120
+ - `lower_text` (date format string _or_ function) - the format for text in lower header. Blank string for none. The function takes in `currentDate`, `previousDate`, and `lang`, and should return a string.
121
+ - `upper_text` (date format string _or_ function) - the format for text in upper header. Blank string for none. The function takes in `currentDate`, `previousDate`, and `lang`, and should return a string.
122
+ - `upper_text_frequency` (number) - how often the upper text has a value. Utilized in internal calculation to improve performance.
123
+ - `thick_line` (function) - takes in `currentDate`, returns Boolean determining whether the line for that date should be thicker than the others.
124
+
125
+ Three other options allow you to override general configuration for this view mode alone:
126
+
127
+ - `date_format`
128
+ - `column_width`
129
+ - `snap_at`
130
+ For details, see the above table.
131
+
132
+ #### Popup Configuration
133
+
134
+ `popup` is a function. If it returns
135
+
136
+ - `false`, there will be no popup.
137
+ - `undefined`, the popup will be rendered based on manipulation within the function
138
+ - a HTML string, the popup will be that string.
139
+
140
+ The function receives one object as an argument, containing:
141
+
142
+ - `task` - the task as an object
143
+ - `chart` - the entire Gantt chart
144
+ - `get_title`, `get_subtitle`, `get_details` (functions) - get the relevant section as a HTML node.
145
+ - `set_title`, `set_subtitle`, `set_details` (functions) - take in the HTML of the relevant section
146
+ - `add_action` (function) - accepts two parameters, `html` and `func` - respectively determining the HTML of the action and the callback when the action is pressed.
147
+
148
+ ### API
149
+
150
+ Frappe Gantt exposes a few helpful methods for you to interact with the chart:
151
+
152
+ | **Name** | **Description** | **Parameters** |
153
+ | ------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
154
+ | `.update_options` | Re-renders the chart after updating specific options. | `new_options` - object containing new options. |
155
+ | `.change_view_mode` | Updates the view mode. | `view_mode` - Name of view mode _or_ view mode object (see above) and `maintain_pos` - whether to go back to current scroll position after rerendering, defaults to `false`. |
156
+ | `.scroll_current` | Scrolls to the current date | No parameters. |
157
+ | `.update_task` | Re-renders a specific task bar alone | `task_id` - id of task and `new_details` - object containing the task properties to be updated. |
158
+
159
+ ## Development Setup
160
+
161
+ If you want to contribute enhancements or fixes:
162
+
163
+ 1. Clone this repo.
164
+ 2. `cd` into project directory.
165
+ 3. Run `pnpm i` to install dependencies.
166
+ 4. `pnpm run build` to build files - or `pnpm run build-dev` to build and watch for changes.
167
+ 5. Open `index.html` in your browser.
168
+ 6. Make your code changes and test them.
169
+
170
+ <br />
171
+ <br />
172
+ <div align="center" style="padding-top: 0.75rem;">
173
+ <a href="https://frappe.io" target="_blank">
174
+ <picture>
175
+ <source media="(prefers-color-scheme: dark)" srcset="https://frappe.io/files/Frappe-white.png">
176
+ <img src="https://frappe.io/files/Frappe-black.png" alt="Frappe Technologies" height="28"/>
177
+ </picture>
178
+ </a>
179
+ </div>
package/license.txt ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Frappe Technologies Pvt. Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "adore-gantt",
3
+ "version": "2.0.0",
4
+ "description": "A simple, modern, interactive gantt library for the web",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "vite build --watch",
9
+ "build": "vite build",
10
+ "lint": "eslint src/**/*.js",
11
+ "prettier": "prettier --write \"{src/*,tests/*,rollup.config}.js\"",
12
+ "prettier-check": "prettier --check \"{src/*,tests/*,rollup.config}.js\""
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/frappe/gantt.git"
17
+ },
18
+ "files": [
19
+ "src",
20
+ "dist",
21
+ "README.md"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "require": "./dist/adore-gantt.umd.js",
26
+ "import": "./dist/adore-gantt.es.js",
27
+ "style": "./dist/adore-gantt.css"
28
+ }
29
+ },
30
+ "keywords": [
31
+ "gantt",
32
+ "svg",
33
+ "simple gantt",
34
+ "project timeline",
35
+ "interactive gantt",
36
+ "project management"
37
+ ],
38
+ "author": "Faris Ansari",
39
+ "license": "MIT",
40
+ "bugs": {
41
+ "url": "https://github.com/frappe/gantt/issues"
42
+ },
43
+ "homepage": "https://github.com/frappe/gantt",
44
+ "devDependencies": {
45
+ "eslint": "^9.15.0",
46
+ "eslint-config-prettier": "^2.9.0",
47
+ "eslint-plugin-prettier": "^2.6.0",
48
+ "postcss-nesting": "^12.1.2",
49
+ "prettier": "3.2.5",
50
+ "vite": "^5.2.10"
51
+ },
52
+ "eslintIgnore": [
53
+ "dist"
54
+ ],
55
+ "sideEffects": [
56
+ "*.css"
57
+ ]
58
+ }
package/src/arrow.js ADDED
@@ -0,0 +1,103 @@
1
+ import { createSVG } from './svg_utils';
2
+
3
+ export default class Arrow {
4
+ constructor(gantt, from_task, to_task) {
5
+ this.gantt = gantt;
6
+ this.from_task = from_task;
7
+ this.to_task = to_task;
8
+
9
+ this.calculate_path();
10
+ this.draw();
11
+ }
12
+
13
+ calculate_path() {
14
+ let start_x =
15
+ this.from_task.$bar.getX() + this.from_task.$bar.getWidth() / 2;
16
+
17
+ const condition = () =>
18
+ this.to_task.$bar.getX() < start_x + this.gantt.options.padding &&
19
+ start_x > this.from_task.$bar.getX() + this.gantt.options.padding;
20
+
21
+ while (condition()) {
22
+ start_x -= 10;
23
+ }
24
+ start_x -= 10;
25
+
26
+ let start_y =
27
+ this.gantt.config.header_height +
28
+ this.gantt.options.bar_height +
29
+ (this.gantt.options.padding + this.gantt.options.bar_height) *
30
+ this.from_task.task._index +
31
+ this.gantt.options.padding / 2;
32
+
33
+ let end_x = this.to_task.$bar.getX() - 13;
34
+ let end_y =
35
+ this.gantt.config.header_height +
36
+ this.gantt.options.bar_height / 2 +
37
+ (this.gantt.options.padding + this.gantt.options.bar_height) *
38
+ this.to_task.task._index +
39
+ this.gantt.options.padding / 2;
40
+
41
+ const from_is_below_to =
42
+ this.from_task.task._index > this.to_task.task._index;
43
+
44
+ let curve = this.gantt.options.arrow_curve;
45
+ const clockwise = from_is_below_to ? 1 : 0;
46
+ let curve_y = from_is_below_to ? -curve : curve;
47
+
48
+ if (
49
+ this.to_task.$bar.getX() <=
50
+ this.from_task.$bar.getX() + this.gantt.options.padding
51
+ ) {
52
+ let down_1 = this.gantt.options.padding / 2 - curve;
53
+ if (down_1 < 0) {
54
+ down_1 = 0;
55
+ curve = this.gantt.options.padding / 2;
56
+ curve_y = from_is_below_to ? -curve : curve;
57
+ }
58
+ const down_2 =
59
+ this.to_task.$bar.getY() +
60
+ this.to_task.$bar.getHeight() / 2 -
61
+ curve_y;
62
+ const left = this.to_task.$bar.getX() - this.gantt.options.padding;
63
+ this.path = `
64
+ M ${start_x} ${start_y}
65
+ v ${down_1}
66
+ a ${curve} ${curve} 0 0 1 ${-curve} ${curve}
67
+ H ${left}
68
+ a ${curve} ${curve} 0 0 ${clockwise} ${-curve} ${curve_y}
69
+ V ${down_2}
70
+ a ${curve} ${curve} 0 0 ${clockwise} ${curve} ${curve_y}
71
+ L ${end_x} ${end_y}
72
+ m -5 -5
73
+ l 5 5
74
+ l -5 5`;
75
+ } else {
76
+ if (end_x < start_x + curve) curve = end_x - start_x;
77
+
78
+ let offset = from_is_below_to ? end_y + curve : end_y - curve;
79
+
80
+ this.path = `
81
+ M ${start_x} ${start_y}
82
+ V ${offset}
83
+ a ${curve} ${curve} 0 0 ${clockwise} ${curve} ${curve}
84
+ L ${end_x} ${end_y}
85
+ m -5 -5
86
+ l 5 5
87
+ l -5 5`;
88
+ }
89
+ }
90
+
91
+ draw() {
92
+ this.element = createSVG('path', {
93
+ d: this.path,
94
+ 'data-from': this.from_task.task.id,
95
+ 'data-to': this.to_task.task.id,
96
+ });
97
+ }
98
+
99
+ update() {
100
+ this.calculate_path();
101
+ this.element.setAttribute('d', this.path);
102
+ }
103
+ }