From 49b41450c3560025fc6f8b51d1604c1b9728cd70 Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 4 May 2024 23:08:59 -0400 Subject: [PATCH] diagonal rungs are drawing. just need tranches. --- src/blockchain/wallet.js | 2 +- src/charts/chart.js | 2 +- src/charts/shape.js | 54 ++++++++++++++++-------- src/components/chart/DiagonalBuilder.vue | 7 +-- src/components/chart/RungBuilder.vue | 19 ++++++--- src/vector.js | 5 +++ 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/src/blockchain/wallet.js b/src/blockchain/wallet.js index bda3969..37f4be7 100644 --- a/src/blockchain/wallet.js +++ b/src/blockchain/wallet.js @@ -2,8 +2,8 @@ import {BrowserProvider, ethers} from "ethers"; import {useStore} from "@/store/store"; import {socket} from "@/socket.js"; import {contractOrNull, vaultAddress} from "@/blockchain/contract.js"; -import {vaultAbi} from "@/blockchain/abi.js"; import {SingletonCoroutine, uuid} from "@/misc.js"; +import {vaultAbi} from "@/blockchain/abi.js"; import {defineStore} from "pinia"; import {ref} from "vue"; import {metadataMap} from "@/version.js"; diff --git a/src/charts/chart.js b/src/charts/chart.js index 2808ce4..9312cd3 100644 --- a/src/charts/chart.js +++ b/src/charts/chart.js @@ -157,7 +157,7 @@ export function drawShape(shapeType, ...callbacks) { export function createShape(shapeType, points, options={}, ...callbacks) { drawingCallbacks = null - co.drawing = false + cancelDrawing() options.shape = shapeType.code // programatically adds a shape to the chart let shapeId diff --git a/src/charts/shape.js b/src/charts/shape.js index 3962a56..161f019 100644 --- a/src/charts/shape.js +++ b/src/charts/shape.js @@ -212,8 +212,8 @@ export class Shape { onCreate(points, props) { // the user has finished creating all the control points. drawing mode is exited and the initial shape is created. - this.tvPoints = points - this.tvProps = props + this.setPoints(points) + this.setProps(props) } @@ -327,18 +327,35 @@ export class Shape { let lineChangeInfo = null function dirtyPoints(pointsA, pointsB) { - if (pointsB===null || pointsB===undefined) - return pointsA !== null && pointsA !== undefined - if (pointsA===null || pointsA===undefined) + const result = dirtyPoints2(pointsA,pointsB) + console.error('dirtyPoints', result, pointsA, pointsB) + return result +} +function dirtyPoints2(pointsA, pointsB) { + console.log('dp2', pointsA, pointsB) + if (pointsA === undefined) + return true + console.log('dp2b') + if (pointsB === undefined) + return false + console.log('dp2c') + if (pointsB===null) + return pointsA !== null + console.log('dp2d') + if (pointsA===null) return pointsB.length > 0 + console.log('dp2e') if (pointsA.length!==pointsB.length) return true + console.log('dp2f') for (const i in pointsA) { const a = pointsA[i] const b = pointsB[i] - if ( a.time !== b.time || a.price !== b.price ) + if ( a === null && b !== null || a !== null && b === null || + a.time !== b.time || a.price !== b.price ) return true } + console.log('dp3') return false } @@ -537,8 +554,6 @@ export class DLine extends Line { constructor(model, onModel=null, onDelete=null, props=null) { super(ShapeType.Line, onModel, onDelete, props) - this.debug = true // todo debug - // Model this.model.pointA = null // {time:..., price:...} this.model.pointB = null @@ -555,27 +570,30 @@ export class DLine extends Line { } setModel(model) { - console.log('DLine setModel', {...this.model}, {...model}) + console.log("DLine setModel", {...this.model}, {...model}) super.setModel(model) - if (model.pointA === null || model.pointB === null) + if (model.pointA === null && model.pointB === null) this.delete() - else if ( - dirtyPoints(this.model.pointA, model.pointA) || - dirtyPoints(this.model.pointB, model.pointB) - ) { - this.model.pointA = model.pointA - this.model.pointB = model.pointB - this.setPoints([model.pointA, model.pointB]) + 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) + } } } onPoints(points) { let dirty = this.tvPoints === null for (let i=0; !dirty && i - (Diagonals) + {{ endpoints }}