Libraryless. Click here for Pure Java version (31205L/199K).
sclass TickerGraphPainter extends AbstractTickerPainter is IToolTipMaker, MakesBufferedImage { settable S pricePrefix = "Price="; settable bool fillRedAndGreen; *() {} *(TickerSequence ticker) { ticker(ticker); } public void drawOn(Graphics2D g) { antiAliasOn(g); if (verticalRange == null) verticalRange(verticalRangeForTicker(ticker)); if (horizontalRange == null) horizontalRange(horizontalRangeForTicker(ticker)); if (horizontalRange == null) ret; drawPercentLines(g); drawAdditionalObjects(g); // Draw ticker graph var xRange = roundToIntRange(xRange()); int idx1 = ticker.indexOfTimestampAtOrBefore(xFromScreen(xRange.start)); int x = xRange.start; if (idx1 == 0) x = max(x, ifloor(xToScreen(ticker.startTime()))); int idx2 = idx1; int y0 = yToScreen_int(0); for (; x < xRange.end; x++) { idx1 = idx2; idx2 = ticker.indexOfTimestampAtOrBefore(xFromScreen(x+1)); var seq = ticker.subSequence(idx1, idx2+1); double minPrice = seq.minPrice(); double maxPrice = seq.maxPrice(); int y1 = yToScreen_int(maxPrice); int y2 = yToScreen_int(minPrice); if (fillRedAndGreen) { if (minPrice > 0) drawLine(g, x, y2+1, x, y0-1, directionToCandleColor(1)); else if (maxPrice < 0) drawLine(g, x, y0, x, y1-1, directionToCandleColor(-1)); } drawLine(g, x, y1, x, y2, Color.white); } drawPositions(g); } public BufferedImage render() { var img = super.render(); var img2 = cloneBufferedImageWithMeta(img); metaSet(img2, IToolTipMaker, this); ret img2; } public S getToolTip(Pt p) { double time = xFromScreen(p.x); double price = ticker.priceAtTimestamp(time); ret spaceCombine( ticker.market, formatPrice(price), "at", formatLocalDateWithSeconds(lround(time))); } swappable S formatPrice(double price) { ret pricePrefix() + formatDouble3X(price); } }
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: | 233 / 430 |
Version history: | 28 change(s) |
Referenced in: | [show references] |