Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.vitepress/config/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function getInstanceApiMenus (lang = '') {
{ text: 'getSize', link: `${prefix}/getSize` },
{ text: 'setStyles', link: `${prefix}/setStyles` },
{ text: 'getStyles', link: `${prefix}/getStyles` },
{ text: 'setLayoutOptions', link: `${prefix}/setLayoutOptions` },
{ text: 'setFormatter', link: `${prefix}/setFormatter` },
{ text: 'getFormatter', link: `${prefix}/getFormatter` },
{ text: 'setLocale', link: `${prefix}/setLocale` },
Expand Down
28 changes: 28 additions & 0 deletions docs/@views/api/references/instance/setLayoutOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
```typescript
(
layout: {
barSpaceLimit?: {
min?: number
max?: number
}
pane?: {
height?: number
minHeight?: number
dragEnabled?: boolean
order?: number
state?: 'normal' | 'maximize' | 'minimize'
}
yAxis?: {
reverse?: boolean
inside?: boolean
needWidget?: boolean
position?: 'left' | 'right'
scrollZoomEnabled?: boolean
gap?: {
top?: number
bottom?: number
}
}
}
) => void
```
28 changes: 28 additions & 0 deletions docs/en-US/api/instance/setLayoutOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
outline: deep
---

# setLayoutOptions(layout)
`setLayoutOptions` set the chart default layout options. It only affects panes and y-axes created after the call, existing panes and y-axes remain unchanged. Incremental values ​​are supported.

## Reference {#reference}
<!--@include: @/@views/api/references/instance/setLayoutOptions.md-->

### Parameters {#parameters}
- `layout` Layout options.
- `barSpaceLimit` Bar space limit.
- `pane` Pane default options.
- `yAxis` Y-axis default options.

### Returns {#returns}
`setLayoutOptions` returns `undefined` .

## Usage {#usage}
```javascript
chart.setLayoutOptions({
yAxis: {
inside: true,
position: 'left'
}
})
```
11 changes: 10 additions & 1 deletion src/Chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type Crosshair from './common/Crosshair'
import type { KLineData } from './common/Data'
import type { DataLoader } from './common/DataLoader'
import type DeepPartial from './common/DeepPartial'
import type DeepRequired from './common/DeepRequired'
import type ExcludePickPartial from './common/ExcludePickPartial'
import type Nullable from './common/Nullable'
import type { Period } from './common/Period'
Expand All @@ -45,7 +46,7 @@ import type { XAxisOverride } from './component/XAxis'
import { Y_AXIS_ID_PREFIX, type YAxis, type YAxisOverride } from './component/YAxis'
import Event from './Event'
import { getIndicatorClass } from './extension/indicator/index'
import type { DecimalFold, Formatter, Hotkey, Options, ThousandsSeparator, ZoomAnchor, ZoomAnchorType } from './Options'
import type { DecimalFold, Formatter, Hotkey, Layout, Options, ThousandsSeparator, ZoomAnchor, ZoomAnchorType } from './Options'
import CandlePane from './pane/CandlePane'
import type DrawPane from './pane/DrawPane'
import IndicatorPane from './pane/IndicatorPane'
Expand Down Expand Up @@ -627,6 +628,14 @@ export default class ChartImp implements Chart {
return this._chartStore.getStyles()
}

setLayoutOptions(layout: DeepPartial<Layout>): void {
this._chartStore.setLayoutOptions(layout)
}

getLayoutOptions(): DeepRequired<Layout> {
return this._chartStore.getLayoutOptions()
}

setFormatter(formatter: Partial<Formatter>): void {
this._setOptions(() => {
this._chartStore.setFormatter(formatter)
Expand Down
6 changes: 6 additions & 0 deletions src/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export const DEFAULT_MIN_TIME_SPAN = 15 * 60 * 1000
export interface Store {
setStyles: (value: string | DeepPartial<Styles>) => void
getStyles: () => Styles
setLayoutOptions: (layout: DeepPartial<Layout>) => void
getLayoutOptions: () => DeepRequired<Layout>
setFormatter: (formatter: Partial<Formatter>) => void
getFormatter: () => Formatter
setLocale: (locale: string) => void
Expand Down Expand Up @@ -464,6 +466,10 @@ export default class StoreImp implements Store {
return this._styles
}

setLayoutOptions(layout: DeepPartial<Layout>): void {
merge(this._layoutOptions, layout)
}

setFormatter(formatter: Partial<Formatter>): void {
merge(this._formatter, formatter)
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { getOverlayClass, getSupportedOverlays, registerOverlay } from './extens
import { registerStyles } from './extension/styles/index'
import { registerXAxis } from './extension/x-axis'
import { registerYAxis } from './extension/y-axis'
import type { FormatDateType, Options, ZoomAnchor } from './Options'
import type { FormatDateType, Layout, Options, ZoomAnchor } from './Options'

const charts = new Map<string, ChartImp>()
let chartBaseId = 1
Expand Down Expand Up @@ -163,6 +163,7 @@ export {
getSupportedOverlays,
type IndicatorSeries,
init,
type Layout,
type LineType,
type OverlayDrawingMode,
type OverlayMode,
Expand Down