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

63
LINES

< > BotCompany Repo | #1036260 // JTickerView

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

Transpiled version (37269L) is out of date.

sclass JTickerView is Swingable {
  settable S coin;
  settable int h = 200;
  settable TickerSequence ticker;
  settable AbstractTickerPainter painter;
  settable IImageSurfaceMaker imageSurfaceMaker = -> imageSurfaceWithToolTip();
  settable ImageSurface isTicker;
  settable G22TradingStrategy strategy;
  settable double cellSize = naN();
  settable bool center;
  
  JSlider timeZoomSlider = jSlider(1, 10, 1);
  ReliableSingleThread rstPaint = rst(l0 repaintImpl);
  
  event settingUpPainter(AbstractTickerPainter painter);
  
  *() {}
  *(TickerSequence *ticker) {}
  
  swappable void makePainter() {
    painter if null = new TickerGraphPainter;
    painter.w(300*intFromSlider(timeZoomSlider)).h(h);
    painter.ticker(ticker);
    painter.drawPercentLines(false);
    if (!isNaN(cellSize))
      painter.cellSize(cellSize);
    /*painter.horizontalRange(
      transformBetweenDoubleRanges (varTimeZoom get) (zeroToOne) (painter horizontalRangeForTicker ticker)
    zoomedRange <- transformBetweenDoubleRanges (varTimeZoom get) (zeroToOne) (toDoubleRange < ticker timeRange)
    painter verticalRange <
    painter verticalRangeForTicker (ticker subSequenceByTimestamps (lround < zoomedRange start) (lround < zoomedRange end))
    */

    //painter.additionalObjects.add(g -> painter drawTimeGrid(g, 60));

    if (strategy != null)
      for (p : strategy.closedPositions())
        painter.positions.add(TradingPosition.fromStrategy(p));

    settingUpPainter(painter);
  }
  
  void repaintImpl() {
    makePainter();
    isTicker.setImage(painter.render());
  }
  
  cachedVisualize {
    if (isTicker == null) isTicker = imageSurfaceMaker.newImageSurface();
    onChange(timeZoomSlider, rstPaint);
    rstPaint.trigger();
    ret jCenteredSection(str(ticker),
      centerAndSouthWithMargin(
        jMinHeight(h, center ? jscroll_horizontal_center_borderless(isTicker) : jscroll_horizontal_borderless(isTicker)),
        withLabel("Time zoom:", timeZoomSlider)
      ));
  }
  
  selfType defaultTimeZoom(int zoom) {
    setSliderValue(timeZoomSlider, zoom);
    this;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036260
Snippet name: JTickerView
Eternal ID of this version: #1036260/34
Text MD5: 0ffadbb09bc5e434737029c27fadc9a5
Author: stefan
Category: javax / trading / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-03-13 13:58:02
Source code size: 2154 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 215 / 392
Version history: 33 change(s)
Referenced in: [show references]