@operato/gantt 2.0.0-beta.0 → 2.0.0-beta.1

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/src/locale.d.ts +1 -0
  3. package/dist/src/locale.js +49 -0
  4. package/dist/src/locale.js.map +1 -0
  5. package/dist/src/ox-gantt-chart.d.ts +39 -0
  6. package/dist/src/ox-gantt-chart.js +707 -0
  7. package/dist/src/ox-gantt-chart.js.map +1 -0
  8. package/dist/src/ox-gantt-resize-splitter.d.ts +13 -0
  9. package/dist/src/ox-gantt-resize-splitter.js +117 -0
  10. package/dist/src/ox-gantt-resize-splitter.js.map +1 -0
  11. package/dist/src/ox-gantt.d.ts +24 -0
  12. package/dist/src/ox-gantt.js +186 -0
  13. package/dist/src/ox-gantt.js.map +1 -0
  14. package/dist/src/types.d.ts +10 -5
  15. package/dist/src/types.js.map +1 -1
  16. package/dist/src/utils.d.ts +3 -0
  17. package/dist/src/utils.js +10 -0
  18. package/dist/src/utils.js.map +1 -0
  19. package/dist/stories/ox-gantt-chart.stories.d.ts +41 -0
  20. package/dist/stories/{ox-lite-gantt.stories.js → ox-gantt-chart.stories.js} +53 -21
  21. package/dist/stories/ox-gantt-chart.stories.js.map +1 -0
  22. package/dist/stories/ox-gantt.stories.d.ts +6 -1
  23. package/dist/stories/ox-gantt.stories.js +286 -15
  24. package/dist/stories/ox-gantt.stories.js.map +1 -1
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +12 -4
  27. package/src/locale.ts +51 -0
  28. package/src/ox-gantt-chart.ts +773 -0
  29. package/src/ox-gantt-resize-splitter.ts +137 -0
  30. package/src/ox-gantt.ts +177 -0
  31. package/src/types.ts +12 -6
  32. package/src/utils.ts +13 -0
  33. package/stories/{ox-lite-gantt.stories.ts → ox-gantt-chart.stories.ts} +65 -22
  34. package/stories/ox-gantt.stories.ts +289 -16
  35. package/themes/dark-hc.css +151 -0
  36. package/themes/dark-mc.css +151 -0
  37. package/themes/dark.css +151 -0
  38. package/themes/grist-theme.css +169 -0
  39. package/themes/light-hc.css +151 -0
  40. package/themes/light-mc.css +151 -0
  41. package/themes/light.css +151 -0
  42. package/themes/md-typescale-styles.css +100 -0
  43. package/themes/spacing.css +43 -0
  44. package/themes/state-color.css +6 -0
  45. package/dist/src/gantt.d.ts +0 -28
  46. package/dist/src/gantt.js +0 -178
  47. package/dist/src/gantt.js.map +0 -1
  48. package/dist/src/lite-gantt.d.ts +0 -27
  49. package/dist/src/lite-gantt.js +0 -146
  50. package/dist/src/lite-gantt.js.map +0 -1
  51. package/dist/stories/ox-lite-gantt.stories.d.ts +0 -22
  52. package/dist/stories/ox-lite-gantt.stories.js.map +0 -1
  53. package/src/gantt.ts +0 -191
  54. package/src/lite-gantt.ts +0 -152
  55. package/src/renderer.txt +0 -775
@@ -1,146 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { LitElement, css, html } from 'lit';
3
- import { customElement, property, query } from 'lit/decorators.js';
4
- import * as d3 from 'd3';
5
- let OxLiteGanttChart = class OxLiteGanttChart extends LitElement {
6
- constructor() {
7
- super(...arguments);
8
- this.width = 0;
9
- this.height = 0;
10
- this.plots = [];
11
- this.precision = 2;
12
- }
13
- static { this.styles = [
14
- css `
15
- :host {
16
- display: flex;
17
- }
18
-
19
- svg {
20
- flex: 1;
21
- margin: 0;
22
- padding: 0;
23
- }
24
-
25
- #tooltip {
26
- position: absolute;
27
- opacity: 0;
28
- background-color: var(--gantt-chart-tooltip-background-color, white);
29
- padding: var(--gantt-chart-tooltip-padding, 5px);
30
- border: var(--gantt-chart-tooltip-border, 1px solid black);
31
- border-radius: var(--gantt-chart-tooltip-border-radius, 5px);
32
- box-shadow: var(--gantt-chart-tooltip-box-shadow, 2px 2px 5px rgba(0, 0, 0, 0.3));
33
- pointer-events: var(--gantt-chart-tooltip-pointer-events, none);
34
- font-size: var(--gantt-chart-tooltip-font-size, 12px);
35
- font-family: var(--gantt-chart-tooltip-font-family, Arial, sans-serif);
36
- transition: opacity 0.3s ease-in-out;
37
- }
38
-
39
- .data-point {
40
- stroke: var(--gantt-chart-plot-stroke, black);
41
- stroke-width: var(--gantt-chart-plot-stroke-width, 1px);
42
- r: var(--gantt-chart-plot-r, 4);
43
- }
44
- `
45
- ]; }
46
- render() {
47
- return html `
48
- <svg id="chart"></svg>
49
- <div id="tooltip"></div>
50
- `;
51
- }
52
- connectedCallback() {
53
- super.connectedCallback();
54
- this.initializeResizeObserver();
55
- }
56
- disconnectedCallback() {
57
- if (this.resizeObserver) {
58
- this.resizeObserver.disconnect();
59
- }
60
- super.disconnectedCallback();
61
- }
62
- initializeResizeObserver() {
63
- this.resizeObserver = new ResizeObserver(entries => {
64
- for (const entry of entries) {
65
- this.initializeChart();
66
- this.drawChart();
67
- }
68
- });
69
- this.resizeObserver.observe(this);
70
- }
71
- updated(changedProperties) {
72
- super.updated(changedProperties);
73
- if (changedProperties.has('plots') && this.plots.length > 0) {
74
- this.initializeChart();
75
- this.drawChart();
76
- }
77
- }
78
- initializeChart() {
79
- const chart = this.chart;
80
- d3.select(chart).selectAll('g').remove();
81
- this.svg = d3.select(chart).append('g');
82
- this.addMouseHandlers();
83
- }
84
- drawChart() { }
85
- addMouseHandlers() {
86
- d3.select(this.chart)
87
- .on('mouseover', this.onMouseOver.bind(this))
88
- .on('mousemove', this.onMouseMove.bind(this))
89
- .on('mouseout', this.onMouseOut.bind(this));
90
- }
91
- onMouseOver(event) {
92
- const target = d3.select(event.target);
93
- if (target.classed('tooltip')) {
94
- const data = target.datum();
95
- this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY);
96
- }
97
- }
98
- onMouseMove(event) {
99
- const target = d3.select(event.target);
100
- if (target.classed('tooltip')) {
101
- const data = target.datum();
102
- this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY);
103
- }
104
- }
105
- onMouseOut(event) {
106
- const target = d3.select(event.target);
107
- if (target.classed('tooltip')) {
108
- this.hideTooltip();
109
- }
110
- }
111
- tooltipContent(data) {
112
- return `Data: ${data}`;
113
- }
114
- showTooltip(content, x, y) {
115
- this.tooltip.style.opacity = '1';
116
- this.tooltip.style.left = `${x}px`;
117
- this.tooltip.style.top = `${y}px`;
118
- this.tooltip.innerHTML = content;
119
- }
120
- hideTooltip() {
121
- this.tooltip.style.opacity = '0';
122
- }
123
- };
124
- __decorate([
125
- property({ type: Number })
126
- ], OxLiteGanttChart.prototype, "width", void 0);
127
- __decorate([
128
- property({ type: Number })
129
- ], OxLiteGanttChart.prototype, "height", void 0);
130
- __decorate([
131
- property({ type: Array })
132
- ], OxLiteGanttChart.prototype, "plots", void 0);
133
- __decorate([
134
- property({ type: Number })
135
- ], OxLiteGanttChart.prototype, "precision", void 0);
136
- __decorate([
137
- query('#tooltip')
138
- ], OxLiteGanttChart.prototype, "tooltip", void 0);
139
- __decorate([
140
- query('#chart')
141
- ], OxLiteGanttChart.prototype, "chart", void 0);
142
- OxLiteGanttChart = __decorate([
143
- customElement('ox-lite-gantt-chart')
144
- ], OxLiteGanttChart);
145
- export { OxLiteGanttChart };
146
- //# sourceMappingURL=lite-gantt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lite-gantt.js","sourceRoot":"","sources":["../../src/lite-gantt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AAGjB,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,UAAU;IAAzC;;QACuB,UAAK,GAAW,CAAC,CAAA;QACjB,WAAM,GAAW,CAAC,CAAA;QACnB,UAAK,GAAe,EAAE,CAAA;QAErB,cAAS,GAAY,CAAC,CAAA;IA6IpD,CAAC;aApIQ,WAAM,GAAG;QACd,GA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E,CAAC,MAAM,CAAC,KAAK,CAAC,MAAqB,CAAC,CAAA;QAErD,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,WAAW,EAAE,CAAA;QACpB,CAAC;IACH,CAAC;IAES,cAAc,CAAC,IAAS;QAChC,OAAO,SAAS,IAAI,EAAE,CAAA;IACxB,CAAC;IAES,WAAW,CAAC,OAAe,EAAE,CAAS,EAAE,CAAS;QACzD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAA;QAChC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QAClC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAA;QACjC,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,OAAO,CAAA;IAClC,CAAC;IAES,WAAW;QACnB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAA;IAClC,CAAC;;AAhJ2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAkB;AACjB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAAmB;AACnB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;+CAAuB;AAErB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mDAAuB;AAE/B;IAAlB,KAAK,CAAC,UAAU,CAAC;iDAAyB;AAC1B;IAAhB,KAAK,CAAC,QAAQ,CAAC;+CAAsB;AAR3B,gBAAgB;IAD5B,aAAa,CAAC,qBAAqB,CAAC;GACxB,gBAAgB,CAkJ5B","sourcesContent":["import { LitElement, css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport * as d3 from 'd3'\n\n@customElement('ox-lite-gantt-chart')\nexport class OxLiteGanttChart extends LitElement {\n @property({ type: Number }) width: number = 0\n @property({ type: Number }) height: number = 0\n @property({ type: Array }) plots: Array<any> = []\n\n @property({ type: Number }) precision?: number = 2\n\n @query('#tooltip') tooltip!: HTMLDivElement\n @query('#chart') chart!: SVGSVGElement\n\n protected svg?: d3.Selection<SVGGElement, unknown, null, undefined>\n\n private resizeObserver?: ResizeObserver\n\n static styles = [\n css`\n :host {\n display: flex;\n }\n\n svg {\n flex: 1;\n margin: 0;\n padding: 0;\n }\n\n #tooltip {\n position: absolute;\n opacity: 0;\n background-color: var(--gantt-chart-tooltip-background-color, white);\n padding: var(--gantt-chart-tooltip-padding, 5px);\n border: var(--gantt-chart-tooltip-border, 1px solid black);\n border-radius: var(--gantt-chart-tooltip-border-radius, 5px);\n box-shadow: var(--gantt-chart-tooltip-box-shadow, 2px 2px 5px rgba(0, 0, 0, 0.3));\n pointer-events: var(--gantt-chart-tooltip-pointer-events, none);\n font-size: var(--gantt-chart-tooltip-font-size, 12px);\n font-family: var(--gantt-chart-tooltip-font-family, Arial, sans-serif);\n transition: opacity 0.3s ease-in-out;\n }\n\n .data-point {\n stroke: var(--gantt-chart-plot-stroke, black);\n stroke-width: var(--gantt-chart-plot-stroke-width, 1px);\n r: var(--gantt-chart-plot-r, 4);\n }\n `\n ]\n\n render() {\n return html`\n <svg id=\"chart\"></svg>\n <div id=\"tooltip\"></div>\n `\n }\n\n connectedCallback(): void {\n super.connectedCallback()\n this.initializeResizeObserver()\n }\n\n disconnectedCallback(): void {\n if (this.resizeObserver) {\n this.resizeObserver.disconnect()\n }\n super.disconnectedCallback()\n }\n\n protected initializeResizeObserver(): void {\n this.resizeObserver = new ResizeObserver(entries => {\n for (const entry of entries) {\n this.initializeChart()\n this.drawChart()\n }\n })\n\n this.resizeObserver.observe(this)\n }\n\n updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated(changedProperties)\n\n if (changedProperties.has('plots') && this.plots.length > 0) {\n this.initializeChart()\n this.drawChart()\n }\n }\n\n protected initializeChart(): void {\n const chart = this.chart\n\n d3.select(chart).selectAll('g').remove()\n\n this.svg = d3.select(chart).append('g')\n\n this.addMouseHandlers()\n }\n\n protected drawChart(): void {}\n\n private addMouseHandlers(): void {\n d3.select(this.chart)\n .on('mouseover', this.onMouseOver.bind(this))\n .on('mousemove', this.onMouseMove.bind(this))\n .on('mouseout', this.onMouseOut.bind(this))\n }\n\n protected onMouseOver(event: MouseEvent): void {\n const target = d3.select(event.target as HTMLElement)\n\n if (target.classed('tooltip')) {\n const data = target.datum()\n this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY)\n }\n }\n\n protected onMouseMove(event: MouseEvent): void {\n const target = d3.select(event.target as HTMLElement)\n\n if (target.classed('tooltip')) {\n const data = target.datum()\n this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY)\n }\n }\n\n protected onMouseOut(event: MouseEvent): void {\n const target = d3.select(event.target as HTMLElement)\n\n if (target.classed('tooltip')) {\n this.hideTooltip()\n }\n }\n\n protected tooltipContent(data: any): string {\n return `Data: ${data}`\n }\n\n protected showTooltip(content: string, x: number, y: number): void {\n this.tooltip.style.opacity = '1'\n this.tooltip.style.left = `${x}px`\n this.tooltip.style.top = `${y}px`\n this.tooltip.innerHTML = content\n }\n\n protected hideTooltip(): void {\n this.tooltip.style.opacity = '0'\n }\n}\n"]}
@@ -1,22 +0,0 @@
1
- import '../src/lite-gantt.js';
2
- import { TemplateResult } from 'lit';
3
- declare const _default: {
4
- title: string;
5
- component: string;
6
- argTypes: {
7
- theme: {
8
- control: string;
9
- options: string[];
10
- };
11
- };
12
- };
13
- export default _default;
14
- interface Story<T> {
15
- (args: T): TemplateResult;
16
- args?: Partial<T>;
17
- argTypes?: Record<string, unknown>;
18
- }
19
- interface ArgTypes {
20
- theme: 'light' | 'dark';
21
- }
22
- export declare const Regular: Story<ArgTypes>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"ox-lite-gantt.stories.js","sourceRoot":"","sources":["../../stories/ox-lite-gantt.stories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,sBAAsB,CAAA;AAE7B,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC1C,OAAO,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,8CAA8C,CAAA;AAI1F,eAAe;IACb,KAAK,EAAE,eAAe;IACtB,SAAS,EAAE,eAAe;IAC1B,QAAQ,EAAE;QACR,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;KACzD;CACF,CAAA;AAYD,MAAM,QAAQ,GAAoB,CAAC,EAAE,KAAK,GAAG,OAAO,EAAY,EAAE,EAAE,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;MAqBnE,iBAAiB,CAAC,OAAO;;;;MAIzB,kBAAkB,CAAC,OAAO;;;;;;;;;;;;;;;;;;;;;mCAqBG,KAAK;;;;;;kBAMtB,CAAC,CAAc,EAAE,EAAE;IAC3B,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;AAC9C,CAAC;;;;;CAKR,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACxC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAA","sourcesContent":["import { CommonHeaderStyles } from '@operato/styles'\nimport '../src/lite-gantt.js'\n\nimport { html, TemplateResult } from 'lit'\nimport { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'\n\nimport { Task, Section } from '../src/types.js'\n\nexport default {\n title: 'ox-lite-gantt',\n component: 'ox-lite-gantt',\n argTypes: {\n theme: { control: 'select', options: ['light', 'dark'] }\n }\n}\n\ninterface Story<T> {\n (args: T): TemplateResult\n args?: Partial<T>\n argTypes?: Record<string, unknown>\n}\n\ninterface ArgTypes {\n theme: 'light' | 'dark'\n}\n\nconst Template: Story<ArgTypes> = ({ theme = 'light' }: ArgTypes) => html`\n <link href=\"https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap\" rel=\"stylesheet\" />\n\n <link href=\"/themes/light.css\" rel=\"stylesheet\" />\n <link href=\"/themes/dark.css\" rel=\"stylesheet\" />\n <link href=\"/themes/spacing.css\" rel=\"stylesheet\" />\n\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n <link\n href=\"https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1\"\n rel=\"stylesheet\"\n />\n\n <style>\n ${MDTypeScaleStyles.cssText}\n </style>\n\n <style>\n ${CommonHeaderStyles.cssText}\n </style>\n\n <style>\n body {\n width: 100%;\n height: 500px;\n text-align: center;\n\n background-color: var(--md-sys-color-background);\n color: var(--md-sys-color-on-background);\n }\n\n .header {\n padding: var(--spacing-medium);\n background-color: var(--md-sys-color-primary-container);\n color: var(--md-sys-color-on-primary-container);\n }\n </style>\n\n <script>\n document.body.classList.add('${theme}')\n </script>\n\n <div class=\"header\">\n <div class=\"filters\">\n <ox-lite-gantt\n @change=${(e: CustomEvent) => {\n console.log('search form changed', e.detail)\n }}\n >\n </ox-lite-gantt>\n </div>\n </div>\n`\n\nexport const Regular = Template.bind({})\nRegular.args = {}\n"]}
package/src/gantt.ts DELETED
@@ -1,191 +0,0 @@
1
- import { LitElement, css, html } from 'lit'
2
- import { customElement, property, query } from 'lit/decorators.js'
3
- import * as d3 from 'd3'
4
-
5
- @customElement('ox-gantt-chart')
6
- export class OxGanttChart extends LitElement {
7
- @property({ type: Number }) width: number = 0
8
- @property({ type: Number }) height: number = 0
9
- @property({ type: Array }) plots: Array<any> = []
10
-
11
- @property({ type: Number }) precision?: number = 2
12
-
13
- @query('#tooltip') tooltip!: HTMLDivElement
14
- @query('#chart') chart!: SVGSVGElement
15
-
16
- protected svg?: d3.Selection<SVGGElement, unknown, null, undefined>
17
-
18
- private resizeObserver?: ResizeObserver
19
-
20
- static styles = [
21
- css`
22
- :host {
23
- display: flex;
24
- }
25
-
26
- svg {
27
- flex: 1;
28
- margin: 0;
29
- padding: 0;
30
- }
31
-
32
- #tooltip {
33
- position: absolute;
34
- opacity: 0;
35
- background-color: var(--gantt-chart-tooltip-background-color, white);
36
- padding: var(--gantt-chart-tooltip-padding, 5px);
37
- border: var(--gantt-chart-tooltip-border, 1px solid black);
38
- border-radius: var(--gantt-chart-tooltip-border-radius, 5px);
39
- box-shadow: var(--gantt-chart-tooltip-box-shadow, 2px 2px 5px rgba(0, 0, 0, 0.3));
40
- pointer-events: var(--gantt-chart-tooltip-pointer-events, none);
41
- font-size: var(--gantt-chart-tooltip-font-size, 12px);
42
- font-family: var(--gantt-chart-tooltip-font-family, Arial, sans-serif);
43
- transition: opacity 0.3s ease-in-out;
44
- }
45
-
46
- .data-point {
47
- stroke: var(--gantt-chart-plot-stroke, black);
48
- stroke-width: var(--gantt-chart-plot-stroke-width, 1px);
49
- r: var(--gantt-chart-plot-r, 4);
50
- }
51
- `
52
- ]
53
-
54
- render() {
55
- return html`
56
- <svg id="chart"></svg>
57
- <div id="tooltip"></div>
58
- `
59
- }
60
-
61
- connectedCallback(): void {
62
- super.connectedCallback()
63
- this.initializeResizeObserver()
64
- }
65
-
66
- disconnectedCallback(): void {
67
- if (this.resizeObserver) {
68
- this.resizeObserver.disconnect()
69
- }
70
- super.disconnectedCallback()
71
- }
72
-
73
- protected initializeResizeObserver(): void {
74
- this.resizeObserver = new ResizeObserver(entries => {
75
- for (const entry of entries) {
76
- this.initializeChart()
77
- this.drawChart()
78
- }
79
- })
80
-
81
- this.resizeObserver.observe(this)
82
- }
83
-
84
- updated(changedProperties: Map<string | number | symbol, unknown>) {
85
- super.updated(changedProperties)
86
-
87
- if (changedProperties.has('plots') && this.plots.length > 0) {
88
- this.initializeChart()
89
- this.drawChart()
90
- }
91
- }
92
-
93
- protected initializeChart(): void {
94
- const chart = this.chart
95
-
96
- d3.select(chart).selectAll('g').remove()
97
-
98
- this.svg = d3.select(chart).append('g')
99
-
100
- this.addMouseHandlers()
101
- }
102
-
103
- protected drawChart(): void {
104
- const tasks = [
105
- { task: 'Task 1', startDate: new Date('2024-02-01'), endDate: new Date('2024-02-07') },
106
- { task: 'Task 2', startDate: new Date('2024-02-05'), endDate: new Date('2024-02-15') },
107
- { task: 'Task 3', startDate: new Date('2024-02-10'), endDate: new Date('2024-02-20') }
108
- ]
109
-
110
- const g = this.svg!
111
-
112
- const x = d3
113
- .scaleTime()
114
- .domain([d3.min(tasks, d => d.startDate)!, d3.max(tasks, d => d.endDate)!])
115
- .range([0, this.width])
116
-
117
- const y = d3
118
- .scaleBand()
119
- .domain(tasks.map(d => d.task))
120
- .range([0, this.height])
121
- .padding(0.1)
122
-
123
- g.selectAll('.task')
124
- .data(tasks)
125
- .enter()
126
- .append('rect')
127
- .attr('class', 'task')
128
- .attr('x', d => x(d.startDate))
129
- .attr('y', d => y(d.task)!)
130
- .attr('width', d => x(d.endDate) - x(d.startDate))
131
- .attr('height', y.bandwidth())
132
-
133
- g.append('g')
134
- .attr('transform', 'translate(0,' + this.height + ')')
135
- .call(d3.axisBottom(x))
136
-
137
- g.append('g').call(d3.axisLeft(y))
138
- }
139
-
140
- private addMouseHandlers(): void {
141
- d3.select(this.chart)
142
- .on('mouseover', this.onMouseOver.bind(this))
143
- .on('mousemove', this.onMouseMove.bind(this))
144
- .on('mouseout', this.onMouseOut.bind(this))
145
- }
146
-
147
- protected onMouseOver(event: MouseEvent): void {
148
- const target = d3.select(event.target as HTMLElement)
149
-
150
- if (target.classed('tooltip')) {
151
- const data = target.datum()
152
- this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY)
153
- }
154
- }
155
-
156
- protected onMouseMove(event: MouseEvent): void {
157
- const target = d3.select(event.target as HTMLElement)
158
-
159
- if (target.classed('tooltip')) {
160
- const data = target.datum()
161
- this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY)
162
- }
163
- }
164
-
165
- protected onMouseOut(event: MouseEvent): void {
166
- const target = d3.select(event.target as HTMLElement)
167
-
168
- if (target.classed('tooltip')) {
169
- this.hideTooltip()
170
- }
171
- }
172
-
173
- protected tooltipContent(data: any): string {
174
- return `Data: ${data}`
175
- }
176
-
177
- protected showTooltip(content: string, x: number, y: number): void {
178
- this.tooltip.style.opacity = '1'
179
- this.tooltip.style.left = `${x}px`
180
- this.tooltip.style.top = `${y}px`
181
- this.tooltip.innerHTML = content
182
- }
183
-
184
- protected hideTooltip(): void {
185
- this.tooltip.style.opacity = '0'
186
- }
187
-
188
- protected plotData(): void {
189
- this.svg!.selectAll('.plot').data(this.plots).enter().append('circle').attr('class', 'plot tooltip')
190
- }
191
- }
package/src/lite-gantt.ts DELETED
@@ -1,152 +0,0 @@
1
- import { LitElement, css, html } from 'lit'
2
- import { customElement, property, query } from 'lit/decorators.js'
3
- import * as d3 from 'd3'
4
-
5
- @customElement('ox-lite-gantt-chart')
6
- export class OxLiteGanttChart extends LitElement {
7
- @property({ type: Number }) width: number = 0
8
- @property({ type: Number }) height: number = 0
9
- @property({ type: Array }) plots: Array<any> = []
10
-
11
- @property({ type: Number }) precision?: number = 2
12
-
13
- @query('#tooltip') tooltip!: HTMLDivElement
14
- @query('#chart') chart!: SVGSVGElement
15
-
16
- protected svg?: d3.Selection<SVGGElement, unknown, null, undefined>
17
-
18
- private resizeObserver?: ResizeObserver
19
-
20
- static styles = [
21
- css`
22
- :host {
23
- display: flex;
24
- }
25
-
26
- svg {
27
- flex: 1;
28
- margin: 0;
29
- padding: 0;
30
- }
31
-
32
- #tooltip {
33
- position: absolute;
34
- opacity: 0;
35
- background-color: var(--gantt-chart-tooltip-background-color, white);
36
- padding: var(--gantt-chart-tooltip-padding, 5px);
37
- border: var(--gantt-chart-tooltip-border, 1px solid black);
38
- border-radius: var(--gantt-chart-tooltip-border-radius, 5px);
39
- box-shadow: var(--gantt-chart-tooltip-box-shadow, 2px 2px 5px rgba(0, 0, 0, 0.3));
40
- pointer-events: var(--gantt-chart-tooltip-pointer-events, none);
41
- font-size: var(--gantt-chart-tooltip-font-size, 12px);
42
- font-family: var(--gantt-chart-tooltip-font-family, Arial, sans-serif);
43
- transition: opacity 0.3s ease-in-out;
44
- }
45
-
46
- .data-point {
47
- stroke: var(--gantt-chart-plot-stroke, black);
48
- stroke-width: var(--gantt-chart-plot-stroke-width, 1px);
49
- r: var(--gantt-chart-plot-r, 4);
50
- }
51
- `
52
- ]
53
-
54
- render() {
55
- return html`
56
- <svg id="chart"></svg>
57
- <div id="tooltip"></div>
58
- `
59
- }
60
-
61
- connectedCallback(): void {
62
- super.connectedCallback()
63
- this.initializeResizeObserver()
64
- }
65
-
66
- disconnectedCallback(): void {
67
- if (this.resizeObserver) {
68
- this.resizeObserver.disconnect()
69
- }
70
- super.disconnectedCallback()
71
- }
72
-
73
- protected initializeResizeObserver(): void {
74
- this.resizeObserver = new ResizeObserver(entries => {
75
- for (const entry of entries) {
76
- this.initializeChart()
77
- this.drawChart()
78
- }
79
- })
80
-
81
- this.resizeObserver.observe(this)
82
- }
83
-
84
- updated(changedProperties: Map<string | number | symbol, unknown>) {
85
- super.updated(changedProperties)
86
-
87
- if (changedProperties.has('plots') && this.plots.length > 0) {
88
- this.initializeChart()
89
- this.drawChart()
90
- }
91
- }
92
-
93
- protected initializeChart(): void {
94
- const chart = this.chart
95
-
96
- d3.select(chart).selectAll('g').remove()
97
-
98
- this.svg = d3.select(chart).append('g')
99
-
100
- this.addMouseHandlers()
101
- }
102
-
103
- protected drawChart(): void {}
104
-
105
- private addMouseHandlers(): void {
106
- d3.select(this.chart)
107
- .on('mouseover', this.onMouseOver.bind(this))
108
- .on('mousemove', this.onMouseMove.bind(this))
109
- .on('mouseout', this.onMouseOut.bind(this))
110
- }
111
-
112
- protected onMouseOver(event: MouseEvent): void {
113
- const target = d3.select(event.target as HTMLElement)
114
-
115
- if (target.classed('tooltip')) {
116
- const data = target.datum()
117
- this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY)
118
- }
119
- }
120
-
121
- protected onMouseMove(event: MouseEvent): void {
122
- const target = d3.select(event.target as HTMLElement)
123
-
124
- if (target.classed('tooltip')) {
125
- const data = target.datum()
126
- this.showTooltip(this.tooltipContent(data), event.clientX, event.clientY)
127
- }
128
- }
129
-
130
- protected onMouseOut(event: MouseEvent): void {
131
- const target = d3.select(event.target as HTMLElement)
132
-
133
- if (target.classed('tooltip')) {
134
- this.hideTooltip()
135
- }
136
- }
137
-
138
- protected tooltipContent(data: any): string {
139
- return `Data: ${data}`
140
- }
141
-
142
- protected showTooltip(content: string, x: number, y: number): void {
143
- this.tooltip.style.opacity = '1'
144
- this.tooltip.style.left = `${x}px`
145
- this.tooltip.style.top = `${y}px`
146
- this.tooltip.innerHTML = content
147
- }
148
-
149
- protected hideTooltip(): void {
150
- this.tooltip.style.opacity = '0'
151
- }
152
- }