This commit is contained in:
Tim
2024-02-08 16:24:54 -04:00
parent 1e426e8dd7
commit 5184a91bde
4 changed files with 48 additions and 38 deletions

View File

@@ -137,7 +137,7 @@ export function drawShape(shapeType, ...callbacks) {
}
export function createShape(shapeType, points, options, ...callbacks) {
export function createShape(shapeType, points, options={}, ...callbacks) {
const co = useChartOrderStore()
co.drawingCallbacks = null
co.drawing = false
@@ -205,7 +205,11 @@ function onSelectedLineToolChanged() {
}
function handleDrawingEvent(id, event) {
// console.log('drawing event', id, event)
setTimeout(()=>doHandleDrawingEvent(id,event), 0)
}
function doHandleDrawingEvent(id, event) {
console.log('drawing event', arguments)
const shape = event === 'remove' ? null : chart.getShapeById(id);
if (event === 'create') {
const co = useChartOrderStore();

View File

@@ -47,6 +47,7 @@ class Shape {
if (onDelete !== null )
this.onDelete = onDelete
this.lock = 0 // used to prevent callbacks when we are the ones forcing the chart change
this.pointsLock = 0
this.propsLock = 0
this.create()
}
@@ -89,6 +90,7 @@ class Shape {
setModel(model) {
console.log('setModel', model, this.id)
for( const [k,v] of Object.entries(model))
this.model[k] = v
this.setPoints(this.pointsFromModel());
@@ -97,19 +99,23 @@ class Shape {
setPoints(points) {
invokeCallback(this, 'onPoints', points)
if (points !== null && points.length)
// invokeCallback(this, 'onPoints', points)
if (points !== null && points.length) {
if (this.id === null)
this.doCreate(points)
else
updatePoints(this, points)
else {
this.pointsLock++
chart.getShapeById(this.id).setPoints(points)
}
}
}
setProps(props) {
invokeCallback(this, 'onProps', props)
// invokeCallback(this, 'onProps', props)
if(this.id) {
updateProps(this, props)
this.propsLock++
chart.getShapeById(this.id).setProperties(props)
}
}
@@ -167,23 +173,6 @@ class Shape {
}
function updatePoints(shape, points) {
shape.lock++
try {
chart.getShapeById(shape.id).setPoints(points)
}
finally {
shape.lock--
}
}
function updateProps(shape, props) {
chart.getShapeById(shape.id).setProperties(props)
shape.propsLock++
}
// B is modifying A
function dirtyProps(propsA, propsB) {
if (propsB===null)
@@ -212,11 +201,17 @@ class ShapeTVCallbacks {
}
onPoints(shapeId, points) {
console.log(`shapetvcb ${shapeId} onPoints`, points, this.shape.lock)
this.shape.points = points
if( this.shape.lock ) return
this.shape.onPoints(points)
this.shape.pointsToModel()
this.shape.onModel(this.shape.model)
if( this.shape.pointsLock ) {
this.shape.pointsLock--
return
}
setTimeout(()=>{
this.shape.onPoints(points)
this.shape.pointsToModel()
this.shape.onModel(this.shape.model)
}, 0)
}
onProps(shapeId, props) {
@@ -225,9 +220,11 @@ class ShapeTVCallbacks {
this.shape.propsLock--
return
}
this.shape.onProps(props)
this.shape.propsToModel()
this.shape.onModel(this.shape.model)
setTimeout(()=>{
this.shape.onProps(props)
this.shape.propsToModel()
this.shape.onModel(this.shape.model)
}, 0)
}
onDraw() {
@@ -285,12 +282,13 @@ export class HLine extends Shape {
pointsFromModel() {
if (this.model.price === null) return null
if (this.points !== null && this.points.length > 0)
return [{time:this.points[0].time, price:this.model.price}]
return [{time:0, price:this.model.price}]
const time = this.points !== null && this.points.length > 0 ? this.points[0].time : 0
console.log(`pointsFromModel ${this.id}`, this.model.price)
return [{time:time, price:this.model.price}]
}
pointsToModel() {
console.log(`pointsToModel ${this.id}`, this.points[0].price)
this.model.price = this.points[0].price
}