@@ -9,7 +9,7 @@ import { GraphLayer } from "./components/canvas/layers/graphLayer/GraphLayer";
99import { SelectionLayer } from "./components/canvas/layers/selectionLayer/SelectionLayer" ;
1010import { TGraphColors , TGraphConstants , initGraphColors , initGraphConstants } from "./graphConfig" ;
1111import { GraphEventParams , GraphEventsDefinitions } from "./graphEvents" ;
12- import { ESchedulerPriority , scheduler } from "./lib/Scheduler" ;
12+ import { scheduler } from "./lib/Scheduler" ;
1313import { HitTest } from "./services/HitTest" ;
1414import { Layer } from "./services/Layer" ;
1515import { Layers } from "./services/LayersService" ;
@@ -22,7 +22,6 @@ import { getXY } from "./utils/functions";
2222import { clearTextCache } from "./utils/renderers/text" ;
2323import { RecursivePartial } from "./utils/types/helpers" ;
2424import { IPoint , IRect , Point , TPoint , TRect , isTRect } from "./utils/types/shapes" ;
25- import { schedule } from "./utils/utils/schedule" ;
2625
2726export type LayerConfig < T extends Constructor < Layer > = Constructor < Layer > > = [
2827 T ,
@@ -102,6 +101,10 @@ export class Graph {
102101 this . graphLayer = this . addLayer ( GraphLayer , { } ) ;
103102 this . selectionLayer = this . addLayer ( SelectionLayer , { } ) ;
104103
104+ this . selectionLayer . hide ( ) ;
105+ this . graphLayer . hide ( ) ;
106+ this . belowLayer . hide ( ) ;
107+
105108 if ( rootEl ) {
106109 this . attach ( rootEl ) ;
107110 }
@@ -119,19 +122,6 @@ export class Graph {
119122 this . setupGraph ( config ) ;
120123 }
121124
122- public scheduleTask ( cb : ( ) => void ) {
123- schedule (
124- ( ) => {
125- cb ( ) ;
126- } ,
127- {
128- priority : ESchedulerPriority . LOWEST ,
129- frameInterval : 10 ,
130- once : true ,
131- }
132- ) ;
133- }
134-
135125 public getGraphLayer ( ) {
136126 return this . graphLayer ;
137127 }
@@ -173,7 +163,7 @@ export class Graph {
173163 }
174164
175165 public getElementsOverPoint < T extends Constructor < GraphComponent > > ( point : IPoint , filter ?: T [ ] ) : InstanceType < T > [ ] {
176- const items = this . hitTest . testPoint ( point , this . graphConstants . system . PIXEL_RATIO ) ;
166+ const items = this . hitTest . testPoint ( point , this . layers . getDPR ( ) ) ;
177167 if ( filter && items . length > 0 ) {
178168 return items . filter ( ( item ) => filter . some ( ( Component ) => item instanceof Component ) ) as InstanceType < T > [ ] ;
179169 }
@@ -362,6 +352,31 @@ export class Graph {
362352 this . layers . start ( ) ;
363353 this . scheduler . start ( ) ;
364354 this . setGraphState ( GraphState . READY ) ;
355+ this . runAfterGraphReady ( ( ) => {
356+ this . selectionLayer . show ( ) ;
357+ this . graphLayer . show ( ) ;
358+ this . belowLayer . show ( ) ;
359+ } ) ;
360+ }
361+
362+ /**
363+ * Graph is ready when the hitboxes are stable.
364+ * In order to initialize hitboxes we need to start scheduler and wait untils every component registered in hitTest service
365+ * Immediatelly after registering startign a rendering process.
366+ * @param cb - Callback to run after graph is ready
367+ */
368+ public runAfterGraphReady ( cb : ( ) => void ) {
369+ if ( this . hitTest . isUnstable ) {
370+ this . hitTest . on ( "update" , ( ) => {
371+ if ( this . hitTest . isUnstable ) {
372+ this . runAfterGraphReady ( cb ) ;
373+ return ;
374+ }
375+ cb ( ) ;
376+ } ) ;
377+ } else {
378+ cb ( ) ;
379+ }
365380 }
366381
367382 public stop ( full = false ) {
0 commit comments