/** * ___ ___ ___ ___ ___ ___ ___ ___ ___ * /\__\ /\__\ ___ /\__\ /\ \ /\ \ /\__\ /\ \ /\ \ /\ \ * /:/ / /:/ / /\ \ /::| | /::\ \ /::\ \ /:/ / /::\ \ /::\ \ \:\ \ * /:/__/ /:/ / \:\ \ /:|:| | /:/\:\ \ /:/\:\ \ /:/__/ /:/\:\ \ /:/\:\ \ \:\ \ * /::\__\____ /:/ / /::\__\ /:/|:| |__ /::\~\:\ \ /:/ \:\ \ /::\ \ ___ /::\~\:\ \ /::\~\:\ \ /::\ \ * /:/\:::::\__\ /:/__/ __/:/\/__/ /:/ |:| /\__\ /:/\:\ \:\__\ /:/__/ \:\__\ /:/\:\ /\__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/\:\__\ * \/_|:|~~|~ \:\ \ /\/:/ / \/__|:|/:/ / \:\~\:\ \/__/ \:\ \ \/__/ \/__\:\/:/ / \/__\:\/:/ / \/_|::\/:/ / /:/ \/__/ * |:| | \:\ \ \::/__/ |:/:/ / \:\ \:\__\ \:\ \ \::/ / \::/ / |:|::/ / /:/ / * |:| | \:\ \ \:\__\ |::/ / \:\ \/__/ \:\ \ /:/ / /:/ / |:|\/__/ \/__/ * |:| | \:\__\ \/__/ /:/ / \:\__\ \:\__\ /:/ / /:/ / |:| | * \|__| \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \|__| * * 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 { LineType, PolygonType, TooltipShowRule, TooltipShowType, TooltipIconPosition, CandleType, YAxisPosition, YAxisType, CandleTooltipRectPosition, } from './common/Styles'; import type Nullable from './common/Nullable'; 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 { calcTextWidth } from './common/utils/canvas'; import { ActionType } from './common/Action'; import { IndicatorSeries } from './component/Indicator'; import { OverlayMode } from './component/Overlay'; import { type Options, FormatDateType } from './Options'; import ChartImp, { type Chart, DomPosition } from './Chart'; import { checkCoordinateOnArc, drawArc } from './extension/figure/arc'; import { checkCoordinateOnCircle, drawCircle } from './extension/figure/circle'; import { checkCoordinateOnLine, drawLine, getLinearYFromSlopeIntercept, getLinearSlopeIntercept, getLinearYFromCoordinates, } from './extension/figure/line'; import { checkCoordinateOnPolygon, drawPolygon, } from './extension/figure/polygon'; import { checkCoordinateOnRect, drawRect } from './extension/figure/rect'; import { drawRectText } from './extension/figure/rectText'; import { checkCoordinateOnText, drawText } from './extension/figure/text'; import { registerFigure, getSupportedFigures, getFigureClass, } from './extension/figure/index'; import { registerIndicator, getSupportedIndicators, } from './extension/indicator/index'; import { registerLocale, getSupportedLocales } from './extension/i18n/index'; import { registerOverlay, getOverlayClass, getSupportedOverlays, } from './extension/overlay/index'; import { registerStyles } from './extension/styles/index'; import { registerYAxis } from './extension/y-axis/index'; import { registerXAxis } from './extension/x-axis/index'; const instances = new Map(); let chartBaseId = 1; /** * Chart version * @return {string} */ function version(): string { return '__VERSION__'; } /** * Init chart instance * @param ds * @param options * @returns {Chart} */ function init(ds: HTMLElement | string, options?: Options): Nullable { logTag(); let dom: Nullable; if (isString(ds)) { dom = document.getElementById(ds); } else { dom = ds; } if (dom === null) { logError( '', '', 'The chart cannot be initialized correctly. Please check the parameters. The chart container cannot be null and child elements need to be added!!!', ); return null; } let chart = instances.get(dom.id); if (isValid(chart)) { logWarn('', '', 'The chart has been initialized on the dom!!!'); return chart; } const id = `k_line_chart_${chartBaseId++}`; chart = new ChartImp(dom, options); chart.id = id; dom.setAttribute('k-line-chart-id', id); instances.set(id, chart); return chart; } /** * Destroy chart instance * @param dcs */ function dispose(dcs: HTMLElement | Chart | string): void { let id: Nullable; if (dcs instanceof ChartImp) { id = dcs.id; } else { let dom: Nullable; if (isString(dcs)) { dom = document.getElementById(dcs); } else { dom = dcs as HTMLElement; } id = dom?.getAttribute('k-line-chart-id') ?? null; } if (id !== null) { instances.get(id)?.destroy(); instances.delete(id); } } const utils = { clone, merge, isString, isNumber, isValid, isObject, isArray, isFunction, isBoolean, formatValue, formatPrecision, formatBigNumber, formatDate, formatThousands, formatFoldDecimal, calcTextWidth, getLinearSlopeIntercept, getLinearYFromSlopeIntercept, getLinearYFromCoordinates, checkCoordinateOnArc, checkCoordinateOnCircle, checkCoordinateOnLine, checkCoordinateOnPolygon, checkCoordinateOnRect, checkCoordinateOnText, drawArc, drawCircle, drawLine, drawPolygon, drawRect, drawText, drawRectText, }; export { version, init, dispose, registerFigure, getSupportedFigures, getFigureClass, registerIndicator, getSupportedIndicators, registerOverlay, getSupportedOverlays, getOverlayClass, registerLocale, getSupportedLocales, registerStyles, registerXAxis, registerYAxis, utils, LineType, PolygonType, TooltipShowRule, TooltipShowType, TooltipIconPosition, CandleTooltipRectPosition, CandleType, YAxisPosition, YAxisType, FormatDateType, DomPosition, ActionType, IndicatorSeries, OverlayMode, };