datafeed fixes; line drawing fix

This commit is contained in:
tim
2024-09-03 23:34:03 -04:00
parent bdad4c7257
commit 5afdc83957
9 changed files with 80 additions and 68 deletions

View File

@@ -1,4 +1,5 @@
import {useChartOrderStore} from "@/orderbuild.js";
import {unique} from "@/misc.js";
// Sunday January 4th, 2009 just before Bitcoin Genesis
@@ -22,3 +23,39 @@ export function pointsToTvOhlcStart(points, periodSeconds=null) {
return {time: nearestOhlcStart(p.time, periodSeconds), price: p.price}
})
}
export function dirtyPoints(pointsA, pointsB) {
if (pointsA === undefined)
return true
if (pointsB === undefined)
return false
if (pointsB === null)
return pointsA !== null
if (pointsA === null)
return pointsB.length > 0
if (pointsA.length !== pointsB.length)
return true
for (const i in pointsA) {
const a = pointsA[i]
const b = pointsB[i]
if (a === null && b !== null || a !== null && b === null ||
a.time !== b.time || a.price !== b.price)
return true
}
return false
} // B is modifying A
function dirtyKeys(propsA, propsB) {
if (propsB === null)
return propsA === null ? [] : [...Object.keys(propsA)]
if (propsA === null)
return [...Object.keys(propsB)]
const keys = unique([...Object.keys(propsA), ...Object.keys(propsB)])
return keys.filter((k) => propsB[k] !== undefined && (!(k in propsA) || propsA[k] !== propsB[k]))
}
export function dirtyItems(a, b) {
const result = {}
for (const k of dirtyKeys(a, b))
result[k] = b[k]
return result
}