Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to Vela, newest first.

## [Unreleased]

### Fixed

- **Extended boxes no longer squeeze the price scale from off-screen.** A box
drawn with a one-sided extension (`extend.right` or `extend.left`) contributes
its prices to the automatic price scale only while some painted part of it —
the anchor span or the side its extension actually covers — crosses the
visible bars. Previously any extended box counted everywhere on the time
axis, so an indicator keeping a box near the latest bars (a common
order-block idiom) flattened the candles in every earlier window the moment
you scrolled back in history. Boxes extended toward the window, and
`extend.both` boxes, still scale into view as before.
### Added

- **Right-click the status line to shape it.** The in-chart status line now opens
Expand Down
7 changes: 6 additions & 1 deletion src/renderers/shared/DrawingSceneRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ export class DrawingSceneRenderer {
priceRange(from: number, to: number): DrawingPriceRange | null {
const lo = Math.min(from, to);
const hi = Math.max(from, to);
// Painted-part coverage: the anchor span plus the side(s) `extend` projects
// toward. A one-sided extension paints nothing on its other side, so a window
// entirely there must not inherit the drawing's prices.
const visible = (a: number, b: number, extend: DrawingExtend): boolean => {
if (extend !== 'none') return true;
if (extend === 'both') return true;
if (extend === 'left') return Math.max(a, b) >= lo;
if (extend === 'right') return Math.min(a, b) <= hi;
return Math.max(a, b) >= lo && Math.min(a, b) <= hi;
};
let min = Infinity;
Expand Down
75 changes: 74 additions & 1 deletion test/drawing-extend-autoscale.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import { DrawingSceneRenderer, EMPTY_DRAWING_SET, type DrawingSet } from '../src/renderers/shared/DrawingSceneRenderer';
import type { DrawingLine } from '../src/core/model/drawings';
import type { DrawingBox, DrawingLine } from '../src/core/model/drawings';
import type { VelaTheme } from '../src/core/options';

/**
Expand Down Expand Up @@ -90,3 +90,76 @@ describe('extended lines and autoscale (priceRange)', () => {
}
});
});

function box(over: Partial<DrawingBox>): DrawingBox {
return {
id: 'bx',
paneId: 'price',
xloc: 'bar_index',
extend: 'none',
left: 100,
top: 6,
right: 110,
bottom: 5,
bgColor: '#0f04',
borderColor: '#0f0',
borderWidth: 1,
borderStyle: 'solid',
textSize: 'auto',
hAlign: 'center',
vAlign: 'center',
wrap: false,
fontFamily: 'default',
bold: false,
italic: false,
...over,
};
}

function boxRangeOf(bx: DrawingBox, from: number, to: number) {
const set: DrawingSet = { ...EMPTY_DRAWING_SET, boxes: [bx] };
const r = new DrawingSceneRenderer({ timeToLogical: () => 0, barAt: () => null, theme });
r.setSet(set);
return r.priceRange(from, to);
}

/**
* Boxes and autoscale: a box folds its top/bottom while some painted part of it —
* anchor span plus its `extend` projection — crosses the visible bar window. An
* `extend.right` box paints nothing LEFT of its anchors, so a window entirely
* before it must not inherit its prices (the box would otherwise squeeze every
* earlier window's pane toward wherever it sits).
*/
describe('extended boxes and autoscale (priceRange)', () => {
it('folds top/bottom while the anchor span is in view — extended or not', () => {
for (const extend of ['none', 'left', 'right', 'both'] as const) {
const r = boxRangeOf(box({ extend }), 90, 120);
expect(r).not.toBeNull();
expect(r!.min).toBe(5);
expect(r!.max).toBe(6);
}
});

it('extend.both keeps folding with OFF-SCREEN anchors — the projection crosses every window', () => {
for (const window of [[500, 600], [0, 50]] as const) {
const r = boxRangeOf(box({ extend: 'both' }), window[0], window[1]);
expect(r).not.toBeNull();
expect(r!.min).toBe(5);
expect(r!.max).toBe(6);
}
});

it('extend.left / extend.right fold only on the side the projection covers', () => {
// Anchors at bars 100..110; extend.right paints over [100, ∞).
expect(boxRangeOf(box({ extend: 'right' }), 500, 600)).not.toBeNull();
expect(boxRangeOf(box({ extend: 'right' }), 0, 50)).toBeNull();
// extend.left paints over (-∞, 110].
expect(boxRangeOf(box({ extend: 'left' }), 0, 50)).not.toBeNull();
expect(boxRangeOf(box({ extend: 'left' }), 500, 600)).toBeNull();
});

it('unextended off-screen boxes stay excluded (regression baseline)', () => {
expect(boxRangeOf(box({}), 500, 600)).toBeNull();
expect(boxRangeOf(box({}), 0, 50)).toBeNull();
});
});
Loading