1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Low-level coordinate conversion and zoom helpers.
//!
//! These utility functions are used by [`pan_zoom`](super::pan_zoom) and the
//! rendering pipeline to convert between screen-space Y coordinates and price
//! values, and to apply price-axis zoom transformations anchored at a given
//! price level.
use Rect;
/// Convert a Y pixel coordinate to its corresponding price value.
///
/// The conversion is linear within the `price_rect`, where the bottom edge
/// maps to `min` and the top edge maps to `max`. Values outside the rect
/// are clamped to the `[min, max]` range.
///
/// # Arguments
///
/// * `y` - Screen-space Y coordinate
/// * `min` - Minimum price at the bottom of `price_rect`
/// * `max` - Maximum price at the top of `price_rect`
/// * `price_rect` - The chart area rectangle used for the conversion
/// Apply a zoom transformation to a price range, anchored at a specific price.
///
/// The zoom uses an exponential response so that equal mouse-wheel deltas produce
/// proportional zoom regardless of the current range. The `anchor` price stays
/// fixed on screen while the range expands or contracts around it.
///
/// # Arguments
///
/// * `bounds` - Current `(min, max)` price range
/// * `anchor` - Price to keep fixed on screen (typically under the cursor)
/// * `delta_y` - Mouse wheel delta (positive = zoom out, negative = zoom in)
/// * `height` - Chart height in pixels (used to normalize delta)
///
/// # Returns
///
/// New `(min, max)` price range after zooming, clamped to 5%..2000% of the original range.