@fc-plot/ts-graph 0.22.17 → 0.22.19
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/dist/BundleReport.html +2 -2
- package/dist/index.js +1 -1
- package/examples/index.js +63 -8725
- package/examples/mock.json +1124 -0
- package/package.json +1 -1
- package/src/index.ts +41 -22
- package/src/zoom.ts +3 -24
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -279,7 +279,6 @@ export default class TsGraph {
|
|
|
279
279
|
const plotleaveType = cascadeScope
|
|
280
280
|
? `plotleave:${cascadeScope}`
|
|
281
281
|
: "plotleave";
|
|
282
|
-
const zoomEventType = cascadeScope ? `zoom:${cascadeScope}` : "zoom";
|
|
283
282
|
let mousedownStatus = false;
|
|
284
283
|
let mousedownPos: EventPosition = {} as EventPosition;
|
|
285
284
|
let mouseupPos: EventPosition = {} as EventPosition;
|
|
@@ -344,7 +343,14 @@ export default class TsGraph {
|
|
|
344
343
|
d3.event.stopPropagation();
|
|
345
344
|
const eventPosition = d3.event as EventPosition;
|
|
346
345
|
if (mousedownPos && mousedownPos.layerX !== eventPosition.layerX) {
|
|
347
|
-
|
|
346
|
+
_this.zoom.clearMarker();
|
|
347
|
+
_this.zoom.onZoom(
|
|
348
|
+
mousedownPos,
|
|
349
|
+
eventPosition,
|
|
350
|
+
(transform: Transform) => {
|
|
351
|
+
_this.handleZoom(transform, [mousedownPos, eventPosition]);
|
|
352
|
+
}
|
|
353
|
+
);
|
|
348
354
|
} else {
|
|
349
355
|
handleClick();
|
|
350
356
|
}
|
|
@@ -393,7 +399,14 @@ export default class TsGraph {
|
|
|
393
399
|
|
|
394
400
|
// 触发 zoom
|
|
395
401
|
if (mousedownPos && mousedownPos.layerX !== mouseupPos.layerX) {
|
|
396
|
-
|
|
402
|
+
_this.zoom.clearMarker();
|
|
403
|
+
_this.zoom.onZoom(
|
|
404
|
+
mousedownPos,
|
|
405
|
+
mouseupPos,
|
|
406
|
+
(transform: Transform) => {
|
|
407
|
+
_this.handleZoom(transform, [mousedownPos, mouseupPos]);
|
|
408
|
+
}
|
|
409
|
+
);
|
|
397
410
|
} else {
|
|
398
411
|
handleClick();
|
|
399
412
|
}
|
|
@@ -405,7 +418,6 @@ export default class TsGraph {
|
|
|
405
418
|
if (cascade) {
|
|
406
419
|
eventEmitter.on(plotmoveType, this.showTooltip);
|
|
407
420
|
eventEmitter.on(plotleaveType, this.hideTooltip);
|
|
408
|
-
eventEmitter.on(zoomEventType, this.handleZoomEvent);
|
|
409
421
|
}
|
|
410
422
|
|
|
411
423
|
// TODO: removeListener
|
|
@@ -413,7 +425,14 @@ export default class TsGraph {
|
|
|
413
425
|
if (!isEmpty(mousedownPos)) {
|
|
414
426
|
const eventPosition = mouseleavePos;
|
|
415
427
|
mousedownStatus = false;
|
|
416
|
-
|
|
428
|
+
_this.zoom.clearMarker();
|
|
429
|
+
_this.zoom.onZoom(
|
|
430
|
+
mousedownPos,
|
|
431
|
+
eventPosition,
|
|
432
|
+
(transform: Transform) => {
|
|
433
|
+
_this.handleZoom(transform, [mousedownPos, eventPosition]);
|
|
434
|
+
}
|
|
435
|
+
);
|
|
417
436
|
mousedownPos = {} as EventPosition;
|
|
418
437
|
}
|
|
419
438
|
});
|
|
@@ -464,16 +483,6 @@ export default class TsGraph {
|
|
|
464
483
|
this.draw(false);
|
|
465
484
|
};
|
|
466
485
|
|
|
467
|
-
handleZoomEvent = (
|
|
468
|
-
mousedownPos: EventPosition,
|
|
469
|
-
eventPosition: EventPosition
|
|
470
|
-
) => {
|
|
471
|
-
this.zoom.clearMarker();
|
|
472
|
-
this.zoom.onZoom(mousedownPos, eventPosition, (transform: Transform) => {
|
|
473
|
-
this.handleZoom(transform, [mousedownPos, eventPosition]);
|
|
474
|
-
});
|
|
475
|
-
};
|
|
476
|
-
|
|
477
486
|
handleZoom = (transform?: Transform, eventPositions?: EventPosition[]) => {
|
|
478
487
|
if (this.options.onZoomWithoutDefult) {
|
|
479
488
|
let times;
|
|
@@ -484,7 +493,7 @@ export default class TsGraph {
|
|
|
484
493
|
}
|
|
485
494
|
this.options.onZoomWithoutDefult(times);
|
|
486
495
|
} else {
|
|
487
|
-
const { ykey, yAxis, ykeyFormatter } = this.options;
|
|
496
|
+
const { ykey, ykey2, yAxis, ykeyFormatter } = this.options;
|
|
488
497
|
let { series } = this.options;
|
|
489
498
|
if (transform) {
|
|
490
499
|
this.transform = transform;
|
|
@@ -504,6 +513,7 @@ export default class TsGraph {
|
|
|
504
513
|
for (dataIdx = 0; dataIdx < data.length; dataIdx++) {
|
|
505
514
|
const item = data[dataIdx];
|
|
506
515
|
const y = getYkeyValue(item[ykey], ykeyFormatter);
|
|
516
|
+
|
|
507
517
|
if (y === null) continue;
|
|
508
518
|
// get axis domain
|
|
509
519
|
if (ymin < y) {
|
|
@@ -512,6 +522,16 @@ export default class TsGraph {
|
|
|
512
522
|
if (ymax > y) {
|
|
513
523
|
ymax = y;
|
|
514
524
|
}
|
|
525
|
+
if (ykey2) {
|
|
526
|
+
const y2 = getYkeyValue(item[ykey2], ykeyFormatter);
|
|
527
|
+
if (y2 === null) continue;
|
|
528
|
+
if (ymin < y2) {
|
|
529
|
+
ymin = y2;
|
|
530
|
+
}
|
|
531
|
+
if (ymax > y2) {
|
|
532
|
+
ymax = y2;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
515
535
|
}
|
|
516
536
|
}
|
|
517
537
|
// 如果缩放至没有数据点(无法计算出 ymin 和 ymax),则不更新 domain
|
|
@@ -619,9 +639,10 @@ export default class TsGraph {
|
|
|
619
639
|
let flag = false; // 起始标记,后面有连续空值即丢掉
|
|
620
640
|
let dataIdx;
|
|
621
641
|
for (dataIdx = 0; dataIdx < data.length; dataIdx++) {
|
|
622
|
-
const ykeyVal =
|
|
623
|
-
|
|
624
|
-
|
|
642
|
+
const ykeyVal =
|
|
643
|
+
data[dataIdx][oykey] !== undefined
|
|
644
|
+
? data[dataIdx][oykey]
|
|
645
|
+
: getYkeyValue(data[dataIdx][ykey], ykeyFormatter);
|
|
625
646
|
const item = {
|
|
626
647
|
[xkey]: data[dataIdx][xkey],
|
|
627
648
|
[ykey]: ykeyVal,
|
|
@@ -631,7 +652,6 @@ export default class TsGraph {
|
|
|
631
652
|
if (ykey2 && ykey2 in data[dataIdx]) {
|
|
632
653
|
item[ykey2] = getYkeyValue(data[dataIdx][ykey2], ykeyFormatter);
|
|
633
654
|
}
|
|
634
|
-
|
|
635
655
|
if (stack.enabled) {
|
|
636
656
|
if (item[oykey] === undefined) {
|
|
637
657
|
item[oykey] = getYkeyValue(item[ykey], ykeyFormatter);
|
|
@@ -773,8 +793,7 @@ export default class TsGraph {
|
|
|
773
793
|
this.options,
|
|
774
794
|
this.handleZoom,
|
|
775
795
|
this.container,
|
|
776
|
-
this.eventCanvas
|
|
777
|
-
eventEmitter
|
|
796
|
+
this.eventCanvas
|
|
778
797
|
);
|
|
779
798
|
}
|
|
780
799
|
|
package/src/zoom.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as d3 from "d3";
|
|
2
|
-
import EventEmitter from "events";
|
|
3
2
|
import { Options, EventPosition, Transform } from "./interface";
|
|
4
3
|
|
|
5
4
|
type ResetFuncType = (
|
|
@@ -11,17 +10,14 @@ export default class Zoom {
|
|
|
11
10
|
options: Options;
|
|
12
11
|
|
|
13
12
|
reset: ResetFuncType;
|
|
14
|
-
eventEmitter: EventEmitter;
|
|
15
13
|
|
|
16
14
|
constructor(
|
|
17
15
|
userOptions: Options,
|
|
18
16
|
reset: ResetFuncType,
|
|
19
17
|
container: HTMLElement,
|
|
20
|
-
canvas: HTMLCanvasElement
|
|
21
|
-
eventEmitter: EventEmitter
|
|
18
|
+
canvas: HTMLCanvasElement
|
|
22
19
|
) {
|
|
23
20
|
this.options = userOptions;
|
|
24
|
-
this.eventEmitter = eventEmitter;
|
|
25
21
|
this.init(container, canvas);
|
|
26
22
|
this.reset = reset;
|
|
27
23
|
}
|
|
@@ -58,32 +54,15 @@ export default class Zoom {
|
|
|
58
54
|
onReset() {
|
|
59
55
|
const {
|
|
60
56
|
chart: { id },
|
|
61
|
-
tooltip,
|
|
62
57
|
} = this.options;
|
|
63
58
|
const resetEle = document.getElementById(
|
|
64
59
|
`${id}-zoom-resetBtn`
|
|
65
60
|
) as HTMLElement;
|
|
66
61
|
|
|
67
|
-
const { cascade, cascadeScope } = tooltip;
|
|
68
|
-
const zoomResetEventType = cascadeScope
|
|
69
|
-
? `zoomReset:${cascadeScope}`
|
|
70
|
-
: "zoomReset";
|
|
71
|
-
|
|
72
|
-
if (cascade) {
|
|
73
|
-
this.eventEmitter.on(zoomResetEventType, () => {
|
|
74
|
-
this.reset();
|
|
75
|
-
this.clearResetBtn();
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
62
|
resetEle?.addEventListener("click", (e) => {
|
|
80
63
|
e.stopPropagation();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} else {
|
|
84
|
-
this.reset();
|
|
85
|
-
this.clearResetBtn();
|
|
86
|
-
}
|
|
64
|
+
this.reset();
|
|
65
|
+
this.clearResetBtn();
|
|
87
66
|
});
|
|
88
67
|
}
|
|
89
68
|
|