diagonals working

This commit is contained in:
Tim
2024-05-13 16:32:16 -04:00
parent c7549e2f99
commit bf39ed946c
5 changed files with 132 additions and 31 deletions

View File

@@ -3,11 +3,27 @@
:shape="DLine" :mode="0"
:get-model-value="getModelValue" :set-model-value="setModelValue"
:set-values="setLines" :set-weights="setWeights"
:set-shapes="setShapes"
:std-width="stdWidth" :build-tranches="buildTranches">
<table>
<tbody>
<tr>
<td rowspan="2" class="label">Line A</td>
<td>&nbsp;</td>
<td colspan="3">
<div class="d-flex align-center">
<v-switch class="d-inline-flex" v-model="extendLeft" inline
:true-value="false" :false-value="true"
true-icon="mdi-circle-outline" false-icon="mdi-arrow-left"
/>
<span class="mx-3">Extend</span>
<v-switch class="d-inline-flex" v-model="extendRight" inline
false-icon="mdi-circle-outline" true-icon="mdi-arrow-right"
/>
</div>
</td>
</tr>
<tr>
<td class="label" rowspan="2">Line A</td>
<td>
<absolute-time-entry v-model="time1A"/>
</td>
@@ -19,7 +35,10 @@
label="Price"
/>
</td>
<td rowspan="2" class="weight" style="vertical-align: bottom">{{ allocationTexts[weights.length-1] }}</td>
<td rowspan="2" class="weight"
:style="'vertical-align: '+(price2A!==null?'bottom':'center')">
{{ allocationTexts[weights.length-1] }}
</td>
</tr>
<tr>
<td>
@@ -75,16 +94,13 @@
<script setup>
import {allocationText, applyLinePoints, builderDefaults, useChartOrderStore} from "@/orderbuild.js";
import {sideColor} from "@/misc.js";
import {useOrderStore, useStore} from "@/store/store.js";
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
import {DISTANT_FUTURE, DISTANT_PAST, MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
import RungBuilder from "@/components/chart/RungBuilder.vue";
import {computed, ref} from "vue";
import {DLine} from "@/charts/shape.js";
import {vectorEquals, vectorInterpolate} from "@/vector.js";
import AbsoluteTimeEntry from "@/components/AbsoluteTimeEntry.vue";
const s = useStore()
const os = useOrderStore()
const co = useChartOrderStore()
const props = defineProps(['order', 'builder'])
const emit = defineEmits(['update:builder'])
@@ -102,6 +118,8 @@ const color = computed(()=>props.builder.color ? props.builder.color : defaultCo
builderDefaults(props.builder, {
lineA: null, // [{time, price}, {time, price}]
lineB: null,
extendLeft: false,
extendRight: false,
rungs: 1,
skew: 0,
color: defaultColor,
@@ -123,7 +141,18 @@ function buildTranches() {
const isMinimum = inverted === order.buy
for (let i = 0; i < ws.length; i++) {
const w = ws[i]
const t = newTranche({fraction: w * MAX_FRACTION})
const line = ws.length === 1 ? la : vectorInterpolate(la, lb, i/(ws.length-1))
const el = extendLeft.value
const er = extendRight.value
const reversed = line[0] > line[2]
if (reversed ? !er : !el)
t.startTime = reversed ? line[2] : line[0]
if (reversed ? !el : !er)
t.endTime = reversed ? line[0] : line[2]
// console.log('tranche start/end',
// t.startTime === DISTANT_PAST ? 'PAST' : t.startTime,
// t.endTime === DISTANT_FUTURE ? 'FUTURE' : t.endTime)
if (inverted) {
// invert prices
line[1] = 1/line[1]
@@ -132,7 +161,6 @@ function buildTranches() {
// scale to pool decimals
line[1] *= scale
line[3] *= scale
const t = newTranche({fraction: w * MAX_FRACTION})
applyLinePoints(t, isMinimum, ...line)
tranches.push(t)
}
@@ -262,6 +290,49 @@ function update(a, b) { // a and b are lines of two points
}
let shapeA = null
let shapeB = null
function setShapes(a,b) {
shapeA = a
shapeB = b
}
const _extendLeft = ref(false)
const extendLeft = computed({
get() {return _extendLeft.value},
set(v) {
console.log('set extendLeft', v)
if (v !== _extendLeft.value) {
console.log('DO set extendLeft')
_extendLeft.value = v;
const b = {...props.builder}
b.extendLeft = v
// shapeA.setModel({extendLeft: v})
// shapeB.setModel({extendLeft: v})
emit('update:builder', b)
}
}
})
const _extendRight = ref(false)
const extendRight = computed({
get() {return _extendRight.value},
set(v) {
if (v !== _extendRight.value) {
_extendRight.value = v;
const b = {...props.builder}
b.extendRight = v
// shapeA.setModel({extendRight: v})
// shapeB.setModel({extendRight: v})
emit('update:builder', b)
}
}
})
const innerIndexes = computed(() => {
const n = flatLines.value.length
const result = []
@@ -294,6 +365,10 @@ function getModelValue(model) {
// model is the DLine shape's model object
if (!model.pointA || !model.pointB)
return null
if (model.extendLeft !== _extendLeft.value)
extendLeft.value = model.extendLeft
if (model.extendRight !== _extendRight.value)
extendRight.value = model.extendRight
const result = flattenLine([model.pointA, model.pointB]);
// console.log('getModelValue', {...model}, result)
return result // this is the vector the RungBuilder will interpolate
@@ -301,7 +376,7 @@ function getModelValue(model) {
function setModelValue(model, value) {
const oldModel = {...model};
// const oldModel = {...model};
// console.log('setModelValue', oldModel, value)
const oldLine = !model.pointA || !model.pointB ? null : [model.pointA, model.pointB]
const line = buildLine(value)
@@ -315,6 +390,10 @@ function setModelValue(model, value) {
model.pointB = line[1]
}
}
if (model.extendLeft !== _extendLeft.value)
model.extendLeft = _extendLeft.value
if (model.extendRight !== _extendRight.value)
model.extendRight = _extendRight.value
// console.log('setModelValue end', oldModel, value, model)
}