@@ -152,6 +152,17 @@ export class RadialUrchin {
152152 this . update ( this . props ) ;
153153 }
154154
155+ hasValidCenter ( ) {
156+ const center = this . center ;
157+ return (
158+ ! ! center &&
159+ typeof center . x === 'number' &&
160+ Number . isFinite ( center . x ) &&
161+ typeof center . y === 'number' &&
162+ Number . isFinite ( center . y )
163+ ) ;
164+ }
165+
155166 setupDom ( ) {
156167 this . root . classList . add ( 'radial-urchin-root' ) ;
157168 this . root . setAttribute ( 'tabindex' , '0' ) ;
@@ -663,13 +674,7 @@ export class RadialUrchin {
663674 return ;
664675 }
665676
666- if (
667- ! this . center ||
668- typeof this . center . x !== 'number' ||
669- Number . isNaN ( this . center . x ) ||
670- typeof this . center . y !== 'number' ||
671- Number . isNaN ( this . center . y )
672- ) {
677+ if ( ! this . hasValidCenter ( ) ) {
673678 if ( ! this . didWarnInvalidCenter ) {
674679 console . warn ( '[RadialUrchin] invalid center point, skipping render' , this . center ) ;
675680 this . didWarnInvalidCenter = true ;
@@ -696,7 +701,9 @@ export class RadialUrchin {
696701 const dpr = window . devicePixelRatio || 1 ;
697702 ctx . save ( ) ;
698703 ctx . scale ( dpr , dpr ) ;
699- ctx . translate ( this . center . x , this . center . y ) ;
704+ const center = this . center ;
705+
706+ ctx . translate ( center . x , center . y ) ;
700707 ctx . lineWidth = 1 ;
701708 ctx . lineCap = 'butt' ;
702709 ctx . lineJoin = 'round' ;
@@ -768,9 +775,13 @@ export class RadialUrchin {
768775 }
769776
770777 processHoverAtPoint ( point ) {
771- if ( ! this . center ) {
778+ if ( ! this . hasValidCenter ( ) ) {
779+ this . state . hoverArc = null ;
780+ this . hoverPath . setAttribute ( 'd' , '' ) ;
781+ this . hideTooltip ( ) ;
772782 return ;
773783 }
784+ const center = this . center ;
774785 const layout = {
775786 arcs : this . displayArcs . map ( ( arc ) => ( {
776787 ...arc ,
@@ -787,8 +798,8 @@ export class RadialUrchin {
787798 }
788799 this . state . hoverArc = hovered ;
789800 const path = describeSegmentPath (
790- this . center . x ,
791- this . center . y ,
801+ center . x ,
802+ center . y ,
792803 hovered . innerRadius ,
793804 hovered . outerRadius ,
794805 hovered . startAngle ,
@@ -886,10 +897,15 @@ export class RadialUrchin {
886897 const html = buildTooltipContent ( arc ) ;
887898 this . tooltipMeta . innerHTML = html ;
888899 this . tooltip . hidden = false ;
900+ if ( ! this . hasValidCenter ( ) ) {
901+ this . hideTooltip ( ) ;
902+ return ;
903+ }
904+ const center = this . center ;
889905 const angle = arc . centerAngle ;
890906 const radius = ( arc . innerRadius + arc . outerRadius ) / 2 ;
891- const x = this . center . x + Math . cos ( angle ) * radius ;
892- const y = this . center . y + Math . sin ( angle ) * radius ;
907+ const x = center . x + Math . cos ( angle ) * radius ;
908+ const y = center . y + Math . sin ( angle ) * radius ;
893909 this . tooltip . style . left = `${ x + 12 } px` ;
894910 this . tooltip . style . top = `${ y + 12 } px` ;
895911 }
@@ -900,13 +916,14 @@ export class RadialUrchin {
900916
901917 updateSelectionOverlay ( ) {
902918 const arc = this . state . selectedArc ;
903- if ( ! arc ) {
919+ if ( ! arc || ! this . hasValidCenter ( ) ) {
904920 this . selectionPath . setAttribute ( 'd' , '' ) ;
905921 return ;
906922 }
923+ const center = this . center ;
907924 const path = describeSegmentPath (
908- this . center . x ,
909- this . center . y ,
925+ center . x ,
926+ center . y ,
910927 arc . innerRadius ,
911928 arc . outerRadius ,
912929 arc . startAngle ,
@@ -916,13 +933,21 @@ export class RadialUrchin {
916933 }
917934
918935 updateScrubOverlay ( ) {
936+ if ( ! this . hasValidCenter ( ) ) {
937+ this . scrubLine . setAttribute ( 'x1' , '0' ) ;
938+ this . scrubLine . setAttribute ( 'y1' , '0' ) ;
939+ this . scrubLine . setAttribute ( 'x2' , '0' ) ;
940+ this . scrubLine . setAttribute ( 'y2' , '0' ) ;
941+ return ;
942+ }
943+ const center = this . center ;
919944 const minutes = this . state . scrubMinutes ;
920945 const angle = this . mapMinutesToAngle ( minutes - this . getZoom ( ) . start ) ;
921946 const radius = this . displayMaxRadius ?? ( this . layout ?. maxRadius ?? 160 ) ;
922- const x2 = this . center . x + Math . cos ( angle ) * radius ;
923- const y2 = this . center . y + Math . sin ( angle ) * radius ;
924- this . scrubLine . setAttribute ( 'x1' , String ( this . center . x ) ) ;
925- this . scrubLine . setAttribute ( 'y1' , String ( this . center . y ) ) ;
947+ const x2 = center . x + Math . cos ( angle ) * radius ;
948+ const y2 = center . y + Math . sin ( angle ) * radius ;
949+ this . scrubLine . setAttribute ( 'x1' , String ( center . x ) ) ;
950+ this . scrubLine . setAttribute ( 'y1' , String ( center . y ) ) ;
926951 this . scrubLine . setAttribute ( 'x2' , String ( x2 ) ) ;
927952 this . scrubLine . setAttribute ( 'y2' , String ( y2 ) ) ;
928953 }
0 commit comments