├── image.png
├── .gitignore
├── .editorconfig
├── rollup.config.js
├── license
├── src
├── index.js
├── layout.js
├── milestones.js
├── tasks.js
└── style.js
├── package.json
├── demo
└── index.html
└── readme.md
/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nextbitlabs/gantt-chart/HEAD/image.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | dist
4 | npm-debug.log*
5 | .vscode
6 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = tab
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import resolve from '@rollup/plugin-node-resolve';
2 | import commonjs from 'rollup-plugin-commonjs';
3 | import pkg from './package.json';
4 |
5 | export default [
6 | {
7 | input: 'src/index.js',
8 | output: {
9 | name: 'ganttChart',
10 | file: pkg.browser,
11 | format: 'umd'
12 | },
13 | plugins: [
14 | resolve(),
15 | commonjs()
16 | ]
17 | },
18 | {
19 | input: 'src/index.js',
20 | external: ['ms'],
21 | output: [
22 | { file: pkg.main, format: 'cjs' },
23 | { file: pkg.module, format: 'es' }
24 | ]
25 | }
26 | ];
27 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | Copyright 2019 Riccardo Scalco
2 |
3 | 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:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | 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.
8 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import {html, define, property} from 'hybrids';
2 | import style from './style';
3 | import {
4 | margin,
5 | trimWidth,
6 | trimHeight,
7 | globalTransform,
8 | taskHeight,
9 | taskVerticalPosition,
10 | latestEnd,
11 | unitWidth,
12 | taskHorizontalPosition,
13 | taskWidth
14 | } from './layout';
15 | import {tasks} from './tasks';
16 | import {milestones} from './milestones';
17 |
18 | function render({
19 | width,
20 | height,
21 | tasks,
22 | milestones,
23 | globalTransform
24 | }) {
25 | return html`
26 | ${style}
27 |
33 | `;
34 | }
35 |
36 | export const GanttChart = {
37 | data: property({
38 | tasks: []
39 | }),
40 | width: 800,
41 | height: 600,
42 | marginRight: 20,
43 | marginBottom: 20,
44 | marginLeft: 20,
45 | marginTop: 20,
46 | margin,
47 | trimWidth,
48 | trimHeight,
49 | globalTransform,
50 | taskHeight,
51 | taskVerticalPosition,
52 | latestEnd,
53 | unitWidth,
54 | taskHorizontalPosition,
55 | taskWidth,
56 | tasks,
57 | milestones,
58 | render
59 | };
60 |
61 | define('gantt-chart', GanttChart);
62 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@nextbitlabs/gantt-chart",
3 | "version": "1.3.2",
4 | "description": "Web component of a gantt chart.",
5 | "main": "dist/gantt-chart.cjs.js",
6 | "module": "dist/gantt-chart.esm.js",
7 | "browser": "dist/gantt-chart.umd.js",
8 | "scripts": {
9 | "build": "rollup -c",
10 | "dev": "rollup -c -w",
11 | "pretest": "npm run build",
12 | "test": "xo src/*",
13 | "lint-fix": "xo --fix src/*",
14 | "release": "np"
15 | },
16 | "keywords": [
17 | "gantt",
18 | "plot",
19 | "chart",
20 | "webcomponent",
21 | "component"
22 | ],
23 | "author": {
24 | "name": "Riccardo Scalco",
25 | "email": "riccardoscalco@gmail.com",
26 | "url": "http://riccardoscalco.github.io/"
27 | },
28 | "license": "MIT",
29 | "repository": "nextbitlabs/gantt-chart",
30 | "homepage": "https://github.com/nextbitlabs/gantt-chart/",
31 | "bugs": "https://github.com/nextbitlabs/gantt-chart/issues",
32 | "devDependencies": {
33 | "@rollup/plugin-node-resolve": "^7.1.1",
34 | "hybrids": "^4.0.3",
35 | "np": "^6.2.0",
36 | "rollup": "^1.27.13",
37 | "rollup-plugin-commonjs": "^10.1.0",
38 | "xo": "^0.27.2"
39 | },
40 | "files": [
41 | "dist"
42 | ],
43 | "publishConfig": {
44 | "access": "public"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/layout.js:
--------------------------------------------------------------------------------
1 | export const margin = {
2 | get: ({marginRight, marginBottom, marginLeft, marginTop}) => ({
3 | top: marginTop,
4 | right: marginRight,
5 | bottom: marginBottom,
6 | left: marginLeft
7 | })
8 | };
9 |
10 | export const trimWidth = {
11 | get: ({width, margin}) => width - margin.left - margin.right
12 | };
13 |
14 | export const trimHeight = {
15 | get: ({height, margin}) => height - margin.top - margin.bottom
16 | };
17 |
18 | export const globalTransform = {
19 | get: ({margin}) => `translate(${margin.left}, ${margin.top})`
20 | };
21 |
22 | export const taskHeight = {
23 | get: ({trimHeight, data}) => trimHeight / Math.max(10, data.tasks.length)
24 | };
25 |
26 | export const taskVerticalPosition = {
27 | get: ({taskHeight}) => index => taskHeight * index
28 | };
29 |
30 | export const latestEnd = {
31 | get: ({data}) => data.tasks.length > 0 ?
32 | data.tasks
33 | .map(el => el.start + el.duration)
34 | .reduce((p, c) => c > p ? c : p, 0) :
35 | 1
36 | };
37 |
38 | export const unitWidth = {
39 | get: ({trimWidth, latestEnd}) => trimWidth / latestEnd
40 | };
41 |
42 | export const taskHorizontalPosition = {
43 | get: ({unitWidth}) => start => unitWidth * start
44 | };
45 |
46 | export const taskWidth = {
47 | get: ({unitWidth}) => duration => unitWidth * duration
48 | };
49 |
--------------------------------------------------------------------------------
/src/milestones.js:
--------------------------------------------------------------------------------
1 | import {svg} from 'hybrids';
2 |
3 | const taskVerticalPadding = 2;
4 |
5 | const shift = (tasks, task, index) => {
6 | const isInTaskInterval = (c, task) =>
7 | (c.start >= task.start) && (c.start <= (task.start + task.duration));
8 | return tasks
9 | .reduce(
10 | (p, c, i) => (i >= index) && isInTaskInterval(c, task) ? p + 1 : p,
11 | 0
12 | );
13 | };
14 |
15 | export const milestones = {
16 | get: ({
17 | data,
18 | taskVerticalPosition,
19 | taskHorizontalPosition,
20 | taskWidth,
21 | taskHeight
22 | }) => {
23 | const sortedTasks = data.tasks
24 | .map(el => el)
25 | .sort((a, b) =>
26 | (a.start < b.start) ||
27 | ((a.start === b.start) && (a.duration < b.duration)) ?
28 | -1 :
29 | 1
30 | );
31 | return data.milestones.map(milestone => {
32 | const index = sortedTasks.findIndex(task => task.id === milestone.taskId);
33 | const task = sortedTasks[index];
34 | return svg`
35 |
11 |