mirror of
https://github.com/klinecharts/KLineChart.git
synced 2024-11-25 16:22:43 +08:00
chore: upgrade eslint
This commit is contained in:
parent
bf54561d4f
commit
c29071d9f7
@ -1,5 +0,0 @@
|
||||
scripts/
|
||||
dist/
|
||||
docs/
|
||||
.eslintrc.cjs
|
||||
index.js
|
@ -1,10 +0,0 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true
|
||||
},
|
||||
extends: 'love',
|
||||
rules: {
|
||||
"@typescript-eslint/no-non-null-assertion": "off"
|
||||
}
|
||||
}
|
24
eslint.config.js
Normal file
24
eslint.config.js
Normal file
@ -0,0 +1,24 @@
|
||||
import config from 'eslint-config-love'
|
||||
|
||||
export default [
|
||||
{
|
||||
...config,
|
||||
files: ['src/**/*.js', 'src/**/*.ts'],
|
||||
},
|
||||
{
|
||||
ignores: [
|
||||
'eslint.config.js',
|
||||
'scripts/**/*',
|
||||
'dist/**/*',
|
||||
'docs/**/*',
|
||||
'index.js'
|
||||
]
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/class-methods-use-this": "off",
|
||||
"@typescript-eslint/max-params": "off"
|
||||
}
|
||||
}
|
||||
]
|
10
package.json
10
package.json
@ -65,6 +65,7 @@
|
||||
"@rollup/plugin-replace": "^5.0.5",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@rollup/plugin-typescript": "^11.1.6",
|
||||
"@rollup/pluginutils": "^5.1.0",
|
||||
"@shikijs/vitepress-twoslash": "^1.4.0",
|
||||
"@stackblitz/sdk": "^1.9.0",
|
||||
"@types/node": "^20.12.7",
|
||||
@ -73,19 +74,16 @@
|
||||
"cross-env": "^7.0.3",
|
||||
"dts-bundle-generator": "^9.5.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-love": "^47.0.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-n": "^16.6.2",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-config-love": "^64.0.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"gh-pages": "^6.1.1",
|
||||
"husky": "^8.0.3",
|
||||
"resize-observer-polyfill": "^1.5.1",
|
||||
"rollup": "^4.16.4",
|
||||
"rollup": "^4.21.3",
|
||||
"rollup-plugin-filesize": "^10.0.0",
|
||||
"rollup-plugin-progress": "^1.1.2",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^4.9.5",
|
||||
"typescript": "^5.5.4",
|
||||
"vitepress": "^1.3.4"
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
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 typescript from '@rollup/plugin-typescript'
|
||||
import terser from '@rollup/plugin-terser'
|
||||
import fileSize from 'rollup-plugin-filesize'
|
||||
import progress from 'rollup-plugin-progress'
|
||||
import eslint from './eslint.js'
|
||||
|
||||
import { resolvePath, getVersion } from './utils.js'
|
||||
|
||||
|
58
scripts/eslint.js
Normal file
58
scripts/eslint.js
Normal file
@ -0,0 +1,58 @@
|
||||
import { resolve, relative, sep } from 'path';
|
||||
import { createFilter } from '@rollup/pluginutils';
|
||||
import { loadESLint } from 'eslint';
|
||||
|
||||
function normalizePath(id) {
|
||||
return relative(process.cwd(), id).split(sep).join('/');
|
||||
}
|
||||
async function eslint(options = {}) {
|
||||
if (typeof options === 'string') {
|
||||
const configFile = resolve(process.cwd(), options);
|
||||
options = require(configFile);
|
||||
options.useEslintrc = true;
|
||||
}
|
||||
const { include, exclude = /node_modules/, throwOnWarning = false, throwOnError = false, formatter = 'stylish', ...eslintOptions } = options;
|
||||
|
||||
const ESLint = await loadESLint({ useFlatConfig: true })
|
||||
|
||||
const eslintInstance = new ESLint(eslintOptions);
|
||||
const filter = createFilter(include, exclude);
|
||||
return {
|
||||
name: 'eslint',
|
||||
async transform(_, id) {
|
||||
const file = normalizePath(id);
|
||||
if (!filter(id) || (await eslintInstance.isPathIgnored(file))) {
|
||||
return null;
|
||||
}
|
||||
const results = await eslintInstance.lintFiles(file);
|
||||
const [result] = results;
|
||||
if (eslintOptions.fix) {
|
||||
await ESLint.outputFixes(results);
|
||||
}
|
||||
if (result.warningCount === 0 && result.errorCount === 0) {
|
||||
return null;
|
||||
}
|
||||
const eslintFormatter = typeof formatter === 'string'
|
||||
? await eslintInstance.loadFormatter(formatter)
|
||||
: { format: formatter };
|
||||
const output = await eslintFormatter.format(results);
|
||||
if (output) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(output);
|
||||
}
|
||||
const errorMessages = [];
|
||||
if (result.warningCount > 0 && throwOnWarning) {
|
||||
errorMessages.push(`${result.warningCount} warning${result.warningCount > 1 ? 's' : ''}`);
|
||||
}
|
||||
if (result.errorCount > 0 && throwOnError) {
|
||||
errorMessages.push(`${result.errorCount} error${result.errorCount > 1 ? 's' : ''}`);
|
||||
}
|
||||
if (errorMessages.length > 0) {
|
||||
throw new Error(`Found ${errorMessages.join(' and ')} in ${relative('.', result.filePath)}`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { eslint as default };
|
@ -1,4 +1,3 @@
|
||||
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
|
24
src/Chart.ts
24
src/Chart.ts
@ -16,14 +16,14 @@ 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 { KLineData } from './common/Data'
|
||||
import type Coordinate from './common/Coordinate'
|
||||
import type Point from './common/Point'
|
||||
import { UpdateLevel } from './common/Updater'
|
||||
import { type Styles } from './common/Styles'
|
||||
import type { Styles } from './common/Styles'
|
||||
import type Crosshair from './common/Crosshair'
|
||||
import { ActionType, type ActionCallback } from './common/Action'
|
||||
import { type LoadDataCallback } from './common/LoadDataCallback'
|
||||
import type { LoadDataCallback } from './common/LoadDataCallback'
|
||||
import type Precision from './common/Precision'
|
||||
import type VisibleRange from './common/VisibleRange'
|
||||
import { type CustomApi, LayoutChildType, type Options } from './Options'
|
||||
@ -51,13 +51,13 @@ import { type PaneOptions, PanePosition, PANE_DEFAULT_HEIGHT, PaneIdConstants }
|
||||
import type AxisImp from './component/Axis'
|
||||
import { AxisPosition, type Axis } from './component/Axis'
|
||||
|
||||
import { type IndicatorFilter, type Indicator, type IndicatorCreate } from './component/Indicator'
|
||||
import { type OverlayFilter, type Overlay, type OverlayCreate } from './component/Overlay'
|
||||
import type { IndicatorFilter, Indicator, IndicatorCreate } from './component/Indicator'
|
||||
import type { OverlayFilter, Overlay, OverlayCreate } from './component/Overlay'
|
||||
|
||||
import { getIndicatorClass } from './extension/indicator/index'
|
||||
|
||||
import Event from './Event'
|
||||
import { type YAxis } from './component/YAxis'
|
||||
import type { YAxis } from './component/YAxis'
|
||||
|
||||
export enum DomPosition {
|
||||
Root = 'root',
|
||||
@ -119,7 +119,7 @@ export interface Chart {
|
||||
zoomAtTimestamp: (scale: number, timestamp: number, animationDuration?: number) => void
|
||||
convertToPixel: (points: Partial<Point> | Array<Partial<Point>>, finder: ConvertFinder) => Partial<Coordinate> | Array<Partial<Coordinate>>
|
||||
convertFromPixel: (coordinates: Array<Partial<Coordinate>>, finder: ConvertFinder) => Partial<Point> | Array<Partial<Point>>
|
||||
executeAction: (type: ActionType, data: any) => void
|
||||
executeAction: (type: ActionType, data: Crosshair) => void
|
||||
subscribeAction: (type: ActionType, callback: ActionCallback) => void
|
||||
unsubscribeAction: (type: ActionType, callback?: ActionCallback) => void
|
||||
getConvertPictureUrl: (includeOverlay?: boolean, type?: string, backgroundColor?: string) => string
|
||||
@ -205,7 +205,7 @@ export default class ChartImp implements Chart {
|
||||
case LayoutChildType.Indicator: {
|
||||
const content = child.content ?? []
|
||||
if (content.length > 0) {
|
||||
let paneId: Nullable<string>
|
||||
let paneId: Nullable<string> = null
|
||||
content.forEach(v => {
|
||||
if (isValid(paneId)) {
|
||||
this.createIndicator(v, true, { id: paneId })
|
||||
@ -261,7 +261,7 @@ export default class ChartImp implements Chart {
|
||||
if (!isValid(pane)) {
|
||||
pane = new DrawPaneClass(this._chartContainer, null, this, id, options ?? {})
|
||||
}
|
||||
let newIndex: number
|
||||
let newIndex = 0
|
||||
if (isNumber(index)) {
|
||||
this._drawPanes.splice(index, 0, pane)
|
||||
newIndex = index
|
||||
@ -389,7 +389,7 @@ export default class ChartImp implements Chart {
|
||||
const leftYAxisBounding = { width: leftYAxisWidth }
|
||||
const rightYAxisBounding = { width: rightYAxisWidth }
|
||||
const separatorFill = styles.separator.fill
|
||||
let separatorBounding: Partial<Bounding>
|
||||
let separatorBounding: Partial<Bounding> = {}
|
||||
if (!separatorFill) {
|
||||
separatorBounding = mainBounding
|
||||
} else {
|
||||
@ -781,7 +781,7 @@ export default class ChartImp implements Chart {
|
||||
build({ name: value })
|
||||
} else if (isArray<Array<string | OverlayCreate>>(value)) {
|
||||
(value as Array<string | OverlayCreate>).forEach(v => {
|
||||
let overlay: OverlayCreate
|
||||
let overlay: Nullable<OverlayCreate> = null
|
||||
if (isString(v)) {
|
||||
overlay = { name: v }
|
||||
} else {
|
||||
@ -959,7 +959,7 @@ export default class ChartImp implements Chart {
|
||||
return isArray(coordinates) ? points : (points[0] ?? {})
|
||||
}
|
||||
|
||||
executeAction (type: ActionType, data: any): void {
|
||||
executeAction (type: ActionType, data: Crosshair): void {
|
||||
switch (type) {
|
||||
case ActionType.OnCrosshairChange: {
|
||||
const crosshair: Crosshair = { ...data }
|
||||
|
@ -19,7 +19,7 @@ import { UpdateLevel } from './common/Updater'
|
||||
import type Crosshair from './common/Crosshair'
|
||||
import { requestAnimationFrame, cancelAnimationFrame } from './common/utils/compatible'
|
||||
|
||||
import { type AxisRange } from './component/Axis'
|
||||
import type { AxisRange } from './component/Axis'
|
||||
import type YAxis from './component/YAxis'
|
||||
import type XAxis from './component/XAxis'
|
||||
|
||||
@ -243,7 +243,7 @@ export default class Event implements EventHandler {
|
||||
const yAxis = (pane as DrawPane<YAxis>).getAxisComponent()
|
||||
if (this._prevYAxisRange !== null && !yAxis.getAutoCalcTickFlag() && yAxis.scrollZoomEnabled) {
|
||||
const { from, to, range } = this._prevYAxisRange
|
||||
let distance: number
|
||||
let distance = 0
|
||||
if (yAxis.reverse) {
|
||||
distance = this._startScrollCoordinate.y - event.y
|
||||
} else {
|
||||
@ -332,7 +332,7 @@ export default class Event implements EventHandler {
|
||||
|
||||
mouseUpEvent (e: MouseTouchEvent): boolean {
|
||||
const { widget } = this._findWidgetByEvent(e)
|
||||
let consumed: boolean = false
|
||||
let consumed = false
|
||||
if (widget !== null) {
|
||||
const event = this._makeWidgetEvent(e, widget)
|
||||
const name = widget.getName()
|
||||
@ -370,7 +370,7 @@ export default class Event implements EventHandler {
|
||||
|
||||
mouseRightClickEvent (e: MouseTouchEvent): boolean {
|
||||
const { widget } = this._findWidgetByEvent(e)
|
||||
let consumed: boolean = false
|
||||
let consumed = false
|
||||
if (widget !== null) {
|
||||
const event = this._makeWidgetEvent(e, widget)
|
||||
const name = widget.getName()
|
||||
|
@ -13,11 +13,11 @@
|
||||
*/
|
||||
|
||||
import type DeepPartial from './common/DeepPartial'
|
||||
import { type Styles } from './common/Styles'
|
||||
import type { Styles } from './common/Styles'
|
||||
import { formatDateToString, formatBigNumber } from './common/utils/format'
|
||||
|
||||
import { type IndicatorCreate } from './component/Indicator'
|
||||
import { type PaneOptions } from './pane/types'
|
||||
import type { IndicatorCreate } from './component/Indicator'
|
||||
import type { PaneOptions } from './pane/types'
|
||||
|
||||
export enum FormatDateType {
|
||||
Tooltip,
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import { isFunction } from './utils/typeChecks'
|
||||
|
||||
export type ActionCallback = (data?: any) => void
|
||||
export type ActionCallback = (data?: unknown) => void
|
||||
|
||||
export enum ActionType {
|
||||
OnZoom = 'onZoom',
|
||||
@ -47,7 +47,7 @@ export default class Delegate {
|
||||
}
|
||||
}
|
||||
|
||||
execute (data?: any): void {
|
||||
execute (data?: unknown): void {
|
||||
this._callbacks.forEach(callback => {
|
||||
callback(data)
|
||||
})
|
||||
|
@ -79,6 +79,7 @@ export default class Canvas {
|
||||
this._resizeObserver.observe(this._element, { box: 'device-pixel-content-box' })
|
||||
} else {
|
||||
this._mediaQueryList = window.matchMedia(`(resolution: ${getPixelRatio(this._element)}dppx)`)
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
this._mediaQueryList.addListener(this._mediaQueryListener)
|
||||
}
|
||||
}).catch(_ => false)
|
||||
@ -136,6 +137,7 @@ export default class Canvas {
|
||||
|
||||
destroy (): void {
|
||||
this._resizeObserver?.unobserve(this._element)
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
this._mediaQueryList?.removeListener(this._mediaQueryListener)
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type Coordinate from './Coordinate'
|
||||
import { type KLineData } from './Data'
|
||||
import type { KLineData } from './Data'
|
||||
|
||||
export default interface Crosshair extends Partial<Coordinate> {
|
||||
paneId?: string
|
||||
|
@ -22,7 +22,7 @@ export interface KLineData {
|
||||
close: number
|
||||
volume?: number
|
||||
turnover?: number
|
||||
[key: string]: any
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export interface VisibleData {
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import { isValid } from './utils/typeChecks'
|
||||
|
||||
import { type EventName, type MouseTouchEvent, type MouseTouchEventCallback } from './SyntheticEvent'
|
||||
import type { EventName, MouseTouchEvent, MouseTouchEventCallback } from './SyntheticEvent'
|
||||
|
||||
export interface EventDispatcher {
|
||||
dispatchEvent: (name: EventName, event: MouseTouchEvent, other?: number) => boolean
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type Nullable from './Nullable'
|
||||
import { type KLineData } from './Data'
|
||||
import type { KLineData } from './Data'
|
||||
|
||||
export enum LoadDataType {
|
||||
Init = 'init',
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type Nullable from './Nullable'
|
||||
import { type KLineData } from './Data'
|
||||
import type { KLineData } from './Data'
|
||||
|
||||
export interface Margin {
|
||||
marginLeft: number
|
||||
@ -272,7 +272,7 @@ export interface IndicatorStyle {
|
||||
circles: IndicatorPolygonStyle[]
|
||||
lastValueMark: IndicatorLastValueMarkStyle
|
||||
tooltip: IndicatorTooltipStyle
|
||||
[key: string]: any
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export type AxisLineStyle = Omit<StateLineStyle, 'style' | 'dashedValue'>
|
||||
@ -325,7 +325,7 @@ export interface OverlayStyle {
|
||||
circle: PolygonStyle
|
||||
arc: LineStyle
|
||||
text: TextStyle
|
||||
[key: string]: any
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export interface SeparatorStyle {
|
||||
|
@ -82,13 +82,17 @@ export interface EventOptions {
|
||||
// so we do not need to have it as variables
|
||||
const enum Delay {
|
||||
ResetClick = 500,
|
||||
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
||||
LongTap = 500,
|
||||
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
||||
PreventFiresTouchEvents = 500,
|
||||
}
|
||||
|
||||
const enum ManhattanDistance {
|
||||
CancelClick = 5,
|
||||
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
||||
CancelTap = 5,
|
||||
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
||||
DoubleClick = 5,
|
||||
DoubleTap = 30,
|
||||
}
|
||||
@ -116,24 +120,24 @@ export default class SyntheticEvent {
|
||||
|
||||
private readonly _options: EventOptions
|
||||
|
||||
private _clickCount: number = 0
|
||||
private _clickCount = 0
|
||||
private _clickTimeoutId: Nullable<TimerId> = null
|
||||
private _clickCoordinate: Coordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY }
|
||||
|
||||
private _tapCount: number = 0
|
||||
private _tapCount = 0
|
||||
private _tapTimeoutId: Nullable<TimerId> = null
|
||||
private _tapCoordinate: Coordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY }
|
||||
|
||||
private _longTapTimeoutId: Nullable<TimerId> = null
|
||||
private _longTapActive: boolean = false
|
||||
private _longTapActive = false
|
||||
|
||||
private _mouseMoveStartCoordinate: Nullable<Coordinate> = null
|
||||
|
||||
private _touchMoveStartCoordinate: Nullable<Coordinate> = null
|
||||
private _touchMoveExceededManhattanDistance: boolean = false
|
||||
private _touchMoveExceededManhattanDistance = false
|
||||
|
||||
private _cancelClick: boolean = false
|
||||
private _cancelTap: boolean = false
|
||||
private _cancelClick = false
|
||||
private _cancelTap = false
|
||||
|
||||
private _unsubscribeOutsideMouseEvents: Nullable<() => void> = null
|
||||
private _unsubscribeOutsideTouchEvents: Nullable<() => void> = null
|
||||
@ -149,13 +153,13 @@ export default class SyntheticEvent {
|
||||
private _unsubscribeRootTouchEvents: Nullable<() => void> = null
|
||||
|
||||
private _startPinchMiddleCoordinate: Nullable<Coordinate> = null
|
||||
private _startPinchDistance: number = 0
|
||||
private _pinchPrevented: boolean = false
|
||||
private _preventTouchDragProcess: boolean = false
|
||||
private _startPinchDistance = 0
|
||||
private _pinchPrevented = false
|
||||
private _preventTouchDragProcess = false
|
||||
|
||||
private _mousePressed: boolean = false
|
||||
private _mousePressed = false
|
||||
|
||||
private _lastTouchEventTimeStamp: number = 0
|
||||
private _lastTouchEventTimeStamp = 0
|
||||
|
||||
// for touchstart/touchmove/touchend events we handle only first touch
|
||||
// i.e. we don't support several active touches at the same time (except pinch event)
|
||||
@ -163,7 +167,7 @@ export default class SyntheticEvent {
|
||||
|
||||
// accept all mouse leave events if it's not an iOS device
|
||||
// see _mouseEnterHandler, _mouseMoveHandler, _mouseLeaveHandler
|
||||
private _acceptMouseLeave: boolean = !isIOS()
|
||||
private _acceptMouseLeave = !isIOS()
|
||||
|
||||
constructor (
|
||||
target: HTMLElement,
|
||||
@ -731,6 +735,7 @@ export default class SyntheticEvent {
|
||||
// it treats a touchstart and the following touchmove events as cancelable=false,
|
||||
// so we can't prevent them (as soon we subscribe on touchmove inside touchstart's handler).
|
||||
// And we'll get scroll of the page along with chart's one instead of only chart's scroll.
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
this._target.addEventListener('touchmove', () => {}, { passive: false })
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type Nullable from '../Nullable'
|
||||
import { isValid } from './typeChecks'
|
||||
|
||||
let measureCtx: CanvasRenderingContext2D
|
||||
let measureCtx: Nullable<CanvasRenderingContext2D> = null
|
||||
|
||||
/**
|
||||
* Get pixel ratio
|
||||
|
@ -16,7 +16,7 @@ import { isFunction } from './typeChecks'
|
||||
|
||||
export const DEFAULT_REQUEST_ID = -1
|
||||
|
||||
export function requestAnimationFrame (fn: (params: any) => any): number {
|
||||
export function requestAnimationFrame (fn: (params: unknown) => unknown): number {
|
||||
if (isFunction(window.requestAnimationFrame)) {
|
||||
return window.requestAnimationFrame(fn)
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ const rePropName = RegExp(
|
||||
export function formatValue (data: unknown, key: string, defaultValue?: unknown): unknown {
|
||||
if (isValid(data)) {
|
||||
const path: string[] = []
|
||||
key.replace(rePropName, (subString: string, ...args: any[]) => {
|
||||
key.replace(rePropName, (subString: string, ...args: unknown[]) => {
|
||||
let k = subString
|
||||
if (isValid(args[1])) {
|
||||
k = args[2].replace(reEscapeChar, '$1')
|
||||
k = (args[2] as string).replace(reEscapeChar, '$1')
|
||||
} else if (isValid(args[0])) {
|
||||
k = args[0].trim()
|
||||
k = (args[0] as string).trim()
|
||||
}
|
||||
path.push(k)
|
||||
return ''
|
||||
|
@ -19,7 +19,7 @@
|
||||
* @param targetValue
|
||||
* @return {number}
|
||||
*/
|
||||
export function binarySearchNearest<T> (dataList: T[], valueKey: keyof T, targetValue: any): number {
|
||||
export function binarySearchNearest<T> (dataList: T[], valueKey: keyof T, targetValue: T[keyof T]): number {
|
||||
let left = 0
|
||||
let right = 0
|
||||
for (right = dataList.length - 1; left !== right;) {
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export function throttle (func: (...args: any[]) => any, wait?: number): () => void {
|
||||
export function throttle (func: (...args: unknown[]) => unknown, wait?: number): () => void {
|
||||
let previous = 0
|
||||
return function () {
|
||||
const now = Date.now()
|
||||
|
@ -23,5 +23,6 @@ export function isIOS (): boolean {
|
||||
if (typeof window === 'undefined') {
|
||||
return false
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
return /iPhone|iPad|iPod/.test(window.navigator.platform)
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function merge (target: any, source: any): void {
|
||||
if ((!isObject(target) && !isObject(source))) {
|
||||
return
|
||||
@ -39,7 +40,8 @@ export function clone<T> (target: T): T {
|
||||
return target
|
||||
}
|
||||
|
||||
let copy
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let copy: any = null
|
||||
if (isArray(target)) {
|
||||
copy = []
|
||||
} else {
|
||||
@ -58,19 +60,19 @@ export function clone<T> (target: T): T {
|
||||
return copy
|
||||
}
|
||||
|
||||
export function isArray<T = any> (value: any): value is T[] {
|
||||
export function isArray<T = unknown> (value: unknown): value is T[] {
|
||||
return Object.prototype.toString.call(value) === '[object Array]'
|
||||
}
|
||||
|
||||
export function isFunction<T = (...args: any) => any> (value: any): value is T {
|
||||
export function isFunction<T = (...args: unknown[]) => unknown> (value: unknown): value is T {
|
||||
return typeof value === 'function'
|
||||
}
|
||||
|
||||
export function isObject (value: any): value is object {
|
||||
export function isObject (value: unknown): value is object {
|
||||
return (typeof value === 'object') && isValid(value)
|
||||
}
|
||||
|
||||
export function isNumber (value: any): value is number {
|
||||
export function isNumber (value: unknown): value is number {
|
||||
return typeof value === 'number' && !Number.isNaN(value)
|
||||
}
|
||||
|
||||
@ -78,10 +80,10 @@ export function isValid<T> (value: T | null | undefined): value is T {
|
||||
return value !== null && value !== undefined
|
||||
}
|
||||
|
||||
export function isBoolean (value: any): value is boolean {
|
||||
export function isBoolean (value: unknown): value is boolean {
|
||||
return typeof value === 'boolean'
|
||||
}
|
||||
|
||||
export function isString (value: any): value is string {
|
||||
export function isString (value: unknown): value is string {
|
||||
return typeof value === 'string'
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ import type VisibleRange from '../common/VisibleRange'
|
||||
import type DrawPane from '../pane/DrawPane'
|
||||
|
||||
import type Bounding from '../common/Bounding'
|
||||
import { type KLineData } from '../common/Data'
|
||||
import { type Indicator } from './Indicator'
|
||||
import type { KLineData } from '../common/Data'
|
||||
import type { Indicator } from './Indicator'
|
||||
|
||||
export interface AxisTick {
|
||||
coord: number
|
||||
|
@ -15,11 +15,11 @@
|
||||
import type Coordinate from '../common/Coordinate'
|
||||
|
||||
import Eventful from '../common/Eventful'
|
||||
import { type MouseTouchEvent } from '../common/SyntheticEvent'
|
||||
import type { MouseTouchEvent } from '../common/SyntheticEvent'
|
||||
|
||||
export const DEVIATION = 2
|
||||
|
||||
export interface Figure<A = any, S = any> {
|
||||
export interface Figure<A = unknown, S = unknown> {
|
||||
name: string
|
||||
attrs: A
|
||||
styles: S
|
||||
@ -27,19 +27,19 @@ export interface Figure<A = any, S = any> {
|
||||
checkEventOn: (coordinate: Coordinate, attrs: A, styles: S) => boolean
|
||||
}
|
||||
|
||||
export type FigureTemplate<A = any, S = any> = Pick<Figure<A, S>, 'name' | 'draw' | 'checkEventOn'>
|
||||
export type FigureTemplate<A = unknown, S = unknown> = Pick<Figure<A, S>, 'name' | 'draw' | 'checkEventOn'>
|
||||
|
||||
export type FigureCreate<A = any, S = any> = Pick<Figure<A, S>, 'name' | 'attrs' | 'styles'>
|
||||
export type FigureCreate<A = unknown, S = unknown> = Pick<Figure<A, S>, 'name' | 'attrs' | 'styles'>
|
||||
|
||||
export type FigureInnerConstructor<A = any, S = any> = new (figure: FigureCreate<A, S>) => FigureImp<A, S>
|
||||
export type FigureInnerConstructor<A = unknown, S = unknown> = new (figure: FigureCreate<A, S>) => FigureImp<A, S>
|
||||
|
||||
export type FigureConstructor<A = any, S = any> = new (figure: FigureCreate<A, S>) => ({ draw: (ctx: CanvasRenderingContext2D) => void })
|
||||
export type FigureConstructor<A = unknown, S = unknown> = new (figure: FigureCreate<A, S>) => ({ draw: (ctx: CanvasRenderingContext2D) => void })
|
||||
|
||||
export default abstract class FigureImp<A = any, S = any> extends Eventful implements Omit<Figure<A, S>, 'name' | 'draw' | 'checkEventOn'> {
|
||||
export default abstract class FigureImp<A = unknown, S = unknown> extends Eventful implements Omit<Figure<A, S>, 'name' | 'draw' | 'checkEventOn'> {
|
||||
attrs: A
|
||||
styles: S
|
||||
|
||||
constructor (figure: FigureCreate) {
|
||||
constructor (figure: FigureCreate<A, S>) {
|
||||
super()
|
||||
this.attrs = figure.attrs
|
||||
this.styles = figure.styles
|
||||
|
@ -14,23 +14,23 @@
|
||||
|
||||
import type Nullable from '../common/Nullable'
|
||||
import type ExcludePickPartial from '../common/ExcludePickPartial'
|
||||
import { type KLineData } from '../common/Data'
|
||||
import type { KLineData } from '../common/Data'
|
||||
import type Bounding from '../common/Bounding'
|
||||
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 type { IndicatorStyle, IndicatorPolygonStyle, SmoothLineStyle, RectStyle, TextStyle, TooltipIconStyle, LineStyle, LineType, TooltipLegend } from '../common/Styles'
|
||||
import { isNumber, isValid, merge, isBoolean, isString, clone, isFunction } from '../common/utils/typeChecks'
|
||||
|
||||
import { type XAxis } from './XAxis'
|
||||
import { type YAxis } from './YAxis'
|
||||
import type { XAxis } from './XAxis'
|
||||
import type { YAxis } from './YAxis'
|
||||
|
||||
import { formatValue } from '../common/utils/format'
|
||||
|
||||
import { type ArcAttrs } from '../extension/figure/arc'
|
||||
import { type RectAttrs } from '../extension/figure/rect'
|
||||
import { type TextAttrs } from '../extension/figure/text'
|
||||
import { type LoadDataType } from '../common/LoadDataCallback'
|
||||
import type { ArcAttrs } from '../extension/figure/arc'
|
||||
import type { RectAttrs } from '../extension/figure/rect'
|
||||
import type { TextAttrs } from '../extension/figure/text'
|
||||
import type { LoadDataType } from '../common/LoadDataCallback'
|
||||
|
||||
export enum IndicatorSeries {
|
||||
Normal = 'normal',
|
||||
@ -38,9 +38,9 @@ export enum IndicatorSeries {
|
||||
Volume = 'volume'
|
||||
}
|
||||
|
||||
export type IndicatorFigureStyle = Partial<Omit<SmoothLineStyle, 'style'>> & Partial<Omit<RectStyle, 'style'>> & Partial<TextStyle> & Partial<{ style: LineType[keyof LineType] | PolygonType[keyof PolygonType] }> & Record<string, any>
|
||||
export type IndicatorFigureStyle = Partial<Omit<SmoothLineStyle, 'style'>> & Partial<Omit<RectStyle, 'style'>> & Partial<TextStyle> & Partial<{ style: LineType[keyof LineType] }> & Record<string, unknown>
|
||||
|
||||
export type IndicatorFigureAttrs = Partial<ArcAttrs> & Partial<LineStyle> & Partial<RectAttrs> & Partial<TextAttrs> & Record<string, any>
|
||||
export type IndicatorFigureAttrs = Partial<ArcAttrs> & Partial<LineStyle> & Partial<RectAttrs> & Partial<TextAttrs> & Record<string, unknown>
|
||||
|
||||
export interface IndicatorFigureCallbackBrother<PCN> {
|
||||
prev: PCN
|
||||
@ -71,7 +71,7 @@ export type IndicatorFigureStylesCallbackData<D> = IndicatorFigureCallbackBrothe
|
||||
export type IndicatorFigureAttrsCallback<D> = (params: IndicatorFigureAttrsCallbackParams<D>) => IndicatorFigureAttrs
|
||||
export type IndicatorFigureStylesCallback<D> = (data: IndicatorFigureStylesCallbackData<D>, indicator: Indicator<D>, defaultStyles: IndicatorStyle) => IndicatorFigureStyle
|
||||
|
||||
export interface IndicatorFigure<D = any> {
|
||||
export interface IndicatorFigure<D = unknown> {
|
||||
key: string
|
||||
title?: string
|
||||
type?: string
|
||||
@ -80,7 +80,7 @@ export interface IndicatorFigure<D = any> {
|
||||
styles?: IndicatorFigureStylesCallback<D>
|
||||
}
|
||||
|
||||
export type IndicatorRegenerateFiguresCallback<D> = (calcParams: any[]) => Array<IndicatorFigure<D>>
|
||||
export type IndicatorRegenerateFiguresCallback<D> = (calcParams: unknown[]) => Array<IndicatorFigure<D>>
|
||||
|
||||
export interface IndicatorTooltipData {
|
||||
name: string
|
||||
@ -131,7 +131,7 @@ export interface IndicatorOnDataStatusChangeParams<D> {
|
||||
}
|
||||
export type IndicatorOnDataStatusChangeCallback<D> = (params: IndicatorOnDataStatusChangeParams<D>) => void
|
||||
|
||||
export interface Indicator<D = any> {
|
||||
export interface Indicator<D = unknown> {
|
||||
/**
|
||||
* Indicator name
|
||||
*/
|
||||
@ -150,7 +150,7 @@ export interface Indicator<D = any> {
|
||||
/**
|
||||
* Calculation parameters
|
||||
*/
|
||||
calcParams: any[]
|
||||
calcParams: unknown[]
|
||||
|
||||
/**
|
||||
* Whether ohlc column is required
|
||||
@ -175,7 +175,7 @@ export interface Indicator<D = any> {
|
||||
/**
|
||||
* Extend data
|
||||
*/
|
||||
extendData: any
|
||||
extendData: unknown
|
||||
|
||||
/**
|
||||
* Indicator series
|
||||
@ -238,17 +238,18 @@ export interface Indicator<D = any> {
|
||||
result: D[]
|
||||
}
|
||||
|
||||
export type IndicatorTemplate<D = any> = ExcludePickPartial<Omit<Indicator<D>, 'result'>, 'name' | 'calc'>
|
||||
export type IndicatorTemplate<D = unknown> = ExcludePickPartial<Omit<Indicator<D>, 'result'>, 'name' | 'calc'>
|
||||
|
||||
export type IndicatorCreate<D = any> = ExcludePickPartial<Omit<Indicator<D>, 'result'>, 'name'> & { paneId?: string }
|
||||
export type IndicatorCreate<D = unknown> = ExcludePickPartial<Omit<Indicator<D>, 'result'>, 'name'> & { paneId?: string }
|
||||
|
||||
export type IndicatorFilter = Partial<Pick<Indicator, 'name'>> & { paneId?: string }
|
||||
|
||||
export type IndicatorConstructor<D = any> = new () => IndicatorImp<D>
|
||||
export type IndicatorConstructor<D = unknown> = new () => IndicatorImp<D>
|
||||
|
||||
export type EachFigureCallback<D> = (figure: IndicatorFigure<D>, figureStyles: IndicatorFigureStyle, index: number) => void
|
||||
|
||||
export function eachFigures<D = any> (
|
||||
// eslint-disable-next-line @typescript-eslint/max-params
|
||||
export function eachFigures<D = unknown> (
|
||||
kLineDataList: KLineData[],
|
||||
indicator: Indicator<D>,
|
||||
dataIndex: number,
|
||||
@ -272,6 +273,7 @@ export function eachFigures<D = any> (
|
||||
let barCount = 0
|
||||
let lineCount = 0
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/init-declarations
|
||||
let defaultFigureStyles
|
||||
let figureIndex = 0
|
||||
figures.forEach(figure => {
|
||||
@ -311,16 +313,16 @@ export function eachFigures<D = any> (
|
||||
})
|
||||
}
|
||||
|
||||
export default class IndicatorImp<D = any> implements Indicator<D> {
|
||||
export default class IndicatorImp<D = unknown> implements Indicator<D> {
|
||||
name: string
|
||||
shortName: string
|
||||
precision = 4
|
||||
calcParams: any[] = []
|
||||
calcParams: unknown[] = []
|
||||
shouldOhlc = false
|
||||
shouldFormatBigNumber = false
|
||||
visible = true
|
||||
zLevel = 0
|
||||
extendData: any
|
||||
extendData: unknown
|
||||
series = IndicatorSeries.Normal
|
||||
figures: Array<IndicatorFigure<D>> = []
|
||||
minValue: Nullable<number> = null
|
||||
@ -358,7 +360,7 @@ export default class IndicatorImp<D = any> implements Indicator<D> {
|
||||
result: D[] = []
|
||||
|
||||
private _prevIndicator: Indicator<D>
|
||||
private _lockSeriesPrecision: boolean = false
|
||||
private _lockSeriesPrecision = false
|
||||
|
||||
constructor (indicator: IndicatorTemplate<D>) {
|
||||
this.override(indicator)
|
||||
@ -425,7 +427,7 @@ export default class IndicatorImp<D = any> implements Indicator<D> {
|
||||
}
|
||||
}
|
||||
|
||||
static extend<D = any> (template: IndicatorTemplate<D>): IndicatorConstructor<D> {
|
||||
static extend<D = unknown> (template: IndicatorTemplate<D>): IndicatorConstructor<D> {
|
||||
class Custom extends IndicatorImp<D> {
|
||||
constructor () {
|
||||
super(template)
|
||||
|
@ -20,14 +20,14 @@ import type Coordinate from '../common/Coordinate'
|
||||
import type Bounding from '../common/Bounding'
|
||||
import type BarSpace from '../common/BarSpace'
|
||||
import type Precision from '../common/Precision'
|
||||
import { type OverlayStyle } from '../common/Styles'
|
||||
import { type MouseTouchEvent } from '../common/SyntheticEvent'
|
||||
import type { OverlayStyle } from '../common/Styles'
|
||||
import type { MouseTouchEvent } from '../common/SyntheticEvent'
|
||||
import { clone, isArray, isFunction, isNumber, isString, isValid, merge } from '../common/utils/typeChecks'
|
||||
|
||||
import type TimeScaleStore from '../store/TimeScaleStore'
|
||||
|
||||
import { type XAxis } from './XAxis'
|
||||
import { type YAxis } from './YAxis'
|
||||
import type { XAxis } from './XAxis'
|
||||
import type { YAxis } from './YAxis'
|
||||
|
||||
export enum OverlayMode {
|
||||
Normal = 'normal',
|
||||
@ -62,8 +62,8 @@ export function getAllOverlayFigureIgnoreEventTypes (): OverlayFigureIgnoreEvent
|
||||
export interface OverlayFigure {
|
||||
key?: string
|
||||
type: string
|
||||
attrs: any
|
||||
styles?: any
|
||||
attrs: unknown
|
||||
styles?: unknown
|
||||
ignoreEvent?: boolean | OverlayFigureIgnoreEventType[]
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ export interface Overlay {
|
||||
/**
|
||||
* Extended Data
|
||||
*/
|
||||
extendData: any
|
||||
extendData: unknown
|
||||
|
||||
/**
|
||||
* The style information and format are consistent with the overlay in the unified configuration
|
||||
@ -297,7 +297,7 @@ export const OVERLAY_FIGURE_KEY_PREFIX = 'overlay_figure_'
|
||||
|
||||
export default class OverlayImp implements Overlay {
|
||||
id: string
|
||||
groupId: string = ''
|
||||
groupId = ''
|
||||
paneId: string
|
||||
name: string
|
||||
totalStep = 1
|
||||
@ -311,7 +311,7 @@ export default class OverlayImp implements Overlay {
|
||||
mode = OverlayMode.Normal
|
||||
modeSensitivity = 8
|
||||
points: Array<Partial<Point>> = []
|
||||
extendData: any = null
|
||||
extendData: unknown = null
|
||||
styles: Nullable<DeepPartial<OverlayStyle>> = null
|
||||
createPointFigures: Nullable<OverlayCreateFiguresCallback> = null
|
||||
createXAxisFigures: Nullable<OverlayCreateFiguresCallback> = null
|
||||
@ -370,7 +370,7 @@ export default class OverlayImp implements Overlay {
|
||||
}
|
||||
|
||||
if (isArray(points) && points.length > 0) {
|
||||
let repeatTotalStep: number
|
||||
let repeatTotalStep = 0
|
||||
this.points = [...points]
|
||||
if (points.length >= this.totalStep - 1) {
|
||||
this.currentStep = OVERLAY_DRAW_STEP_FINISHED
|
||||
@ -481,11 +481,11 @@ export default class OverlayImp implements Overlay {
|
||||
|
||||
eventPressedOtherMove (point: Partial<Point>, timeScaleStore: TimeScaleStore): void {
|
||||
if (this._prevPressedPoint !== null) {
|
||||
let difDataIndex: number
|
||||
let difDataIndex: Nullable<number> = null
|
||||
if (isNumber(point.dataIndex) && isNumber(this._prevPressedPoint.dataIndex)) {
|
||||
difDataIndex = point.dataIndex - this._prevPressedPoint.dataIndex
|
||||
}
|
||||
let difValue: number
|
||||
let difValue: Nullable<number> = null
|
||||
if (isNumber(point.value) && isNumber(this._prevPressedPoint.value)) {
|
||||
difValue = point.value - this._prevPressedPoint.value
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ export default abstract class YAxisImp extends AxisImp implements YAxis {
|
||||
})
|
||||
}
|
||||
const textHeight = chartStore.getStyles().xAxis.tickText.size
|
||||
let validY: number
|
||||
let validY = NaN
|
||||
ticks.forEach(({ value }) => {
|
||||
let v = this.displayValueToText(+value, precision)
|
||||
const y = this.convertToPixel(
|
||||
|
@ -18,7 +18,7 @@ import { type LineStyle, LineType } from '../../common/Styles'
|
||||
|
||||
import { type FigureTemplate, DEVIATION } from '../../component/Figure'
|
||||
|
||||
import { type CircleAttrs } from './circle'
|
||||
import type { CircleAttrs } from './circle'
|
||||
|
||||
export function checkCoordinateOnArc (coordinate: Coordinate, attrs: ArcAttrs | ArcAttrs[]): boolean {
|
||||
let arcs: ArcAttrs[] = []
|
||||
|
@ -17,7 +17,7 @@ import { type PolygonStyle, PolygonType, LineType } from '../../common/Styles'
|
||||
import { isString } from '../../common/utils/typeChecks'
|
||||
import { isTransparent } from '../../common/utils/color'
|
||||
|
||||
import { type FigureTemplate } from '../../component/Figure'
|
||||
import type { FigureTemplate } from '../../component/Figure'
|
||||
|
||||
export function checkCoordinateOnCircle (coordinate: Coordinate, attrs: CircleAttrs | CircleAttrs[]): boolean {
|
||||
let circles: CircleAttrs[] = []
|
||||
|
@ -34,15 +34,15 @@ function getSupportedFigures (): string[] {
|
||||
return Object.keys(figures)
|
||||
}
|
||||
|
||||
function registerFigure<A = any, S = any> (figure: FigureTemplate<A, S>): void {
|
||||
function registerFigure<A = unknown, S = unknown> (figure: FigureTemplate<A, S>): void {
|
||||
figures[figure.name] = FigureImp.extend(figure)
|
||||
}
|
||||
|
||||
function getInnerFigureClass<A = any, S = any> (name: string): Nullable<FigureInnerConstructor<A, S>> {
|
||||
function getInnerFigureClass (name: string): Nullable<FigureInnerConstructor> {
|
||||
return figures[name] ?? null
|
||||
}
|
||||
|
||||
function getFigureClass<A = any, S = any> (name: string): Nullable<FigureConstructor<A, S>> {
|
||||
function getFigureClass<A = unknown, S = unknown> (name: string): Nullable<FigureConstructor<A, S>> {
|
||||
return figures[name] ?? null
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ import { type PolygonStyle, PolygonType, LineType } from '../../common/Styles'
|
||||
import { isString } from '../../common/utils/typeChecks'
|
||||
import { isTransparent } from '../../common/utils/color'
|
||||
|
||||
import { type FigureTemplate } from '../../component/Figure'
|
||||
import type { FigureTemplate } from '../../component/Figure'
|
||||
|
||||
export function checkCoordinateOnPolygon (coordinate: Coordinate, attrs: PolygonAttrs | PolygonAttrs[]): boolean {
|
||||
let polygons: PolygonAttrs[] = []
|
||||
|
@ -13,11 +13,11 @@
|
||||
*/
|
||||
|
||||
import type Coordinate from '../../common/Coordinate'
|
||||
import { type TextStyle } from '../../common/Styles'
|
||||
import type { TextStyle } from '../../common/Styles'
|
||||
|
||||
import { createFont, calcTextWidth } from '../../common/utils/canvas'
|
||||
|
||||
import { type FigureTemplate } from '../../component/Figure'
|
||||
import type { FigureTemplate } from '../../component/Figure'
|
||||
|
||||
import { type RectAttrs, drawRect } from './rect'
|
||||
|
||||
@ -26,7 +26,7 @@ export function getTextRect (attrs: TextAttrs, styles: Partial<TextStyle>): Rect
|
||||
const { x, y, text, align = 'left', baseline = 'top', width: w, height: h } = attrs
|
||||
const width = w ?? (paddingLeft + calcTextWidth(text, size, weight, family) + paddingRight)
|
||||
const height = h ?? (paddingTop + size + paddingBottom)
|
||||
let startX: number
|
||||
let startX = 0
|
||||
switch (align) {
|
||||
case 'left':
|
||||
case 'start': {
|
||||
@ -43,7 +43,7 @@ export function getTextRect (attrs: TextAttrs, styles: Partial<TextStyle>): Rect
|
||||
break
|
||||
}
|
||||
}
|
||||
let startY: number
|
||||
let startY = 0
|
||||
switch (baseline) {
|
||||
case 'top':
|
||||
case 'hanging': {
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type Locales } from '../../Options'
|
||||
import type { Locales } from '../../Options'
|
||||
|
||||
const enUS: Locales = {
|
||||
time: 'Time: ',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type Locales } from '../../Options'
|
||||
import type { Locales } from '../../Options'
|
||||
|
||||
import zhCN from './zh-CN'
|
||||
import enUS from './en-US'
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type Locales } from '../../Options'
|
||||
import type { Locales } from '../../Options'
|
||||
|
||||
const zhCN: Locales = {
|
||||
time: '时间:',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
|
||||
|
||||
interface Avp {
|
||||
|
@ -12,11 +12,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type IndicatorStyle, PolygonType } from '../../common/Styles'
|
||||
import { formatValue } from '../../common/utils/format'
|
||||
|
||||
import { type Indicator, type IndicatorTemplate, type IndicatorFigureStylesCallbackData } from '../../component/Indicator'
|
||||
import type { Indicator, IndicatorTemplate, IndicatorFigureStylesCallbackData } from '../../component/Indicator'
|
||||
|
||||
interface Ao {
|
||||
ao?: number
|
||||
@ -35,7 +35,7 @@ const awesomeOscillator: IndicatorTemplate<Ao> = {
|
||||
const { prev, current } = data
|
||||
const prevAo = prev.indicatorData?.ao ?? Number.MIN_SAFE_INTEGER
|
||||
const currentAo = current.indicatorData?.ao ?? Number.MIN_SAFE_INTEGER
|
||||
let color: string
|
||||
let color = ''
|
||||
if (currentAo > prevAo) {
|
||||
color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor) as string
|
||||
} else {
|
||||
@ -46,8 +46,8 @@ const awesomeOscillator: IndicatorTemplate<Ao> = {
|
||||
}
|
||||
}],
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Ao>) => {
|
||||
const params = indicator.calcParams
|
||||
const maxPeriod = Math.max(params[0] as number, params[1] as number)
|
||||
const params = indicator.calcParams as number[]
|
||||
const maxPeriod = Math.max(params[0], params[1])
|
||||
let shortSum = 0
|
||||
let longSum = 0
|
||||
let short = 0
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Bias {
|
||||
bias1?: number
|
||||
@ -34,13 +34,14 @@ const bias: IndicatorTemplate<Bias> = {
|
||||
{ key: 'bias2', title: 'BIAS12: ', type: 'line' },
|
||||
{ key: 'bias3', title: 'BIAS24: ', type: 'line' }
|
||||
],
|
||||
regenerateFigures: (params: any[]) => {
|
||||
regenerateFigures: (params: unknown[]) => {
|
||||
return params.map((p: number, i: number) => {
|
||||
return { key: `bias${i + 1}`, title: `BIAS${p}: `, type: 'line' }
|
||||
})
|
||||
},
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Bias>) => {
|
||||
const { calcParams: params, figures } = indicator
|
||||
const { calcParams, figures } = indicator
|
||||
const params = calcParams as number[]
|
||||
const closeSums: number[] = []
|
||||
return dataList.map((kLineData: KLineData, i: number) => {
|
||||
const bias: Bias = {}
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
|
||||
|
||||
interface Boll {
|
||||
@ -54,7 +54,7 @@ const bollingerBands: IndicatorTemplate<Boll> = {
|
||||
{ key: 'dn', title: 'DN: ', type: 'line' }
|
||||
],
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Boll>) => {
|
||||
const params = indicator.calcParams
|
||||
const params = indicator.calcParams as number[]
|
||||
const p = params[0] - 1
|
||||
let closeSum = 0
|
||||
return dataList.map((kLineData: KLineData, i: number) => {
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Brar {
|
||||
br?: number
|
||||
@ -38,7 +38,7 @@ const brar: IndicatorTemplate<Brar> = {
|
||||
{ key: 'ar', title: 'AR: ', type: 'line' }
|
||||
],
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Brar>) => {
|
||||
const params = indicator.calcParams
|
||||
const params = indicator.calcParams as number[]
|
||||
let hcy = 0
|
||||
let cyl = 0
|
||||
let ho = 0
|
||||
|
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
|
||||
|
||||
interface Bbi {
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Cci {
|
||||
cci?: number
|
||||
@ -35,7 +35,7 @@ const commodityChannelIndex: IndicatorTemplate<Cci> = {
|
||||
{ key: 'cci', title: 'CCI: ', type: 'line' }
|
||||
],
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Cci>) => {
|
||||
const params = indicator.calcParams
|
||||
const params = indicator.calcParams as number[]
|
||||
const p = params[0] - 1
|
||||
let tpSum = 0
|
||||
const tpList: number[] = []
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Cr {
|
||||
cr?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Dma {
|
||||
dma?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Dmi {
|
||||
pdi?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Emv {
|
||||
emv?: number
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
|
||||
|
||||
interface Ema {
|
||||
@ -36,7 +36,7 @@ const exponentialMovingAverage: IndicatorTemplate<Ema> = {
|
||||
{ key: 'ema2', title: 'EMA12: ', type: 'line' },
|
||||
{ key: 'ema3', title: 'EMA20: ', type: 'line' }
|
||||
],
|
||||
regenerateFigures: (params: any[]) => {
|
||||
regenerateFigures: (params: unknown[]) => {
|
||||
return params.map((p: number, i: number) => {
|
||||
return { key: `ema${i + 1}`, title: `EMA${p}: `, type: 'line' }
|
||||
})
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Mtm {
|
||||
mtm?: number
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
|
||||
|
||||
interface Ma {
|
||||
@ -38,7 +38,7 @@ const movingAverage: IndicatorTemplate<Ma> = {
|
||||
{ key: 'ma30', title: 'MA30: ', type: 'line' },
|
||||
{ key: 'ma60', title: 'MA60: ', type: 'line' }
|
||||
],
|
||||
regenerateFigures: (params: any[]) => {
|
||||
regenerateFigures: (params: unknown[]) => {
|
||||
return params.map((p: number, i: number) => {
|
||||
return { key: `ma${i + 1}`, title: `MA${p}: `, type: 'line' }
|
||||
})
|
||||
|
@ -12,12 +12,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type IndicatorStyle, PolygonType } from '../../common/Styles'
|
||||
|
||||
import { formatValue } from '../../common/utils/format'
|
||||
|
||||
import { type Indicator, type IndicatorTemplate, type IndicatorFigureStylesCallbackData } from '../../component/Indicator'
|
||||
import type { Indicator, IndicatorTemplate, IndicatorFigureStylesCallbackData } from '../../component/Indicator'
|
||||
|
||||
interface Macd {
|
||||
dif?: number
|
||||
@ -49,7 +49,7 @@ const movingAverageConvergenceDivergence: IndicatorTemplate<Macd> = {
|
||||
const { prev, current } = data
|
||||
const prevMacd = prev.indicatorData?.macd ?? Number.MIN_SAFE_INTEGER
|
||||
const currentMacd = current.indicatorData?.macd ?? Number.MIN_SAFE_INTEGER
|
||||
let color: string
|
||||
let color = ''
|
||||
if (currentMacd > 0) {
|
||||
color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor) as string
|
||||
} else if (currentMacd < 0) {
|
||||
@ -65,8 +65,8 @@ const movingAverageConvergenceDivergence: IndicatorTemplate<Macd> = {
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Macd>) => {
|
||||
const params = indicator.calcParams as number[]
|
||||
let closeSum = 0
|
||||
let emaShort: number
|
||||
let emaLong: number
|
||||
let emaShort = 0
|
||||
let emaLong = 0
|
||||
let dif = 0
|
||||
let difSum = 0
|
||||
let dea = 0
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Obv {
|
||||
obv?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Pvt {
|
||||
pvt?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Psy {
|
||||
psy?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Roc {
|
||||
roc?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Rsi {
|
||||
rsi1?: number
|
||||
@ -34,14 +34,15 @@ const relativeStrengthIndex: IndicatorTemplate<Rsi> = {
|
||||
{ key: 'rsi2', title: 'RSI2: ', type: 'line' },
|
||||
{ key: 'rsi3', title: 'RSI3: ', type: 'line' }
|
||||
],
|
||||
regenerateFigures: (params: any[]) => {
|
||||
return params.map((_: any, index: number) => {
|
||||
regenerateFigures: (params: unknown[]) => {
|
||||
return params.map((_: unknown, index: number) => {
|
||||
const num = index + 1
|
||||
return { key: `rsi${num}`, title: `RSI${num}: `, type: 'line' }
|
||||
})
|
||||
},
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Rsi>) => {
|
||||
const { calcParams: params, figures } = indicator
|
||||
const { calcParams, figures } = indicator
|
||||
const params = calcParams as number[]
|
||||
const sumCloseAs: number[] = []
|
||||
const sumCloseBs: number[] = []
|
||||
return dataList.map((kLineData, i) => {
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate, IndicatorSeries } from '../../component/Indicator'
|
||||
|
||||
interface Sma {
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
import { getMaxMin } from '../../common/utils/number'
|
||||
|
||||
@ -41,7 +41,7 @@ const stoch: IndicatorTemplate<Kdj> = {
|
||||
{ key: 'j', title: 'J: ', type: 'line' }
|
||||
],
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Kdj>) => {
|
||||
const params = indicator.calcParams
|
||||
const params = indicator.calcParams as number[]
|
||||
const result: Kdj[] = []
|
||||
dataList.forEach((kLineData: KLineData, i: number) => {
|
||||
const kdj: Kdj = {}
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type IndicatorStyle } from '../../common/Styles'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { IndicatorStyle } from '../../common/Styles'
|
||||
import { formatValue } from '../../common/utils/format'
|
||||
|
||||
import { type Indicator, type IndicatorTemplate, IndicatorSeries, type IndicatorFigureStylesCallbackData } from '../../component/Indicator'
|
||||
@ -47,7 +47,7 @@ const stopAndReverse: IndicatorTemplate<Sar> = {
|
||||
}
|
||||
],
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Sar>) => {
|
||||
const params = indicator.calcParams
|
||||
const params = indicator.calcParams as number[]
|
||||
const startAf = params[0] / 100
|
||||
const step = params[1] / 100
|
||||
const maxAf = params[2] / 100
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Trix {
|
||||
trix?: number
|
||||
@ -44,9 +44,9 @@ const tripleExponentiallySmoothedAverage: IndicatorTemplate<Trix> = {
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Trix>) => {
|
||||
const params = indicator.calcParams as number[]
|
||||
let closeSum = 0
|
||||
let ema1: number
|
||||
let ema2: number
|
||||
let oldTr: number
|
||||
let ema1 = 0
|
||||
let ema2 = 0
|
||||
let oldTr = 0
|
||||
let ema1Sum = 0
|
||||
let ema2Sum = 0
|
||||
let trixSum = 0
|
||||
@ -70,7 +70,7 @@ const tripleExponentiallySmoothedAverage: IndicatorTemplate<Trix> = {
|
||||
}
|
||||
ema2Sum += ema2
|
||||
if (i >= params[0] * 3 - 3) {
|
||||
let tr: number
|
||||
let tr = 0
|
||||
let trixValue = 0
|
||||
if (i > params[0] * 3 - 3) {
|
||||
tr = (2 * ema2 + (params[0] - 1) * oldTr) / (params[0] + 1)
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type IndicatorStyle } from '../../common/Styles'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { IndicatorStyle } from '../../common/Styles'
|
||||
import { formatValue } from '../../common/utils/format'
|
||||
import { isValid } from '../../common/utils/typeChecks'
|
||||
|
||||
@ -61,7 +61,7 @@ const volume: IndicatorTemplate<Vol> = {
|
||||
{ key: 'ma3', title: 'MA20: ', type: 'line' },
|
||||
getVolumeFigure()
|
||||
],
|
||||
regenerateFigures: (params: any[]) => {
|
||||
regenerateFigures: (params: unknown[]) => {
|
||||
const figures: Array<IndicatorFigure<Vol>> = params.map((p: number, i: number) => {
|
||||
return { key: `ma${i + 1}`, title: `MA${p}: `, type: 'line' }
|
||||
})
|
||||
@ -69,7 +69,8 @@ const volume: IndicatorTemplate<Vol> = {
|
||||
return figures
|
||||
},
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Vol>) => {
|
||||
const { calcParams: params, figures } = indicator
|
||||
const { calcParams, figures } = indicator
|
||||
const params = calcParams as number[]
|
||||
const volSums: number[] = []
|
||||
return dataList.map((kLineData: KLineData, i: number) => {
|
||||
const volume = kLineData.volume ?? 0
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
interface Vr {
|
||||
vr?: number
|
||||
|
@ -12,8 +12,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type KLineData } from '../../common/Data'
|
||||
import { type Indicator, type IndicatorTemplate } from '../../component/Indicator'
|
||||
import type { KLineData } from '../../common/Data'
|
||||
import type { Indicator, IndicatorTemplate } from '../../component/Indicator'
|
||||
|
||||
import { getMaxMin } from '../../common/utils/number'
|
||||
|
||||
@ -36,13 +36,14 @@ const williamsR: IndicatorTemplate<Wr> = {
|
||||
{ key: 'wr2', title: 'WR2: ', type: 'line' },
|
||||
{ key: 'wr3', title: 'WR3: ', type: 'line' }
|
||||
],
|
||||
regenerateFigures: (params: any[]) => {
|
||||
regenerateFigures: (params: unknown[]) => {
|
||||
return params.map((_, i: number) => {
|
||||
return { key: `wr${i + 1}`, title: `WR${i + 1}: `, type: 'line' }
|
||||
})
|
||||
},
|
||||
calc: (dataList: KLineData[], indicator: Indicator<Wr>) => {
|
||||
const { calcParams: params, figures } = indicator
|
||||
const { calcParams, figures } = indicator
|
||||
const params = calcParams as number[]
|
||||
return dataList.map((kLineData, i) => {
|
||||
const wr: Wr = {}
|
||||
const close = kLineData.close
|
||||
|
@ -15,10 +15,10 @@
|
||||
import { formatThousands, formatFoldDecimal } from '../../common/utils/format'
|
||||
import { isNumber } from '../../common/utils/typeChecks'
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
import { type LineAttrs } from '../figure/line'
|
||||
import { type TextAttrs } from '../figure/text'
|
||||
import type { LineAttrs } from '../figure/line'
|
||||
import type { TextAttrs } from '../figure/text'
|
||||
|
||||
const fibonacciLine: OverlayTemplate = {
|
||||
name: 'fibonacciLine',
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import { isValid } from '../../common/utils/typeChecks'
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
const horizontalRayLine: OverlayTemplate = {
|
||||
name: 'horizontalRayLine',
|
||||
|
@ -12,9 +12,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
import { type LineAttrs } from '../figure/line'
|
||||
import type { LineAttrs } from '../figure/line'
|
||||
|
||||
const horizontalSegment: OverlayTemplate = {
|
||||
name: 'horizontalSegment',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
const horizontalStraightLine: OverlayTemplate = {
|
||||
name: 'horizontalStraightLine',
|
||||
|
@ -15,7 +15,7 @@
|
||||
import type Coordinate from '../../common/Coordinate'
|
||||
import type Bounding from '../../common/Bounding'
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
import { type LineAttrs, getLinearSlopeIntercept } from '../figure/line'
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
import { getParallelLines } from './parallelStraightLine'
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
import { formatThousands, formatFoldDecimal } from '../../common/utils/format'
|
||||
|
||||
|
@ -15,13 +15,13 @@
|
||||
import type Coordinate from '../../common/Coordinate'
|
||||
import type Bounding from '../../common/Bounding'
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
import { getLinearYFromCoordinates, type LineAttrs } from '../figure/line'
|
||||
|
||||
export function getRayLine (coordinates: Coordinate[], bounding: Bounding): LineAttrs | LineAttrs[] {
|
||||
if (coordinates.length > 1) {
|
||||
let coordinate: Coordinate
|
||||
let coordinate = { x: 0, y: 0 }
|
||||
if (coordinates[0].x === coordinates[1].x && coordinates[0].y !== coordinates[1].y) {
|
||||
if (coordinates[0].y < coordinates[1].y) {
|
||||
coordinate = {
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
const segment: OverlayTemplate = {
|
||||
name: 'segment',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
import { isFunction, isValid } from '../../common/utils/typeChecks'
|
||||
import { LineType } from '../../common/Styles'
|
||||
|
||||
@ -23,12 +23,12 @@ const simpleAnnotation: OverlayTemplate = {
|
||||
line: { style: LineType.Dashed }
|
||||
},
|
||||
createPointFigures: ({ overlay, coordinates }) => {
|
||||
let text
|
||||
let text = ''
|
||||
if (isValid(overlay.extendData)) {
|
||||
if (!isFunction(overlay.extendData)) {
|
||||
text = overlay.extendData ?? ''
|
||||
text = (overlay.extendData ?? '') as string
|
||||
} else {
|
||||
text = overlay.extendData(overlay)
|
||||
text = (overlay.extendData(overlay)) as string
|
||||
}
|
||||
}
|
||||
const startX = coordinates[0].x
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import { formatPrecision } from '../../common/utils/format'
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
import { isFunction, isNumber, isValid } from '../../common/utils/typeChecks'
|
||||
|
||||
@ -40,8 +40,8 @@ const simpleTag: OverlayTemplate = {
|
||||
},
|
||||
createYAxisFigures: ({ overlay, coordinates, bounding, yAxis, precision }) => {
|
||||
const isFromZero = yAxis?.isFromZero() ?? false
|
||||
let textAlign: CanvasTextAlign
|
||||
let x: number
|
||||
let textAlign: CanvasTextAlign = 'left'
|
||||
let x = 0
|
||||
if (isFromZero) {
|
||||
textAlign = 'left'
|
||||
x = 0
|
||||
@ -49,12 +49,12 @@ const simpleTag: OverlayTemplate = {
|
||||
textAlign = 'right'
|
||||
x = bounding.width
|
||||
}
|
||||
let text
|
||||
let text = ''
|
||||
if (isValid(overlay.extendData)) {
|
||||
if (!isFunction(overlay.extendData)) {
|
||||
text = overlay.extendData ?? ''
|
||||
text = (overlay.extendData ?? '') as string
|
||||
} else {
|
||||
text = overlay.extendData(overlay)
|
||||
text = overlay.extendData(overlay) as string
|
||||
}
|
||||
}
|
||||
if (!isValid(text) && isNumber(overlay.points[0].value)) {
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import { getLinearYFromCoordinates } from '../figure/line'
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
const straightLine: OverlayTemplate = {
|
||||
name: 'straightLine',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
const verticalRayLine: OverlayTemplate = {
|
||||
name: 'verticalRayLine',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
const verticalSegment: OverlayTemplate = {
|
||||
name: 'verticalSegment',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type OverlayTemplate } from '../../component/Overlay'
|
||||
import type { OverlayTemplate } from '../../component/Overlay'
|
||||
|
||||
const verticalStraightLine: OverlayTemplate = {
|
||||
name: 'verticalStraightLine',
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type DeepPartial from '../../common/DeepPartial'
|
||||
import { type Styles } from '../../common/Styles'
|
||||
import type { Styles } from '../../common/Styles'
|
||||
|
||||
const dark: DeepPartial<Styles> = {
|
||||
grid: {
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import type Nullable from '../../common/Nullable'
|
||||
import type DeepPartial from '../../common/DeepPartial'
|
||||
import { type Styles } from '../../common/Styles'
|
||||
import type { Styles } from '../../common/Styles'
|
||||
|
||||
import light from './light'
|
||||
import dark from './dark'
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type DeepPartial from '../../common/DeepPartial'
|
||||
import { type Styles } from '../../common/Styles'
|
||||
import type { Styles } from '../../common/Styles'
|
||||
|
||||
const light: DeepPartial<Styles> = {
|
||||
grid: {
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type AxisTemplate } from '../../component/Axis'
|
||||
import type { AxisTemplate } from '../../component/Axis'
|
||||
import XAxisImp, { type XAxisConstructor } from '../../component/XAxis'
|
||||
|
||||
import normal from './normal'
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type AxisTemplate } from '../../component/Axis'
|
||||
import type { AxisTemplate } from '../../component/Axis'
|
||||
|
||||
const defaultXAxis: AxisTemplate = {
|
||||
name: 'default'
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type AxisTemplate } from '../../component/Axis'
|
||||
import type { AxisTemplate } from '../../component/Axis'
|
||||
import YAxisImp, { type YAxisConstructor } from '../../component/YAxis'
|
||||
|
||||
import normal from './normal'
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import { log10, index10 } from '../../common/utils/number'
|
||||
import { type AxisTemplate } from '../../component/Axis'
|
||||
import type { AxisTemplate } from '../../component/Axis'
|
||||
|
||||
const logarithm: AxisTemplate = {
|
||||
name: 'logarithm',
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type AxisTemplate } from '../../component/Axis'
|
||||
import type { AxisTemplate } from '../../component/Axis'
|
||||
|
||||
const normal: AxisTemplate = {
|
||||
name: 'normal'
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import { formatPrecision } from '../../common/utils/format'
|
||||
import { isValid } from '../../common/utils/typeChecks'
|
||||
import { type AxisTemplate } from '../../component/Axis'
|
||||
import type { AxisTemplate } from '../../component/Axis'
|
||||
|
||||
const percentage: AxisTemplate = {
|
||||
name: 'percentage',
|
||||
|
@ -81,7 +81,7 @@ function version (): string {
|
||||
*/
|
||||
function init (ds: HTMLElement | string, options?: Options): Nullable<Chart> {
|
||||
logTag()
|
||||
let dom: Nullable<HTMLElement>
|
||||
let dom: Nullable<HTMLElement> = null
|
||||
if (isString(ds)) {
|
||||
dom = document.getElementById(ds)
|
||||
} else {
|
||||
@ -109,11 +109,11 @@ function init (ds: HTMLElement | string, options?: Options): Nullable<Chart> {
|
||||
* @param dcs
|
||||
*/
|
||||
function dispose (dcs: HTMLElement | Chart | string): void {
|
||||
let id: Nullable<string>
|
||||
let id: Nullable<string> = null
|
||||
if (dcs instanceof ChartImp) {
|
||||
id = dcs.id
|
||||
} else {
|
||||
let dom: Nullable<HTMLElement>
|
||||
let dom: Nullable<HTMLElement> = null
|
||||
if (isString(dcs)) {
|
||||
dom = document.getElementById(dcs)
|
||||
} else {
|
||||
|
@ -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>> {
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import type DeepRequired from '../common/DeepRequired'
|
||||
import type Nullable from '../common/Nullable'
|
||||
import { type UpdateLevel } from '../common/Updater'
|
||||
import type { UpdateLevel } from '../common/Updater'
|
||||
import type Bounding from '../common/Bounding'
|
||||
|
||||
import { isValid, merge } from '../common/utils/typeChecks'
|
||||
@ -74,8 +74,8 @@ export default abstract class DrawPane<C extends Axis = Axis> extends Pane {
|
||||
name,
|
||||
...this._options.axis
|
||||
})
|
||||
let container: HTMLElement
|
||||
let cursor: string
|
||||
let container: Nullable<HTMLElement> = null
|
||||
let cursor = 'default'
|
||||
if (this.getId() === PaneIdConstants.X_AXIS) {
|
||||
container = this.getMainWidget().getContainer()
|
||||
cursor = 'ew-resize'
|
||||
|
@ -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'
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type AxisCreate } from '../component/Axis'
|
||||
import type { AxisCreate } from '../component/Axis'
|
||||
|
||||
export const enum PanePosition {
|
||||
Top = 'top',
|
||||
|
@ -21,7 +21,7 @@ export default class ActionStore {
|
||||
*/
|
||||
private readonly _actions = new Map<ActionType, Action>()
|
||||
|
||||
execute (type: ActionType, data?: any): void {
|
||||
execute (type: ActionType, data?: unknown): void {
|
||||
this._actions.get(type)?.execute(data)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type Nullable from '../common/Nullable'
|
||||
import { type KLineData, type VisibleData } from '../common/Data'
|
||||
import type { KLineData, VisibleData } from '../common/Data'
|
||||
import type Precision from '../common/Precision'
|
||||
import type DeepPartial from '../common/DeepPartial'
|
||||
import { formatValue } from '../common/utils/format'
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import type Nullable from '../common/Nullable'
|
||||
import { UpdateLevel } from '../common/Updater'
|
||||
import { type MouseTouchEvent } from '../common/SyntheticEvent'
|
||||
import type { MouseTouchEvent } from '../common/SyntheticEvent'
|
||||
import { isFunction, isValid, isString, isBoolean } from '../common/utils/typeChecks'
|
||||
import { createId } from '../common/utils/id'
|
||||
import { LoadDataType } from '../common/LoadDataCallback'
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import type Nullable from '../common/Nullable'
|
||||
import type Coordinate from '../common/Coordinate'
|
||||
import { type KLineData } from '../common/Data'
|
||||
import type { KLineData } from '../common/Data'
|
||||
import type BarSpace from '../common/BarSpace'
|
||||
import type VisibleRange from '../common/VisibleRange'
|
||||
import { getDefaultVisibleRange } from '../common/VisibleRange'
|
||||
@ -81,17 +81,17 @@ export default class TimeScaleStore {
|
||||
/**
|
||||
* Scale enabled flag
|
||||
*/
|
||||
private _zoomEnabled: boolean = true
|
||||
private _zoomEnabled = true
|
||||
|
||||
/**
|
||||
* Scroll enabled flag
|
||||
*/
|
||||
private _scrollEnabled: boolean = true
|
||||
private _scrollEnabled = true
|
||||
|
||||
/**
|
||||
* Total space of drawing area
|
||||
*/
|
||||
private _totalBarSpace: number = 0
|
||||
private _totalBarSpace = 0
|
||||
|
||||
/**
|
||||
* Space occupied by a single piece of data
|
||||
@ -266,8 +266,8 @@ export default class TimeScaleStore {
|
||||
const totalBarCount = dataList.length
|
||||
const visibleBarCount = this._totalBarSpace / this._barSpace
|
||||
|
||||
let leftMinVisibleBarCount: number
|
||||
let rightMinVisibleBarCount: number
|
||||
let leftMinVisibleBarCount = 0
|
||||
let rightMinVisibleBarCount = 0
|
||||
|
||||
if (this._scrollLimitRole === ScrollLimitRole.Distance) {
|
||||
leftMinVisibleBarCount = (this._totalBarSpace - this._maxOffsetDistance.right) / this._barSpace
|
||||
@ -521,7 +521,7 @@ export default class TimeScaleStore {
|
||||
const crosshair = this._chartStore.getTooltipStore().getCrosshair()
|
||||
zoomCoordinate = { x: crosshair?.x ?? this._totalBarSpace / 2 }
|
||||
}
|
||||
const x = zoomCoordinate!.x!
|
||||
const x = zoomCoordinate.x!
|
||||
const floatIndex = this.coordinateToFloatIndex(x)
|
||||
const prevBarSpace = this._barSpace
|
||||
const barSpace = this._barSpace + scale * (this._barSpace / SCALE_MULTIPLIER)
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
import type Nullable from '../common/Nullable'
|
||||
import { type KLineData } from '../common/Data'
|
||||
import type { KLineData } from '../common/Data'
|
||||
import type Crosshair from '../common/Crosshair'
|
||||
import { UpdateLevel } from '../common/Updater'
|
||||
import { isNumber } from '../common/utils/typeChecks'
|
||||
@ -43,8 +43,8 @@ export default class TooltipStore {
|
||||
setCrosshair (crosshair?: Crosshair, notInvalidate?: boolean): void {
|
||||
const dataList = this._chartStore.getDataList()
|
||||
const cr = crosshair ?? {}
|
||||
let realDataIndex: number
|
||||
let dataIndex: number
|
||||
let realDataIndex = 0
|
||||
let dataIndex = 0
|
||||
if (isNumber(cr.x)) {
|
||||
realDataIndex = this._chartStore.getTimeScaleStore().coordinateToDataIndex(cr.x)
|
||||
if (realDataIndex < 0) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user