skew flipping improvements
This commit is contained in:
@@ -266,7 +266,7 @@ function drawingEventWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doHandleDrawingEvent(id, event) {
|
function doHandleDrawingEvent(id, event) {
|
||||||
console.log('drawing event', id, event)
|
// console.log('drawing event', id, event)
|
||||||
let shape
|
let shape
|
||||||
if (event==='remove')
|
if (event==='remove')
|
||||||
shape = null
|
shape = null
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export class Shape {
|
|||||||
//
|
//
|
||||||
|
|
||||||
setModel(model) {
|
setModel(model) {
|
||||||
console.log('shape setModel', model)
|
// console.log('shape setModel', model)
|
||||||
|
|
||||||
if (model.color)
|
if (model.color)
|
||||||
this.model.color = model.color
|
this.model.color = model.color
|
||||||
@@ -261,7 +261,7 @@ export class Shape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onProps(props) { // the display properties of an existing shape were changed
|
onProps(props) { // the display properties of an existing shape were changed
|
||||||
console.log('shape onProps', this.model, props)
|
if (this.debug) console.log('shape onProps', this.model, props)
|
||||||
if (props.textcolor && props.textcolor !== this.tvProps.textcolor)
|
if (props.textcolor && props.textcolor !== this.tvProps.textcolor)
|
||||||
this.updateModel({color:props.textcolor})
|
this.updateModel({color:props.textcolor})
|
||||||
else if (props.linecolor && props.linecolor !== this.tvProps.linecolor)
|
else if (props.linecolor && props.linecolor !== this.tvProps.linecolor)
|
||||||
|
|||||||
@@ -9,30 +9,30 @@
|
|||||||
<template v-if="prices.length>1">
|
<template v-if="prices.length>1">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<v-text-field type="number" v-model="priceB" min="0"
|
<v-text-field type="number" v-model="higherPrice" min="0"
|
||||||
density="compact" hide-details class="mx-1 my-2" variant="outlined"
|
density="compact" hide-details class="mx-1 my-2" variant="outlined"
|
||||||
label="Price"
|
label="Price"
|
||||||
:color="color" :base-color="color"
|
:color="color" :base-color="color"
|
||||||
style="flex: 6em"
|
style="flex: 6em"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td class="weight">{{ allocationText(weights[weights.length - 1]) }}</td>
|
<td class="weight">{{ allocationText(weights[higherIndex]) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-for="i in prices.length-2" class="ml-5">
|
<tr v-for="i in innerIndexes" class="ml-5">
|
||||||
<td class="pl-5">{{ prices[prices.length-i-1] }}</td>
|
<td class="pl-5">{{ prices[i] }}</td>
|
||||||
<td class="weight">{{ allocationText(weights[prices.length-i-1]) }}</td>
|
<td class="weight">{{ allocationText(weights[i]) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<v-text-field type="number" v-model="priceA" min="0"
|
<v-text-field type="number" v-model="lowerPrice" min="0"
|
||||||
density="compact" hide-details class="mx-1 my-2" variant="outlined"
|
density="compact" hide-details class="mx-1 my-2" variant="outlined"
|
||||||
label="Price"
|
label="Price"
|
||||||
:color="color" :base-color="color"
|
:color="color" :base-color="color"
|
||||||
style="flex: 6em"
|
style="flex: 6em"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td class="weight">{{ weights.length ? allocationText(weights[0]) : '' }}</td>
|
<td class="weight">{{ weights.length ? allocationText(weights[lowerIndex]) : '' }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -46,7 +46,7 @@ import {useTheme} from "vuetify";
|
|||||||
import {useOrderStore, useStore} from "@/store/store.js";
|
import {useOrderStore, useStore} from "@/store/store.js";
|
||||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||||
import RungBuilder from "@/components/chart/RungBuilder.vue";
|
import RungBuilder from "@/components/chart/RungBuilder.vue";
|
||||||
import {computed, ref} from "vue";
|
import {computed, ref, watchEffect} from "vue";
|
||||||
import {chart} from "@/charts/chart.js";
|
import {chart} from "@/charts/chart.js";
|
||||||
import {HLine} from "@/charts/shape.js";
|
import {HLine} from "@/charts/shape.js";
|
||||||
|
|
||||||
@@ -112,6 +112,45 @@ const priceB = computed({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const flipped = computed(()=>{
|
||||||
|
const a = props.builder.priceA
|
||||||
|
const b = props.builder.priceB
|
||||||
|
return a !== null && b !== null && a > b
|
||||||
|
})
|
||||||
|
|
||||||
|
const higherPrice = computed({
|
||||||
|
get() { return flipped.value ? priceA.value : priceB.value },
|
||||||
|
set(v) {
|
||||||
|
if (flipped.value)
|
||||||
|
priceA.value = v
|
||||||
|
else
|
||||||
|
priceB.value = v
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const higherIndex = computed(()=>flipped.value ? 0 : weights.value.length-1)
|
||||||
|
const lowerIndex = computed(()=>!flipped.value ? 0 : weights.value.length-1)
|
||||||
|
const innerIndexes = computed(()=>{
|
||||||
|
const result = []
|
||||||
|
const n = prices.value.length
|
||||||
|
const f = flipped.value
|
||||||
|
for (let i=1; i<n-1; i++)
|
||||||
|
result.push(f?i:n-1-i)
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
|
||||||
|
const lowerPrice = computed({
|
||||||
|
get() {
|
||||||
|
return !flipped.value ? priceA.value : priceB.value
|
||||||
|
},
|
||||||
|
set(v) {
|
||||||
|
if (!flipped.value)
|
||||||
|
priceA.value = v
|
||||||
|
else
|
||||||
|
priceB.value = v
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const start = computed({
|
const start = computed({
|
||||||
get() {return props.builder.start || 0},
|
get() {return props.builder.start || 0},
|
||||||
set(v) {props.builder.start=v; },
|
set(v) {props.builder.start=v; },
|
||||||
@@ -125,10 +164,7 @@ const end = computed({
|
|||||||
|
|
||||||
const prices = ref([])
|
const prices = ref([])
|
||||||
const weights = ref([])
|
const weights = ref([])
|
||||||
function setPrices(ps) {
|
function setPrices(ps) {prices.value = ps}
|
||||||
console.log('setPrices', ps)
|
|
||||||
prices.value = ps
|
|
||||||
}
|
|
||||||
function setWeights(ws) { weights.value = ws }
|
function setWeights(ws) { weights.value = ws }
|
||||||
|
|
||||||
|
|
||||||
@@ -175,20 +211,11 @@ function getModelValue(model) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setModelValue(model, value) {
|
function setModelValue(model, value) {
|
||||||
console.log('setModelValue->', {...model}, value)
|
// console.log('setModelValue->', {...model}, value)
|
||||||
if (model.price !== value)
|
if (model.price !== value)
|
||||||
model.price = value
|
model.price = value
|
||||||
}
|
}
|
||||||
|
|
||||||
function setValues(values) {
|
|
||||||
prices.value = values
|
|
||||||
}
|
|
||||||
|
|
||||||
function valueFromPoints(points) {
|
|
||||||
const result = points[0].time;
|
|
||||||
console.log('valueFromPoints', points, result);
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import {useOrderStore} from "@/store/store.js";
|
|||||||
import {allocationText, deleteBuilder, linearWeights, useChartOrderStore, weightColors} from "@/orderbuild.js";
|
import {allocationText, deleteBuilder, linearWeights, useChartOrderStore, weightColors} from "@/orderbuild.js";
|
||||||
import {useTheme} from "vuetify";
|
import {useTheme} from "vuetify";
|
||||||
import {linspace, sideColor} from "@/misc.js";
|
import {linspace, sideColor} from "@/misc.js";
|
||||||
import {computed, watchEffect} from "vue";
|
import {computed, onUnmounted, watchEffect} from "vue";
|
||||||
import Color from "color";
|
import Color from "color";
|
||||||
import {cancelDrawing} from "@/charts/chart.js";
|
import {cancelDrawing} from "@/charts/chart.js";
|
||||||
|
|
||||||
@@ -62,9 +62,12 @@ const props = defineProps({
|
|||||||
setWeights: Function, // setValues(values:Array) -> void
|
setWeights: Function, // setValues(values:Array) -> void
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const flipped = computed(() => valueA.value !== null && valueB.value !== null && valueA.value > valueB.value)
|
||||||
|
const flippedSign = computed(()=>flipped.value?-1:1)
|
||||||
|
|
||||||
const skew100 = computed( {
|
const skew100 = computed( {
|
||||||
get() {return props.builder.skew*100},
|
get() {console.log('skew100 flipped?',flippedSign.value); return flippedSign.value*props.builder.skew*100},
|
||||||
set(v) {props.builder.skew = v/100; }
|
set(v) {props.builder.skew = flippedSign.value*v/100; }
|
||||||
} )
|
} )
|
||||||
|
|
||||||
// validity checks
|
// validity checks
|
||||||
@@ -83,7 +86,6 @@ const rungs = computed({
|
|||||||
return props.builder.rungs
|
return props.builder.rungs
|
||||||
},
|
},
|
||||||
set(r) {
|
set(r) {
|
||||||
// todo this is subclass specific: make TWAP extend the range rather than compressing it
|
|
||||||
if (!r) {
|
if (!r) {
|
||||||
props.builder.rungs = 1
|
props.builder.rungs = 1
|
||||||
return
|
return
|
||||||
@@ -91,13 +93,12 @@ const rungs = computed({
|
|||||||
r = Number(r)
|
r = Number(r)
|
||||||
props.builder.rungs = r
|
props.builder.rungs = r
|
||||||
const b = valueB.value
|
const b = valueB.value
|
||||||
console.log('set rungs', r, valueA.value, b)
|
// console.log('set rungs', r, valueA.value, b)
|
||||||
if ( r > 0 && b === null ) {
|
if ( r > 0 && b === null ) {
|
||||||
// convert single shape to a range
|
// convert single shape to a range
|
||||||
if (props.mode===0) {
|
if (props.mode===0) {
|
||||||
const width = props.stdWidth
|
const width = props.stdWidth
|
||||||
const mid = valueA.value
|
const mid = valueA.value
|
||||||
console.log('single to range', mid - width/2, mid + width/2)
|
|
||||||
valueA.value = mid - width/2
|
valueA.value = mid - width/2
|
||||||
valueB.value = mid + width/2
|
valueB.value = mid + width/2
|
||||||
}
|
}
|
||||||
@@ -139,6 +140,7 @@ const values = computed(()=>{
|
|||||||
|
|
||||||
|
|
||||||
const weights = computed(() => {
|
const weights = computed(() => {
|
||||||
|
// const skew = flipped.value ? -props.builder.skew : props.builder.skew
|
||||||
const ws = linearWeights(props.builder.rungs, -props.builder.skew)
|
const ws = linearWeights(props.builder.rungs, -props.builder.skew)
|
||||||
if (props.setWeights)
|
if (props.setWeights)
|
||||||
props.setWeights(ws)
|
props.setWeights(ws)
|
||||||
@@ -159,28 +161,16 @@ const color = computed({
|
|||||||
get() {return props.builder.color},
|
get() {return props.builder.color},
|
||||||
set(v) {
|
set(v) {
|
||||||
const maxLightness = 60
|
const maxLightness = 60
|
||||||
|
// noinspection JSUnresolvedReference
|
||||||
const c = new Color(v).hsl()
|
const c = new Color(v).hsl()
|
||||||
props.builder.color = c.saturation <= maxLightness ? v : c.lightness(maxLightness).rgb().string()
|
props.builder.color = c.saturation <= maxLightness ? v : c.lightness(maxLightness).rgb().string()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const colors = computed( ()=> {
|
|
||||||
const color = props.builder.color !== null ? props.builder.color
|
|
||||||
: props.buy ? theme.value.colors.success : theme.value.colors.error
|
|
||||||
const ws = weights.value;
|
|
||||||
return weightColors(ws, color);
|
|
||||||
})
|
|
||||||
const colorStyle = computed(() => {
|
const colorStyle = computed(() => {
|
||||||
return {'color': color.value}
|
return {'color': color.value}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function allocText(weight) {
|
|
||||||
const alloc = props.builder.allocation
|
|
||||||
if (alloc===null) return ''
|
|
||||||
return allocationText(weight * alloc, props.order.amount * alloc, amountSymbol.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// SHAPE MANAGEMENT
|
// SHAPE MANAGEMENT
|
||||||
//
|
//
|
||||||
@@ -214,7 +204,6 @@ function translateOnDrag(shape) {
|
|||||||
|
|
||||||
const shapeA = createShape(valueA.value, {color: defaultColor},
|
const shapeA = createShape(valueA.value, {color: defaultColor},
|
||||||
function (model) {
|
function (model) {
|
||||||
console.log('shapeA onModel', model)
|
|
||||||
const value = props.getModelValue(model);
|
const value = props.getModelValue(model);
|
||||||
if (value!==null && value!==undefined)
|
if (value!==null && value!==undefined)
|
||||||
valueA.value = value;
|
valueA.value = value;
|
||||||
@@ -259,7 +248,6 @@ function removeInteriorShape() {
|
|||||||
|
|
||||||
function makeModel(index) {
|
function makeModel(index) {
|
||||||
const ws = weights.value
|
const ws = weights.value
|
||||||
const w = ws[index]
|
|
||||||
const alloc = props.builder.allocation * ws[index];
|
const alloc = props.builder.allocation * ws[index];
|
||||||
const result = {
|
const result = {
|
||||||
color: color.value,
|
color: color.value,
|
||||||
@@ -274,12 +262,10 @@ function makeModel(index) {
|
|||||||
|
|
||||||
function adjustShapes() {
|
function adjustShapes() {
|
||||||
// this is where all the shapes are created or adjusted
|
// this is where all the shapes are created or adjusted
|
||||||
console.log('adjustShapes()', valueA.value, valueB.value)
|
// console.log('adjustShapes()', valueA.value, valueB.value)
|
||||||
const vs = values.value
|
const vs = values.value
|
||||||
if (vs.length)
|
if (vs.length)
|
||||||
cancelDrawing()
|
cancelDrawing()
|
||||||
const ws = weights.value
|
|
||||||
const colorStrings = colors.value
|
|
||||||
// shape properties
|
// shape properties
|
||||||
if( vs.length === 0 ) {
|
if( vs.length === 0 ) {
|
||||||
shapeA.delete()
|
shapeA.delete()
|
||||||
@@ -312,8 +298,6 @@ function adjustShapes() {
|
|||||||
removeInteriorShape()
|
removeInteriorShape()
|
||||||
// adjust the interior shape values and/or add shapes
|
// adjust the interior shape values and/or add shapes
|
||||||
for( let i=1; i<vs.length-1; i++ ) {
|
for( let i=1; i<vs.length-1; i++ ) {
|
||||||
const v = vs[i]
|
|
||||||
const w = ws[i];
|
|
||||||
if (i-1 === interiorShapes.length)
|
if (i-1 === interiorShapes.length)
|
||||||
createInteriorShape(i)
|
createInteriorShape(i)
|
||||||
else
|
else
|
||||||
@@ -335,12 +319,11 @@ function deleteShapes() {
|
|||||||
interiorShapes = []
|
interiorShapes = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUnmounted(deleteShapes)
|
||||||
|
|
||||||
console.log('valueA', valueA.value, shapeA)
|
|
||||||
if (!valueA.value)
|
if (!valueA.value)
|
||||||
shapeA.createOrDraw(); // initiate drawing mode
|
shapeA.createOrDraw(); // initiate drawing mode
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user