Libraryless. Click here for Pure Java version (31205L/199K).
1 | sclass TickerGraphPainter extends AbstractTickerPainter is IToolTipMaker, MakesBufferedImage { |
2 | settable S pricePrefix = "Price="; |
3 | settable bool fillRedAndGreen; |
4 | |
5 | *() {} |
6 | *(TickerSequence ticker) { ticker(ticker); } |
7 | |
8 | public void drawOn(Graphics2D g) { |
9 | antiAliasOn(g); |
10 | |
11 | if (verticalRange == null) |
12 | verticalRange(verticalRangeForTicker(ticker)); |
13 | if (horizontalRange == null) |
14 | horizontalRange(horizontalRangeForTicker(ticker)); |
15 | if (horizontalRange == null) |
16 | ret; |
17 | |
18 | drawPercentLines(g); |
19 | drawAdditionalObjects(g); |
20 | |
21 | // Draw ticker graph |
22 | |
23 | var xRange = roundToIntRange(xRange()); |
24 | int idx1 = ticker.indexOfTimestampAtOrBefore(xFromScreen(xRange.start)); |
25 | int x = xRange.start; |
26 | if (idx1 == 0) |
27 | x = max(x, ifloor(xToScreen(ticker.startTime()))); |
28 | int idx2 = idx1; |
29 | int y0 = yToScreen_int(0); |
30 | |
31 | for (; x < xRange.end; x++) { |
32 | idx1 = idx2; |
33 | idx2 = ticker.indexOfTimestampAtOrBefore(xFromScreen(x+1)); |
34 | var seq = ticker.subSequence(idx1, idx2+1); |
35 | double minPrice = seq.minPrice(); |
36 | double maxPrice = seq.maxPrice(); |
37 | int y1 = yToScreen_int(maxPrice); |
38 | int y2 = yToScreen_int(minPrice); |
39 | |
40 | if (fillRedAndGreen) { |
41 | if (minPrice > 0) |
42 | drawLine(g, x, y2+1, x, y0-1, directionToCandleColor(1)); |
43 | else if (maxPrice < 0) |
44 | drawLine(g, x, y0, x, y1-1, directionToCandleColor(-1)); |
45 | } |
46 | |
47 | drawLine(g, x, y1, x, y2, Color.white); |
48 | } |
49 | |
50 | drawPositions(g); |
51 | } |
52 | |
53 | public BufferedImage render() { |
54 | var img = super.render(); |
55 | var img2 = cloneBufferedImageWithMeta(img); |
56 | metaSet(img2, IToolTipMaker, this); |
57 | ret img2; |
58 | } |
59 | |
60 | public S getToolTip(Pt p) { |
61 | double time = xFromScreen(p.x); |
62 | double price = ticker.priceAtTimestamp(time); |
63 | ret spaceCombine( |
64 | ticker.market, |
65 | formatPrice(price), |
66 | "at", |
67 | formatLocalDateWithSeconds(lround(time))); |
68 | } |
69 | |
70 | swappable S formatPrice(double price) { |
71 | ret pricePrefix() + formatDouble3X(price); |
72 | } |
73 | } |
Began life as a copy of #1036145
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036170 |
Snippet name: | TickerGraphPainter |
Eternal ID of this version: | #1036170/29 |
Text MD5: | bcefb0d87485eaf7bcf6e203e3b8d0d5 |
Transpilation MD5: | 9950ff211ee25d36bd88a0a0c0872032 |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-03-16 16:48:47 |
Source code size: | 2128 bytes / 73 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 235 / 433 |
Version history: | 28 change(s) |
Referenced in: | [show references] |