forked from eclipse-cdt-cloud/timeline-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All PIXI.Applications are initiated on the PIXI shared ticker, allowing them to all be controlled simultaneously. PIXI.Ticker.shared is controlled via TimeGraphRenderController and RenderEvents. RenderEvents fires custom events that are handled by event handlers initiated in the RenderController. RenderController is created in the UnitController; this is only because we need one RenderController and there is already only one UnitController. RenderEvents currently fires start-render events in: - TimeGraphComponent on creation and update. - StateController when scrolling up/down Stop render is debounced at a 1500 timeout after start render. Fixes eclipse-cdt-cloud#7 Signed-off-by: Will Yang <william.yang@ericsson.com>
- Loading branch information
1 parent
e5136fa
commit f5ee5b7
Showing
5 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { throttle, debounce } from 'lodash'; | ||
import * as PIXI from 'pixi.js-legacy'; | ||
|
||
const START_RENDER_STRING = 'startPixiRender'; | ||
const STOP_RENDER_STRING = 'stopPixiRender'; | ||
interface RenderEvents { | ||
startRender: () => void; | ||
stopRender: () => void; | ||
} | ||
|
||
const throttledStart = throttle(() => { | ||
window.dispatchEvent(new Event(START_RENDER_STRING)); | ||
}, 450, { leading: true }); | ||
|
||
export const RenderEvents: RenderEvents = { | ||
/** | ||
* Fires an event that will start the PIXI.Ticker. | ||
* This will start rendering. | ||
* Event handler located in time-graph-render-controller.ts | ||
*/ | ||
startRender: () => { | ||
throttledStart(); | ||
}, | ||
/** | ||
* Fires an event that will stop the PIXI.Ticker. | ||
* This will stop rendering. | ||
* StopRender event handler is debounced @ 1.5s. | ||
* Event handler located in time-graph-render-controller.ts | ||
*/ | ||
stopRender: () => { | ||
window.dispatchEvent(new Event(STOP_RENDER_STRING)); | ||
} | ||
}; | ||
export class TimeGraphRenderController { | ||
constructor() { | ||
this.initializeRenderEvents(); | ||
} | ||
|
||
public initializeRenderEvents() { | ||
|
||
const stopRenderDebounced = debounce(() => { | ||
PIXI.Ticker.shared.stop(); | ||
}, 1500); | ||
|
||
|
||
const startRender = () => { | ||
PIXI.Ticker.shared.start(); | ||
stopRenderDebounced(); | ||
}; | ||
|
||
window.addEventListener(START_RENDER_STRING, startRender); | ||
window.addEventListener(STOP_RENDER_STRING, stopRenderDebounced); | ||
window.addEventListener('beforeunload', () => { | ||
window.removeEventListener(START_RENDER_STRING, startRender); | ||
window.removeEventListener(STOP_RENDER_STRING, stopRenderDebounced); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters