datafeed fixes; line drawing fix
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
|
||||
import {invokeCallback, mixin} from "@/common.js";
|
||||
import {chart, createShape, deleteShapeId, dragging, draggingShapeIds, drawShape, widget} from "@/charts/chart.js";
|
||||
import {unique} from "@/misc.js";
|
||||
import {allocationText} from "@/orderbuild.js";
|
||||
import Color from "color";
|
||||
import {pointsToTvOhlcStart} from "@/charts/chart-misc.js";
|
||||
import {dirtyItems, dirtyPoints, pointsToTvOhlcStart} from "@/charts/chart-misc.js";
|
||||
|
||||
|
||||
//
|
||||
@@ -140,7 +139,7 @@ export class Shape {
|
||||
}
|
||||
|
||||
if (this.debug && this.id)
|
||||
console.log('newProps', chart.getShapeById(this.id).getProperties(), newProps)
|
||||
console.log('newProps', this.id, chart.getShapeById(this.id).getProperties(), newProps)
|
||||
this.setProps(newProps)
|
||||
}
|
||||
|
||||
@@ -206,7 +205,7 @@ export class Shape {
|
||||
this.tvCallbacks = new ShapeTVCallbacks(this);
|
||||
const id = createShape(this.type, this.tvPoints, options, this.tvCallbacks)
|
||||
// todo set id?
|
||||
if (this.debug) console.log('created', this.type.name, this.tvPoints, id)
|
||||
if (this.debug) console.log('created', id, this.type.name, this.tvPoints)
|
||||
}
|
||||
|
||||
onCreate(points, props) {
|
||||
@@ -239,7 +238,7 @@ export class Shape {
|
||||
setPoints(points) {
|
||||
// setting points to null will delete the shape from the chart. setting points to a valid value will cause the
|
||||
// shape to be drawn.
|
||||
if (this.debug) console.log('setPoints', this.id, this.ourPoints, points)
|
||||
if (this.debug) console.error('setPoints', this.id, this.ourPoints, points)
|
||||
this.ourPoints = points
|
||||
if (points === null || !points.length)
|
||||
this.delete()
|
||||
@@ -249,12 +248,27 @@ export class Shape {
|
||||
else {
|
||||
points = pointsToTvOhlcStart(points)
|
||||
if (dirtyPoints(this.tvPoints, points)) {
|
||||
/*
|
||||
setPoints(e) {
|
||||
if (this._source.isFixed())
|
||||
return;
|
||||
const t = o(this._source);
|
||||
if (t !== e.length)
|
||||
throw new Error(`Wrong points count. Required: ${t}, provided: ${e.length}`);
|
||||
const i = this._pointsConverter.apiPointsToDataSource(e);
|
||||
this._model.startChangingLinetool(this._source),
|
||||
this._model.changeLinePoints(this._source, i),
|
||||
this._model.endChangingLinetool(!0),
|
||||
this._source.createServerPoints()
|
||||
}
|
||||
*/
|
||||
const s = this.tvShape();
|
||||
const lbe = s._model._lineBeingEdited
|
||||
const lpbc = s._model._linePointBeingChanged
|
||||
const lpbe = s._model._linePointBeingEdited
|
||||
if (lpbc!==null)
|
||||
s._model.endChangingLinetool(lbe, lpbc)
|
||||
s._model.endChangingLinetool(!0)
|
||||
// s._source.createServerPoints() // todo necessary?
|
||||
s.setPoints(points)
|
||||
if (lpbc!==null)
|
||||
s._model.startChangingLinetool(lbe, lpbc, lpbe)
|
||||
@@ -267,7 +281,7 @@ export class Shape {
|
||||
|
||||
setProps(props) {
|
||||
if (!props || Object.keys(props).length===0) return
|
||||
if (this.debug) console.log('setProps', props)
|
||||
if (this.debug) console.log('setProps', this.id, props)
|
||||
this.ourProps = mixin(props, this.ourProps)
|
||||
if(this.id) {
|
||||
const p = dirtyItems(this.tvProps, props)
|
||||
@@ -278,7 +292,7 @@ export class Shape {
|
||||
}
|
||||
|
||||
onProps(props) { // the display properties of an existing shape were changed
|
||||
if (this.debug) console.log('shape onProps', this.model, props)
|
||||
if (this.debug) console.log('shape onProps', this.id, this.model, props)
|
||||
if (props.textcolor && typeof props.textcolor !== 'object' && props.textcolor !== this.tvProps.textcolor)
|
||||
this.updateModel({color:props.textcolor})
|
||||
else if (props.linecolor && typeof props.linecolor !== 'object' && props.linecolor !== this.tvProps.linecolor)
|
||||
@@ -323,46 +337,6 @@ export class Shape {
|
||||
}
|
||||
|
||||
|
||||
function dirtyPoints(pointsA, pointsB) {
|
||||
if (pointsA === undefined)
|
||||
return true
|
||||
if (pointsB === undefined)
|
||||
return false
|
||||
if (pointsB===null)
|
||||
return pointsA !== null
|
||||
if (pointsA===null)
|
||||
return pointsB.length > 0
|
||||
if (pointsA.length!==pointsB.length)
|
||||
return true
|
||||
for (const i in pointsA) {
|
||||
const a = pointsA[i]
|
||||
const b = pointsB[i]
|
||||
if ( a === null && b !== null || a !== null && b === null ||
|
||||
a.time !== b.time || a.price !== b.price )
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// B is modifying A
|
||||
function dirtyKeys(propsA, propsB) {
|
||||
if (propsB===null)
|
||||
return propsA === null ? [] : [...Object.keys(propsA)]
|
||||
if (propsA===null)
|
||||
return [...Object.keys(propsB)]
|
||||
const keys = unique([...Object.keys(propsA), ...Object.keys(propsB)])
|
||||
return keys.filter((k)=> propsB[k] !== undefined && (!(k in propsA) || propsA[k] !== propsB[k]))
|
||||
}
|
||||
|
||||
|
||||
function dirtyItems(a, b) {
|
||||
const result = {}
|
||||
for (const k of dirtyKeys(a,b))
|
||||
result[k] = b[k]
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
class ShapeTVCallbacks {
|
||||
// These methods are called by TradingView and provide some default handling before invoking our own Shape callbacks
|
||||
|
||||
@@ -380,7 +354,7 @@ class ShapeTVCallbacks {
|
||||
|
||||
onPoints(shapeId, _tvShape, points) {
|
||||
if (!this.enabled) return // possible when shape is deleted and re-created
|
||||
if (this.shape.debug) console.log('tvcb onPoints', points)
|
||||
if (this.shape.debug) console.log('tvcb onPoints', shapeId, points)
|
||||
if (!dragging || this.shape.beingDragged())
|
||||
this.shape.onPoints(points)
|
||||
this.shape.tvPoints = points
|
||||
@@ -388,7 +362,7 @@ class ShapeTVCallbacks {
|
||||
|
||||
onProps(shapeId, _tvShape, props) {
|
||||
if (!this.enabled) return // possible when shape is deleted and re-created
|
||||
if (this.shape.debug) console.error('tvOnProps', props)
|
||||
if (this.shape.debug) console.log('tvOnProps', shapeId, props)
|
||||
if (!dragging) // do not listen to props during redraw
|
||||
this.shape.onProps(props)
|
||||
this.shape.tvProps = props
|
||||
@@ -421,7 +395,7 @@ class ShapeTVCallbacks {
|
||||
|
||||
onDrag(shapeId, _tvShape, points) {
|
||||
if (!this.enabled) return // possible when shape is deleted and re-created
|
||||
if (this.shape.debug) console.log('onDrag')
|
||||
if (this.shape.debug) console.log('onDrag', shapeId)
|
||||
invokeCallback(this.shape, 'onDrag', points)
|
||||
}
|
||||
|
||||
@@ -452,7 +426,7 @@ export class Line extends Shape {
|
||||
onDrag(points) {
|
||||
const s = this.tvShape();
|
||||
if (this.debug) {
|
||||
console.log('shape', s)
|
||||
console.log('shape', s.id, s)
|
||||
console.log('currentMovingPoint', s._source.currentMovingPoint())
|
||||
console.log('startMovingPoint', s._source.startMovingPoint())
|
||||
console.log('isBeingEdited', s._source.isBeingEdited())
|
||||
|
||||
Reference in New Issue
Block a user