@@ -8,26 +8,9 @@ export interface EditableChartStoreProps {
88 config : Record < string , unknown > ;
99 data : Array < Record < string , unknown > > ;
1010}
11-
12- /**
13- * EditableChartStore holds the current layout, configuration, and data for a chart.
14- * These fields are made observable by MobX so any component relying on them
15- * will automatically react to changes.
16- */
1711export class EditableChartStore implements SetupComponent {
18- /**
19- * Current layout configuration.
20- */
2112 layout : Record < string , unknown > = { } ;
22-
23- /**
24- * Current configuration object.
25- */
2613 config : Record < string , unknown > = { } ;
27-
28- /**
29- * Array of data items.
30- */
3114 data : Array < Record < string , unknown > > = [ ] ;
3215
3316 constructor (
@@ -60,69 +43,37 @@ export class EditableChartStore implements SetupComponent {
6043 return disposeAll ;
6144 }
6245
63- /**
64- * JSON string representation of the current layout.
65- * @returns Stringified layout object.
66- */
6746 get layoutJson ( ) : JSONString {
6847 return JSON . stringify ( this . layout ) ;
6948 }
7049
71- /**
72- * Replace the layout with a shallow copy of the provided object.
73- * Null/undefined values are ignored to prevent accidental clearing.
74- * @param layout - New layout object (will be shallow-copied)
75- */
7650 setLayout ( layout : Record < string , unknown > ) : void {
7751 if ( layout != null ) {
7852 this . layout = { ...layout } ;
7953 }
8054 }
8155
82- /**
83- * JSON string representation of the current configuration.
84- * @returns Stringified configuration object.
85- */
8656 get configJson ( ) : JSONString {
8757 return JSON . stringify ( this . config ) ;
8858 }
8959
90- /**
91- * Replace the configuration with a shallow copy of the provided object.
92- * @param config - New config object (will be shallow-copy)
93- */
9460 setConfig ( config : Record < string , unknown > ) : void {
9561 if ( config != null ) {
9662 this . config = { ...config } ;
9763 }
9864 }
9965
100- /**
101- * JSON string representation of the current data array.
102- * @returns Stringified data array.
103- */
10466 get dataJson ( ) : JSONString [ ] {
10567 return this . data . map ( item => JSON . stringify ( item ) ) ;
10668 }
10769
108- /**
109- * Replace the entire data array with a validated copy.
110- * Throws if the input is not an array.
111- * @param data - New data array to set
112- */
11370 private setData ( data : Array < Record < string , unknown > > ) : void {
11471 if ( ! Array . isArray ( data ) ) {
11572 throw new Error ( `setData expects an array, got ${ typeof data } ` ) ;
11673 }
11774 this . data = [ ...data ] ;
11875 }
11976
120- /**
121- * Parse a JSON string and replace the data item at the given index.
122- * Performs error handling for invalid JSON or malformed objects.
123- * @param index - Position in the data array to replace
124- * @param jsonString - JSON string representing the new item
125- */
12677 setDataAt ( index : number , jsonString : string ) : void {
12778 if ( index < 0 || index >= this . data . length ) {
12879 return ;
@@ -140,13 +91,6 @@ export class EditableChartStore implements SetupComponent {
14091 }
14192 }
14293
143- /**
144- * Reset the entire store with new layout, configuration, and data objects.
145- * Each argument is shallow-copied into the corresponding field.
146- * @param layout - New layout object
147- * @param config - New config object
148- * @param data - New data array
149- */
15094 reset (
15195 layout : Record < string , unknown > ,
15296 config : Record < string , unknown > ,
0 commit comments