From 1a752d3080671aba38d220fd0e8f79eb8a3f20ab Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 16 Apr 2024 18:50:14 -0400 Subject: [PATCH] LimitBuilder as RungBuilder; HLine fixes; cant place orders yet --- src/charts/shape.js | 83 +++--- src/components/chart/BuilderPanel.vue | 2 +- src/components/chart/LimitBuilder.vue | 393 +++++--------------------- src/components/chart/RungBuilder.vue | 11 +- 4 files changed, 117 insertions(+), 372 deletions(-) diff --git a/src/charts/shape.js b/src/charts/shape.js index c659989..a47bd55 100644 --- a/src/charts/shape.js +++ b/src/charts/shape.js @@ -150,7 +150,7 @@ export class Shape { doCreate() { // createShape(this.type, this.points, {overrides:this.props}, new ShapeTVCallbacks(this)) this.tvPoints = [...this.ourPoints] - this.id = createShape(this.type, this.ourPoints, {overrides:this.ourProps}, new ShapeTVCallbacks(this)) + createShape(this.type, this.ourPoints, {overrides:this.ourProps}, new ShapeTVCallbacks(this)) if (this.debug) console.log('created', this.type.name, this.ourPoints, this.id) } @@ -171,7 +171,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', points) + if (this.debug) console.log('setPoints', points, this.id) this.ourPoints = points if (points === null || !points.length) this.delete() @@ -185,15 +185,6 @@ export class Shape { 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() - } } } } @@ -292,6 +283,7 @@ class ShapeTVCallbacks { onCreate(shapeId, _tvShape, points, props) { this.creating = true + this.shape.id = shapeId invokeCallback(this.shape, 'onCreate', points, props) } @@ -371,10 +363,23 @@ export class Line extends Shape { export class HLine extends Line { constructor(model, onModel=null, onDelete=null, props=null) { - super(ShapeType.HLine, model, onModel, onDelete, props) + super(ShapeType.HLine, onModel, onDelete, props) + + // Model + this.model.price = null + + this.setModel(model) // call setModel at the end } + delete() { + this.model.price = null + super.delete() + } + + setModel(model) { + console.log('hline setModel', model) + super.setModel(model) if (model.price !== undefined && model.price !== this.model.price) { this.model.price = model.price this.setPoints([{time:0,price:this.model.price}]) @@ -383,19 +388,8 @@ export class HLine extends Line { onPoints(points) { super.onPoints(points); - } - - pointsFromModel(model) { - if (model.price === null || model.price===undefined) return null - // take any time available, or 0 - const time = - this.ourPoints !== null && this.ourPoints.length > 0 ? this.ourPoints[0].time : - this.tvPoints !== null && this.tvPoints.length > 0 ? this.tvPoints[0].time : 0 - return [{time:time, price:model.price}] - } - - pointsToModel(points) { - return {price: this.ourPoints[0].price} + const price = points[0].price; + this.updateModel({price}) } } @@ -410,9 +404,9 @@ function timeAdjustmentTooSmall(orig, newValue) { } -function ohlcStart(time) { +function nearestOhlcStart(time) { const period = useChartOrderStore().intervalSecs - return Math.floor(time/period) * period + return Math.round(time/period) * period } @@ -426,38 +420,33 @@ export class VLine extends Line { this.setModel(model) // call setModel at the end } - onPoints(points) { - if (this.debug) console.log('vline onPoints', this.ourPoints, points) - super.onPoints(points); - const orig = this.ourPoints && this.ourPoints.length ? this.ourPoints[0].time : null - if (!timeAdjustmentTooSmall(orig, points[0].time)) { - if (this.debug) console.log('updateModel', points[0].time) - this.updateModel({time: points[0].time}) - } + delete() { + this.model.time = null + super.delete() } + setModel(model) { if (this.debug) console.log('vline setModel', this.model.time, model ) super.setModel(model) if (model.time !== undefined && model.time !== this.model.time) { this.model.time = model.time - const time = ohlcStart(model.time); + const time = nearestOhlcStart(model.time); if (this.debug) console.log('vline setPoints', this.id, time) - this.setPoints([{time, price:1}]) + this.setPoints([{time, price:0}]) } } - delete() { - this.model.time = null - super.delete() + onPoints(points) { + if (this.debug) console.log('vline onPoints', this.ourPoints, points) + super.onPoints(points); + const orig = this.ourPoints && this.ourPoints.length ? this.ourPoints[0].time : null + const time = points[0].time; + if (!timeAdjustmentTooSmall(orig, time)) { + if (this.debug) console.log('updateModel', time) + this.updateModel({time: time}) + } } - dirtyPoints(pointsA, pointsB) { - const a = pointsA ? pointsA[0].time : null - const b = pointsB ? pointsB[0].time : null - const result = !timeAdjustmentTooSmall(a, b) - if (this.debug) console.log('vline dirty points?', a, b, result) - return result - } } diff --git a/src/components/chart/BuilderPanel.vue b/src/components/chart/BuilderPanel.vue index 40dc444..396a712 100644 --- a/src/components/chart/BuilderPanel.vue +++ b/src/components/chart/BuilderPanel.vue @@ -8,7 +8,7 @@ - + diff --git a/src/components/chart/LimitBuilder.vue b/src/components/chart/LimitBuilder.vue index ee0d48f..f3977c2 100644 --- a/src/components/chart/LimitBuilder.vue +++ b/src/components/chart/LimitBuilder.vue @@ -1,95 +1,60 @@ diff --git a/src/components/chart/RungBuilder.vue b/src/components/chart/RungBuilder.vue index bf3f6cf..826999e 100644 --- a/src/components/chart/RungBuilder.vue +++ b/src/components/chart/RungBuilder.vue @@ -59,6 +59,7 @@ const props = defineProps({ getModelValue: Function, // getModelValue(model) -> value setModelValue: Function, // setModelValue(model,value) -> void setValues: Function, // setValues(values:Array) -> void + setWeights: Function, // setValues(values:Array) -> void }) const skew100 = computed( { @@ -137,7 +138,12 @@ const values = computed(()=>{ }) -const weights = computed(() => linearWeights(props.builder.rungs, -props.builder.skew)) +const weights = computed(() => { + const ws = linearWeights(props.builder.rungs, -props.builder.skew) + if (props.setWeights) + props.setWeights(ws) + return ws +}) const amountSymbol = computed(()=>props.order.amountIsTokenA ? co.selectedSymbol.base.s : co.selectedSymbol.quote.s ) @@ -182,7 +188,6 @@ function allocText(weight) { // we keep two special control shapes as the edges of the range, with deletable shapes in-between function createShape(value, model, onModel, onDelete) { - console.log('createShape setModelValue', model, value) props.setModelValue(model, value) return new props.shape(model, onModel, onDelete) // props.shape is the constructor function } @@ -199,7 +204,6 @@ function translateOnDrag(shape) { oldOnPoints.call(this, points) const cur = props.getModelValue(this.model) const delta = cur - prev - console.log('move prev/cur', prev, cur, delta) if (delta !== 0) { valueA.value += delta valueB.value += delta @@ -280,6 +284,7 @@ function adjustShapes() { const model = {text: allocText(ws[0]), color: colorStrings[0]}; console.log('single shape A setModelValue', model, vs[0]) props.setModelValue(model, vs[0]) + console.log('shapeA setModel', model, shapeA.id) shapeA.setModel(model) } shapeB.delete()