post-order line draw improvements
This commit is contained in:
@@ -4,7 +4,7 @@ import {invokeCallback, mixin} from "@/common.js";
|
||||
import {chart, createShape, deleteShapeId, dragging, draggingShapeIds, drawShape, widget} from "@/charts/chart.js";
|
||||
import Color from "color";
|
||||
import {dirtyItems, dirtyPoints, nearestOhlcStart} from "@/charts/chart-misc.js";
|
||||
import {computeInterceptSlope} from "@/misc.js";
|
||||
import {defined} from "@/misc.js";
|
||||
|
||||
|
||||
//
|
||||
@@ -40,6 +40,7 @@ export const ShapeType = {
|
||||
|
||||
|
||||
export function allocationText(weight, amount, symbol, separator = ' ') {
|
||||
// set breakout=true for a buy breakout and breakout=false for a sell breakout
|
||||
const hasAmount = amount !== null && amount !== undefined && amount > 0
|
||||
if (hasAmount)
|
||||
amount = Number(amount)
|
||||
@@ -109,7 +110,7 @@ export class Shape {
|
||||
this.model.amount = null
|
||||
this.model.amountSymbol = null
|
||||
this.model.extraText = null
|
||||
this.model.textLocation = 'above'
|
||||
this.model.textLocation = null // defaults to 'above' if not set
|
||||
|
||||
// LEAF SUBCLASSES MUST CALL setModel(model) AFTER ALL CONSTRUCTION.
|
||||
}
|
||||
@@ -119,19 +120,21 @@ export class Shape {
|
||||
//
|
||||
|
||||
setModel(model) {
|
||||
if (model.color)
|
||||
if (defined(model.color))
|
||||
this.model.color = model.color
|
||||
if (model.allocation !== null && model.allocation !== undefined)
|
||||
if (defined(model.allocation))
|
||||
this.model.allocation = model.allocation
|
||||
if (model.maxAllocation !== null && model.maxAllocation !== undefined)
|
||||
if (defined(model.maxAllocation))
|
||||
this.model.maxAllocation = model.maxAllocation
|
||||
if (model.amount !== null && model.amount !== undefined)
|
||||
if (defined(model.amount))
|
||||
this.model.amount = model.amount
|
||||
if (model.amountSymbol)
|
||||
if (defined(model.amountSymbol))
|
||||
this.model.amountSymbol = model.amountSymbol
|
||||
if (model.extraText)
|
||||
if (defined(model.extraText))
|
||||
this.model.extraText = model.extraText
|
||||
if (model.textLocation)
|
||||
if (defined(model.breakout))
|
||||
this.model.breakout = model.breakout
|
||||
if (defined(model.textLocation))
|
||||
this.model.textLocation = model.textLocation
|
||||
|
||||
const newProps = {}
|
||||
@@ -141,7 +144,7 @@ export class Shape {
|
||||
newProps.textcolor = color
|
||||
|
||||
// line color
|
||||
if (this.model.allocation && this.model.maxAllocation) {
|
||||
if (defined(this.model.allocation) && defined(this.model.maxAllocation)) {
|
||||
const w = this.model.allocation / this.model.maxAllocation
|
||||
if (!w)
|
||||
newProps.linecolor = 'rgba(0,0,0,0)'
|
||||
@@ -158,6 +161,8 @@ export class Shape {
|
||||
|
||||
// text label
|
||||
let text = allocationText(this.model.allocation, this.model.amount, this.model.amountSymbol)
|
||||
if (this.model.breakout)
|
||||
text += ' ' + (this.model.textLocation==='above' ? '▲Breakout▲' : '▼Breakout▼')
|
||||
if (this.model.extraText)
|
||||
text += ' '+this.model.extraText
|
||||
if (this.debug) text = `${this.id} ` + text
|
||||
@@ -199,10 +204,13 @@ export class Shape {
|
||||
const p = this.type.drawingProp
|
||||
const lc = this.model.lineColor ? this.model.lineColor : this.model.color;
|
||||
const tc = this.model.textColor ? this.model.textColor : this.model.color;
|
||||
const tl = this.model.textLocation ? this.model.textLocation : 'above';
|
||||
if (lc)
|
||||
o[p+".linecolor"] = lc
|
||||
if (tc)
|
||||
o[p+".textcolor"] = tc
|
||||
if (tl)
|
||||
o[p+".textlocation"] = tl
|
||||
return o
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user