@@ -6,25 +6,21 @@ import type Highcharts from "highcharts";
66import AsyncStore from "../../internal/utils/async-store" ;
77import { ChartExtraContext } from "./chart-extra-context" ;
88
9- import styles from "../styles.css.js" ;
10-
119// The reactive state is used to propagate updates to the corresponding no-data React component.
1210// It can be used by other components to assert if the chart is in no-data state (by checking if container is present).
1311export interface ReactiveNodataState {
14- container : null | Element ;
12+ visible : boolean ;
13+ style : React . CSSProperties ;
1514 noMatch : boolean ;
1615}
1716
1817// Chart helper that implements custom nodata behaviors.
1918export class ChartExtraNodata extends AsyncStore < ReactiveNodataState > {
2019 private context : ChartExtraContext ;
21- private noDataContainer : HTMLElement ;
2220
2321 constructor ( context : ChartExtraContext ) {
24- super ( { container : null , noMatch : false } ) ;
22+ super ( { visible : false , style : { } , noMatch : false } ) ;
2523 this . context = context ;
26- this . noDataContainer = document . createElement ( "div" ) ;
27- this . noDataContainer . className = styles [ "no-data-container" ] ;
2824 }
2925
3026 public onChartRender = ( ) => {
@@ -35,26 +31,14 @@ export class ChartExtraNodata extends AsyncStore<ReactiveNodataState> {
3531 const visibleSeries = findAllVisibleSeries ( this . chart ) ;
3632 // The no-data is not shown when there is at least one series or point (for pie series) non-empty and visible.
3733 if ( visibleSeries . length > 0 ) {
38- this . removeContainer ( ) ;
39- this . set ( ( ) => ( { container : null , noMatch : false } ) ) ;
34+ this . set ( ( ) => ( { visible : false , style : { } , noMatch : false } ) ) ;
4035 } else {
41- this . appendContainer ( ) ;
42- this . set ( ( ) => ( { container : this . noDataContainer , noMatch : allSeriesWithData . length > 0 } ) ) ;
36+ this . set ( ( ) => ( { visible : true , style : this . getContainerStyle ( ) , noMatch : allSeriesWithData . length > 0 } ) ) ;
4337 }
4438 } ;
4539
46- private appendContainer ( ) {
47- if ( ! this . chart . container . contains ( this . noDataContainer ) ) {
48- this . chart . container . appendChild ( this . noDataContainer ) ;
49- }
50- this . noDataContainer . style . left = `${ this . chart . plotLeft } px` ;
51- this . noDataContainer . style . bottom = `${ this . chart . chartHeight - this . chart . plotHeight } px` ;
52- }
53-
54- private removeContainer ( ) {
55- if ( this . chart . container . contains ( this . noDataContainer ) ) {
56- this . chart . container . removeChild ( this . noDataContainer ) ;
57- }
40+ private getContainerStyle ( ) {
41+ return { left : `${ this . chart . plotLeft } px` , bottom : `${ this . chart . chartHeight - this . chart . plotHeight } px` } ;
5842 }
5943
6044 private get chart ( ) {
0 commit comments