bugfixes
This commit is contained in:
@@ -175,6 +175,7 @@ function getModelValue(model) {
|
||||
}
|
||||
|
||||
function setModelValue(model, value) {
|
||||
console.log('setModelValue->', {...model}, value)
|
||||
if (model.price !== value)
|
||||
model.price = value
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ const color = computed({
|
||||
set(v) {
|
||||
const maxLightness = 60
|
||||
const c = new Color(v).hsl()
|
||||
props.builder.color = c.saturation <= maxLightness ? v : c.lightness(maxLightness).string()
|
||||
props.builder.color = c.saturation <= maxLightness ? v : c.lightness(maxLightness).rgb().string()
|
||||
}
|
||||
})
|
||||
const colors = computed( ()=> {
|
||||
@@ -177,7 +177,7 @@ const colorStyle = computed(() => {
|
||||
function allocText(weight) {
|
||||
const alloc = props.builder.allocation
|
||||
if (alloc===null) return ''
|
||||
return allocationText(props.order.amount, weight * alloc, amountSymbol.value);
|
||||
return allocationText(weight * alloc, props.order.amount * alloc, amountSymbol.value);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,11 +214,12 @@ function translateOnDrag(shape) {
|
||||
|
||||
const shapeA = createShape(valueA.value, {color: defaultColor},
|
||||
function (model) {
|
||||
console.log('shapeA onModel', model)
|
||||
const value = props.getModelValue(model);
|
||||
if (value!==null && value!==undefined)
|
||||
valueA.value = value;
|
||||
if (model.color)
|
||||
props.builder.color = model.color;
|
||||
color.value = model.color
|
||||
},
|
||||
deleteSelf)
|
||||
|
||||
@@ -231,25 +232,21 @@ const shapeB = createShape(valueB.value, {color:defaultColor},
|
||||
if (value!==null && value!==undefined)
|
||||
valueB.value = value;
|
||||
if (model.color)
|
||||
props.builder.color = model.color;
|
||||
color.value = model.color
|
||||
},
|
||||
deleteSelf)
|
||||
|
||||
function interiorOnModel(model) {
|
||||
const v = model.textColor || model.lineColor || model.color
|
||||
if (v)
|
||||
color.value = v
|
||||
if (model.color)
|
||||
color.value = model.color
|
||||
}
|
||||
|
||||
let interiorShapes = []
|
||||
|
||||
function createInteriorShape(price, weight) {
|
||||
const model = {text: allocText(weight), color: props.builder.color};
|
||||
const shape = createShape(price, model, interiorOnModel, deleteSelf)
|
||||
shape.debug = true
|
||||
function createInteriorShape(index) {
|
||||
const shape = new props.shape(makeModel(index), interiorOnModel, deleteSelf)
|
||||
translateOnDrag(shape)
|
||||
interiorShapes.push(shape)
|
||||
// shape.create() // should happen automatically when a model with valid points is set
|
||||
}
|
||||
|
||||
|
||||
@@ -260,6 +257,23 @@ function removeInteriorShape() {
|
||||
}
|
||||
}
|
||||
|
||||
function makeModel(index) {
|
||||
const ws = weights.value
|
||||
const w = ws[index]
|
||||
const alloc = props.builder.allocation * ws[index];
|
||||
console.log('makeModel', index, ws, w, alloc)
|
||||
const result = {
|
||||
color: color.value,
|
||||
allocation: alloc,
|
||||
maxAllocation: Math.max(...weights.value),
|
||||
amount: props.order.amount * alloc,
|
||||
amountSymbol: amountSymbol.value,
|
||||
}
|
||||
props.setModelValue(result, values.value[index])
|
||||
console.log('made model', result)
|
||||
return result
|
||||
}
|
||||
|
||||
function adjustShapes() {
|
||||
// this is where all the shapes are created or adjusted
|
||||
console.log('adjustShapes()', valueA.value, valueB.value)
|
||||
@@ -280,13 +294,7 @@ function adjustShapes() {
|
||||
//
|
||||
// SINGLE SHAPE
|
||||
//
|
||||
if (!shapeA.beingDragged()) {
|
||||
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)
|
||||
}
|
||||
shapeA.setModel(makeModel(0))
|
||||
shapeB.delete()
|
||||
if (interiorShapes.length) {
|
||||
for( const shape of interiorShapes )
|
||||
@@ -298,19 +306,8 @@ function adjustShapes() {
|
||||
//
|
||||
// VALUE RANGE
|
||||
//
|
||||
if (!shapeA.beingDragged()) {
|
||||
const model = {text: allocText(ws[0]), color: colorStrings[0]};
|
||||
console.log('shape A not dragged setModelValue', model, vs[0])
|
||||
props.setModelValue(model, vs[0])
|
||||
shapeA.setModel(model)
|
||||
}
|
||||
if (!shapeB.beingDragged()) {
|
||||
const last = colorStrings.length - 1
|
||||
const model = {text: allocText(ws[last]), color: colorStrings[last]};
|
||||
console.log('shape B not dragged setModelValue', model, vs[last])
|
||||
props.setModelValue(model, vs[last])
|
||||
shapeB.setModel(model)
|
||||
}
|
||||
shapeA.setModel(makeModel(0))
|
||||
shapeB.setModel(makeModel(vs.length-1))
|
||||
const numInterior = Math.max(0,vs.length-2);
|
||||
// trim excess interior shapes
|
||||
while( interiorShapes.length > numInterior )
|
||||
@@ -320,13 +317,9 @@ function adjustShapes() {
|
||||
const v = vs[i]
|
||||
const w = ws[i];
|
||||
if (i-1 === interiorShapes.length)
|
||||
createInteriorShape(v, w)
|
||||
else if (!interiorShapes[i-1].beingDragged()) {
|
||||
const model = {text: allocText(w), color: colorStrings[i]};
|
||||
console.log('interior setModelValue', model, v)
|
||||
props.setModelValue(model, v)
|
||||
interiorShapes[i-1].setModel(model)
|
||||
}
|
||||
createInteriorShape(i)
|
||||
else
|
||||
interiorShapes[i-1].setModel(makeModel(i))
|
||||
}
|
||||
}
|
||||
return ''
|
||||
|
||||
Reference in New Issue
Block a user