@hpcc-js/timeline 3.3.5 → 3.3.6

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.
@@ -1,286 +1,286 @@
1
- import { Axis } from "@hpcc-js/chart";
2
- import { SVGWidget } from "@hpcc-js/common";
3
- import { ReactGantt } from "./ReactGantt.ts";
4
-
5
- export type IAxisGanttData = [string, number | string, number | string, any?] | any[];
6
-
7
- export class ReactAxisGantt extends SVGWidget {
8
-
9
- protected _topAxis: Axis = new Axis("center")
10
- .orientation("top")
11
- .type("linear")
12
- .shrinkToFit("none")
13
- .overlapMode("hide")
14
- .extend(0)
15
- .tickFormat("d")
16
- ;
17
- protected _gantt: ReactGantt = new ReactGantt("center")
18
- .stroke("#000000")
19
- ;
20
- protected _bottomAxis: Axis = new Axis("center")
21
- .orientation("bottom")
22
- .type("linear")
23
- .shrinkToFit("none")
24
- .overlapMode("hide")
25
- .extend(0)
26
- .tickFormat("d")
27
- ;
28
-
29
- protected _topAxisElement;
30
- protected _contentElement;
31
- protected _bottomAxisElement;
32
- protected _topRect;
33
- protected _contentRect;
34
- protected _bottomRect;
35
-
36
- protected rangeRenderer;
37
-
38
- constructor() {
39
- super();
40
- this._drawStartPos = "origin";
41
- this.rangeRenderer = function () {
42
- const ret = this._gantt.rangeRenderer.apply(this._gantt, arguments);
43
- if (!arguments.length) return ret;
44
- return this;
45
- };
46
- }
47
-
48
- selection(_: any[]): this;
49
- selection(): any[];
50
- selection(_?: any[]): any[] | this {
51
- if (!arguments.length) return this._gantt.selection();
52
- this._gantt.selection(_);
53
- return this;
54
- }
55
-
56
- resizeWrappers() {
57
-
58
- const w = this.width();
59
- const h = this.height();
60
-
61
- const axisHeight = this.axisHeight(); //TODO: Dynamic scaling to allow for small resolutions?
62
-
63
- const contentHeight = (h - (axisHeight * 2));
64
- const borderOffset1 = this.strokeWidth();
65
- this._topRect
66
- .attr("height", axisHeight)
67
- .attr("width", w)
68
- .attr("fill", "transparent")
69
- ;
70
- this._topAxisElement.attr("transform", "translate(0 0)");
71
- this._topAxis.resize({ height: axisHeight, width: w });
72
- this._contentRect
73
- .attr("height", contentHeight)
74
- .attr("width", w)
75
- .attr("fill", "transparent")
76
- ;
77
- this._contentElement.attr("transform", `translate(0 ${axisHeight + borderOffset1})`);
78
- this._gantt.resize({ height: contentHeight, width: w });
79
- this._bottomRect
80
- .attr("height", axisHeight)
81
- .attr("width", w)
82
- .attr("fill", "transparent")
83
- ;
84
- this._bottomAxisElement.attr("transform", `translate(0 ${axisHeight + contentHeight + borderOffset1})`);
85
- this._bottomAxis.resize({ height: axisHeight, width: w });
86
- }
87
-
88
- enter(domNode, element) {
89
- super.enter(domNode, element);
90
-
91
- this._gantt.click = (row, col, sel) => {
92
- this.click(row, col, sel);
93
- };
94
-
95
- this._gantt.dblclick = (row, col, sel) => {
96
- this.dblclick(row, col, sel);
97
- };
98
-
99
- this._topAxisElement = element.append("g")
100
- .attr("class", "top-axis-wrapper")
101
- ;
102
- this._topRect = this._topAxisElement.append("rect")
103
- .attr("class", "top-axis-rect")
104
- ;
105
- this._contentElement = element.append("g")
106
- .attr("class", "content-wrapper")
107
- ;
108
- this._contentRect = this._contentElement.append("rect")
109
- .attr("class", "content-rect")
110
- ;
111
- this._bottomAxisElement = element.append("g")
112
- .attr("class", "bottom-axis-wrapper")
113
- ;
114
- this._bottomRect = this._bottomAxisElement.append("rect")
115
- .attr("class", "top-axis-rect")
116
- ;
117
- this._topAxis.target(this._topAxisElement.node());
118
- this._gantt.target(this._contentElement.node()).bucketHeight(30);
119
- this._bottomAxis.target(this._bottomAxisElement.node());
120
-
121
- this.resizeWrappers();
122
-
123
- this._gantt.zoomedHook = (transform) => {
124
- this.onzoom(transform);
125
- };
126
- }
127
-
128
- onzoom(transform) {
129
-
130
- const w = this.width();
131
- const low = this._gantt._minStart;
132
- const high = this._gantt._maxEnd;
133
- const range = high - low;
134
- const wpp = range / w;
135
- const nextLow = Math.floor(low - (wpp * (transform.x / transform.k)));
136
- const nextHigh = Math.ceil((range / transform.k) + nextLow);
137
-
138
- this._topAxis
139
- .fontFamily(this.axisFontFamily())
140
- .fontSize(this.axisFontSize())
141
- .tickLength(this.axisTickLength())
142
- .low(nextLow)
143
- .high(nextHigh)
144
- .render()
145
- ;
146
- this._bottomAxis
147
- .fontFamily(this.axisFontFamily())
148
- .fontSize(this.axisFontSize())
149
- .tickLength(this.axisTickLength())
150
- .low(nextLow)
151
- .high(nextHigh)
152
- .render()
153
- ;
154
- }
155
-
156
- update(domNode, element) {
157
- super.update(domNode, element);
158
- this._topAxis.tickFormat(this.tickFormat()).render();
159
- this._bottomAxis.tickFormat(this.tickFormat()).render();
160
- this._gantt.render();
161
- }
162
-
163
- exit(domNode, element) {
164
- this._bottomAxis.target(null);
165
- this._gantt.target(null);
166
- this._topAxis.target(null);
167
- super.exit(domNode, element);
168
- }
169
-
170
- columns(): string[];
171
- columns(_: string[]): this;
172
- columns(_?: string[]): this | string[] {
173
- const retVal = super.columns.apply(this, arguments);
174
- if (arguments.length > 0) {
175
- this._gantt.columns(_);
176
- }
177
- return retVal;
178
- }
179
-
180
- data(): IAxisGanttData[];
181
- data(_: IAxisGanttData[]): this;
182
- data(_?: IAxisGanttData[]): this | IAxisGanttData[] {
183
- const retVal = super.data.apply(this, arguments);
184
- if (arguments.length > 0) {
185
- const ganttData: any[] = this.data().map(n => {
186
- const ret = [...n];
187
- ret[1] = isNaN(n[1] as any) ? new Date(n[1]).getTime() : Number(n[1]);
188
- ret[2] = isNaN(n[2] as any) ? new Date(n[2]).getTime() : Number(n[2]);
189
- return ret;
190
- });
191
- this._gantt._minStart = Math.min(...ganttData.map(n => n[1])) ?? 0;
192
- this._gantt._maxEnd = Math.max(...ganttData.map(n => n[2])) ?? 1;
193
- this._gantt.data(ganttData);
194
- }
195
- return retVal;
196
- }
197
-
198
- resize(_size?: { width: number, height: number }) {
199
- const retVal = super.resize.apply(this, arguments);
200
-
201
- if (this._topAxisElement) {
202
- this.resizeWrappers();
203
- }
204
-
205
- return retVal;
206
- }
207
-
208
- click(row, col, sel) {
209
-
210
- }
211
-
212
- dblclick(row, col, sel) {
213
-
214
- }
215
-
216
- tooltip() {
217
- return this._gantt._tooltip;
218
- }
219
- }
220
- ReactAxisGantt.prototype._class += " timeline_ReactAxisGantt";
221
-
222
- export interface ReactAxisGantt {
223
- tickFormat(): string;
224
- tickFormat(_: string): this;
225
- tickFormat_exists(): boolean;
226
- overlapTolerence(): number;
227
- overlapTolerence(_: number): this;
228
- smallestRangeWidth(): number;
229
- smallestRangeWidth(_: number): this;
230
- scaleMode(): boolean;
231
- scaleMode(_: boolean): this;
232
- fontSize(): number;
233
- fontSize(_: number): this;
234
- fontFamily(): string;
235
- fontFamily(_: string): this;
236
- strokeWidth(): number;
237
- strokeWidth(_: number): this;
238
- stroke(): string;
239
- stroke(_: string): this;
240
- cornerRadius(): number;
241
- cornerRadius(_: number): this;
242
- axisFontSize(): number;
243
- axisFontSize(_: number): this;
244
- axisFontFamily(): string;
245
- axisFontFamily(_: string): this;
246
- axisTickLength(): number;
247
- axisTickLength(_: number): this;
248
- axisHeight(): number;
249
- axisHeight(_: number): this;
250
- titleColumn(): string;
251
- titleColumn(_: string): this;
252
- startDateColumn(): string;
253
- startDateColumn(_: string): this;
254
- endDateColumn(): string;
255
- endDateColumn(_: string): this;
256
- iconColumn(): string;
257
- iconColumn(_: string): this;
258
- colorColumn(): string;
259
- colorColumn(_: string): this;
260
- bucketColumn(): string;
261
- bucketColumn(_: string): this;
262
- maxZoom(): number;
263
- maxZoom(_: number): this;
264
- }
265
- ReactAxisGantt.prototype.publish("tickFormat", null, "string", "Format rule applied to axis tick labels", undefined, { optional: true });
266
- ReactAxisGantt.prototype.publish("axisHeight", 22, "number", "Height of axes (pixels)");
267
- ReactAxisGantt.prototype.publish("overlapTolerence", 2, "number", "overlapTolerence");
268
- ReactAxisGantt.prototype.publish("smallestRangeWidth", 10, "number", "Width of the shortest range (pixels)");
269
- ReactAxisGantt.prototype.publish("axisFontSize", null, "number", "Font size of axis tick labels");
270
- ReactAxisGantt.prototype.publish("axisFontFamily", null, "string", "Font family of axis tick labels");
271
- ReactAxisGantt.prototype.publish("axisTickLength", null, "number", "Length of axis ticks");
272
- ReactAxisGantt.prototype.publishProxy("gutter", "_gantt");
273
- ReactAxisGantt.prototype.publishProxy("renderMode", "_gantt");
274
- ReactAxisGantt.prototype.publishProxy("strokeWidth", "_gantt");
275
- ReactAxisGantt.prototype.publishProxy("fontSize", "_gantt");
276
- ReactAxisGantt.prototype.publishProxy("fontFamily", "_gantt");
277
- ReactAxisGantt.prototype.publishProxy("stroke", "_gantt");
278
- ReactAxisGantt.prototype.publishProxy("cornerRadius", "_gantt");
279
- ReactAxisGantt.prototype.publishProxy("titleColumn", "_gantt");
280
- ReactAxisGantt.prototype.publishProxy("startDateColumn", "_gantt");
281
- ReactAxisGantt.prototype.publishProxy("endDateColumn", "_gantt");
282
- ReactAxisGantt.prototype.publishProxy("iconColumn", "_gantt");
283
- ReactAxisGantt.prototype.publishProxy("colorColumn", "_gantt");
284
- ReactAxisGantt.prototype.publishProxy("bucketColumn", "_gantt");
285
- ReactAxisGantt.prototype.publishProxy("maxZoom", "_gantt");
286
- ReactAxisGantt.prototype.publishProxy("bucketHeight", "_gantt");
1
+ import { Axis } from "@hpcc-js/chart";
2
+ import { SVGWidget } from "@hpcc-js/common";
3
+ import { ReactGantt } from "./ReactGantt.ts";
4
+
5
+ export type IAxisGanttData = [string, number | string, number | string, any?] | any[];
6
+
7
+ export class ReactAxisGantt extends SVGWidget {
8
+
9
+ protected _topAxis: Axis = new Axis("center")
10
+ .orientation("top")
11
+ .type("linear")
12
+ .shrinkToFit("none")
13
+ .overlapMode("hide")
14
+ .extend(0)
15
+ .tickFormat("d")
16
+ ;
17
+ protected _gantt: ReactGantt = new ReactGantt("center")
18
+ .stroke("#000000")
19
+ ;
20
+ protected _bottomAxis: Axis = new Axis("center")
21
+ .orientation("bottom")
22
+ .type("linear")
23
+ .shrinkToFit("none")
24
+ .overlapMode("hide")
25
+ .extend(0)
26
+ .tickFormat("d")
27
+ ;
28
+
29
+ protected _topAxisElement;
30
+ protected _contentElement;
31
+ protected _bottomAxisElement;
32
+ protected _topRect;
33
+ protected _contentRect;
34
+ protected _bottomRect;
35
+
36
+ protected rangeRenderer;
37
+
38
+ constructor() {
39
+ super();
40
+ this._drawStartPos = "origin";
41
+ this.rangeRenderer = function () {
42
+ const ret = this._gantt.rangeRenderer.apply(this._gantt, arguments);
43
+ if (!arguments.length) return ret;
44
+ return this;
45
+ };
46
+ }
47
+
48
+ selection(_: any[]): this;
49
+ selection(): any[];
50
+ selection(_?: any[]): any[] | this {
51
+ if (!arguments.length) return this._gantt.selection();
52
+ this._gantt.selection(_);
53
+ return this;
54
+ }
55
+
56
+ resizeWrappers() {
57
+
58
+ const w = this.width();
59
+ const h = this.height();
60
+
61
+ const axisHeight = this.axisHeight(); //TODO: Dynamic scaling to allow for small resolutions?
62
+
63
+ const contentHeight = (h - (axisHeight * 2));
64
+ const borderOffset1 = this.strokeWidth();
65
+ this._topRect
66
+ .attr("height", axisHeight)
67
+ .attr("width", w)
68
+ .attr("fill", "transparent")
69
+ ;
70
+ this._topAxisElement.attr("transform", "translate(0 0)");
71
+ this._topAxis.resize({ height: axisHeight, width: w });
72
+ this._contentRect
73
+ .attr("height", contentHeight)
74
+ .attr("width", w)
75
+ .attr("fill", "transparent")
76
+ ;
77
+ this._contentElement.attr("transform", `translate(0 ${axisHeight + borderOffset1})`);
78
+ this._gantt.resize({ height: contentHeight, width: w });
79
+ this._bottomRect
80
+ .attr("height", axisHeight)
81
+ .attr("width", w)
82
+ .attr("fill", "transparent")
83
+ ;
84
+ this._bottomAxisElement.attr("transform", `translate(0 ${axisHeight + contentHeight + borderOffset1})`);
85
+ this._bottomAxis.resize({ height: axisHeight, width: w });
86
+ }
87
+
88
+ enter(domNode, element) {
89
+ super.enter(domNode, element);
90
+
91
+ this._gantt.click = (row, col, sel) => {
92
+ this.click(row, col, sel);
93
+ };
94
+
95
+ this._gantt.dblclick = (row, col, sel) => {
96
+ this.dblclick(row, col, sel);
97
+ };
98
+
99
+ this._topAxisElement = element.append("g")
100
+ .attr("class", "top-axis-wrapper")
101
+ ;
102
+ this._topRect = this._topAxisElement.append("rect")
103
+ .attr("class", "top-axis-rect")
104
+ ;
105
+ this._contentElement = element.append("g")
106
+ .attr("class", "content-wrapper")
107
+ ;
108
+ this._contentRect = this._contentElement.append("rect")
109
+ .attr("class", "content-rect")
110
+ ;
111
+ this._bottomAxisElement = element.append("g")
112
+ .attr("class", "bottom-axis-wrapper")
113
+ ;
114
+ this._bottomRect = this._bottomAxisElement.append("rect")
115
+ .attr("class", "top-axis-rect")
116
+ ;
117
+ this._topAxis.target(this._topAxisElement.node());
118
+ this._gantt.target(this._contentElement.node()).bucketHeight(30);
119
+ this._bottomAxis.target(this._bottomAxisElement.node());
120
+
121
+ this.resizeWrappers();
122
+
123
+ this._gantt.zoomedHook = (transform) => {
124
+ this.onzoom(transform);
125
+ };
126
+ }
127
+
128
+ onzoom(transform) {
129
+
130
+ const w = this.width();
131
+ const low = this._gantt._minStart;
132
+ const high = this._gantt._maxEnd;
133
+ const range = high - low;
134
+ const wpp = range / w;
135
+ const nextLow = Math.floor(low - (wpp * (transform.x / transform.k)));
136
+ const nextHigh = Math.ceil((range / transform.k) + nextLow);
137
+
138
+ this._topAxis
139
+ .fontFamily(this.axisFontFamily())
140
+ .fontSize(this.axisFontSize())
141
+ .tickLength(this.axisTickLength())
142
+ .low(nextLow)
143
+ .high(nextHigh)
144
+ .render()
145
+ ;
146
+ this._bottomAxis
147
+ .fontFamily(this.axisFontFamily())
148
+ .fontSize(this.axisFontSize())
149
+ .tickLength(this.axisTickLength())
150
+ .low(nextLow)
151
+ .high(nextHigh)
152
+ .render()
153
+ ;
154
+ }
155
+
156
+ update(domNode, element) {
157
+ super.update(domNode, element);
158
+ this._topAxis.tickFormat(this.tickFormat()).render();
159
+ this._bottomAxis.tickFormat(this.tickFormat()).render();
160
+ this._gantt.render();
161
+ }
162
+
163
+ exit(domNode, element) {
164
+ this._bottomAxis.target(null);
165
+ this._gantt.target(null);
166
+ this._topAxis.target(null);
167
+ super.exit(domNode, element);
168
+ }
169
+
170
+ columns(): string[];
171
+ columns(_: string[]): this;
172
+ columns(_?: string[]): this | string[] {
173
+ const retVal = super.columns.apply(this, arguments);
174
+ if (arguments.length > 0) {
175
+ this._gantt.columns(_);
176
+ }
177
+ return retVal;
178
+ }
179
+
180
+ data(): IAxisGanttData[];
181
+ data(_: IAxisGanttData[]): this;
182
+ data(_?: IAxisGanttData[]): this | IAxisGanttData[] {
183
+ const retVal = super.data.apply(this, arguments);
184
+ if (arguments.length > 0) {
185
+ const ganttData: any[] = this.data().map(n => {
186
+ const ret = [...n];
187
+ ret[1] = isNaN(n[1] as any) ? new Date(n[1]).getTime() : Number(n[1]);
188
+ ret[2] = isNaN(n[2] as any) ? new Date(n[2]).getTime() : Number(n[2]);
189
+ return ret;
190
+ });
191
+ this._gantt._minStart = Math.min(...ganttData.map(n => n[1])) ?? 0;
192
+ this._gantt._maxEnd = Math.max(...ganttData.map(n => n[2])) ?? 1;
193
+ this._gantt.data(ganttData);
194
+ }
195
+ return retVal;
196
+ }
197
+
198
+ resize(_size?: { width: number, height: number }) {
199
+ const retVal = super.resize.apply(this, arguments);
200
+
201
+ if (this._topAxisElement) {
202
+ this.resizeWrappers();
203
+ }
204
+
205
+ return retVal;
206
+ }
207
+
208
+ click(row, col, sel) {
209
+
210
+ }
211
+
212
+ dblclick(row, col, sel) {
213
+
214
+ }
215
+
216
+ tooltip() {
217
+ return this._gantt._tooltip;
218
+ }
219
+ }
220
+ ReactAxisGantt.prototype._class += " timeline_ReactAxisGantt";
221
+
222
+ export interface ReactAxisGantt {
223
+ tickFormat(): string;
224
+ tickFormat(_: string): this;
225
+ tickFormat_exists(): boolean;
226
+ overlapTolerence(): number;
227
+ overlapTolerence(_: number): this;
228
+ smallestRangeWidth(): number;
229
+ smallestRangeWidth(_: number): this;
230
+ scaleMode(): boolean;
231
+ scaleMode(_: boolean): this;
232
+ fontSize(): number;
233
+ fontSize(_: number): this;
234
+ fontFamily(): string;
235
+ fontFamily(_: string): this;
236
+ strokeWidth(): number;
237
+ strokeWidth(_: number): this;
238
+ stroke(): string;
239
+ stroke(_: string): this;
240
+ cornerRadius(): number;
241
+ cornerRadius(_: number): this;
242
+ axisFontSize(): number;
243
+ axisFontSize(_: number): this;
244
+ axisFontFamily(): string;
245
+ axisFontFamily(_: string): this;
246
+ axisTickLength(): number;
247
+ axisTickLength(_: number): this;
248
+ axisHeight(): number;
249
+ axisHeight(_: number): this;
250
+ titleColumn(): string;
251
+ titleColumn(_: string): this;
252
+ startDateColumn(): string;
253
+ startDateColumn(_: string): this;
254
+ endDateColumn(): string;
255
+ endDateColumn(_: string): this;
256
+ iconColumn(): string;
257
+ iconColumn(_: string): this;
258
+ colorColumn(): string;
259
+ colorColumn(_: string): this;
260
+ bucketColumn(): string;
261
+ bucketColumn(_: string): this;
262
+ maxZoom(): number;
263
+ maxZoom(_: number): this;
264
+ }
265
+ ReactAxisGantt.prototype.publish("tickFormat", null, "string", "Format rule applied to axis tick labels", undefined, { optional: true });
266
+ ReactAxisGantt.prototype.publish("axisHeight", 22, "number", "Height of axes (pixels)");
267
+ ReactAxisGantt.prototype.publish("overlapTolerence", 2, "number", "overlapTolerence");
268
+ ReactAxisGantt.prototype.publish("smallestRangeWidth", 10, "number", "Width of the shortest range (pixels)");
269
+ ReactAxisGantt.prototype.publish("axisFontSize", null, "number", "Font size of axis tick labels");
270
+ ReactAxisGantt.prototype.publish("axisFontFamily", null, "string", "Font family of axis tick labels");
271
+ ReactAxisGantt.prototype.publish("axisTickLength", null, "number", "Length of axis ticks");
272
+ ReactAxisGantt.prototype.publishProxy("gutter", "_gantt");
273
+ ReactAxisGantt.prototype.publishProxy("renderMode", "_gantt");
274
+ ReactAxisGantt.prototype.publishProxy("strokeWidth", "_gantt");
275
+ ReactAxisGantt.prototype.publishProxy("fontSize", "_gantt");
276
+ ReactAxisGantt.prototype.publishProxy("fontFamily", "_gantt");
277
+ ReactAxisGantt.prototype.publishProxy("stroke", "_gantt");
278
+ ReactAxisGantt.prototype.publishProxy("cornerRadius", "_gantt");
279
+ ReactAxisGantt.prototype.publishProxy("titleColumn", "_gantt");
280
+ ReactAxisGantt.prototype.publishProxy("startDateColumn", "_gantt");
281
+ ReactAxisGantt.prototype.publishProxy("endDateColumn", "_gantt");
282
+ ReactAxisGantt.prototype.publishProxy("iconColumn", "_gantt");
283
+ ReactAxisGantt.prototype.publishProxy("colorColumn", "_gantt");
284
+ ReactAxisGantt.prototype.publishProxy("bucketColumn", "_gantt");
285
+ ReactAxisGantt.prototype.publishProxy("maxZoom", "_gantt");
286
+ ReactAxisGantt.prototype.publishProxy("bucketHeight", "_gantt");