@funnest/charts 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +23 -2
- package/dist/render/painter.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1554,6 +1554,10 @@ var Painter = class {
|
|
|
1554
1554
|
* A row of joined label segments ("pill") centered vertically on `y`.
|
|
1555
1555
|
* Returns each segment's rect for hit testing (e.g. an order's cancel button).
|
|
1556
1556
|
*/
|
|
1557
|
+
/** Width `pill` will take for these segments. */
|
|
1558
|
+
pillWidth(segments) {
|
|
1559
|
+
return segments.reduce((w, seg) => w + Math.ceil(this.measure(seg.text)) + (seg.padding ?? 8) * 2, 0);
|
|
1560
|
+
}
|
|
1557
1561
|
pill(segments, x, y, height = 20, radius = 4) {
|
|
1558
1562
|
const { ctx } = this;
|
|
1559
1563
|
const rects = [];
|
|
@@ -1581,6 +1585,7 @@ var inRect = (r, x, y, pad = 0) => x >= r.x - pad && x <= r.x + r.w + pad && y >
|
|
|
1581
1585
|
// src/objects/trading.ts
|
|
1582
1586
|
var LABEL_X = 12;
|
|
1583
1587
|
var LABEL_HEIGHT = 20;
|
|
1588
|
+
var LABEL_GAP = 6;
|
|
1584
1589
|
var ORDER_DASH = [6, 4];
|
|
1585
1590
|
var ALERT_DASH = [2, 3];
|
|
1586
1591
|
var TradingLayer = class {
|
|
@@ -1738,6 +1743,22 @@ var TradingLayer = class {
|
|
|
1738
1743
|
ctx.fill();
|
|
1739
1744
|
if (g.count > 1) p.text(String(g.count), g.x + 7, g.y, buy ? palette.up : palette.down, "left", "middle");
|
|
1740
1745
|
}
|
|
1746
|
+
const placed = [];
|
|
1747
|
+
const placeX = (width, y) => {
|
|
1748
|
+
let x = LABEL_X;
|
|
1749
|
+
for (let moved = true; moved; ) {
|
|
1750
|
+
moved = false;
|
|
1751
|
+
for (const r of placed) {
|
|
1752
|
+
const overlapsY = Math.abs(r.y + LABEL_HEIGHT / 2 - y) < LABEL_HEIGHT + 2;
|
|
1753
|
+
if (overlapsY && x < r.x + r.w + LABEL_GAP && x + width > r.x - LABEL_GAP) {
|
|
1754
|
+
x = r.x + r.w + LABEL_GAP;
|
|
1755
|
+
moved = true;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
placed.push({ x, y: y - LABEL_HEIGHT / 2, w: width, h: LABEL_HEIGHT });
|
|
1760
|
+
return x;
|
|
1761
|
+
};
|
|
1741
1762
|
for (const pos of this.positions.values()) {
|
|
1742
1763
|
const y = c.priceToY(pos.price);
|
|
1743
1764
|
badges.push({ y, text: c.formatPrice(pos.price), bg: palette.text, fg: palette.background });
|
|
@@ -1756,7 +1777,7 @@ var TradingLayer = class {
|
|
|
1756
1777
|
fg: "#FFFFFF"
|
|
1757
1778
|
});
|
|
1758
1779
|
}
|
|
1759
|
-
p.pill(segments,
|
|
1780
|
+
p.pill(segments, placeX(p.pillWidth(segments), y), y, LABEL_HEIGHT);
|
|
1760
1781
|
}
|
|
1761
1782
|
for (const [id, order] of this.orders) {
|
|
1762
1783
|
const price = this.drag?.id === id ? this.drag.price : order.price;
|
|
@@ -1768,7 +1789,7 @@ var TradingLayer = class {
|
|
|
1768
1789
|
const main = order.alert ? order.label ?? labels.alert : [order.side === "buy" ? labels.buy : labels.sell, order.label, String(order.quantity)].filter(Boolean).join(" ");
|
|
1769
1790
|
const segments = [{ text: main, bg: color, fg: "#FFFFFF" }];
|
|
1770
1791
|
if (order.onCancel) segments.push({ text: "\xD7", bg: color, fg: "#FFFFFF", padding: 7 });
|
|
1771
|
-
const rects = p.pill(segments,
|
|
1792
|
+
const rects = p.pill(segments, placeX(p.pillWidth(segments), y), y, LABEL_HEIGHT);
|
|
1772
1793
|
if (order.onCancel && rects[1]) p.vLine(rects[1].x, y - 6, y + 6, "rgba(255,255,255,0.4)");
|
|
1773
1794
|
this.labelRects.set(id, {
|
|
1774
1795
|
label: { x: rects[0].x, y: rects[0].y, w: rects.reduce((w, r) => w + r.w, 0), h: LABEL_HEIGHT },
|
package/dist/render/painter.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export declare class Painter {
|
|
|
21
21
|
* A row of joined label segments ("pill") centered vertically on `y`.
|
|
22
22
|
* Returns each segment's rect for hit testing (e.g. an order's cancel button).
|
|
23
23
|
*/
|
|
24
|
+
/** Width `pill` will take for these segments. */
|
|
25
|
+
pillWidth(segments: readonly PillSegment[]): number;
|
|
24
26
|
pill(segments: readonly PillSegment[], x: number, y: number, height?: number, radius?: number): Rect[];
|
|
25
27
|
}
|
|
26
28
|
export interface Rect {
|