File tree Expand file tree Collapse file tree 3 files changed +32
-41
lines changed
packages/layerchart/src/lib Expand file tree Collapse file tree 3 files changed +32
-41
lines changed Original file line number Diff line number Diff line change 4949 chartDataArray ,
5050 defaultChartPadding ,
5151 getObjectOrNull ,
52- type Accessor ,
5352 } from ' $lib/utils/common.js' ;
5453 import { SeriesState , type StackLayout } from ' $lib/states/series.svelte.js' ;
5554 import type { BrushDomainType } from ' ../../states/brush.svelte.js' ;
110109 console .timeEnd (' AreaChart render' );
111110 });
112111 }
113-
114- function resolveAccessor(acc : Accessor <TData > | undefined ) {
115- if (seriesState .isStacked ) {
116- // For stacked series, collect all y0/y1 values for domain calculation
117- return (d : TData ) => {
118- const values: number [] = [];
119- for (const s of seriesState .visibleSeries ) {
120- const stackValue = seriesState .getStackValue (s .key , d );
121- if (stackValue ) {
122- values .push (stackValue [0 ], stackValue [1 ]);
123- }
124- }
125- return values .length ? values : undefined ;
126- };
127- }
128- if (acc ) return acc ;
129- return seriesState .visibleSeries .map ((s ) => s .value ?? s .key );
130- }
131112 </script >
132113
133114<Chart
134115 bind:context
135116 {data }
136117 {x }
137118 {xDomain }
138- y ={resolveAccessor (y )}
119+ y ={seriesState . getValueDomainAccessor (y )}
139120 yBaseline ={0 }
140121 yNice
141122 {radial }
Original file line number Diff line number Diff line change 8080 accessor ,
8181 chartDataArray ,
8282 defaultChartPadding ,
83- type Accessor ,
8483 } from ' $lib/utils/common.js' ;
8584 import { isScaleTime , type AnyScale } from ' $lib/utils/scales.svelte.js' ;
8685 import { SeriesState , type StackLayout } from ' $lib/states/series.svelte.js' ;
224223 console .timeEnd (' BarChart render' );
225224 });
226225 }
227-
228- function resolveAccessor(acc : Accessor <TData > | undefined ) {
229- if (acc ) return acc ;
230- if (seriesState .isStacked ) {
231- // For stacked series, collect all y0/y1 values for domain calculation
232- return (d : TData ) => {
233- const values: number [] = [];
234- for (const s of seriesState .visibleSeries ) {
235- const stackValue = seriesState .getStackValue (s .key , d );
236- if (stackValue ) {
237- values .push (stackValue [0 ], stackValue [1 ]);
238- }
239- }
240- return values .length ? values : undefined ;
241- };
242- }
243- return seriesState .visibleSeries .map ((s ) => s .value ?? s .key );
244- }
245226 </script >
246227
247228<Chart
248229 bind:context
249230 {data }
250- x ={resolveAccessor (xProp )}
231+ x ={valueAxis === ' x ' ? seriesState . getValueDomainAccessor (xProp ) : xProp }
251232 {xDomain }
252233 {xScale }
253234 {xBaseline }
256237 {x1Domain }
257238 {x1Range }
258239 {xInterval }
259- y ={resolveAccessor (yProp )}
240+ y ={valueAxis === ' y ' ? seriesState . getValueDomainAccessor (yProp ) : yProp }
260241 {yScale }
261242 {yBaseline }
262243 yNice ={valueAxis === ' y' }
Original file line number Diff line number Diff line change @@ -122,6 +122,35 @@ export class SeriesState<TData, TComponent extends Component> {
122122 } ;
123123 }
124124
125+ /**
126+ * Resolve accessor for domain calculation, handling stacked and multi-series cases.
127+ * For stacked series, returns a function that collects all y0/y1 values.
128+ * For multi-series without explicit accessor, returns array of series value accessors.
129+ * @param acc - The explicit accessor provided by the user, if any
130+ * @returns The resolved accessor for domain calculation
131+ */
132+ getValueDomainAccessor < T extends Accessor < TData > > ( acc : T | undefined ) : T | Accessor < TData > {
133+ // If explicit accessor provided, use it
134+ if ( acc ) return acc ;
135+
136+ // For stacked series, collect all y0/y1 values for domain calculation
137+ if ( this . isStacked ) {
138+ return ( ( d : TData ) => {
139+ const values : number [ ] = [ ] ;
140+ for ( const s of this . visibleSeries ) {
141+ const stackValue = this . getStackValue ( s . key , d ) ;
142+ if ( stackValue ) {
143+ values . push ( stackValue [ 0 ] , stackValue [ 1 ] ) ;
144+ }
145+ }
146+ return values . length ? values : undefined ;
147+ } ) as Accessor < TData > ;
148+ }
149+
150+ // Multi-series: use all visible series accessors
151+ return this . visibleSeries . map ( ( s ) => s . value ?? s . key ) as Accessor < TData > ;
152+ }
153+
125154 /**
126155 * Get all series for the chart.
127156 */
You can’t perform that action at this time.
0 commit comments