MCPcopy
hub / github.com/klinecharts/KLineChart / createDataLoader

Function createDataLoader

debug/main.js:137–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

135}
136
137function createDataLoader () {
138 return {
139 getBars: ({ type, timestamp, period, callback }) => {
140 let dataList = []
141 switch (type) {
142 case 'init': {
143 const duration = getPeriodDuration(period)
144 dataList = createBackDataList(2680, (timestamp ?? Date.now()) - LOAD_BAR_COUNT * duration, period)
145 break
146 }
147 case 'forward': {
148 const historyDataList = chart.getDataList()
149 const firstData = historyDataList[0]
150 dataList = createForwardDataList(firstData.open, timestamp, period)
151 break
152 }
153 case 'backward': {
154 const historyDataList = chart.getDataList()
155 const lastData = historyDataList[historyDataList.length - 1]
156 dataList = createBackDataList(lastData.close, timestamp, period)
157 break
158 }
159 }
160 // callback(dataList, { forward: true, backward: true })
161 setTimeout(() => {
162 callback(dataList, { forward: true, backward: true })
163 }, 1000)
164 },
165 subscribeBar: ({ period, callback }) => {
166 },
167 unsubscribeBar: () => {
168 }
169 }
170}
171
172function switchPeriod (periodKey) {
173 const config = PERIODS.find(({ key }) => key === periodKey)

Callers 1

mountChartFunction · 0.85

Calls 4

getPeriodDurationFunction · 0.85
createBackDataListFunction · 0.85
createForwardDataListFunction · 0.85
getDataListMethod · 0.45

Tested by

no test coverage detected