Node com.nodelab.view.Ticker

com.nodelab.0.10373
Instance of TypeScriptInfo

Node dataValue
org.edgescript.TypeScriptInfo.prerequisiteParcelsList{}
org.edgescript.TypeScriptInfo.prerequisiteMethodsList{}
org.edgescript.TypeScriptInfo.scriptimport org.uninode.collection.Collection; import org.uninode.collection.Array; import org.uninode.collection.List; import com.nodelab.view.WidgetDiagram; import com.nodelab.view.PanelDiagram; import com.nodelab.view.WidgetAxes; import com.nodelab.view.PanelAxes; import com.nodelab.view.WidgetHeader; import com.nodelab.Listable; import com.nodelab.Actor; import com.nodelab.Mixable; import com.nodelab.Source; import org.uninode.dimension.DimensionHistory; import org.uninode.widget.Workspace; import org.uninode.widget.Place; import com.nodelab.view.DiagramPainterTicker; Array[Array[Real]] values; Int size; Int next; Int first; WidgetDiagram wDiagram; Int delay; List[Int] dayShifts; constructor() { Diagram:(); TickReceiver:(); setResolution(5, 100); } /* Boolean isSourceListener() { false; } */ type Boolean isResourceOf(Listable node, Signature aspect) { if (aspect == 'view') return true; return false; } Collection[Type] requiredDimensions() { #(); } trace void setResolution(Int delay, Int size) { this.delay = delay; this.size = size; next = 0; first = size; } Int rtDelay() { delay; } trace Boolean tick(Int counter) { if (counter % delay > 0) return; Int i = 0; while (i < actorCount()) { Actor actor = getActor(i); Real val = actor.evaluate(); values.get(i).put(next, val); WidgetAxes axes = wDiagram.axesFor(actor); if (counter % 120 == 0) { axes.reset(); axes.adjustMinMax(values.get(i)); } else axes.adjustMinMax(val); i = i + 1; } next = (next + 1) % size; if (next == first) first = -1; if (dayShifts.size > 0 && next == dayShifts.last) dayShifts.removeLast; wDiagram.repaint; true; } trace void prepare() { Int aCount = actorCount(); values = new Array[Array[Real]](aCount); scene().setRealtime(true); DimensionHistory@'org.uninode.Dimension.to' = Date.now.addDays(1); DimensionHistory@'org.uninode.Dimension.from' = Date.now.addDays(-7); // DimensionHistory@'org.uninode.DimensionHistory.resolution' = 'minute'; Int index = 0; while (index < aCount) { Actor actor = getActor(index); List[Date] dates = new List[Date](100); List[Real] vs = new List[Real](100); actor.source.collectValues(dates, vs, DimensionHistory); Array[Real] pv = new Array[Real](size); if (vs.size <= size) { pv.copyFrom(0, vs.size, vs, 0); next = vs.size; first = next - 1; } else { pv.copyFrom(0, size, vs, vs.size - size); next = 0; first = size - 1; } wDiagram.axesFor(actor).adjustMinMax(pv); values.put(index, pv); index = index + 1; } /* Int i = times.size - 1; Time trailTime = times.last; external cond_history_resolution = #day; instance dayShifts = new List(Int); while (i >= valueStart) { if (trailTime != times.at(i)) { instance dayShifts.add(i - valueStart); } trailTime = times.at(i); i = i - 1; } */ } trace void designView(Workspace ws) { ws.addWidget(new WidgetHeader(ws), new Place(0, 0).setFill('horizontal').setDimensions(2, 1)); wDiagram = new WidgetDiagram(ws, this); ws.addWidget(wDiagram, new Place(0, 1).setWeight(1.0, 1.0, 'both')); // axes = new WidgetAxes(ws, wd, 0); // ws.addWidget(axes, new Place(1, 1).setWeight(0.0, 1.0, 'vertical').setPreferredSize(30, 0)); // prepareAxis(wDiagram); registerForTick(); } trace void addAxis(Workspace ws, WidgetDiagram wd, Int count) { wd.removeAxis; Int i = 0; while (i < count) { WidgetAxes axes = new WidgetAxes(ws, wd, 0); ws.addWidget(axes, new Place(i + 1, 1).setWeight(0.0, 1.0, 'vertical').setPreferredSize(30, 0)); i = i + 1; } } /* void designEditor(Workspace ws) { ws.addWidget(new Button(new Place(0, 0).setPadding(2, 2), "Add", "Add source").addListener(void(){ Mixable mix = Producer.mix(0); if (mix.class.subclassOf(Source)) addSource(Source{mix}); diagram.prepareAxis(); prepare()}); } */ trace void paint(Graphics g, PanelDiagram diagram, Rectangle bounds) { prepareAxis(wDiagram); Rectangle r = new Rectangle(bounds.left, bounds.top, bounds.right - 3, bounds.bottom); PanelAxes axes = diagram.axesFor(getActor(0)); axes.adjustMinMax(values.get(0)); axes.paintGrid(g, r); Int i = 0; g.setColor(Color.paleGreen); while (i < dayShifts.size) { Int ind = dayShifts.get(i); Int dayIndex = (size + ind - next) % size; Int x = Int{r.left + r.width * dayIndex / size}; g.drawLine(x, r.top, x, r.bottom); i = i + 1; } i = actorCount() - 1; while (i >= 0) { Actor actor = getActor(i); // DiagramPainterTicker.draw(g, actor, r, values.get(i), next, diagram.axesFor(actor)); i = i - 1; } Real val = getActor(0).evaluate(); Int y = Int{axes.coordinateFor(val)}; g.setColor(Color.darkGray); if (bounds.height > 50) { if (y > bounds.height / 2) g.drawString(bounds.right - 30, bounds.top + 14, val.toString); else g.drawString(bounds.right - 30, bounds.bottom - 14, val.toString); } g.drawLine(bounds.right - 2, y, bounds.right, y); if (first > 0) { Int firstIndex = (size + first - next) % size; x = Int{r.left + r.width * firstIndex / size}; g.setColor(Color.red); g.drawLine(x, r.top, x, r.bottom); } }
org.edgescript.TypeScriptInfo.defineTypecom.nodelab.view.Ticker
org.edgescript.TypeScriptInfo.prerequisiteScriptsList{}