diagonals working

This commit is contained in:
Tim
2024-05-13 16:32:16 -04:00
parent c7549e2f99
commit bf39ed946c
5 changed files with 132 additions and 31 deletions

13
src/charts/chart-misc.js Normal file
View File

@@ -0,0 +1,13 @@
import {useChartOrderStore} from "@/orderbuild.js";
export function nearestOhlcStart(time) {
// todo subtract OHLC root time
const period = useChartOrderStore().intervalSecs
return Math.round(time / period) * period
}
export function pointsToOhlcStart(points) {
return points === null ? null : points.map((p) => {
return {time: nearestOhlcStart(p.time), price: p.price}
})
}

View File

@@ -2,9 +2,10 @@
import {invokeCallback, mixin} from "@/common.js";
import {chart, createShape, deleteShapeId, dragging, draggingShapeIds, drawShape, widget} from "@/charts/chart.js";
import {pointsToOhlcStart, unique} from "@/misc.js";
import {unique} from "@/misc.js";
import {allocationText} from "@/orderbuild.js";
import Color from "color";
import {pointsToOhlcStart} from "@/charts/chart-misc.js";
//
@@ -544,6 +545,8 @@ export class DLine extends Line {
// Model
this.model.pointA = null // {time:..., price:...}
this.model.pointB = null
this.model.extendLeft = false
this.model.extendRight = false
this.setModel(model) // call setModel at the end
}
@@ -551,8 +554,8 @@ export class DLine extends Line {
drawingOverrides() {
const result = super.drawingOverrides();
result.extendLeft = false
result.extendRight = false
result.extendLeft = this.model.extendLeft
result.extendRight = this.model.extendRight
return result
}
@@ -567,14 +570,17 @@ export class DLine extends Line {
super.setModel(model)
if (model.pointA === null && model.pointB === null)
this.delete()
else if ('pointA' in model && 'pointB' in model) {
const newPoints = [model.pointA, model.pointB];
const oldPoints = [this.model.pointA, this.model.pointB];
if (dirtyPoints(oldPoints, newPoints)) {
this.model.pointA = newPoints[0]
this.model.pointB = newPoints[1]
this.setPoints(newPoints)
else {
if ('pointA' in model && 'pointB' in model) {
const newPoints = [model.pointA, model.pointB];
const oldPoints = [this.model.pointA, this.model.pointB];
if (dirtyPoints(oldPoints, newPoints)) {
this.model.pointA = newPoints[0]
this.model.pointB = newPoints[1]
this.setPoints(newPoints)
}
}
this.setProps({extendLeft:model.extendLeft, extendRight: model.extendRight})
}
}
@@ -589,4 +595,9 @@ export class DLine extends Line {
this.updateModel({pointA: points[0], pointB: points[1]})
}
}
onProps(props) {
super.onProps(props);
this.updateModel({extendLeft: props.extendLeft, extendRight: props.extendRight})
}
}