@krainovsd/graph 0.8.4 → 0.9.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/lib/cjs/index.cjs +569 -162
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/lib/get-controls-info.js +212 -65
- package/lib/esm/lib/get-controls-info.js.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +260 -76
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/settings.js +41 -20
- package/lib/esm/module/GraphCanvas/constants/settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +55 -0
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/pointer-getter.js +8 -2
- package/lib/esm/module/GraphCanvas/lib/utils/pointer-getter.js.map +1 -1
- package/lib/index.d.ts +67 -26
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -178,8 +178,14 @@ function nodeIdGetter(node) {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
function pointerGetter(mouseEvent, areaRect, areaTransform) {
|
|
181
|
-
const
|
|
182
|
-
|
|
181
|
+
const clientX = "clientX" in mouseEvent
|
|
182
|
+
? mouseEvent.clientX
|
|
183
|
+
: (mouseEvent.touches[0]?.clientX ?? mouseEvent.changedTouches[0]?.clientX);
|
|
184
|
+
const clientY = "clientX" in mouseEvent
|
|
185
|
+
? mouseEvent.clientY
|
|
186
|
+
: (mouseEvent.touches[0]?.clientY ?? mouseEvent.changedTouches[0]?.clientY);
|
|
187
|
+
const px = (clientX - areaRect.left - areaTransform.x) / areaTransform.k;
|
|
188
|
+
const py = (clientY - areaRect.top - areaTransform.y) / areaTransform.k;
|
|
183
189
|
return [px, py];
|
|
184
190
|
}
|
|
185
191
|
|
|
@@ -387,6 +393,55 @@ function getParticlePosition(opts) {
|
|
|
387
393
|
opts.particle.step++;
|
|
388
394
|
}
|
|
389
395
|
|
|
396
|
+
/* eslint-disable id-length */
|
|
397
|
+
function linkByPointerGetter({ areaRect, areaTransform, mouseEvent, links, graphSettings, }) {
|
|
398
|
+
if (!areaRect)
|
|
399
|
+
return undefined;
|
|
400
|
+
const [pointerX, pointerY] = pointerGetter(mouseEvent, areaRect, areaTransform);
|
|
401
|
+
return d3Array.greatest(links, (link) => {
|
|
402
|
+
if (isNearLink(pointerX, pointerY, link, graphSettings.hoverLinkThreshold))
|
|
403
|
+
return link.index;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function isNearLink(mouseX, mouseY, link, threshold = 2) {
|
|
407
|
+
if (!jsHelpers.isObject(link.source) || !jsHelpers.isObject(link.target))
|
|
408
|
+
return false;
|
|
409
|
+
const x1 = link.source.x;
|
|
410
|
+
const y1 = link.source.y;
|
|
411
|
+
const x2 = link.target.x;
|
|
412
|
+
const y2 = link.target.y;
|
|
413
|
+
const distance = distanceToLine(mouseX, mouseY, x1, y1, x2, y2);
|
|
414
|
+
return distance <= threshold;
|
|
415
|
+
}
|
|
416
|
+
function distanceToLine(x, y, x1, y1, x2, y2) {
|
|
417
|
+
const A = x - x1;
|
|
418
|
+
const B = y - y1;
|
|
419
|
+
const C = x2 - x1;
|
|
420
|
+
const D = y2 - y1;
|
|
421
|
+
const dot = A * C + B * D;
|
|
422
|
+
const lenSq = C * C + D * D;
|
|
423
|
+
let param = -1;
|
|
424
|
+
if (lenSq !== 0) {
|
|
425
|
+
param = dot / lenSq;
|
|
426
|
+
}
|
|
427
|
+
let xx, yy;
|
|
428
|
+
if (param < 0) {
|
|
429
|
+
xx = x1;
|
|
430
|
+
yy = y1;
|
|
431
|
+
}
|
|
432
|
+
else if (param > 1) {
|
|
433
|
+
xx = x2;
|
|
434
|
+
yy = y2;
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
xx = x1 + param * C;
|
|
438
|
+
yy = y1 + param * D;
|
|
439
|
+
}
|
|
440
|
+
const dx = x - xx;
|
|
441
|
+
const dy = y - yy;
|
|
442
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
443
|
+
}
|
|
444
|
+
|
|
390
445
|
const FORCE_SETTINGS = {
|
|
391
446
|
centerPosition: {},
|
|
392
447
|
centerStrength: 1,
|
|
@@ -412,20 +467,34 @@ const GRAPH_SETTINGS = {
|
|
|
412
467
|
translateExtent: [[], []],
|
|
413
468
|
translateExtentEnable: true,
|
|
414
469
|
translateExtentCoefficient: [3, 3],
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
470
|
+
highlightByNodeNodeSizingAdditional: 0.5,
|
|
471
|
+
highlightByNodeNodeColorFadingMin: 0.15,
|
|
472
|
+
highlightByNodeTextShiftXAdditional: 0,
|
|
473
|
+
highlightByNodeTextShiftYAdditional: 2,
|
|
474
|
+
highlightByNodeTextSizingAdditional: 1,
|
|
475
|
+
highlightByNodeTextWeightAdditional: 0,
|
|
476
|
+
highlightByNodeTextWidthAdditional: 10,
|
|
477
|
+
highlightByNodeLinkFadingMin: 0.21,
|
|
478
|
+
highlightByNodeNodeFadingMin: 0.21,
|
|
479
|
+
highlightByNodeTextFadingMin: 0.21,
|
|
480
|
+
highlightByNodeArrowFadingMin: 0.21,
|
|
481
|
+
highlightByNodeOnlyRoot: true,
|
|
482
|
+
highlightByLinkNodeSizingAdditional: 0.5,
|
|
483
|
+
highlightByLinkNodeColorFadingMin: 0.15,
|
|
484
|
+
highlightByLinkTextShiftXAdditional: 0,
|
|
485
|
+
highlightByLinkTextShiftYAdditional: 2,
|
|
486
|
+
highlightByLinkTextSizingAdditional: 1,
|
|
487
|
+
highlightByLinkTextWeightAdditional: 0,
|
|
488
|
+
highlightByLinkTextWidthAdditional: 10,
|
|
489
|
+
highlightByLinkLinkFadingMin: 0.21,
|
|
490
|
+
highlightByLinkNodeFadingMin: 0.21,
|
|
491
|
+
highlightByLinkTextFadingMin: 0.21,
|
|
492
|
+
highlightByLinkArrowFadingMin: 0.21,
|
|
493
|
+
highlightByLinkOnlyRoot: true,
|
|
423
494
|
stickAfterDrag: false,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
highlightTextFadingMin: 0.21,
|
|
428
|
-
highlightArrowFadingMin: 0.21,
|
|
495
|
+
highlightByHoverNode: true,
|
|
496
|
+
highlightByHoverLink: true,
|
|
497
|
+
hoverLinkThreshold: 2,
|
|
429
498
|
highlightDownStep: 0.2,
|
|
430
499
|
highlightUpStep: 0.2,
|
|
431
500
|
dragPlaceCoefficient: dragPlaceCoefficientGetter,
|
|
@@ -454,11 +523,16 @@ const NODE_OPTIONS = {
|
|
|
454
523
|
textStyle: "normal",
|
|
455
524
|
textWeight: 500,
|
|
456
525
|
textGap: 1,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
526
|
+
highlightByNodeNodeFading: true,
|
|
527
|
+
highlightByNodeNodeColor: false,
|
|
528
|
+
highlightByNodeNodeSizing: true,
|
|
529
|
+
highlightByNodeTextFading: true,
|
|
530
|
+
highlightByNodeTextSizing: true,
|
|
531
|
+
highlightByLinkNodeFading: false,
|
|
532
|
+
highlightByLinkNodeColor: false,
|
|
533
|
+
highlightByLinkNodeSizing: true,
|
|
534
|
+
highlightByLinkTextFading: false,
|
|
535
|
+
highlightByLinkTextSizing: true,
|
|
462
536
|
};
|
|
463
537
|
const LINK_SETTINGS = {
|
|
464
538
|
cache: false,
|
|
@@ -466,12 +540,14 @@ const LINK_SETTINGS = {
|
|
|
466
540
|
};
|
|
467
541
|
const LINK_OPTIONS = {
|
|
468
542
|
alpha: 1,
|
|
469
|
-
|
|
543
|
+
highlightByNodeLinkFading: true,
|
|
544
|
+
highlightByNodeArrowFading: true,
|
|
545
|
+
highlightByLinkLinkFading: false,
|
|
546
|
+
highlightByLinkArrowFading: false,
|
|
470
547
|
pretty: true,
|
|
471
548
|
arrow: true,
|
|
472
549
|
arrowAlpha: 1,
|
|
473
550
|
arrowSize: 2,
|
|
474
|
-
arrowHighlightFading: true,
|
|
475
551
|
arrowReverseAppear: true,
|
|
476
552
|
particleAlpha: 1,
|
|
477
553
|
particleColor: "#000000FF",
|
|
@@ -608,103 +684,214 @@ function getForceControls(keys) {
|
|
|
608
684
|
function getGraphControls(keys) {
|
|
609
685
|
const GRAPH_CONTROLS = [
|
|
610
686
|
{
|
|
611
|
-
id: "
|
|
612
|
-
initialValue: GRAPH_SETTINGS.
|
|
687
|
+
id: "highlightByNodeNodeSizingAdditional",
|
|
688
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeNodeSizingAdditional,
|
|
613
689
|
max: 10,
|
|
614
690
|
min: 0.1,
|
|
615
691
|
step: 0.01,
|
|
616
692
|
type: "range",
|
|
617
|
-
label: "Дополнительный размер при анимации",
|
|
693
|
+
label: "Дополнительный размер при анимации ноды",
|
|
618
694
|
},
|
|
619
695
|
{
|
|
620
|
-
id: "
|
|
621
|
-
initialValue: GRAPH_SETTINGS.
|
|
696
|
+
id: "highlightByNodeNodeColorFadingMin",
|
|
697
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeNodeColorFadingMin,
|
|
622
698
|
max: 1,
|
|
623
699
|
min: 0.01,
|
|
624
700
|
step: 0.01,
|
|
625
701
|
type: "range",
|
|
626
|
-
label: "Граница затухания цвета",
|
|
702
|
+
label: "Граница затухания цвета при анимации ноды",
|
|
627
703
|
},
|
|
628
704
|
{
|
|
629
|
-
id: "
|
|
630
|
-
initialValue: GRAPH_SETTINGS.
|
|
705
|
+
id: "highlightByNodeTextShiftXAdditional",
|
|
706
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeTextShiftXAdditional,
|
|
631
707
|
max: 50,
|
|
632
708
|
min: 0,
|
|
633
709
|
step: 0.1,
|
|
634
710
|
type: "range",
|
|
635
|
-
label: "Смещение текста по X при анимации",
|
|
711
|
+
label: "Смещение текста по X при анимации ноды",
|
|
636
712
|
},
|
|
637
713
|
{
|
|
638
|
-
id: "
|
|
639
|
-
initialValue: GRAPH_SETTINGS.
|
|
714
|
+
id: "highlightByNodeTextShiftYAdditional",
|
|
715
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeTextShiftYAdditional,
|
|
640
716
|
max: 50,
|
|
641
717
|
min: 0,
|
|
642
718
|
step: 0.1,
|
|
643
719
|
type: "range",
|
|
644
|
-
label: "Смещение текста по Y при анимации",
|
|
720
|
+
label: "Смещение текста по Y при анимации ноды",
|
|
645
721
|
},
|
|
646
722
|
{
|
|
647
|
-
id: "
|
|
648
|
-
initialValue: GRAPH_SETTINGS.
|
|
723
|
+
id: "highlightByNodeTextSizingAdditional",
|
|
724
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeTextSizingAdditional,
|
|
649
725
|
max: 10,
|
|
650
726
|
min: 0.1,
|
|
651
727
|
step: 0.1,
|
|
652
728
|
type: "range",
|
|
653
|
-
label: "Увеличение текста при анимации",
|
|
729
|
+
label: "Увеличение текста при анимации ноды",
|
|
654
730
|
},
|
|
655
731
|
{
|
|
656
|
-
id: "
|
|
657
|
-
initialValue: GRAPH_SETTINGS.
|
|
732
|
+
id: "highlightByNodeTextWeightAdditional",
|
|
733
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeTextWeightAdditional,
|
|
658
734
|
max: 1000,
|
|
659
735
|
min: 0,
|
|
660
736
|
step: 100,
|
|
661
737
|
type: "range",
|
|
662
|
-
label: "Увеличение жирности текста при анимации",
|
|
738
|
+
label: "Увеличение жирности текста при анимации ноды",
|
|
663
739
|
},
|
|
664
740
|
{
|
|
665
|
-
id: "
|
|
666
|
-
initialValue: GRAPH_SETTINGS.
|
|
741
|
+
id: "highlightByNodeTextWidthAdditional",
|
|
742
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeTextWidthAdditional,
|
|
667
743
|
max: 100,
|
|
668
744
|
min: 0,
|
|
669
745
|
step: 0.1,
|
|
670
746
|
type: "range",
|
|
671
|
-
label: "Увеличение ширины текста при анимации",
|
|
747
|
+
label: "Увеличение ширины текста при анимации ноды",
|
|
672
748
|
},
|
|
673
749
|
{
|
|
674
|
-
id: "
|
|
675
|
-
initialValue: GRAPH_SETTINGS.
|
|
750
|
+
id: "highlightByNodeTextFadingMin",
|
|
751
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeTextFadingMin,
|
|
676
752
|
max: 1,
|
|
677
753
|
min: 0,
|
|
678
754
|
step: 0.01,
|
|
679
755
|
type: "range",
|
|
680
|
-
label: "Граница затухания текста при анимации",
|
|
756
|
+
label: "Граница затухания текста при анимации ноды",
|
|
681
757
|
},
|
|
682
758
|
{
|
|
683
|
-
id: "
|
|
684
|
-
initialValue: GRAPH_SETTINGS.
|
|
759
|
+
id: "highlightByNodeLinkFadingMin",
|
|
760
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeLinkFadingMin,
|
|
685
761
|
max: 1,
|
|
686
762
|
min: 0,
|
|
687
763
|
step: 0.01,
|
|
688
764
|
type: "range",
|
|
689
|
-
label: "Граница затухания связи при анимации",
|
|
765
|
+
label: "Граница затухания связи при анимации ноды",
|
|
690
766
|
},
|
|
691
767
|
{
|
|
692
|
-
id: "
|
|
693
|
-
initialValue: GRAPH_SETTINGS.
|
|
768
|
+
id: "highlightByNodeNodeFadingMin",
|
|
769
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeNodeFadingMin,
|
|
694
770
|
max: 1,
|
|
695
771
|
min: 0,
|
|
696
772
|
step: 0.01,
|
|
697
773
|
type: "range",
|
|
698
|
-
label: "Граница затухания ноды при анимации",
|
|
774
|
+
label: "Граница затухания ноды при анимации ноды",
|
|
699
775
|
},
|
|
700
776
|
{
|
|
701
|
-
id: "
|
|
702
|
-
initialValue: GRAPH_SETTINGS.
|
|
777
|
+
id: "highlightByNodeArrowFadingMin",
|
|
778
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeArrowFadingMin,
|
|
703
779
|
max: 1,
|
|
704
780
|
min: 0,
|
|
705
781
|
step: 0.01,
|
|
706
782
|
type: "range",
|
|
707
|
-
label: "Граница затухания стрелки при анимации",
|
|
783
|
+
label: "Граница затухания стрелки при анимации ноды",
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
id: "highlightByNodeOnlyRoot",
|
|
787
|
+
type: "checkbox",
|
|
788
|
+
initialValue: GRAPH_SETTINGS.highlightByNodeOnlyRoot,
|
|
789
|
+
label: "Дополнительная анимация только главное цели при анимации ноды",
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
id: "highlightByLinkNodeSizingAdditional",
|
|
793
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkNodeSizingAdditional,
|
|
794
|
+
max: 10,
|
|
795
|
+
min: 0.1,
|
|
796
|
+
step: 0.01,
|
|
797
|
+
type: "range",
|
|
798
|
+
label: "Дополнительный размер при анимации связи",
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
id: "highlightByLinkNodeColorFadingMin",
|
|
802
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkNodeColorFadingMin,
|
|
803
|
+
max: 1,
|
|
804
|
+
min: 0.01,
|
|
805
|
+
step: 0.01,
|
|
806
|
+
type: "range",
|
|
807
|
+
label: "Граница затухания цвета при анимации связи",
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
id: "highlightByLinkTextShiftXAdditional",
|
|
811
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkTextShiftXAdditional,
|
|
812
|
+
max: 50,
|
|
813
|
+
min: 0,
|
|
814
|
+
step: 0.1,
|
|
815
|
+
type: "range",
|
|
816
|
+
label: "Смещение текста по X при анимации связи",
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
id: "highlightByLinkTextShiftYAdditional",
|
|
820
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkTextShiftYAdditional,
|
|
821
|
+
max: 50,
|
|
822
|
+
min: 0,
|
|
823
|
+
step: 0.1,
|
|
824
|
+
type: "range",
|
|
825
|
+
label: "Смещение текста по Y при анимации связи",
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
id: "highlightByLinkTextSizingAdditional",
|
|
829
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkTextSizingAdditional,
|
|
830
|
+
max: 10,
|
|
831
|
+
min: 0.1,
|
|
832
|
+
step: 0.1,
|
|
833
|
+
type: "range",
|
|
834
|
+
label: "Увеличение текста при анимации связи",
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
id: "highlightByLinkTextWeightAdditional",
|
|
838
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkTextWeightAdditional,
|
|
839
|
+
max: 1000,
|
|
840
|
+
min: 0,
|
|
841
|
+
step: 100,
|
|
842
|
+
type: "range",
|
|
843
|
+
label: "Увеличение жирности текста при анимации связи",
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
id: "highlightByLinkTextWidthAdditional",
|
|
847
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkTextWidthAdditional,
|
|
848
|
+
max: 100,
|
|
849
|
+
min: 0,
|
|
850
|
+
step: 0.1,
|
|
851
|
+
type: "range",
|
|
852
|
+
label: "Увеличение ширины текста при анимации связи",
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
id: "highlightByLinkTextFadingMin",
|
|
856
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkTextFadingMin,
|
|
857
|
+
max: 1,
|
|
858
|
+
min: 0,
|
|
859
|
+
step: 0.01,
|
|
860
|
+
type: "range",
|
|
861
|
+
label: "Граница затухания текста при анимации связи",
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
id: "highlightByLinkLinkFadingMin",
|
|
865
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkLinkFadingMin,
|
|
866
|
+
max: 1,
|
|
867
|
+
min: 0,
|
|
868
|
+
step: 0.01,
|
|
869
|
+
type: "range",
|
|
870
|
+
label: "Граница затухания связи при анимации связи",
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
id: "highlightByLinkNodeFadingMin",
|
|
874
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkNodeFadingMin,
|
|
875
|
+
max: 1,
|
|
876
|
+
min: 0,
|
|
877
|
+
step: 0.01,
|
|
878
|
+
type: "range",
|
|
879
|
+
label: "Граница затухания ноды при анимации связи",
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
id: "highlightByLinkArrowFadingMin",
|
|
883
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkArrowFadingMin,
|
|
884
|
+
max: 1,
|
|
885
|
+
min: 0,
|
|
886
|
+
step: 0.01,
|
|
887
|
+
type: "range",
|
|
888
|
+
label: "Граница затухания стрелки при анимации связи",
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
id: "highlightByLinkOnlyRoot",
|
|
892
|
+
type: "checkbox",
|
|
893
|
+
initialValue: GRAPH_SETTINGS.highlightByLinkOnlyRoot,
|
|
894
|
+
label: "Дополнительная анимация только главное цели при анимации связи",
|
|
708
895
|
},
|
|
709
896
|
{
|
|
710
897
|
id: "highlightDownStep",
|
|
@@ -751,12 +938,6 @@ function getGraphControls(keys) {
|
|
|
751
938
|
type: "range",
|
|
752
939
|
label: "Коэффициент увеличения радиуса",
|
|
753
940
|
},
|
|
754
|
-
{
|
|
755
|
-
id: "highlightOnlyRoot",
|
|
756
|
-
type: "checkbox",
|
|
757
|
-
initialValue: GRAPH_SETTINGS.highlightOnlyRoot,
|
|
758
|
-
label: "Дополнительная анимация только главное цели",
|
|
759
|
-
},
|
|
760
941
|
{
|
|
761
942
|
id: "stickAfterDrag",
|
|
762
943
|
type: "checkbox",
|
|
@@ -764,9 +945,9 @@ function getGraphControls(keys) {
|
|
|
764
945
|
label: "Фиксировании ноды после перетаскивания",
|
|
765
946
|
},
|
|
766
947
|
{
|
|
767
|
-
id: "
|
|
948
|
+
id: "highlightByHoverNode",
|
|
768
949
|
type: "checkbox",
|
|
769
|
-
initialValue: GRAPH_SETTINGS.
|
|
950
|
+
initialValue: GRAPH_SETTINGS.highlightByHoverNode,
|
|
770
951
|
label: "Анимации при наведении",
|
|
771
952
|
},
|
|
772
953
|
{
|
|
@@ -874,34 +1055,64 @@ function getNodeControls(keys) {
|
|
|
874
1055
|
initialValue: NODE_OPTIONS.textGap,
|
|
875
1056
|
},
|
|
876
1057
|
{
|
|
877
|
-
id: "
|
|
1058
|
+
id: "highlightByNodeNodeFading",
|
|
1059
|
+
type: "checkbox",
|
|
1060
|
+
initialValue: NODE_OPTIONS.highlightByNodeNodeFading,
|
|
1061
|
+
label: "Затухание при анимации ноды",
|
|
1062
|
+
},
|
|
1063
|
+
{
|
|
1064
|
+
id: "highlightByNodeNodeColor",
|
|
878
1065
|
type: "checkbox",
|
|
879
|
-
initialValue: NODE_OPTIONS.
|
|
880
|
-
label: "
|
|
1066
|
+
initialValue: NODE_OPTIONS.highlightByNodeNodeColor,
|
|
1067
|
+
label: "Затухание цвета при анимации ноды",
|
|
881
1068
|
},
|
|
882
1069
|
{
|
|
883
|
-
id: "
|
|
1070
|
+
id: "highlightByNodeNodeSizing",
|
|
884
1071
|
type: "checkbox",
|
|
885
|
-
initialValue: NODE_OPTIONS.
|
|
886
|
-
label: "
|
|
1072
|
+
initialValue: NODE_OPTIONS.highlightByNodeNodeSizing,
|
|
1073
|
+
label: "Изменение размера при анимации ноды",
|
|
887
1074
|
},
|
|
888
1075
|
{
|
|
889
|
-
id: "
|
|
1076
|
+
id: "highlightByNodeTextFading",
|
|
890
1077
|
type: "checkbox",
|
|
891
|
-
initialValue: NODE_OPTIONS.
|
|
892
|
-
label: "
|
|
1078
|
+
initialValue: NODE_OPTIONS.highlightByNodeTextFading,
|
|
1079
|
+
label: "Затухание текста при анимации ноды",
|
|
893
1080
|
},
|
|
894
1081
|
{
|
|
895
|
-
id: "
|
|
1082
|
+
id: "highlightByNodeTextSizing",
|
|
896
1083
|
type: "checkbox",
|
|
897
|
-
initialValue: NODE_OPTIONS.
|
|
898
|
-
label: "
|
|
1084
|
+
initialValue: NODE_OPTIONS.highlightByNodeTextSizing,
|
|
1085
|
+
label: "Изменение размера текста при анимации ноды",
|
|
899
1086
|
},
|
|
900
1087
|
{
|
|
901
|
-
id: "
|
|
1088
|
+
id: "highlightByLinkNodeFading",
|
|
902
1089
|
type: "checkbox",
|
|
903
|
-
initialValue: NODE_OPTIONS.
|
|
904
|
-
label: "
|
|
1090
|
+
initialValue: NODE_OPTIONS.highlightByLinkNodeFading,
|
|
1091
|
+
label: "Затухание при анимации связи",
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
id: "highlightByLinkNodeColor",
|
|
1095
|
+
type: "checkbox",
|
|
1096
|
+
initialValue: NODE_OPTIONS.highlightByLinkNodeColor,
|
|
1097
|
+
label: "Затухание цвета при анимации связи",
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
id: "highlightByLinkNodeSizing",
|
|
1101
|
+
type: "checkbox",
|
|
1102
|
+
initialValue: NODE_OPTIONS.highlightByLinkNodeSizing,
|
|
1103
|
+
label: "Изменение размера при анимации связи",
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
id: "highlightByLinkTextFading",
|
|
1107
|
+
type: "checkbox",
|
|
1108
|
+
initialValue: NODE_OPTIONS.highlightByLinkTextFading,
|
|
1109
|
+
label: "Затухание текста при анимации связи",
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
id: "highlightByLinkTextSizing",
|
|
1113
|
+
type: "checkbox",
|
|
1114
|
+
initialValue: NODE_OPTIONS.highlightByLinkTextSizing,
|
|
1115
|
+
label: "Изменение размера текста при анимации связи",
|
|
905
1116
|
},
|
|
906
1117
|
];
|
|
907
1118
|
return keys ? NODE_CONTROLS.filter((control) => keys.includes(control.id)) : NODE_CONTROLS;
|
|
@@ -998,12 +1209,6 @@ function getLinkControls(keys) {
|
|
|
998
1209
|
initialValue: "#000000FF",
|
|
999
1210
|
label: "Цвет частиц",
|
|
1000
1211
|
},
|
|
1001
|
-
{
|
|
1002
|
-
id: "highlightFading",
|
|
1003
|
-
type: "checkbox",
|
|
1004
|
-
label: "Анимация Затухания",
|
|
1005
|
-
initialValue: LINK_OPTIONS.highlightFading,
|
|
1006
|
-
},
|
|
1007
1212
|
{
|
|
1008
1213
|
id: "pretty",
|
|
1009
1214
|
type: "checkbox",
|
|
@@ -1017,10 +1222,28 @@ function getLinkControls(keys) {
|
|
|
1017
1222
|
initialValue: LINK_OPTIONS.arrow,
|
|
1018
1223
|
},
|
|
1019
1224
|
{
|
|
1020
|
-
id: "
|
|
1225
|
+
id: "highlightByNodeLinkFading",
|
|
1021
1226
|
type: "checkbox",
|
|
1022
|
-
label: "
|
|
1023
|
-
initialValue: LINK_OPTIONS.
|
|
1227
|
+
label: "Затухание при анимации ноды",
|
|
1228
|
+
initialValue: LINK_OPTIONS.highlightByNodeLinkFading,
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
id: "highlightByNodeArrowFading",
|
|
1232
|
+
type: "checkbox",
|
|
1233
|
+
label: "Затухание стрелки при анимации ноды",
|
|
1234
|
+
initialValue: LINK_OPTIONS.highlightByNodeArrowFading,
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
id: "highlightByLinkLinkFading",
|
|
1238
|
+
type: "checkbox",
|
|
1239
|
+
label: "Затухание при анимации связи",
|
|
1240
|
+
initialValue: LINK_OPTIONS.highlightByLinkLinkFading,
|
|
1241
|
+
},
|
|
1242
|
+
{
|
|
1243
|
+
id: "highlightByLinkArrowFading",
|
|
1244
|
+
type: "checkbox",
|
|
1245
|
+
label: "Затухание стрелки при анимации связи",
|
|
1246
|
+
initialValue: LINK_OPTIONS.highlightByLinkArrowFading,
|
|
1024
1247
|
},
|
|
1025
1248
|
{
|
|
1026
1249
|
id: "arrowReverseAppear",
|
|
@@ -1083,6 +1306,7 @@ class GraphCanvas {
|
|
|
1083
1306
|
nodeOptionsCache = {};
|
|
1084
1307
|
isDragging = false;
|
|
1085
1308
|
highlightedNode = null;
|
|
1309
|
+
highlightedLink = null;
|
|
1086
1310
|
highlightedNeighbors = null;
|
|
1087
1311
|
highlightProgress = 1;
|
|
1088
1312
|
highlightWorking = false;
|
|
@@ -1104,6 +1328,7 @@ class GraphCanvas {
|
|
|
1104
1328
|
highlightDrawing: this.highlightDrawing,
|
|
1105
1329
|
highlightedNeighbors: this.highlightedNeighbors,
|
|
1106
1330
|
highlightedNode: this.highlightedNode,
|
|
1331
|
+
highlightedLink: this.highlightedLink,
|
|
1107
1332
|
highlightWorking: this.highlightWorking,
|
|
1108
1333
|
isDragging: this.isDragging,
|
|
1109
1334
|
simulation: this.simulation,
|
|
@@ -1234,6 +1459,7 @@ class GraphCanvas {
|
|
|
1234
1459
|
clearState() {
|
|
1235
1460
|
this.isDragging = false;
|
|
1236
1461
|
this.highlightedNode = null;
|
|
1462
|
+
this.highlightedLink = null;
|
|
1237
1463
|
this.highlightedNeighbors = null;
|
|
1238
1464
|
this.highlightProgress = 0;
|
|
1239
1465
|
this.highlightWorking = false;
|
|
@@ -1394,9 +1620,10 @@ class GraphCanvas {
|
|
|
1394
1620
|
return void requestAnimationFrame(() => this.draw());
|
|
1395
1621
|
}
|
|
1396
1622
|
if (!this.highlightWorking && this.highlightProgress <= 0) {
|
|
1397
|
-
if (this.highlightedNeighbors || this.highlightedNode) {
|
|
1623
|
+
if (this.highlightedNeighbors || this.highlightedNode || this.highlightedLink) {
|
|
1398
1624
|
this.highlightedNeighbors = null;
|
|
1399
1625
|
this.highlightedNode = null;
|
|
1626
|
+
this.highlightedLink = null;
|
|
1400
1627
|
this.particles = {};
|
|
1401
1628
|
if (!this.simulationWorking)
|
|
1402
1629
|
return void requestAnimationFrame(() => this.draw());
|
|
@@ -1416,6 +1643,8 @@ class GraphCanvas {
|
|
|
1416
1643
|
this.highlightedNeighbors = null;
|
|
1417
1644
|
if (this.highlightedNode)
|
|
1418
1645
|
this.highlightedNode = null;
|
|
1646
|
+
if (this.highlightedLink)
|
|
1647
|
+
this.highlightedLink = null;
|
|
1419
1648
|
});
|
|
1420
1649
|
return;
|
|
1421
1650
|
}
|
|
@@ -1464,21 +1693,49 @@ class GraphCanvas {
|
|
|
1464
1693
|
}
|
|
1465
1694
|
let alpha = linkOptions.alpha;
|
|
1466
1695
|
let arrowAlpha = linkOptions.arrowReverseAppear ? 0 : linkOptions.arrowAlpha;
|
|
1696
|
+
/** NODE HIGHLIGHT */
|
|
1467
1697
|
if (this.highlightedNeighbors && this.highlightedNode) {
|
|
1468
1698
|
/** Not highlighted */
|
|
1469
1699
|
if (this.highlightedNode.id != link.source.id &&
|
|
1470
1700
|
this.highlightedNode.id != link.target.id) {
|
|
1471
|
-
if (linkOptions.
|
|
1472
|
-
const min = this.graphSettings.
|
|
1473
|
-
? this.graphSettings.
|
|
1701
|
+
if (linkOptions.highlightByNodeLinkFading) {
|
|
1702
|
+
const min = this.graphSettings.highlightByNodeLinkFadingMin < alpha
|
|
1703
|
+
? this.graphSettings.highlightByNodeLinkFadingMin
|
|
1704
|
+
: alpha;
|
|
1705
|
+
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
1706
|
+
}
|
|
1707
|
+
if (linkOptions.arrow &&
|
|
1708
|
+
linkOptions.highlightByNodeArrowFading &&
|
|
1709
|
+
!linkOptions.arrowReverseAppear) {
|
|
1710
|
+
const min = this.graphSettings.highlightByNodeArrowFadingMin < arrowAlpha
|
|
1711
|
+
? this.graphSettings.highlightByNodeArrowFadingMin
|
|
1712
|
+
: arrowAlpha;
|
|
1713
|
+
arrowAlpha = animationByProgress(min, arrowAlpha - min, 1 - this.highlightProgress);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
else {
|
|
1717
|
+
// eslint-disable-next-line no-lonely-if
|
|
1718
|
+
if (linkOptions.arrow && linkOptions.arrowReverseAppear) {
|
|
1719
|
+
/** Highlighted */
|
|
1720
|
+
arrowAlpha = animationByProgress(0, linkOptions.arrowAlpha, this.highlightProgress);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
/** LINK HIGHLIGHT */
|
|
1725
|
+
if (this.highlightedNeighbors && this.highlightedLink) {
|
|
1726
|
+
/** Not highlighted */
|
|
1727
|
+
if (this.highlightedLink !== link) {
|
|
1728
|
+
if (linkOptions.highlightByLinkLinkFading) {
|
|
1729
|
+
const min = this.graphSettings.highlightByLinkLinkFadingMin < alpha
|
|
1730
|
+
? this.graphSettings.highlightByLinkLinkFadingMin
|
|
1474
1731
|
: alpha;
|
|
1475
1732
|
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
1476
1733
|
}
|
|
1477
1734
|
if (linkOptions.arrow &&
|
|
1478
|
-
linkOptions.
|
|
1735
|
+
linkOptions.highlightByLinkArrowFading &&
|
|
1479
1736
|
!linkOptions.arrowReverseAppear) {
|
|
1480
|
-
const min = this.graphSettings.
|
|
1481
|
-
? this.graphSettings.
|
|
1737
|
+
const min = this.graphSettings.highlightByLinkArrowFadingMin < arrowAlpha
|
|
1738
|
+
? this.graphSettings.highlightByLinkArrowFadingMin
|
|
1482
1739
|
: arrowAlpha;
|
|
1483
1740
|
arrowAlpha = animationByProgress(min, arrowAlpha - min, 1 - this.highlightProgress);
|
|
1484
1741
|
}
|
|
@@ -1518,8 +1775,10 @@ class GraphCanvas {
|
|
|
1518
1775
|
this.context.stroke();
|
|
1519
1776
|
/** Particle */
|
|
1520
1777
|
if (this.linkSettings.particles &&
|
|
1521
|
-
this.highlightedNode &&
|
|
1522
|
-
|
|
1778
|
+
((this.highlightedNode &&
|
|
1779
|
+
(this.highlightedNode.id === link.source.id ||
|
|
1780
|
+
this.highlightedNode.id === link.target.id)) ||
|
|
1781
|
+
(this.highlightedLink && this.highlightedLink === link))) {
|
|
1523
1782
|
if (!this.particles[id]) {
|
|
1524
1783
|
const sourceId = link.source.id;
|
|
1525
1784
|
const targetId = link.target.id;
|
|
@@ -1608,42 +1867,84 @@ class GraphCanvas {
|
|
|
1608
1867
|
let textShiftY = nodeOptions.textShiftY;
|
|
1609
1868
|
let textWeight = nodeOptions.textWeight;
|
|
1610
1869
|
let textWidth = nodeOptions.textWidth;
|
|
1870
|
+
/** Node Highlight */
|
|
1611
1871
|
if (this.highlightedNeighbors && this.highlightedNode) {
|
|
1612
1872
|
/** Not highlighted */
|
|
1613
1873
|
if (!this.highlightedNeighbors.has(node.id) && this.highlightedNode.id != node.id) {
|
|
1614
|
-
if (nodeOptions.
|
|
1615
|
-
const min = this.graphSettings.
|
|
1616
|
-
? this.graphSettings.
|
|
1874
|
+
if (nodeOptions.highlightByNodeNodeFading) {
|
|
1875
|
+
const min = this.graphSettings.highlightByNodeNodeFadingMin < alpha
|
|
1876
|
+
? this.graphSettings.highlightByNodeNodeFadingMin
|
|
1617
1877
|
: alpha;
|
|
1618
1878
|
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
1619
1879
|
}
|
|
1620
|
-
if (nodeOptions.
|
|
1621
|
-
const min = this.graphSettings.
|
|
1622
|
-
? this.graphSettings.
|
|
1880
|
+
if (nodeOptions.highlightByNodeTextFading) {
|
|
1881
|
+
const min = this.graphSettings.highlightByNodeTextFadingMin < textAlpha
|
|
1882
|
+
? this.graphSettings.highlightByNodeTextFadingMin
|
|
1623
1883
|
: textAlpha;
|
|
1624
1884
|
textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);
|
|
1625
1885
|
}
|
|
1626
|
-
if (nodeOptions.
|
|
1886
|
+
if (nodeOptions.highlightByNodeNodeColor) {
|
|
1627
1887
|
const colorRgb = extractRgb(colorToRgb(color));
|
|
1628
1888
|
if (colorRgb) {
|
|
1629
|
-
const colorRgbFade = fadeRgb(colorRgb, this.graphSettings.
|
|
1889
|
+
const colorRgbFade = fadeRgb(colorRgb, this.graphSettings.highlightByNodeNodeColorFadingMin);
|
|
1630
1890
|
const colorFadeAnimation = rgbAnimationByProgress(colorRgb, colorRgbFade, this.highlightProgress);
|
|
1631
1891
|
color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;
|
|
1632
1892
|
}
|
|
1633
1893
|
}
|
|
1634
1894
|
}
|
|
1635
|
-
else if (!this.graphSettings.
|
|
1636
|
-
(this.graphSettings.
|
|
1895
|
+
else if (!this.graphSettings.highlightByNodeOnlyRoot ||
|
|
1896
|
+
(this.graphSettings.highlightByNodeOnlyRoot && this.highlightedNode.id === node.id)) {
|
|
1637
1897
|
/** Highlighted */
|
|
1638
|
-
if (nodeOptions.
|
|
1639
|
-
radiusInitial = animationByProgress(radiusInitial, this.graphSettings.
|
|
1898
|
+
if (nodeOptions.highlightByNodeNodeSizing) {
|
|
1899
|
+
radiusInitial = animationByProgress(radiusInitial, this.graphSettings.highlightByNodeNodeSizingAdditional, this.highlightProgress);
|
|
1640
1900
|
}
|
|
1641
|
-
if (nodeOptions.
|
|
1642
|
-
textSize = animationByProgress(textSize, this.graphSettings.
|
|
1643
|
-
textShiftX = animationByProgress(textShiftX, this.graphSettings.
|
|
1644
|
-
textShiftY = animationByProgress(textShiftY, this.graphSettings.
|
|
1645
|
-
textWeight = animationByProgress(textWeight, this.graphSettings.
|
|
1646
|
-
textWidth = animationByProgress(textWidth, this.graphSettings.
|
|
1901
|
+
if (nodeOptions.highlightByNodeTextSizing) {
|
|
1902
|
+
textSize = animationByProgress(textSize, this.graphSettings.highlightByNodeTextSizingAdditional, this.highlightProgress);
|
|
1903
|
+
textShiftX = animationByProgress(textShiftX, this.graphSettings.highlightByNodeTextShiftXAdditional, this.highlightProgress);
|
|
1904
|
+
textShiftY = animationByProgress(textShiftY, this.graphSettings.highlightByNodeTextShiftYAdditional, this.highlightProgress);
|
|
1905
|
+
textWeight = animationByProgress(textWeight, this.graphSettings.highlightByNodeTextWeightAdditional, this.highlightProgress);
|
|
1906
|
+
textWidth = animationByProgress(textWidth, this.graphSettings.highlightByNodeTextWidthAdditional, this.highlightProgress);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
/** LinkHighlight */
|
|
1911
|
+
if (this.highlightedNeighbors && this.highlightedLink) {
|
|
1912
|
+
/** Not highlighted */
|
|
1913
|
+
if (!this.highlightedNeighbors.has(node.id) &&
|
|
1914
|
+
this.highlightedLink.source !== node &&
|
|
1915
|
+
this.highlightedLink.target !== node) {
|
|
1916
|
+
if (nodeOptions.highlightByLinkNodeFading) {
|
|
1917
|
+
const min = this.graphSettings.highlightByLinkNodeFadingMin < alpha
|
|
1918
|
+
? this.graphSettings.highlightByLinkNodeFadingMin
|
|
1919
|
+
: alpha;
|
|
1920
|
+
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
1921
|
+
}
|
|
1922
|
+
if (nodeOptions.highlightByLinkTextFading) {
|
|
1923
|
+
const min = this.graphSettings.highlightByLinkTextFadingMin < textAlpha
|
|
1924
|
+
? this.graphSettings.highlightByLinkTextFadingMin
|
|
1925
|
+
: textAlpha;
|
|
1926
|
+
textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);
|
|
1927
|
+
}
|
|
1928
|
+
if (nodeOptions.highlightByLinkNodeColor) {
|
|
1929
|
+
const colorRgb = extractRgb(colorToRgb(color));
|
|
1930
|
+
if (colorRgb) {
|
|
1931
|
+
const colorRgbFade = fadeRgb(colorRgb, this.graphSettings.highlightByLinkNodeColorFadingMin);
|
|
1932
|
+
const colorFadeAnimation = rgbAnimationByProgress(colorRgb, colorRgbFade, this.highlightProgress);
|
|
1933
|
+
color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
else {
|
|
1938
|
+
/** Highlighted */
|
|
1939
|
+
if (nodeOptions.highlightByLinkNodeSizing) {
|
|
1940
|
+
radiusInitial = animationByProgress(radiusInitial, this.graphSettings.highlightByLinkNodeSizingAdditional, this.highlightProgress);
|
|
1941
|
+
}
|
|
1942
|
+
if (nodeOptions.highlightByLinkTextSizing) {
|
|
1943
|
+
textSize = animationByProgress(textSize, this.graphSettings.highlightByLinkTextSizingAdditional, this.highlightProgress);
|
|
1944
|
+
textShiftX = animationByProgress(textShiftX, this.graphSettings.highlightByLinkTextShiftXAdditional, this.highlightProgress);
|
|
1945
|
+
textShiftY = animationByProgress(textShiftY, this.graphSettings.highlightByLinkTextShiftYAdditional, this.highlightProgress);
|
|
1946
|
+
textWeight = animationByProgress(textWeight, this.graphSettings.highlightByLinkTextWeightAdditional, this.highlightProgress);
|
|
1947
|
+
textWidth = animationByProgress(textWidth, this.graphSettings.highlightByLinkTextWidthAdditional, this.highlightProgress);
|
|
1647
1948
|
}
|
|
1648
1949
|
}
|
|
1649
1950
|
}
|
|
@@ -1785,10 +2086,14 @@ class GraphCanvas {
|
|
|
1785
2086
|
initPointer() {
|
|
1786
2087
|
if (!this.area || !this.nodes || !this.simulation)
|
|
1787
2088
|
throw new Error("bad init data");
|
|
1788
|
-
|
|
1789
|
-
|
|
2089
|
+
function onHover(event) {
|
|
2090
|
+
if (!this.area)
|
|
2091
|
+
return;
|
|
1790
2092
|
let currentNode;
|
|
1791
|
-
|
|
2093
|
+
let currentLink;
|
|
2094
|
+
const checkHighlightNode = this.graphSettings.highlightByHoverNode && !this.isDragging;
|
|
2095
|
+
const checkHighlightLink = this.graphSettings.highlightByHoverLink && !this.isDragging;
|
|
2096
|
+
if (checkHighlightNode) {
|
|
1792
2097
|
currentNode = nodeByPointerGetter({
|
|
1793
2098
|
graphSettings: this.graphSettings,
|
|
1794
2099
|
areaRect: this.areaRect,
|
|
@@ -1796,26 +2101,61 @@ class GraphCanvas {
|
|
|
1796
2101
|
mouseEvent: event,
|
|
1797
2102
|
nodes: this.nodes,
|
|
1798
2103
|
});
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
2104
|
+
}
|
|
2105
|
+
if (currentNode) {
|
|
2106
|
+
this.area.style.cursor = "pointer";
|
|
2107
|
+
}
|
|
2108
|
+
else if (checkHighlightLink) {
|
|
2109
|
+
currentLink = linkByPointerGetter({
|
|
2110
|
+
graphSettings: this.graphSettings,
|
|
2111
|
+
areaRect: this.areaRect,
|
|
2112
|
+
areaTransform: this.areaTransform,
|
|
2113
|
+
mouseEvent: event,
|
|
2114
|
+
links: this.links,
|
|
2115
|
+
});
|
|
2116
|
+
if (currentLink) {
|
|
2117
|
+
this.area.style.cursor = "pointer";
|
|
1807
2118
|
}
|
|
1808
|
-
else
|
|
1809
|
-
this.
|
|
1810
|
-
if (!this.simulationWorking && !this.highlightDrawing)
|
|
1811
|
-
requestAnimationFrame(() => {
|
|
1812
|
-
this.draw();
|
|
1813
|
-
});
|
|
2119
|
+
else {
|
|
2120
|
+
this.area.style.cursor = "default";
|
|
1814
2121
|
}
|
|
1815
2122
|
}
|
|
2123
|
+
else {
|
|
2124
|
+
this.area.style.cursor = "default";
|
|
2125
|
+
}
|
|
2126
|
+
if (currentNode && this.highlightedNode !== currentNode) {
|
|
2127
|
+
this.highlightedNode = currentNode;
|
|
2128
|
+
this.highlightedLink = null;
|
|
2129
|
+
this.highlightedNeighbors = new Set(this.highlightedNode?.neighbors ?? []);
|
|
2130
|
+
this.highlightWorking = true;
|
|
2131
|
+
if (!this.simulationWorking && !this.highlightDrawing)
|
|
2132
|
+
requestAnimationFrame(() => {
|
|
2133
|
+
this.draw();
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
else if (currentLink &&
|
|
2137
|
+
checkType(currentLink.source, jsHelpers.isObject(currentLink.source)) &&
|
|
2138
|
+
checkType(currentLink.target, jsHelpers.isObject(currentLink.target)) &&
|
|
2139
|
+
this.highlightedLink !== currentLink) {
|
|
2140
|
+
this.highlightedLink = currentLink;
|
|
2141
|
+
this.highlightedNode = null;
|
|
2142
|
+
this.highlightedNeighbors = new Set([currentLink.source.id, currentLink.target.id]);
|
|
2143
|
+
this.highlightWorking = true;
|
|
2144
|
+
if (!this.simulationWorking && !this.highlightDrawing)
|
|
2145
|
+
requestAnimationFrame(() => {
|
|
2146
|
+
this.draw();
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
else if (!currentNode && !currentLink && (this.highlightedNode || this.highlightedLink)) {
|
|
2150
|
+
this.highlightWorking = false;
|
|
2151
|
+
if (!this.simulationWorking && !this.highlightDrawing)
|
|
2152
|
+
requestAnimationFrame(() => {
|
|
2153
|
+
this.draw();
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
1816
2156
|
if (!this.listeners.onMove)
|
|
1817
2157
|
return;
|
|
1818
|
-
if (!currentNode)
|
|
2158
|
+
if (!currentNode && !checkHighlightNode)
|
|
1819
2159
|
currentNode = nodeByPointerGetter({
|
|
1820
2160
|
graphSettings: this.graphSettings,
|
|
1821
2161
|
areaRect: this.areaRect,
|
|
@@ -1823,13 +2163,23 @@ class GraphCanvas {
|
|
|
1823
2163
|
mouseEvent: event,
|
|
1824
2164
|
nodes: this.nodes,
|
|
1825
2165
|
});
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
2166
|
+
if (!currentNode && (!checkHighlightNode || (!checkHighlightLink && !currentLink))) {
|
|
2167
|
+
currentLink = linkByPointerGetter({
|
|
2168
|
+
graphSettings: this.graphSettings,
|
|
2169
|
+
areaRect: this.areaRect,
|
|
2170
|
+
areaTransform: this.areaTransform,
|
|
2171
|
+
mouseEvent: event,
|
|
2172
|
+
links: this.links,
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
if (!currentNode)
|
|
2176
|
+
return void this.listeners.onMove(event, currentNode, currentLink);
|
|
2177
|
+
}
|
|
2178
|
+
function onWheelClick(event) {
|
|
2179
|
+
if (this.isDragging ||
|
|
2180
|
+
!this.listeners.onWheelClick ||
|
|
2181
|
+
!("button" in event) ||
|
|
2182
|
+
event.button !== 1)
|
|
1833
2183
|
return;
|
|
1834
2184
|
const currentNode = nodeByPointerGetter({
|
|
1835
2185
|
graphSettings: this.graphSettings,
|
|
@@ -1838,11 +2188,20 @@ class GraphCanvas {
|
|
|
1838
2188
|
mouseEvent: event,
|
|
1839
2189
|
nodes: this.nodes,
|
|
1840
2190
|
});
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
2191
|
+
if (!currentNode) {
|
|
2192
|
+
const currentLink = linkByPointerGetter({
|
|
2193
|
+
graphSettings: this.graphSettings,
|
|
2194
|
+
areaRect: this.areaRect,
|
|
2195
|
+
areaTransform: this.areaTransform,
|
|
2196
|
+
mouseEvent: event,
|
|
2197
|
+
links: this.links,
|
|
2198
|
+
});
|
|
2199
|
+
return void this.listeners.onWheelClick(event, undefined, currentLink);
|
|
2200
|
+
}
|
|
2201
|
+
return void this.listeners.onWheelClick(event, currentNode, undefined);
|
|
2202
|
+
}
|
|
2203
|
+
function onRightClick(event) {
|
|
2204
|
+
if (!this.listeners.onContextMenu)
|
|
1846
2205
|
return;
|
|
1847
2206
|
const currentNode = nodeByPointerGetter({
|
|
1848
2207
|
graphSettings: this.graphSettings,
|
|
@@ -1851,13 +2210,20 @@ class GraphCanvas {
|
|
|
1851
2210
|
mouseEvent: event,
|
|
1852
2211
|
nodes: this.nodes,
|
|
1853
2212
|
});
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
2213
|
+
if (!currentNode) {
|
|
2214
|
+
const currentLink = linkByPointerGetter({
|
|
2215
|
+
graphSettings: this.graphSettings,
|
|
2216
|
+
areaRect: this.areaRect,
|
|
2217
|
+
areaTransform: this.areaTransform,
|
|
2218
|
+
mouseEvent: event,
|
|
2219
|
+
links: this.links,
|
|
2220
|
+
});
|
|
2221
|
+
return void this.listeners.onContextMenu(event, undefined, currentLink);
|
|
2222
|
+
}
|
|
2223
|
+
return void this.listeners.onContextMenu(event, currentNode, undefined);
|
|
2224
|
+
}
|
|
2225
|
+
function onDoubleClick(event) {
|
|
2226
|
+
if (!this.listeners.onDoubleClick)
|
|
1861
2227
|
return;
|
|
1862
2228
|
const currentNode = nodeByPointerGetter({
|
|
1863
2229
|
graphSettings: this.graphSettings,
|
|
@@ -1866,13 +2232,20 @@ class GraphCanvas {
|
|
|
1866
2232
|
mouseEvent: event,
|
|
1867
2233
|
nodes: this.nodes,
|
|
1868
2234
|
});
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
2235
|
+
if (!currentNode) {
|
|
2236
|
+
const currentLink = linkByPointerGetter({
|
|
2237
|
+
graphSettings: this.graphSettings,
|
|
2238
|
+
areaRect: this.areaRect,
|
|
2239
|
+
areaTransform: this.areaTransform,
|
|
2240
|
+
mouseEvent: event,
|
|
2241
|
+
links: this.links,
|
|
2242
|
+
});
|
|
2243
|
+
return void this.listeners.onDoubleClick(event, undefined, currentLink);
|
|
2244
|
+
}
|
|
2245
|
+
return void this.listeners.onDoubleClick(event, currentNode, undefined);
|
|
2246
|
+
}
|
|
2247
|
+
function onClick(event) {
|
|
2248
|
+
if (this.isDragging || !this.listeners.onClick || ("button" in event && event.button !== 0))
|
|
1876
2249
|
return;
|
|
1877
2250
|
const currentNode = nodeByPointerGetter({
|
|
1878
2251
|
graphSettings: this.graphSettings,
|
|
@@ -1881,15 +2254,46 @@ class GraphCanvas {
|
|
|
1881
2254
|
mouseEvent: event,
|
|
1882
2255
|
nodes: this.nodes,
|
|
1883
2256
|
});
|
|
1884
|
-
|
|
1885
|
-
|
|
2257
|
+
if (!currentNode) {
|
|
2258
|
+
const currentLink = linkByPointerGetter({
|
|
2259
|
+
graphSettings: this.graphSettings,
|
|
2260
|
+
areaRect: this.areaRect,
|
|
2261
|
+
areaTransform: this.areaTransform,
|
|
2262
|
+
mouseEvent: event,
|
|
2263
|
+
links: this.links,
|
|
2264
|
+
});
|
|
2265
|
+
return void this.listeners.onClick(event, undefined, currentLink);
|
|
2266
|
+
}
|
|
2267
|
+
return void this.listeners.onClick(event, currentNode, undefined);
|
|
2268
|
+
}
|
|
2269
|
+
/** hover */
|
|
2270
|
+
this.area.addEventListener("mousemove", onHover.bind(this), {
|
|
2271
|
+
signal: this.eventAbortController.signal,
|
|
2272
|
+
});
|
|
2273
|
+
this.area.addEventListener("touchmove", onHover.bind(this), {
|
|
2274
|
+
signal: this.eventAbortController.signal,
|
|
2275
|
+
});
|
|
2276
|
+
/** dblclick */
|
|
2277
|
+
this.area.addEventListener("dblclick", onDoubleClick.bind(this), {
|
|
2278
|
+
signal: this.eventAbortController.signal,
|
|
2279
|
+
});
|
|
2280
|
+
/** wheel click */
|
|
2281
|
+
this.area.addEventListener("mousedown", onWheelClick.bind(this), {
|
|
2282
|
+
signal: this.eventAbortController.signal,
|
|
2283
|
+
});
|
|
2284
|
+
/** click */
|
|
2285
|
+
this.area.addEventListener("click", onClick.bind(this), {
|
|
2286
|
+
signal: this.eventAbortController.signal,
|
|
2287
|
+
});
|
|
2288
|
+
/** right click */
|
|
2289
|
+
this.area.addEventListener("contextmenu", onRightClick.bind(this), {
|
|
1886
2290
|
signal: this.eventAbortController.signal,
|
|
1887
2291
|
});
|
|
1888
2292
|
}
|
|
1889
2293
|
initDnd() {
|
|
1890
2294
|
if (!this.area || !this.nodes || !this.simulation)
|
|
1891
2295
|
throw new Error("bad init data");
|
|
1892
|
-
|
|
2296
|
+
const dragHandler = d3Drag.drag()
|
|
1893
2297
|
.subject((event) => {
|
|
1894
2298
|
if (this.listeners.onDragSubject) {
|
|
1895
2299
|
return this.listeners.onDragSubject(event, this.state);
|
|
@@ -1951,7 +2355,8 @@ class GraphCanvas {
|
|
|
1951
2355
|
event.subject.fy = null;
|
|
1952
2356
|
}
|
|
1953
2357
|
this.listeners.onEndDragFinished?.(event, this.state);
|
|
1954
|
-
})
|
|
2358
|
+
});
|
|
2359
|
+
d3Selection.select(this.area).call(dragHandler);
|
|
1955
2360
|
}
|
|
1956
2361
|
initZoom(currentZoom) {
|
|
1957
2362
|
if (!this.area)
|
|
@@ -1996,8 +2401,10 @@ exports.getGraphControls = getGraphControls;
|
|
|
1996
2401
|
exports.getLinkControls = getLinkControls;
|
|
1997
2402
|
exports.getNodeControls = getNodeControls;
|
|
1998
2403
|
exports.getParticlePosition = getParticlePosition;
|
|
2404
|
+
exports.linkByPointerGetter = linkByPointerGetter;
|
|
1999
2405
|
exports.linkIterationExtractor = linkIterationExtractor;
|
|
2000
2406
|
exports.linkOptionsGetter = linkOptionsGetter;
|
|
2407
|
+
exports.nodeByPointerGetter = nodeByPointerGetter;
|
|
2001
2408
|
exports.nodeIterationExtractor = nodeIterationExtractor;
|
|
2002
2409
|
exports.nodeOptionsGetter = nodeOptionsGetter;
|
|
2003
2410
|
exports.nodeRadiusGetter = nodeRadiusGetter;
|