Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

50
LINES

< > BotCompany Repo | #1036170 // TickerGraphPainter

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (17538L/103K).

sclass TickerGraphPainter extends AbstractTickerPainter is IToolTipMaker, MakesBufferedImage {
  settable S pricePrefix = "Price=";  
  
  public void drawOn(Graphics2D 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());
    for (int x = xRange.start; x < xRange.end; x++) {
      int idx1 = ticker.indexOfTimestamp(xFromScreen(x));
      int idx2 = ticker.indexOfTimestamp(xFromScreen(x+1));
      var seq = ticker.subSequence(idx1, idx2+1);
      int y1 = iround(yToScreen(seq.maxPrice()));
      int y2 = iround(yToScreen(seq.minPrice()));
      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);
  }
}

Author comment

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/22
Text MD5: 3f92844166f3af376087c961a251003b
Transpilation MD5: 27ba9f7caecb19a8103069b814bcad4a
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-30 17:49:37
Source code size: 1502 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 61 / 163
Version history: 21 change(s)
Referenced in: [show references]