@@ -46,12 +46,31 @@ export class LunarHorizonChart extends LitElement {
46
46
this . setupChart ( ) ;
47
47
}
48
48
49
- protected shouldUpdate ( _changedProperties : PropertyValues ) : boolean {
49
+ protected updated ( _changedProperties : PropertyValues ) : void {
50
50
if ( _changedProperties . has ( 'cardWidth' ) ) {
51
- this . _chart ?. resize ( ) ;
51
+ if ( this . _chart ) {
52
+ this . _chart . resize ( this . cardWidth , this . cardHeight ) ;
53
+ }
52
54
}
53
- return true ;
54
55
}
56
+
57
+ // protected shouldUpdate(_changedProperties: PropertyValues): boolean {
58
+ // if (_changedProperties.has('moon')) {
59
+ // if (this._chart) {
60
+ // this._chart.data = this.chartData;
61
+ // this._chart.update('none');
62
+ // }
63
+ // }
64
+ // return true;
65
+ // }
66
+
67
+ get cardHeight ( ) : number {
68
+ let height = this . cardWidth * 0.5 - 96 ;
69
+ height = this . card . config . hide_header ? height + 48 : height ;
70
+
71
+ return height ;
72
+ }
73
+
55
74
static get styles ( ) : CSSResultGroup {
56
75
return [
57
76
styles ,
@@ -198,15 +217,6 @@ export class LunarHorizonChart extends LitElement {
198
217
} ,
199
218
} ,
200
219
201
- onResize : ( ) => {
202
- const width = this . cardWidth ;
203
- const height = this . cardWidth / 2 ;
204
- if ( this . _chart ) {
205
- this . _chart . canvas . width = width ;
206
- this . _chart . canvas . height = height ;
207
- this . _chart . update ( ) ;
208
- }
209
- } ,
210
220
// Hover on point
211
221
onHover : ( _event , elements ) => {
212
222
if ( elements . length > 0 ) {
@@ -236,10 +246,17 @@ export class LunarHorizonChart extends LitElement {
236
246
}
237
247
238
248
protected render ( ) : TemplateResult {
249
+ const dataContainer = this . renderDataContainer ( ) ;
239
250
return html `
240
251
< div class ="moon-horizon ">
241
- < canvas id ="moonPositionChart " width ="${ this . cardWidth } "> </ canvas >
252
+ < canvas id ="moonPositionChart " width ="${ this . cardWidth } " height =" ${ this . cardHeight } " > </ canvas >
242
253
</ div >
254
+ ${ dataContainer }
255
+ ` ;
256
+ }
257
+
258
+ private renderDataContainer ( ) : TemplateResult {
259
+ return html `
243
260
< div class ="moon-data-header ">
244
261
${ this . renderHeaderTime ( ) }
245
262
< ha-icon-button
@@ -397,8 +414,8 @@ export class LunarHorizonChart extends LitElement {
397
414
// Scales
398
415
const scales = { } as ScaleOptions ;
399
416
scales [ 'y' ] = {
400
- suggestedMax : sugestedYMax + 30 ,
401
- suggestedMin : sugestedYMin > - 60 ? - 60 : sugestedYMin ,
417
+ suggestedMin : sugestedYMin ,
418
+ suggestedMax : sugestedYMax ,
402
419
ticks : {
403
420
...ticksOptions ,
404
421
display : graphConfig ?. y_ticks || false ,
@@ -432,18 +449,15 @@ export class LunarHorizonChart extends LitElement {
432
449
const plugins : ChartOptions [ 'plugins' ] = { } ;
433
450
434
451
plugins [ 'legend' ] = {
435
- display : graphConfig ?. show_legend ?? true ,
452
+ display : false ,
436
453
align : graphConfig ?. legend_align || 'center' ,
437
454
position : graphConfig ?. legend_position || 'bottom' ,
438
455
labels : {
439
456
usePointStyle : false ,
440
457
boxWidth : 0 ,
441
458
boxHeight : 0 ,
442
- padding : 10 ,
459
+ padding : 4 ,
443
460
color : secondaryTextColor ,
444
- font : {
445
- size : 14 ,
446
- } ,
447
461
} ,
448
462
} ;
449
463
@@ -703,7 +717,7 @@ export class LunarHorizonChart extends LitElement {
703
717
704
718
const yPosition = y . getPixelForValue ( 0 ) ;
705
719
706
- const lineOffset = isUp ? Math . round ( ( yPosition - top ) / 3 ) : Math . round ( ( bottom - yPosition ) / 2 ) ;
720
+ const lineOffset = isUp ? Math . round ( ( yPosition - top ) / 4 ) : Math . round ( ( bottom - yPosition ) / 2 ) ;
707
721
const maxTextWidth = getMaxValueText ( ctx , isUp ? 'Rise' : 'Set' , formatedTime , direction ) ;
708
722
709
723
let textAlign : CanvasTextAlign = 'start' ;
@@ -754,16 +768,16 @@ export class LunarHorizonChart extends LitElement {
754
768
id : 'expandChartArea' ,
755
769
beforeDraw : ( chart : Chart ) => {
756
770
chart . chartArea . left = 0 ;
757
- chart . chartArea . right = chart . width ;
771
+ chart . chartArea . right = this . cardWidth ;
758
772
chart . chartArea . top = 0 ;
759
- chart . chartArea . bottom = chart . height ;
773
+ chart . chartArea . bottom = this . cardHeight ;
760
774
} ,
761
775
762
776
afterUpdate : ( chart : Chart ) => {
763
777
chart . chartArea . left = 0 ;
764
- chart . chartArea . right = chart . width ;
778
+ chart . chartArea . right = this . cardWidth ;
765
779
chart . chartArea . top = 0 ;
766
- chart . chartArea . bottom = chart . height ;
780
+ chart . chartArea . bottom = this . cardHeight ;
767
781
} ,
768
782
} ;
769
783
} ;
0 commit comments