impr: merge ts type

This commit is contained in:
liihuu 2024-08-28 00:29:20 +08:00
parent 7d3390cea0
commit e203b858a9
47 changed files with 87 additions and 71 deletions

View File

@ -15,7 +15,7 @@
import type Nullable from './common/Nullable'
import type DeepPartial from './common/DeepPartial'
import type Bounding from './common/Bounding'
import type KLineData from './common/KLineData'
import { type KLineData } from './common/Data'
import type Coordinate from './common/Coordinate'
import type Point from './common/Point'
import { UpdateLevel } from './common/Updater'

View File

@ -14,7 +14,7 @@
import type DeepPartial from './common/DeepPartial'
import { type Styles } from './common/Styles'
import { formatDate, formatBigNumber } from './common/utils/format'
import { formatDateToString, formatBigNumber } from './common/utils/format'
import { type IndicatorCreate } from './component/Indicator'
import { type PaneOptions } from './pane/types'
@ -36,7 +36,7 @@ export interface CustomApi {
export function getDefaultCustomApi (): CustomApi {
return {
formatDate,
formatDate: formatDateToString,
formatBigNumber
}
}

View File

@ -13,7 +13,7 @@
*/
import type Coordinate from './Coordinate'
import type KLineData from './KLineData'
import { type KLineData } from './Data'
export default interface Crosshair extends Partial<Coordinate> {
paneId?: string

View File

@ -12,7 +12,10 @@
* limitations under the License.
*/
export default interface KLineData {
import type Nullable from './Nullable'
import { type DateTime } from './utils/format'
export interface KLineData {
timestamp: number
open: number
high: number
@ -22,3 +25,16 @@ export default interface KLineData {
turnover?: number
[key: string]: any
}
export interface VisibleData {
dataIndex: number
x: number
data: Nullable<KLineData>
}
export interface TimeWeightData {
weight: number
dataIndex: number
dateTime: DateTime
data: KLineData
}

View File

@ -13,7 +13,7 @@
*/
import type Nullable from './Nullable'
import type KLineData from './KLineData'
import { type KLineData } from './Data'
enum LoadDataType {
Init = 'init',

View File

@ -13,7 +13,7 @@
*/
import type Nullable from './Nullable'
import type KLineData from './KLineData'
import { type KLineData } from './Data'
export interface Margin {
marginLeft: number

View File

@ -1,22 +0,0 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type Nullable from './Nullable'
import type KLineData from './KLineData'
export default interface VisibleData {
dataIndex: number
x: number
data: Nullable<KLineData>
}

View File

@ -14,6 +14,15 @@
import { isNumber, isValid } from './typeChecks'
export interface DateTime {
year: string
month: string
day: string
hour: string
minute: string
second: string
}
const reEscapeChar = /\\(\\)?/g
const rePropName = RegExp(
'[^.[\\]]+' + '|' +
@ -48,7 +57,7 @@ export function formatValue (data: unknown, key: string, defaultValue?: unknown)
return defaultValue ?? '--'
}
export function formatDate (dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string): string {
export function formatDateToDateTime (dateTimeFormat: Intl.DateTimeFormat, timestamp: number): DateTime {
const date: Record<string, string> = {}
dateTimeFormat.formatToParts(new Date(timestamp)).forEach(({ type, value }) => {
switch (type) {
@ -78,6 +87,11 @@ export function formatDate (dateTimeFormat: Intl.DateTimeFormat, timestamp: numb
}
}
})
return date as unknown as DateTime
}
export function formatDateToString (dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string): string {
const date = formatDateToDateTime(dateTimeFormat, timestamp)
return format.replace(/YYYY|MM|DD|HH|mm|ss/g, key => date[key])
}

View File

@ -14,7 +14,7 @@
import type Nullable from '../common/Nullable'
import type ExcludePickPartial from '../common/ExcludePickPartial'
import type KLineData from '../common/KLineData'
import { type KLineData } from '../common/Data'
import type Bounding from '../common/Bounding'
import type VisibleRange from '../common/VisibleRange'
import type BarSpace from '../common/BarSpace'

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
interface Avp {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type IndicatorStyle, PolygonType } from '../../common/Styles'
import { formatValue } from '../../common/utils/format'

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Bias {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
interface Boll {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Brar {

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
interface Bbi {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Cci {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Cr {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Dma {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Dmi {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Emv {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
interface Ema {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Mtm {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
interface Ma {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type IndicatorStyle, PolygonType } from '../../common/Styles'
import { formatValue } from '../../common/utils/format'

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Obv {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type IndicatorTemplate } from '../../component/Indicator'
interface Pvt {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Psy {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Roc {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Rsi {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
interface Sma {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
import { getMaxMin } from '../../common/utils/number'

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type IndicatorStyle } from '../../common/Styles'
import { formatValue } from '../../common/utils/format'

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Trix {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type IndicatorStyle } from '../../common/Styles'
import { formatValue } from '../../common/utils/format'
import { isValid } from '../../common/utils/typeChecks'

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
interface Vr {

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
import type KLineData from '../../common/KLineData'
import { type KLineData } from '../../common/Data'
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
import { getMaxMin } from '../../common/utils/number'

View File

@ -35,7 +35,7 @@ import { logError, logTag, logWarn } from './common/utils/logger'
import {
clone, merge, isString, isNumber, isValid, isObject, isArray, isFunction, isBoolean
} from './common/utils/typeChecks'
import { formatValue, formatPrecision, formatBigNumber, formatDate, formatThousands, formatFoldDecimal } from './common/utils/format'
import { formatValue, formatPrecision, formatBigNumber, formatDateToString, formatThousands, formatFoldDecimal } from './common/utils/format'
import { calcTextWidth } from './common/utils/canvas'
import { ActionType } from './common/Action'
import { IndicatorSeries } from './component/Indicator'
@ -141,7 +141,7 @@ const utils = {
formatValue,
formatPrecision,
formatBigNumber,
formatDate,
formatDate: formatDateToString,
formatThousands,
formatFoldDecimal,
calcTextWidth,

View File

@ -13,9 +13,8 @@
*/
import type Nullable from '../common/Nullable'
import type KLineData from '../common/KLineData'
import { type KLineData, type VisibleData } from '../common/Data'
import type Precision from '../common/Precision'
import type VisibleData from '../common/VisibleData'
import type DeepPartial from '../common/DeepPartial'
import { getDefaultStyles, type Styles, type TooltipLegend } from '../common/Styles'
import { isArray, isNumber, isString, isValid, merge } from '../common/utils/typeChecks'
@ -133,6 +132,8 @@ export default class ChartStore {
*/
private _visibleDataList: VisibleData[] = []
// private _dataMap = new Map<number, TimeClassifyData[]>()
constructor (chart: Chart, options?: Options) {
this._chart = chart
this.setOptions(options)

View File

@ -14,7 +14,7 @@
import type Nullable from '../common/Nullable'
import type Coordinate from '../common/Coordinate'
import type KLineData from '../common/KLineData'
import { type KLineData } from '../common/Data'
import type BarSpace from '../common/BarSpace'
import type VisibleRange from '../common/VisibleRange'
import { getDefaultVisibleRange } from '../common/VisibleRange'
@ -27,6 +27,13 @@ import { isNumber, isString } from '../common/utils/typeChecks'
import type ChartStore from './ChartStore'
import { LoadDataType } from '../common/LoadDataCallback'
export interface TimeCategoryDataMapValue {
category: number
dataIndex: number
timestamp: number
data: KLineData
}
interface LeftRightSide {
left: number
right: number

View File

@ -13,7 +13,7 @@
*/
import type Nullable from '../common/Nullable'
import type KLineData from '../common/KLineData'
import { type KLineData } from '../common/Data'
import type Crosshair from '../common/Crosshair'
import { UpdateLevel } from '../common/Updater'
import { isNumber } from '../common/utils/typeChecks'

View File

@ -13,7 +13,7 @@
*/
import type Coordinate from '../common/Coordinate'
import type VisibleData from '../common/VisibleData'
import { type VisibleData } from '../common/Data'
import { type GradientColor } from '../common/Styles'
import Animation from '../common/Animation'
import { isNumber, isArray, isValid } from '../common/utils/typeChecks'

View File

@ -13,7 +13,7 @@
*/
import type Nullable from '../common/Nullable'
import type VisibleData from '../common/VisibleData'
import { type VisibleData } from '../common/Data'
import type BarSpace from '../common/BarSpace'
import { type EventHandler } from '../common/SyntheticEvent'
import { ActionType } from '../common/Action'

View File

@ -13,7 +13,7 @@
*/
import type Coordinate from '../common/Coordinate'
import type VisibleData from '../common/VisibleData'
import { type VisibleData } from '../common/Data'
import { type CandleHighLowPriceMarkStyle } from '../common/Styles'
import ChildrenView from './ChildrenView'

View File

@ -14,7 +14,7 @@
import type Nullable from '../common/Nullable'
import type Bounding from '../common/Bounding'
import type KLineData from '../common/KLineData'
import { type KLineData } from '../common/Data'
import type Precision from '../common/Precision'
import type Crosshair from '../common/Crosshair'
import {

View File

@ -13,7 +13,7 @@
*/
import View from './View'
import type VisibleData from '../common/VisibleData'
import { type VisibleData } from '../common/Data'
import type BarSpace from '../common/BarSpace'
import type YAxis from '../component/YAxis'

View File

@ -13,7 +13,7 @@
*/
import type Nullable from '../common/Nullable'
import type KLineData from '../common/KLineData'
import { type KLineData } from '../common/Data'
import type Crosshair from '../common/Crosshair'
import { type IndicatorStyle, type TooltipStyle, type TooltipIconStyle, type TooltipTextStyle, type TooltipLegend, TooltipShowRule, type TooltipLegendChild, TooltipIconPosition } from '../common/Styles'
import { ActionType } from '../common/Action'

View File

@ -13,7 +13,7 @@
*/
import type Nullable from '../common/Nullable'
import type VisibleData from '../common/VisibleData'
import { type VisibleData } from '../common/Data'
import type BarSpace from '../common/BarSpace'
import { CandleType, type SmoothLineStyle } from '../common/Styles'
import { formatValue } from '../common/utils/format'