From bf39ed946c3f5f7f610fde5ff0430517a3b89cff Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 13 May 2024 16:32:16 -0400 Subject: [PATCH] diagonals working --- src/charts/chart-misc.js | 13 ++++ src/charts/shape.js | 31 +++++--- src/components/chart/DiagonalBuilder.vue | 95 ++++++++++++++++++++++-- src/components/chart/RungBuilder.vue | 12 ++- src/misc.js | 12 --- 5 files changed, 132 insertions(+), 31 deletions(-) create mode 100644 src/charts/chart-misc.js diff --git a/src/charts/chart-misc.js b/src/charts/chart-misc.js new file mode 100644 index 0000000..9e42f9d --- /dev/null +++ b/src/charts/chart-misc.js @@ -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} + }) +} \ No newline at end of file diff --git a/src/charts/shape.js b/src/charts/shape.js index 6cd0d7f..005b667 100644 --- a/src/charts/shape.js +++ b/src/charts/shape.js @@ -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}) + } } diff --git a/src/components/chart/DiagonalBuilder.vue b/src/components/chart/DiagonalBuilder.vue index bf1455d..ae98f63 100644 --- a/src/components/chart/DiagonalBuilder.vue +++ b/src/components/chart/DiagonalBuilder.vue @@ -3,11 +3,27 @@ :shape="DLine" :mode="0" :get-model-value="getModelValue" :set-model-value="setModelValue" :set-values="setLines" :set-weights="setWeights" + :set-shapes="setShapes" :std-width="stdWidth" :build-tranches="buildTranches"> - + + + + + @@ -19,7 +35,10 @@ label="Price" /> - +
Line A  +
+ + Extend + +
+
Line A {{ allocationTexts[weights.length-1] }} + {{ allocationTexts[weights.length-1] }} +
@@ -75,16 +94,13 @@