2020 other uses are restricted.
2121*/
2222
23- import { AfterViewInit } from '@angular/core' ;
23+ import { AfterViewInit , ElementRef , ViewChild } from '@angular/core' ;
2424import { AppService , CurrentTab } from '../app.service' ;
2525import {
2626 ASTEROID_BASE , COMET_BASE , EARTH , FIRST_PLANET , HALF_MINUTE , ISkyObserver , LAST_PLANET , NO_MATCH , SkyObserver , SolarSystem ,
2727 StarCatalog , UT_to_TDB
2828} from 'ks-astronomy' ;
2929import { ceil , max , round , sqrt } from 'ks-math' ;
30- import { FontMetrics , getFontMetrics , isSafari } from 'ks-util' ;
30+ import { FontMetrics , getFontMetrics , isSafari , padLeft } from 'ks-util' ;
3131import * as _ from 'lodash' ;
3232import { KsDateTime } from 'ks-date-time-zone' ;
3333import { SafeStyle } from '@angular/platform-browser' ;
3434import { Subscription , BehaviorSubject , Observable } from 'rxjs' ;
3535import { getXYForTouchEvent } from '../util/ks-touch-events' ;
36+ import { KsMarqueeComponent } from '../widgets/ks-marquee/ks-marquee.component' ;
3637
3738export const PROPERTY_ADDITIONALS = 'additionals' ;
3839export enum ADDITIONALS { NONE , ALL_ASTEROIDS , ALL_COMETS , ALL }
@@ -69,6 +70,9 @@ export abstract class GenericView implements AfterViewInit {
6970
7071 protected wrapper : HTMLDivElement ;
7172 protected canvas : HTMLCanvasElement ;
73+ protected marquee : HTMLElement ;
74+ protected lastMarqueeClick = 0 ;
75+ protected marqueeClickCount = 0 ;
7276 protected canvasScaling = 1 ;
7377 protected touchGuard : HTMLDivElement ;
7478 protected lastWidth = - 1 ;
@@ -99,13 +103,19 @@ export abstract class GenericView implements AfterViewInit {
99103 protected planetsToDraw : number [ ] = [ ] ;
100104 protected additional : ADDITIONALS | string = ADDITIONALS . NONE ;
101105
106+ protected showMetrics = false ;
107+ protected lastDrawStart = 0 ;
108+ protected lastFullDrawTime : number ;
109+
102110 protected sanitizedHandCursor : SafeStyle ;
103111 protected sanitizedLabelCrosshair : SafeStyle ;
104112
105113 protected readonly largeLabelFont = '12px Arial, Helvetica, sans-serif' ;
106114 protected readonly mediumLabelFont = '11px Arial, Helvetica, sans-serif' ;
107115 protected readonly smallLabelFont = '10px Arial, Helvetica, sans-serif' ;
108116
117+ @ViewChild ( KsMarqueeComponent , { read : ElementRef } ) protected marqueeRef : ElementRef ;
118+
109119 public marqueeText = '' ;
110120
111121 cursor : SafeStyle ;
@@ -184,6 +194,47 @@ export abstract class GenericView implements AfterViewInit {
184194 GenericView . getPrintingUpdate ( printing => {
185195 this . doResize ( printing ) ;
186196 } ) ;
197+
198+ if ( this . marqueeRef ) {
199+ this . marquee = this . marqueeRef . nativeElement as HTMLElement ;
200+ this . marquee . addEventListener ( 'click' , event => this . marqueeClick ( event ) ) ;
201+ this . marquee . addEventListener ( 'touchstart' , event => this . marqueeTouch ( event ) ) ;
202+ }
203+ }
204+
205+ private marqueeClick ( event : MouseEvent ) : void {
206+ if ( event . detail === 3 )
207+ this . toggleMarqueeMetrics ( ) ;
208+ else if ( event . detail === 0 || event . detail === undefined )
209+ this . countMarqueeClicks ( ) ;
210+ }
211+
212+ private marqueeTouch ( event : TouchEvent ) : void {
213+ if ( event . touches . length > 2 )
214+ this . toggleMarqueeMetrics ( ) ;
215+ else if ( event . touches . length === 1 )
216+ this . countMarqueeClicks ( ) ;
217+ }
218+
219+ private countMarqueeClicks ( ) : void {
220+ const now = performance . now ( ) ;
221+
222+ if ( now > this . lastMarqueeClick + 500 )
223+ this . marqueeClickCount = 1 ;
224+ else if ( ++ this . marqueeClickCount === 3 )
225+ this . toggleMarqueeMetrics ( ) ;
226+
227+ this . lastMarqueeClick = now ;
228+ }
229+
230+ private toggleMarqueeMetrics ( ) : void {
231+ const saveBackground = this . marquee . style . backgroundColor ;
232+
233+ this . showMetrics = ! this . showMetrics ;
234+ this . marqueeText = '' ;
235+ this . clearMouseHighlighting ( ) ;
236+ this . marquee . style . backgroundColor = 'cyan' ;
237+ setTimeout ( ( ) => this . marquee . style . backgroundColor = saveBackground , 500 ) ;
187238 }
188239
189240 onResize ( ) : void {
@@ -410,14 +461,15 @@ export abstract class GenericView implements AfterViewInit {
410461 this . lastDrawingContext = dc ;
411462
412463 const now = performance . now ( ) ;
464+ const drawingTime = now - startTime ;
413465
414466 if ( dc . fullDraw ) {
415- const fullDrawingTime = now - startTime ;
467+ this . lastFullDrawTime = max ( drawingTime , 1 ) ;
416468
417469 if ( forceFullDraw )
418470 this . slowFrameCount = 0 ;
419471
420- if ( fullDrawingTime > SLOW_DRAWING_THRESHOLD ) {
472+ if ( this . lastFullDrawTime > SLOW_DRAWING_THRESHOLD ) {
421473 ++ this . slowFrameCount ;
422474 this . lastSlowFrameTime = now ;
423475 }
@@ -426,6 +478,18 @@ export abstract class GenericView implements AfterViewInit {
426478 this . debouncedFullRedraw ( ) ;
427479 this . lastSlowFrameTime = now ;
428480 }
481+
482+ if ( this . showMetrics ) {
483+ const interval = max ( startTime - this . lastDrawStart , 1 ) ;
484+
485+ this . marqueeText = padLeft ( drawingTime . toFixed ( 1 ) , 6 , '\u2007' ) + ( dc . fullDraw ? 'F' : 'Q' ) + ', ' +
486+ padLeft ( interval . toFixed ( 1 ) , 6 , '\u2007' ) ;
487+
488+ if ( ! dc . fullDraw )
489+ this . marqueeText += ', ' + padLeft ( this . lastFullDrawTime . toFixed ( 1 ) , 6 , '\u2007' ) + 'F' ;
490+ }
491+
492+ this . lastDrawStart = startTime ;
429493 }
430494
431495 protected additionalDrawingSetup ( dc : DrawingContext ) : void {
0 commit comments