Skip to content

feat: add setLayoutOptions to change layout defaults after init - #852

Open
NemeZZiZZ wants to merge 1 commit into
klinecharts:mainfrom
NemeZZiZZ:feature/set-layout-options
Open

NemeZZiZZ wants to merge 1 commit into
klinecharts:mainfrom
NemeZZiZZ:feature/set-layout-options

Conversation

@NemeZZiZZ

Copy link
Copy Markdown
Contributor

What

Add chart.setLayoutOptions(layout) to change layout defaults after init().

Why

Axes of panes created after init() are built from layout options merged in the Store constructor, and there is no public way to change them afterwards: overrideYAxis writes only to the addressed axis instances and never back to the layout defaults. An app that lets users switch y-axis placement at runtime (e.g. inside: true) ends up with new panes whose axes silently revert to the init-time defaults, while the shared gutter width is held by the single axis that stayed outside.

How

setLayoutOptions(layout: DeepPartial<Layout>) merges into the same _layoutOptions the constructor populates, so panes and axes created afterwards pick the new defaults up automatically — both call sites (_createOrUseIndicatorYAxis, createYAxis) read getLayoutOptions() at creation time, and explicit arguments still win over defaults.

Semantics: affects only panes/axes created after the call; existing axes and panes are untouched (overrideYAxis / setPaneOptions remain the tools for those). No behavior change unless the new method is called.

Also declares the existing getLayoutOptions() in the Store interface (implementation already existed) and exports the Layout type.

Verification

Browser acceptance test on the built dev bundle:

  • control chart without the call: new indicator pane axis gets init defaults (inside: false, position: 'right') — unchanged behavior
  • after setLayoutOptions({ yAxis: { inside: true, position: 'right' } }): new MACD pane axis is created with inside: true, position: 'right'
  • existing candle pane axis stays inside: false before and after the call
  • explicit argument still wins: createYAxis({ position: 'left' }) after setLayoutOptions({ yAxis: { position: 'right' } }) yields position: 'left'

type-check and code-lint clean. Docs page + reference + menu entry included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant