DCA work, shape rendering
This commit is contained in:
@@ -64,7 +64,7 @@ export class Shape {
|
||||
this.tvCallbacks = null
|
||||
this.ourPoints = null
|
||||
this.tvPoints = null
|
||||
this.creationOptions = {disableSave:true, disableUndo:false, disableSelection:false}
|
||||
this.creationOptions = {disableSave:true, disableUndo:true, disableSelection:false}
|
||||
this.ourProps = {}
|
||||
if (props !== null)
|
||||
this.ourProps = mixin(props, this.ourProps)
|
||||
@@ -131,9 +131,8 @@ export class Shape {
|
||||
newProps.linecolor = color
|
||||
|
||||
// text label
|
||||
const text =
|
||||
// `${this.id} ` +
|
||||
allocationText(this.model.allocation, this.model.amount, this.model.amountSymbol)
|
||||
let text = allocationText(this.model.allocation, this.model.amount, this.model.amountSymbol)
|
||||
if (this.debug) text = `${this.id} ` + text
|
||||
if (!text.length)
|
||||
newProps.showLabel = false
|
||||
else {
|
||||
@@ -206,10 +205,18 @@ export class Shape {
|
||||
options['overrides'] = props
|
||||
this.tvPoints = [...points]
|
||||
this.tvCallbacks = new ShapeTVCallbacks(this);
|
||||
createShape(this.type, points, options, this.tvCallbacks)
|
||||
if (this.debug) console.log('created', this.type.name, points, this.id)
|
||||
const id = createShape(this.type, points, options, this.tvCallbacks)
|
||||
// todo set id?
|
||||
if (this.debug) console.log('created', this.type.name, points, id)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
createOrDraw() {
|
||||
if(this.id) return
|
||||
if(this.ourPoints && this.ourPoints.length)
|
||||
@@ -243,50 +250,14 @@ export class Shape {
|
||||
this.create()
|
||||
else if (dirtyPoints(this.tvPoints, points)) {
|
||||
const s = this.tvShape();
|
||||
let sbm = false
|
||||
if( draggingShapeIds.length ) {
|
||||
let dragShape
|
||||
try {
|
||||
dragShape = chart.getShapeById(draggingShapeIds[0])
|
||||
const sbms = [...dragShape._model._sourcesBeingMoved]
|
||||
// console.log('shape setPoints', this.id, dragShape, sbm)
|
||||
sbm = !sbms.length
|
||||
// if (!sbms.length) {
|
||||
// console.log('shape setPoints SBM return')
|
||||
// return
|
||||
// }
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`could not get drag shape ${draggingShapeIds[0]}`)
|
||||
}
|
||||
}
|
||||
if (this.debug) console.log('adjusting tv points', this.tvPoints, points, dragging, this.beingDragged())
|
||||
// if ( dragging && !this.beingDragged())
|
||||
// s.setSelectionEnabled(false)
|
||||
// s.setPoints(points)
|
||||
// if ( dragging && !this.beingDragged())
|
||||
// s.setSelectionEnabled(true)
|
||||
|
||||
// best so far
|
||||
if (sbm && this.type === ShapeType.VLine) {
|
||||
// console.log('sbm: re-create shape')
|
||||
this.delete()
|
||||
this.ourPoints = points
|
||||
this.create()
|
||||
} else
|
||||
if (!dragging || this.type !== ShapeType.HLine) {
|
||||
if (this.debug) console.log('not dragging. use setPoints.')
|
||||
s.setPoints(points)
|
||||
}
|
||||
else {
|
||||
if (this.debug) console.log('dragging. use QUIET setPoints.')
|
||||
// quiet setPoints doesn't disturb tool editing mode
|
||||
const i = s._pointsConverter.apiPointsToDataSource(points)
|
||||
// s._model.startChangingLinetool(this._source)
|
||||
s._model.changeLinePoints(s._source, i)
|
||||
// s._model.endChangingLinetool(!0)
|
||||
s._source.createServerPoints()
|
||||
}
|
||||
const lbe = s._model._lineBeingEdited
|
||||
const lpbc = s._model._linePointBeingChanged
|
||||
const lpbe = s._model._linePointBeingEdited
|
||||
if (lpbc!==null)
|
||||
s._model.endChangingLinetool(lbe, lpbc)
|
||||
s.setPoints(points)
|
||||
if (lpbc!==null)
|
||||
s._model.startChangingLinetool(lbe, lpbc, lpbe)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,10 +312,6 @@ export class Shape {
|
||||
onRedraw() {} // the mouse moved while in drawing mode
|
||||
onUndraw() {} // drawing was canceled by clicking on a different tool
|
||||
onAddPoint() {} // the user clicked a point while drawing (that point is added to the points list)
|
||||
onCreate(points, props) {
|
||||
this.tvPoints = points
|
||||
this.tvProps = props
|
||||
} // the user has finished creating all the control points. drawing mode is exited and the initial shape is created.
|
||||
onMove(points) {} // the shape was moved by dragging a drawing element not the control point
|
||||
onDrag(points) {}
|
||||
onHide(props) {}
|
||||
@@ -354,6 +321,9 @@ export class Shape {
|
||||
|
||||
}
|
||||
|
||||
|
||||
let lineChangeInfo = null
|
||||
|
||||
function dirtyPoints(pointsA, pointsB) {
|
||||
if (pointsB===null)
|
||||
return pointsA !== null
|
||||
@@ -394,13 +364,11 @@ class ShapeTVCallbacks {
|
||||
|
||||
constructor(shape) {
|
||||
this.shape = shape
|
||||
this.creating = false
|
||||
this.enabled = true // gets disabled when the shape is deleted, squelching any further callbacks
|
||||
}
|
||||
|
||||
onCreate(shapeId, _tvShape, points, props) {
|
||||
if (!this.enabled) return // possible when shape is deleted and re-created
|
||||
this.creating = true
|
||||
this.shape.id = shapeId
|
||||
invokeCallback(this.shape, 'onCreate', points, props)
|
||||
}
|
||||
@@ -415,10 +383,6 @@ class ShapeTVCallbacks {
|
||||
onProps(shapeId, _tvShape, props) {
|
||||
if (!this.enabled) return // possible when shape is deleted and re-created
|
||||
if (this.shape.debug) console.log('tvOnProps', props)
|
||||
if (this.creating) { // todo still useful?
|
||||
this.creating = false
|
||||
return
|
||||
}
|
||||
this.shape.tvProps = props
|
||||
this.shape.onProps(props)
|
||||
}
|
||||
@@ -538,6 +502,7 @@ export class VLine extends Line {
|
||||
constructor(model, onModel=null, onDelete=null, props=null) {
|
||||
super(ShapeType.VLine, onModel, onDelete, props)
|
||||
|
||||
this.debug = true // todo debug
|
||||
// Model
|
||||
this.model.time = null
|
||||
|
||||
@@ -551,6 +516,7 @@ export class VLine extends Line {
|
||||
doCreate(points, props, options = {}) {
|
||||
this.shapeTime = nearestOhlcStart(points[0].time);
|
||||
points = [{time: this.shapeTime, price:0}]
|
||||
if (this.debug) console.log('VLine.doCreate', this.shapeTime, points)
|
||||
super.doCreate(points, props, options);
|
||||
}
|
||||
|
||||
@@ -562,7 +528,7 @@ export class VLine extends Line {
|
||||
|
||||
|
||||
setModel(model) {
|
||||
// console.log('VLine setModel', this.id, {...this.model}, model)
|
||||
// if (this.debug) console.error('VLine setModel', this.id, {...this.model}, model)
|
||||
super.setModel(model)
|
||||
if (model.time === null)
|
||||
this.delete()
|
||||
@@ -573,7 +539,7 @@ export class VLine extends Line {
|
||||
}
|
||||
|
||||
setPoints(points) {
|
||||
if (this.debug) console.error('VLine setPoints...', points)
|
||||
// if (this.debug) console.error('VLine setPoints...', points)
|
||||
if (points !== null && points.length) {
|
||||
// adjust shape to ohlc boundry
|
||||
const time = nearestOhlcStart(points[0].time);
|
||||
@@ -586,7 +552,7 @@ export class VLine extends Line {
|
||||
this.shapeTime = null
|
||||
super.setPoints(points);
|
||||
}
|
||||
if (this.debug) console.error('VLine setPoints', points)
|
||||
// if (this.debug) console.error('VLine setPoints', points)
|
||||
}
|
||||
|
||||
onPoints(points) {
|
||||
|
||||
Reference in New Issue
Block a user