MCPcopy
hub / github.com/klinecharts/KLineChart / ChartImp

Class ChartImp

src/Chart.ts:113–1378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113export default class ChartImp implements Chart {
114 id: string
115
116 private _container: HTMLElement
117 private _chartContainer: HTMLElement
118 private readonly _chartBounding = createDefaultBounding()
119 private readonly _chartEvent: Event
120 private readonly _chartStore: ChartStore
121 private _drawPanes: DrawPane[] = []
122 private readonly _candlePane: CandlePane
123 private readonly _xAxisPane: XAxisPane
124 private readonly _separatorPanes = new Map<DrawPane, SeparatorPane>()
125
126 private _layoutUpdateOptions = {
127 sort: true,
128 measureHeight: true,
129 measureWidth: true,
130 secondMeasureWidth: false,
131 update: true,
132 buildYAxisTick: false,
133 cacheYAxisWidth: false,
134 forceBuildYAxisTick: false
135 }
136
137 private _layoutPending = false
138
139 private _resizeObserver: Nullable<ResizeObserver> = null
140
141 private _resizeRequestAnimationId = DEFAULT_REQUEST_ID
142
143 private readonly _scheduleResize = (): void => {
144 if (this._resizeRequestAnimationId === DEFAULT_REQUEST_ID) {
145 this._resizeRequestAnimationId = requestAnimationFrame(() => {
146 this._resizeRequestAnimationId = DEFAULT_REQUEST_ID
147 if (
148 this._chartBounding.width !== Math.floor(this._chartContainer.clientWidth) ||
149 this._chartBounding.height !== Math.floor(this._chartContainer.clientHeight)
150 ) {
151 this.resize()
152 }
153 })
154 }
155 }
156
157 private readonly _cacheYAxisWidth = { left: 0, right: 0 }
158
159 constructor (container: HTMLElement, options?: Options) {
160 this._initContainer(container)
161 this._chartEvent = new Event(this._chartContainer, this)
162 this._chartStore = new ChartStore(this, options)
163 const defaultPaneOptions = this._getLayoutDefaultPaneOptions(this._chartStore.getLayoutBasicParams())
164 const defaultYAxis = this._getLayoutDefaultYAxis(this._chartStore.getLayoutBasicParams())
165 this._candlePane = this._createPane<CandlePane>(CandlePane, { ...defaultPaneOptions, id: PaneIdConstants.CANDLE })
166 this._candlePane.createYAxis({ ...defaultYAxis, id: DEFAULT_AXIS_ID })
167 this._xAxisPane = this._createPane<XAxisPane>(XAxisPane, { ...defaultPaneOptions, id: PaneIdConstants.X_AXIS, order: Number.MAX_SAFE_INTEGER })
168 this._applyLayout(options?.layout)
169 this._layout()
170 this._initResizeListener()

Callers

nothing calls this directly

Calls 3

resizeMethod · 0.95
createDefaultBoundingFunction · 0.90
requestAnimationFrameFunction · 0.90

Tested by

no test coverage detected