Skip to content

Commit

Permalink
DC sampler improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
C451 committed Dec 15, 2020
1 parent 2447812 commit 4a9cedd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/Chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export default {
if (this._hook_xlocked) this.ce('?x-locked', state)
},
calc_interval() {
if (this.ohlcv.length < 2) return
let tf = Utils.parse_tf(this.forced_tf)
if (this.ohlcv.length < 2 && !tf) return
this.interval_ms = tf || Utils.detect_interval(this.ohlcv)
this.interval = this.$props.ib ? 1 : this.interval_ms
Utils.warn(
Expand Down
12 changes: 9 additions & 3 deletions src/helpers/dc_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,16 @@ export default class DCCore extends DCEvents {
let tick = data['price']
let volume = data['volume'] || 0
let tf = this.tv.$refs.chart.interval_ms
let t_next = last[0] + tf
if (!tf) {
return console.warn('Define the main timeframe')
}
let now = data.t || Utils.now()
if (!last) last = [now - now % tf]
let t_next = last[0] + tf

let t = now >= t_next ? (now - now % tf) : last[0]

if (t >= t_next && tick !== undefined) {
if ((t >= t_next || !ohlcv.length) && tick !== undefined) {
// And new zero-height candle
let nc = [t, tick, tick, tick, tick, volume]
this.agg.push('ohlcv', nc, tf)
Expand Down Expand Up @@ -484,7 +488,9 @@ export default class DCCore extends DCEvents {

scroll_to(t) {
if (this.tv.$refs.chart.cursor.locked) return
let tl = this.tv.$refs.chart.last_candle[0]
let last = this.tv.$refs.chart.last_candle
if (!last) return
let tl = last[0]
let d = this.tv.getRange()[1] - tl
if (d > 0) this.tv.goto(t + d)
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/dc_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export default class DCEvents {
}

set_loading(flag) {
let skrr = dc.get('.').filter(x => x.settings.$props)
let skrr = this.get('.').filter(x => x.settings.$props)
for (var s of skrr) {
this.merge(`${s.id}`, { loading: flag })
}
Expand Down
2 changes: 1 addition & 1 deletion test/tests/DataHelper/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Stream(url) {
data = JSON.parse(data.data)
cb(data)
} catch(e) {
console.log(e.toString())
console.log(e)
}
}

Expand Down

0 comments on commit 4a9cedd

Please sign in to comment.