Skip to content

Commit

Permalink
Partially fixes time gaps bug
Browse files Browse the repository at this point in the history
  • Loading branch information
C451 committed Apr 26, 2019
1 parent 056b3aa commit f482119
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/components/js/grid_maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,13 @@ function GridMaker(id, params, master_grid = null) {

self.t_step = time_step()
self.xs = []
const dt = range[1] - range[0]
const r = self.spacex / dt

// TODO: IMPORTANT missing candles. Will not work
// Solution: use t2sreen() to convert timestamps
// to screen coordinates. Also need to check how
// the whole thing works with missing data points.
for (var i = 0; i < sub.length; i++) {
let p = sub[i]
if (p[0] % self.t_step === 0) {
let x = Math.floor(self.startx + i * self.px_step)
let x = Math.floor((p[0] - range[0]) * r)
self.xs.push([x, p])
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/components/js/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ function Layout(params) {

}

function t2screen(t) {
const dt = range[1] - range[0]
const r = self.spacex / dt
return Math.floor((t - range[0]) * r)
}

function candles_n_vol() {

self.candles = []
Expand All @@ -59,16 +65,20 @@ function Layout(params) {

for (var i = 0; i < sub.length; i++) {
let p = sub[i]
mid = t2screen(p[0])
self.candles.push({
x: self.startx + i * self.px_step,
x: mid,
w: self.px_step * CANDLEW,
o: p[1] * self.A + self.B,
h: p[2] * self.A + self.B,
l: p[3] * self.A + self.B,
c: p[4] * self.A + self.B,
sent: p
})
mid = self.startx + i * self.px_step
// Clear volume bar if there is a time gap
if (sub[i-1] && p[0] - sub[i-1][0] > interval) {
prev = null
}
x1 = prev || Math.floor(mid - self.px_step * 0.5)
x2 = Math.floor(mid + self.px_step * 0.5) - 0.5
self.volume.push({
Expand Down
3 changes: 1 addition & 2 deletions src/components/js/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ class CursorUpdater {
}

// Nearest datapoints
// TODO: switch to screen2t() method for ohlcv
cursor_data(grid, e) {

const data = this.comp.main_section.sub

let xs = data.map((x, i) => grid.startx + i * grid.px_step)
let xs = data.map((x, i) => grid.t2screen(x[0]) + 0.5)
let i = Utils.nearest_a(e.x, xs)[0]
if (!xs[i]) return {}
return {
Expand Down

0 comments on commit f482119

Please sign in to comment.