mirror of
https://github.com/klinecharts/KLineChart.git
synced 2024-11-25 16:22:43 +08:00
impr: opt axis type
This commit is contained in:
parent
4dc9d7e72e
commit
3752c89124
14
src/Chart.ts
14
src/Chart.ts
@ -48,7 +48,8 @@ import SeparatorPane from './pane/SeparatorPane'
|
||||
|
||||
import { type PaneOptions, PanePosition, PANE_DEFAULT_HEIGHT, PaneIdConstants } from './pane/types'
|
||||
|
||||
import type Axis from './component/Axis'
|
||||
import type AxisImp from './component/Axis'
|
||||
import { type Axis } from './component/Axis'
|
||||
|
||||
import { type Indicator, type IndicatorCreate } from './component/Indicator'
|
||||
import { type Overlay, type OverlayCreate, type OverlayRemove } from './component/Overlay'
|
||||
@ -458,7 +459,7 @@ export default class ChartImp implements Chart {
|
||||
const forceAdjustYAxis = shouldForceAdjustYAxis ?? false
|
||||
if (adjustYAxis || forceAdjustYAxis) {
|
||||
this._drawPanes.forEach(pane => {
|
||||
const adjust = pane.getAxisComponent().buildTicks(forceAdjustYAxis)
|
||||
const adjust = (pane.getAxisComponent() as AxisImp).buildTicks(forceAdjustYAxis)
|
||||
if (!forceMeasureWidth) {
|
||||
forceMeasureWidth = adjust
|
||||
}
|
||||
@ -468,7 +469,7 @@ export default class ChartImp implements Chart {
|
||||
this._measurePaneWidth()
|
||||
}
|
||||
if (shouldUpdate ?? false) {
|
||||
this._xAxisPane.getAxisComponent().buildTicks(true)
|
||||
(this._xAxisPane.getAxisComponent() as unknown as AxisImp).buildTicks(true)
|
||||
this.updatePane(UpdateLevel.All)
|
||||
}
|
||||
}
|
||||
@ -572,7 +573,7 @@ export default class ChartImp implements Chart {
|
||||
realStyles = styles
|
||||
}
|
||||
if (isValid(realStyles?.yAxis?.type)) {
|
||||
this._candlePane?.getAxisComponent().setAutoCalcTickFlag(true)
|
||||
(this._candlePane?.getAxisComponent() as unknown as AxisImp).setAutoCalcTickFlag(true)
|
||||
}
|
||||
this.adjustPaneViewport(true, true, true, true, true)
|
||||
}
|
||||
@ -605,7 +606,8 @@ export default class ChartImp implements Chart {
|
||||
|
||||
setTimezone (timezone: string): void {
|
||||
this._chartStore.setOptions({ timezone })
|
||||
this._xAxisPane.getAxisComponent().buildTicks(true)
|
||||
const axis = (this._xAxisPane.getAxisComponent() as unknown as AxisImp)
|
||||
axis.buildTicks(true)
|
||||
this._xAxisPane.update(UpdateLevel.Drawer)
|
||||
}
|
||||
|
||||
@ -724,7 +726,7 @@ export default class ChartImp implements Chart {
|
||||
if (currentPane !== null) {
|
||||
const result = this._chartStore.getIndicatorStore().addInstance(indicator, paneId ?? '', isStack ?? false)
|
||||
if (result) {
|
||||
this._setPaneOptions(paneOptions ?? {}, currentPane.getAxisComponent().buildTicks(true) ?? false)
|
||||
this._setPaneOptions(paneOptions ?? {}, (currentPane.getAxisComponent() as AxisImp).buildTicks(true) ?? false)
|
||||
}
|
||||
} else {
|
||||
paneId ??= createId(PaneIdConstants.INDICATOR)
|
||||
|
@ -31,6 +31,8 @@ export interface AxisRange extends VisibleRange {
|
||||
|
||||
export interface Axis {
|
||||
getTicks: () => AxisTick[]
|
||||
getRange: () => AxisRange
|
||||
getAutoSize: () => number
|
||||
convertToPixel: (value: number) => number
|
||||
convertFromPixel: (px: number) => number
|
||||
}
|
||||
@ -56,7 +58,7 @@ export interface AxisTemplate {
|
||||
}
|
||||
|
||||
export default abstract class AxisImp implements AxisTemplate, Axis {
|
||||
private readonly _parent: DrawPane<AxisImp>
|
||||
private readonly _parent: DrawPane<Axis>
|
||||
|
||||
private _range: AxisRange = { from: 0, to: 0, range: 0, realFrom: 0, realTo: 0, realRange: 0 }
|
||||
private _prevRange: AxisRange = { from: 0, to: 0, range: 0, realFrom: 0, realTo: 0, realRange: 0 }
|
||||
@ -64,13 +66,13 @@ export default abstract class AxisImp implements AxisTemplate, Axis {
|
||||
|
||||
private _autoCalcTickFlag = true
|
||||
|
||||
constructor (parent: DrawPane<AxisImp>) {
|
||||
constructor (parent: DrawPane<Axis>) {
|
||||
this._parent = parent
|
||||
}
|
||||
|
||||
name: string
|
||||
|
||||
getParent (): DrawPane<AxisImp> { return this._parent }
|
||||
getParent (): DrawPane<Axis> { return this._parent }
|
||||
|
||||
buildTicks (force: boolean): boolean {
|
||||
if (this._autoCalcTickFlag) {
|
||||
|
@ -25,7 +25,7 @@ export interface XAxis extends Axis {
|
||||
convertTimestampToPixel: (timestamp: number) => number
|
||||
}
|
||||
|
||||
export type XAxisConstructor = new (parent: DrawPane<AxisImp>) => XAxisImp
|
||||
export type XAxisConstructor = new (parent: DrawPane<Axis>) => XAxis
|
||||
|
||||
export default abstract class XAxisImp extends AxisImp implements XAxis {
|
||||
protected override createDefaultRange (): AxisRange {
|
||||
|
@ -35,10 +35,11 @@ interface FiguresResult {
|
||||
export interface YAxis extends Axis {
|
||||
isFromZero: () => boolean
|
||||
isInCandle: () => boolean
|
||||
getType: () => YAxisType
|
||||
convertToNicePixel: (value: number) => number
|
||||
}
|
||||
|
||||
export type YAxisConstructor = new (parent: DrawPane<AxisImp>) => YAxisImp
|
||||
export type YAxisConstructor = new (parent: DrawPane<Axis>) => YAxis
|
||||
|
||||
export default abstract class YAxisImp extends AxisImp implements YAxis {
|
||||
protected override createDefaultRange (): AxisRange {
|
||||
|
@ -17,7 +17,7 @@ import CandleWidget from '../widget/CandleWidget'
|
||||
|
||||
import type DrawPane from './DrawPane'
|
||||
import IndicatorPane from './IndicatorPane'
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
export default class CandlePane extends IndicatorPane {
|
||||
override createMainWidget (container: HTMLElement): DrawWidget<DrawPane<YAxis>> {
|
||||
|
@ -19,7 +19,7 @@ import type Bounding from '../common/Bounding'
|
||||
|
||||
import { isString, isValid, merge } from '../common/utils/typeChecks'
|
||||
|
||||
import type Axis from '../component/Axis'
|
||||
import { type Axis } from '../component/Axis'
|
||||
|
||||
import type DrawWidget from '../widget/DrawWidget'
|
||||
import type YAxisWidget from '../widget/YAxisWidget'
|
||||
|
@ -18,7 +18,7 @@ import type DrawWidget from '../widget/DrawWidget'
|
||||
import IndicatorWidget from '../widget/IndicatorWidget'
|
||||
import YAxisWidget from '../widget/YAxisWidget'
|
||||
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
import { getYAxisClass } from '../extension/y-axis'
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
import type DrawWidget from '../widget/DrawWidget'
|
||||
import XAxisWidget from '../widget/XAxisWidget'
|
||||
|
||||
import type XAxis from '../component/XAxis'
|
||||
import { type XAxis } from '../component/XAxis'
|
||||
|
||||
import DrawPane from './DrawPane'
|
||||
|
||||
|
@ -18,8 +18,7 @@ import { type AxisStyle, type Styles } from '../common/Styles'
|
||||
import { type LineAttrs } from '../extension/figure/line'
|
||||
import { type TextAttrs } from '../extension/figure/text'
|
||||
|
||||
import { type AxisTick } from '../component/Axis'
|
||||
import type Axis from '../component/Axis'
|
||||
import { type AxisTick, type Axis } from '../component/Axis'
|
||||
|
||||
import View from './View'
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
import View from './View'
|
||||
import { type VisibleData } from '../common/Data'
|
||||
import type BarSpace from '../common/BarSpace'
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
export type EachChildCallback = (
|
||||
data: VisibleData,
|
||||
|
@ -19,8 +19,8 @@ import { isString } from '../common/utils/typeChecks'
|
||||
import { formatPrecision, formatThousands, formatFoldDecimal } from '../common/utils/format'
|
||||
import { createFont } from '../common/utils/canvas'
|
||||
|
||||
import type Axis from '../component/Axis'
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type Axis } from '../component/Axis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
import { type TextAttrs } from '../extension/figure/text'
|
||||
|
||||
|
@ -19,8 +19,8 @@ import { isValid } from '../common/utils/typeChecks'
|
||||
|
||||
import { FormatDateType } from '../Options'
|
||||
|
||||
import type Axis from '../component/Axis'
|
||||
import type XAxis from '../component/XAxis'
|
||||
import { type Axis } from '../component/Axis'
|
||||
import { type XAxis } from '../component/XAxis'
|
||||
|
||||
import type ChartStore from '../store/ChartStore'
|
||||
|
||||
|
@ -19,7 +19,7 @@ import { eachFigures, type IndicatorFigure, type IndicatorFigureStyle } from '..
|
||||
|
||||
import View from './View'
|
||||
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
export default class IndicatorLastValueView extends View<YAxis> {
|
||||
override drawImp (ctx: CanvasRenderingContext2D): void {
|
||||
|
@ -24,7 +24,7 @@ import type Coordinate from '../common/Coordinate'
|
||||
|
||||
import { type CustomApi } from '../Options'
|
||||
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
import { type Indicator, type IndicatorFigure, type IndicatorFigureStyle, type IndicatorTooltipData } from '../component/Indicator'
|
||||
import type IndicatorImp from '../component/Indicator'
|
||||
|
@ -23,14 +23,13 @@ import type Coordinate from '../common/Coordinate'
|
||||
import type ChartStore from '../store/ChartStore'
|
||||
|
||||
import { eachFigures, type IndicatorFigure, type IndicatorFigureAttrs, type IndicatorFigureStyle } from '../component/Indicator'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
import CandleBarView, { type CandleBarOptions } from './CandleBarView'
|
||||
|
||||
export default class IndicatorView extends CandleBarView {
|
||||
override getCandleBarOptions (chartStore: ChartStore): Nullable<CandleBarOptions> {
|
||||
const pane = this.getWidget().getPane()
|
||||
const yAxis = pane.getAxisComponent() as YAxis
|
||||
const yAxis = pane.getAxisComponent()
|
||||
if (!yAxis.isInCandle()) {
|
||||
const indicators = chartStore.getIndicatorStore().getInstances(pane.getId())
|
||||
for (const indicator of indicators) {
|
||||
|
@ -23,9 +23,9 @@ import { isBoolean, isNumber, isValid } from '../common/utils/typeChecks'
|
||||
|
||||
import { type CustomApi } from '../Options'
|
||||
|
||||
import type Axis from '../component/Axis'
|
||||
import type XAxis from '../component/XAxis'
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type Axis } from '../component/Axis'
|
||||
import { type XAxis } from '../component/XAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
import { type OverlayPrecision, type OverlayFigure, type OverlayFigureIgnoreEventType, type Overlay } from '../component/Overlay'
|
||||
import type OverlayImp from '../component/Overlay'
|
||||
import { OVERLAY_FIGURE_KEY_PREFIX, OverlayMode, getAllOverlayFigureIgnoreEventTypes } from '../component/Overlay'
|
||||
|
@ -22,8 +22,8 @@ import { isNumber } from '../common/utils/typeChecks'
|
||||
|
||||
import { type CustomApi, FormatDateType } from '../Options'
|
||||
|
||||
import type XAxis from '../component/XAxis'
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type XAxis } from '../component/XAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
import { type OverlayPrecision, type OverlayFigure, type Overlay } from '../component/Overlay'
|
||||
import type OverlayImp from '../component/Overlay'
|
||||
|
||||
|
@ -21,9 +21,9 @@ import { type CustomApi } from '../Options'
|
||||
import { formatPrecision, formatThousands, formatFoldDecimal } from '../common/utils/format'
|
||||
import { isNumber } from '../common/utils/typeChecks'
|
||||
|
||||
import type Axis from '../component/Axis'
|
||||
import type XAxis from '../component/XAxis'
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type Axis } from '../component/Axis'
|
||||
import { type XAxis } from '../component/XAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
import { type OverlayPrecision, type OverlayFigure, type Overlay } from '../component/Overlay'
|
||||
import type OverlayImp from '../component/Overlay'
|
||||
|
||||
|
@ -18,7 +18,7 @@ import Eventful from '../common/Eventful'
|
||||
import { isValid } from '../common/utils/typeChecks'
|
||||
|
||||
import type Figure from '../component/Figure'
|
||||
import type Axis from '../component/Axis'
|
||||
import { type Axis } from '../component/Axis'
|
||||
import { type FigureCreate } from '../component/Figure'
|
||||
|
||||
import { getInnerFigureClass } from '../extension/figure/index'
|
||||
|
@ -19,7 +19,7 @@ import { type LineAttrs } from '../extension/figure/line'
|
||||
import { type TextAttrs } from '../extension/figure/text'
|
||||
|
||||
import { type AxisTick } from '../component/Axis'
|
||||
import type XAxis from '../component/XAxis'
|
||||
import { type XAxis } from '../component/XAxis'
|
||||
|
||||
import AxisView from './AxisView'
|
||||
|
||||
|
@ -19,7 +19,7 @@ import { type LineAttrs } from '../extension/figure/line'
|
||||
import { type TextAttrs } from '../extension/figure/text'
|
||||
|
||||
import { type AxisTick } from '../component/Axis'
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
import AxisView from './AxisView'
|
||||
|
||||
|
@ -26,7 +26,7 @@ import { CandleType } from '../common/Styles'
|
||||
|
||||
import type AxisPane from '../pane/DrawPane'
|
||||
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
export default class CandleWidget extends IndicatorWidget {
|
||||
private readonly _candleBarView = new CandleBarView(this)
|
||||
|
@ -17,7 +17,7 @@ import type DrawPane from '../pane/DrawPane'
|
||||
import { WidgetNameConstants } from './types'
|
||||
import DrawWidget from './DrawWidget'
|
||||
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
import GridView from '../view/GridView'
|
||||
import IndicatorView from '../view/IndicatorView'
|
||||
|
@ -17,7 +17,7 @@ import DrawWidget from './DrawWidget'
|
||||
|
||||
import type DrawPane from '../pane/DrawPane'
|
||||
|
||||
import type XAxis from '../component/XAxis'
|
||||
import { type XAxis } from '../component/XAxis'
|
||||
|
||||
import XAxisView from '../view/XAxisView'
|
||||
import OverlayXAxisView from '../view/OverlayXAxisView'
|
||||
|
@ -17,7 +17,7 @@ import type DrawPane from '../pane/DrawPane'
|
||||
import { WidgetNameConstants } from './types'
|
||||
import DrawWidget from './DrawWidget'
|
||||
|
||||
import type YAxis from '../component/YAxis'
|
||||
import { type YAxis } from '../component/YAxis'
|
||||
|
||||
import YAxisView from '../view/YAxisView'
|
||||
import CandleLastPriceLabelView from '../view/CandleLastPriceLabelView'
|
||||
|
Loading…
Reference in New Issue
Block a user