Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@klinecharts/pro",
"name": "@hasee_hive/klinecharts-pro",
"version": "0.1.1",
"description": "Financial chart built out of the box based on KLineChart.",
"type": "module",
Expand Down
55 changes: 31 additions & 24 deletions src/ChartProComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface PrevSymbolPeriod {
period: Period
}

function createIndicator (widget: Nullable<Chart>, indicatorName: string, isStack?: boolean, paneOptions?: PaneOptions): Nullable<string> {
function createIndicator(widget: Nullable<Chart>, indicatorName: string, isStack?: boolean, paneOptions?: PaneOptions): Nullable<string> {
if (indicatorName === 'VOL') {
paneOptions = { gap: { bottom: 2 }, ...paneOptions }
}
Expand Down Expand Up @@ -101,21 +101,6 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {
visible: false, indicatorName: '', paneId: '', calcParams: [] as Array<any>
})

props.ref({
setTheme,
getTheme: () => theme(),
setStyles,
getStyles: () => widget!.getStyles(),
setLocale,
getLocale: () => locale(),
setTimezone: (timezone: string) => { setTimezone({ key: timezone, text: translateTimezone(props.timezone, locale()) }) },
getTimezone: () => timezone().key,
setSymbol,
getSymbol: () => symbol(),
setPeriod,
getPeriod: () => period()
})

const documentResize = () => {
widget?.resize()
}
Expand Down Expand Up @@ -211,6 +196,28 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {
}
})

props.ref({
setTheme,
getTheme: () => theme(),
setStyles,
getStyles: () => widget!.getStyles(),
setLocale,
getLocale: () => locale(),
setTimezone: (timezone: string) => { setTimezone({ key: timezone, text: translateTimezone(props.timezone, locale()) }) },
getTimezone: () => timezone().key,
setSymbol,
getSymbol: () => symbol(),
setPeriod,
getPeriod: () => period(),
applyNewData: (data: any) => {
console.log(widget);
widget!.applyNewData(data);
},
getKLineChartWidget: () => {
return widget;
}
})

if (widget) {
const watermarkContainer = widget.getDom('candle_pane', DomPosition.Main)
if (watermarkContainer) {
Expand Down Expand Up @@ -440,13 +447,13 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {

return (
<>
<i class="icon-close klinecharts-pro-load-icon"/>
<i class="icon-close klinecharts-pro-load-icon" />
<Show when={symbolSearchModalVisible()}>
<SymbolSearchModal
locale={props.locale}
datafeed={props.datafeed}
onSymbolSelected={symbol => { setSymbol(symbol) }}
onClose={() => { setSymbolSearchModalVisible(false) }}/>
onClose={() => { setSymbolSearchModalVisible(false) }} />
</Show>
<Show when={indicatorModalVisible()}>
<IndicatorModal
Expand Down Expand Up @@ -481,7 +488,7 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {
}
}
setSubIndicators(newSubIndicators)
}}/>
}} />
</Show>
<Show when={timezoneModalVisible()}>
<TimezoneModal
Expand Down Expand Up @@ -521,7 +528,7 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {
locale={props.locale}
params={indicatorSettingModalParams()}
onClose={() => { setIndicatorSettingModalParams({ visible: false, indicatorName: '', paneId: '', calcParams: [] }) }}
onConfirm={(params)=> {
onConfirm={(params) => {
const modalParams = indicatorSettingModalParams()
widget?.overrideIndicator({ name: modalParams.indicatorName, calcParams: params }, modalParams.paneId)
}}
Expand All @@ -537,7 +544,7 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {
try {
await startTransition(() => setDrawingBarVisible(!drawingBarVisible()))
widget?.resize()
} catch (e) {}
} catch (e) { }
}}
onSymbolClick={() => { setSymbolSearchModalVisible(!symbolSearchModalVisible()) }}
onPeriodChange={setPeriod}
Expand All @@ -554,7 +561,7 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {
<div
class="klinecharts-pro-content">
<Show when={loadingVisible()}>
<Loading/>
<Loading />
</Show>
<Show when={drawingBarVisible()}>
<DrawingBar
Expand All @@ -563,12 +570,12 @@ const ChartProComponent: Component<ChartProComponentProps> = props => {
onModeChange={mode => { widget?.overrideOverlay({ mode: mode as OverlayMode }) }}
onLockChange={lock => { widget?.overrideOverlay({ lock }) }}
onVisibleChange={visible => { widget?.overrideOverlay({ visible }) }}
onRemoveClick={(groupId) => { widget?.removeOverlay({ groupId }) }}/>
onRemoveClick={(groupId) => { widget?.removeOverlay({ groupId }) }} />
</Show>
<div
ref={widgetRef}
class='klinecharts-pro-widget'
data-drawing-bar-visible={drawingBarVisible()}/>
data-drawing-bar-visible={drawingBarVisible()} />
</div>
</>
)
Expand Down
8 changes: 8 additions & 0 deletions src/KLineChartPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ export default class KLineChartPro implements ChartPro {
getPeriod (): Period {
return this._chartApi!.getPeriod()
}

applyNewData (data: any): void {
this._chartApi!.applyNewData(data);
}

getKLineChartWidget () {
return this._chartApi!.getKLineChartWidget();
}
}
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

import { KLineData, Styles, DeepPartial } from 'klinecharts'
import { KLineData, Styles, DeepPartial, Chart, Nullable } from 'klinecharts'

export interface SymbolInfo {
ticker: string
Expand Down Expand Up @@ -71,4 +71,6 @@ export interface ChartPro {
getSymbol(): SymbolInfo
setPeriod(period: Period): void
getPeriod(): Period
applyNewData(data : any): void
getKLineChartWidget(): Nullable<Chart>
}
16 changes: 16 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

import { defineConfig } from 'vite'
import solidPlugin from 'vite-plugin-solid'
import path from "path"


export default defineConfig({
plugins: [solidPlugin()],
resolve: {
alias: {
"@klinecharts/pro": path.resolve(__dirname, "../pro/src"),
},
},
optimizeDeps: {
exclude: ["@klinecharts/pro"], // important — prevent prebundling
},
server: {
fs: {
// allow vite to serve files outside project root
allow: [".."],
},
},
build: {
cssTarget: 'chrome61',
sourcemap: true,
Expand Down