Skip to content

Commit 935bb9f

Browse files
committed
Add global time => index search, fix #185
1 parent 239fde0 commit 935bb9f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/TradingVue.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export default {
269269
// TODO: limit goto & setRange (out of data error)
270270
if (this.chart_props.ib) {
271271
const ti_map = this.$refs.chart.ti_map
272-
t = ti_map.smth2i(t)
272+
t = ti_map.gt2i(t, this.$refs.chart.ohlcv)
273273
}
274274
this.$refs.chart.goto(t)
275275
},

src/components/js/ti_mapping.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,20 @@ export default class TI {
225225
}
226226
}
227227

228+
// Global Time => Index (uses all data, approx. method)
229+
// Used by tv.goto()
230+
gt2i(smth, ohlcv) {
231+
if (smth > MAX_ARR) {
232+
let E = 0.1 // Fixes the arrayslicer bug
233+
let [i1, i2] = Utils.fast_nearest(ohlcv, smth+E)
234+
if (typeof i1 === 'number') {
235+
return i1
236+
} else {
237+
return this.t2i(smth) // fallback
238+
}
239+
} else {
240+
return smth // it was an index
241+
}
242+
}
243+
228244
}

0 commit comments

Comments
 (0)