fix: fix indicator regenerateFigures error

This commit is contained in:
liihuu 2024-09-10 01:28:17 +08:00
parent 6558650d58
commit bf54561d4f
6 changed files with 33 additions and 24 deletions

View File

@ -86,6 +86,6 @@
"rollup-plugin-progress": "^1.1.2",
"tslib": "^2.6.2",
"typescript": "^4.9.5",
"vitepress": "^1.2.3"
"vitepress": "^1.3.4"
}
}

View File

@ -3,7 +3,6 @@ import child_process from 'child_process'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import eslint from '@rollup/plugin-eslint'
import replace from '@rollup/plugin-replace'
// import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript'
import terser from '@rollup/plugin-terser'
import fileSize from 'rollup-plugin-filesize'
@ -12,7 +11,12 @@ import progress from 'rollup-plugin-progress'
import { resolvePath, getVersion } from './utils.js'
const version = getVersion()
const commitId = child_process.execSync('git rev-parse --short HEAD').toString().trim()
let commitId = ''
try {
commitId = child_process.execSync(`git rev-parse --short v${version}^{}`).toString().trim()
} catch {
}
const env = process.env.NODE_ENV
@ -31,12 +35,11 @@ function createInputConfig ({ input, replaceValues }) {
throwOnError: true
}),
nodeResolve(),
// commonjs(),
progress(),
replace({
preventAssignment: true,
values: {
'__VERSION__': `v${version}(${commitId})`,
'__VERSION__': `v${version}(${commitId.length > 0 ? `${commitId}, ` : ''}${new Date().toISOString()})`,
...replaceValues
}
}),

View File

@ -15,6 +15,7 @@
import type Nullable from './common/Nullable'
import type DeepPartial from './common/DeepPartial'
import type Bounding from './common/Bounding'
import { createDefaultBounding } from './common/Bounding'
import { type KLineData } from './common/Data'
import type Coordinate from './common/Coordinate'
import type Point from './common/Point'
@ -130,6 +131,7 @@ export default class ChartImp implements Chart {
private _container: HTMLElement
private _chartContainer: HTMLElement
private readonly _chartBounding = createDefaultBounding()
private readonly _chartEvent: Event
private readonly _chartStore: ChartStore
private _drawPanes: DrawPane[] = []
@ -164,6 +166,12 @@ export default class ChartImp implements Chart {
})
this._chartContainer.tabIndex = 1
container.appendChild(this._chartContainer)
this._cacheChartBounding()
}
_cacheChartBounding (): void {
this._chartBounding.width = Math.floor(this._container.clientWidth)
this._chartBounding.height = Math.floor(this._container.clientHeight)
}
private _initPanes (options?: Options): void {
@ -292,7 +300,7 @@ export default class ChartImp implements Chart {
}
private _measurePaneHeight (): void {
const totalHeight = Math.floor(this._container.clientHeight)
const totalHeight = this._chartBounding.height
const separatorSize = this._chartStore.getStyles().separator.size
const xAxisHeight = this._xAxisPane.getAxisComponent().getAutoSize()
let paneExcludeXAxisHeight = totalHeight - xAxisHeight - this._separatorPanes.size * separatorSize
@ -334,7 +342,7 @@ export default class ChartImp implements Chart {
}
private _measurePaneWidth (): void {
const totalWidth = Math.floor(this._container.clientWidth)
const totalWidth = this._chartBounding.width
const styles = this._chartStore.getStyles()
let leftYAxisWidth = 0
@ -549,14 +557,7 @@ export default class ChartImp implements Chart {
}
}
} else {
return {
width: Math.floor(this._chartContainer.clientWidth),
height: Math.floor(this._chartContainer.clientHeight),
left: 0,
top: 0,
right: 0,
bottom: 0
}
return this._chartBounding
}
return null
}
@ -978,8 +979,7 @@ export default class ChartImp implements Chart {
}
getConvertPictureUrl (includeOverlay?: boolean, type?: string, backgroundColor?: string): string {
const width = this._chartContainer.clientWidth
const height = this._chartContainer.clientHeight
const { width, height } = this._chartBounding
const canvas = createDom('canvas', {
width: `${width}px`,
height: `${height}px`,
@ -1014,6 +1014,7 @@ export default class ChartImp implements Chart {
}
resize (): void {
this._cacheChartBounding()
this.adjustPaneViewport(true, true, true, true, true)
}

View File

@ -61,7 +61,7 @@ export default class Canvas {
constructor (style: Partial<CSSStyleDeclaration>, listener: DrawListener) {
this._listener = listener
this._element = createDom('canvas', style)
this._ctx = this._element.getContext('2d', { willReadFrequently: true })!
this._ctx = this._element.getContext('2d')!
isSupportedDevicePixelContentBox().then(result => {
this._supportedDevicePixelContentBox = result
if (result) {
@ -88,14 +88,14 @@ export default class Canvas {
this._executeListener(() => {
const width = this._element.clientWidth
const height = this._element.clientHeight
const horizontalPixelRatio = this._nextPixelWidth / width
const verticalPixelRatio = this._nextPixelHeight / height
this._width = width
this._height = height
this._pixelWidth = this._nextPixelWidth
this._pixelHeight = this._nextPixelHeight
this._element.width = this._nextPixelWidth
this._element.height = this._nextPixelHeight
const horizontalPixelRatio = this._nextPixelWidth / width
const verticalPixelRatio = this._nextPixelHeight / height
this._ctx.scale(horizontalPixelRatio, verticalPixelRatio)
})
}

View File

@ -20,7 +20,7 @@ import type VisibleRange from '../common/VisibleRange'
import type BarSpace from '../common/BarSpace'
import type Crosshair from '../common/Crosshair'
import { type IndicatorStyle, type IndicatorPolygonStyle, type SmoothLineStyle, type RectStyle, type TextStyle, type TooltipIconStyle, type LineStyle, type LineType, type PolygonType, type TooltipLegend } from '../common/Styles'
import { isNumber, isValid, merge, isBoolean, isString, clone } from '../common/utils/typeChecks'
import { isNumber, isValid, merge, isBoolean, isString, clone, isFunction } from '../common/utils/typeChecks'
import { type XAxis } from './XAxis'
import { type YAxis } from './YAxis'
@ -390,9 +390,14 @@ export default class IndicatorImp<D = any> implements Indicator<D> {
this.styles ??= {}
merge(this.styles, styles)
}
this.figures = figures ?? this.figures
this.calcParams = calcParams ?? this.calcParams
merge(this, others)
if (isValid(calcParams)) {
this.calcParams = calcParams
if (isFunction(this.regenerateFigures)) {
this.figures = this.regenerateFigures(this.calcParams)
}
}
this.figures = figures ?? this.figures
}
setSeriesPrecision (precision: number): void {

View File

@ -163,7 +163,7 @@ export default class ChartStore {
merge(this._styles, ss)
// `candle.tooltip.custom` should override
if (isArray(ss?.candle?.tooltip?.custom)) {
this._styles.candle.tooltip.custom = ss?.candle?.tooltip?.custom as unknown as TooltipLegend[]
this._styles.candle.tooltip.custom = ss.candle.tooltip.custom as unknown as TooltipLegend[]
}
}
if (isValid(customApi)) {