DCA work, shape rendering
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {useChartOrderStore} from "@/orderbuild.js";
|
||||
import {invokeCallbacks, prototype} from "@/common.js";
|
||||
import {DataFeed, initFeeDropdown, lookupSymbol} from "@/charts/datafeed.js";
|
||||
import {intervalToSeconds} from "@/misc.js";
|
||||
import {intervalToSeconds, SingletonCoroutine} from "@/misc.js";
|
||||
|
||||
export let widget = null
|
||||
export let chart = null
|
||||
@@ -123,14 +123,15 @@ export const VerboseCallback = prototype(ShapeCallback, {
|
||||
|
||||
let drawingTool = null
|
||||
let previousDrawingTool = null
|
||||
let drawingCallbacks = null
|
||||
|
||||
export function drawShape(shapeType, ...callbacks) {
|
||||
// puts the chart into a line-drawing mode for a new shape
|
||||
console.log('drawShape', callbacks, shapeType.name, shapeType.code)
|
||||
const co = useChartOrderStore()
|
||||
if( co.drawingCallbacks )
|
||||
invokeCallbacks(co.drawingCallbacks, 'onUndraw')
|
||||
co.drawingCallbacks = callbacks
|
||||
if( drawingCallbacks )
|
||||
invokeCallbacks(drawingCallbacks, 'onUndraw')
|
||||
drawingCallbacks = callbacks
|
||||
drawingTool = null
|
||||
previousDrawingTool = widget.selectedLineTool()
|
||||
co.drawing = true
|
||||
@@ -140,8 +141,9 @@ export function drawShape(shapeType, ...callbacks) {
|
||||
|
||||
|
||||
export function createShape(shapeType, points, options={}, ...callbacks) {
|
||||
console.log('tvShape creating')
|
||||
const co = useChartOrderStore()
|
||||
co.drawingCallbacks = null
|
||||
drawingCallbacks = null
|
||||
co.drawing = false
|
||||
options.shape = shapeType.code
|
||||
// programatically adds a shape to the chart
|
||||
@@ -155,26 +157,60 @@ export function createShape(shapeType, points, options={}, ...callbacks) {
|
||||
shapeId = chart.createMultipointShape(points, options)
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Could not create shape', shapeType, points, options, e)
|
||||
console.error('tvShape could not create', shapeType, points, options, e)
|
||||
return null
|
||||
}
|
||||
allShapeIds.push(shapeId)
|
||||
if( callbacks.length )
|
||||
shapeCallbacks[shapeId] = callbacks
|
||||
// console.log(`created ${shapeType.name}`, shapeId)
|
||||
const shape = chart.getShapeById(shapeId)
|
||||
console.log('tvShape created', shape) // todo debug
|
||||
shape.bringToFront()
|
||||
const props = shape.getProperties()
|
||||
invokeCallbacks(callbacks, 'onCreate', shapeId, shape, points, props)
|
||||
|
||||
stub(shape)
|
||||
|
||||
return shapeId
|
||||
}
|
||||
|
||||
|
||||
let stubbed = true
|
||||
// todo debug
|
||||
function stub(shape) {
|
||||
if(stubbed||shape===null) return
|
||||
function stubFunc(funcName) {
|
||||
const obj = shape._model
|
||||
console.log('stubbing', funcName, obj)
|
||||
const func = obj[funcName]
|
||||
obj[funcName] = function () {
|
||||
console.error(shapeId, funcName+'()', [...arguments])
|
||||
func(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
stubFunc('start')
|
||||
stubFunc('stop')
|
||||
stubFunc('startChanging')
|
||||
stubFunc('endChanging')
|
||||
stubFunc('startMoving')
|
||||
stubFunc('endMoving')
|
||||
stubFunc('startMovingPoint')
|
||||
stubFunc('move')
|
||||
stubFunc('restart')
|
||||
stubFunc('restorePoints')
|
||||
stubbed = true
|
||||
}
|
||||
|
||||
|
||||
export let allShapeIds = []
|
||||
|
||||
export function cancelDrawing() {
|
||||
const co = useChartOrderStore()
|
||||
if (co.drawing) {
|
||||
co.drawing = false
|
||||
widget.selectLineTool(previousDrawingTool)
|
||||
invokeCallbacks(co.drawingCallbacks, 'onUndraw')
|
||||
invokeCallbacks(drawingCallbacks, 'onUndraw')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,12 +228,14 @@ function onSelectedLineToolChanged() {
|
||||
|
||||
export let dragging = false
|
||||
function mouseDown() {
|
||||
// console.log('mouseDown')
|
||||
console.log('mouseDown')
|
||||
dump()
|
||||
dragging = true
|
||||
}
|
||||
|
||||
function mouseUp() {
|
||||
// console.log('mouseUp')
|
||||
console.log('mouseUp')
|
||||
dump()
|
||||
dragging = false
|
||||
draggingShapeIds = []
|
||||
}
|
||||
@@ -205,15 +243,40 @@ function mouseUp() {
|
||||
|
||||
export let draggingShapeIds = []
|
||||
|
||||
function dump() {
|
||||
return
|
||||
console.log('all', allShapeIds)
|
||||
for (const shapeId of allShapeIds) {
|
||||
const shape = chart.getShapeById(shapeId)
|
||||
console.log('shape', shape)
|
||||
console.log('_linePointBeingChanged', shape._model._linePointBeingChanged)
|
||||
// console.log('_lineBeingEdited', shape._model._lineBeingEdited)
|
||||
// console.log('_lineBeingCreated', shape._model._lineBeingCreated)
|
||||
// console.log('_linePointBeingEdited', shape._model._linePointBeingEdited)
|
||||
// console.log('_lastHoveredHittestData', shape._model._lastHoveredHittestData)
|
||||
// console.log('_lastSelectedHittestData', shape._model._lastSelectedHittestData)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function handleCrosshairMovement(point) {
|
||||
crosshairHandler.invoke(point) // delayed invocation to await selection to register later in the tv loop
|
||||
}
|
||||
|
||||
|
||||
const crosshairHandler = new SingletonCoroutine(doHandleCrosshairMovement, 0)
|
||||
|
||||
|
||||
function doHandleCrosshairMovement(point) {
|
||||
// console.log('crosshair moved')
|
||||
crosshairPoint = point
|
||||
const co = useChartOrderStore()
|
||||
if (co.drawing)
|
||||
invokeCallbacks(co.drawingCallbacks, 'onRedraw')
|
||||
invokeCallbacks(drawingCallbacks, 'onRedraw')
|
||||
else if (dragging) {
|
||||
draggingShapeIds = chart.selection().allSources();
|
||||
const selection = chart.selection().allSources();
|
||||
if (selection.length)
|
||||
draggingShapeIds = selection
|
||||
// console.log('dragging selected', draggingShapeIds)
|
||||
for (const shapeId of draggingShapeIds) {
|
||||
let shape
|
||||
@@ -224,7 +287,8 @@ function handleCrosshairMovement(point) {
|
||||
continue
|
||||
}
|
||||
const points = shape.getPoints();
|
||||
// console.log(`dragging ${shapeId}`, shape, points1, points2, points3)
|
||||
|
||||
// console.log('dragging', shapeId)
|
||||
// invokeCallbacks(shapeCallbacks[shapeId], 'onDrag', shapeId, shape, points)
|
||||
// console.log('calling onPoints')
|
||||
invokeCallbacks(shapeCallbacks[shapeId], 'onPoints', shapeId, shape, points)
|
||||
@@ -288,8 +352,12 @@ function doHandleDrawingEvent(id, event) {
|
||||
}
|
||||
}
|
||||
if (event === 'create') {
|
||||
console.log('created tvShape', id, shape) // todo remove debug
|
||||
stub(shape) // todo debug
|
||||
allShapeIds.push(id)
|
||||
|
||||
const co = useChartOrderStore();
|
||||
const callbacks = co.drawingCallbacks
|
||||
const callbacks = drawingCallbacks
|
||||
// console.log('drawing callbacks', callbacks)
|
||||
if (callbacks !== null) {
|
||||
shapeCallbacks[id] = callbacks
|
||||
@@ -301,6 +369,7 @@ function doHandleDrawingEvent(id, event) {
|
||||
invokeCallbacks(shapeCallbacks[id], 'onProps', id, shape, props)
|
||||
}
|
||||
} else if (event === 'points_changed') {
|
||||
if (dragging) return
|
||||
if (id in shapeCallbacks) {
|
||||
const points = shape.getPoints()
|
||||
// console.log('points', points)
|
||||
@@ -318,6 +387,7 @@ function doHandleDrawingEvent(id, event) {
|
||||
invokeCallbacks(shapeCallbacks[id], 'onMove', id, shape)
|
||||
}
|
||||
} else if (event === 'remove') {
|
||||
allShapeIds = allShapeIds.filter((v)=>v!==id)
|
||||
if (id in shapeCallbacks) {
|
||||
invokeCallbacks(shapeCallbacks[id], 'onDelete', id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user