com.nodelab.view

Type Ticker

com.nodelab.0.10021
Instance of Type
Inheriting from Diagram, TickReceiver

Type dataValue
org.uninode.Type.displayPatterna {att:org.uninode.Node.type}
org.uninode.Resource.resourceType
org.uninode.Resource.label
org.uninode.Resource.resourceOfList{}
org.uninode.Listable.resourcesReference[org.uninode.Listable.resources] of com.nodelab.view.Ticker

Attribute summaryDefined inUninode® IdPropertiesDefault
Reference[org.uninode.Listable.resources]resourcesListableorg.uninode.0.2001type
StringtoString
This is the display string.
Nodeorg.uninode.0.102
Typetype
The type of an object determines the behaviour and attributes of the object.
Nodeorg.uninode.0.101
StringuriNodeorg.uninode.0.103
StringlabelResourceorg.uninode.0.2041type
List[Type]resourceOfResourceorg.uninode.0.2042type
SignatureresourceType
This defines the type of resource. It can be 'view', 'adapter' or 'action'
Resourceorg.uninode.0.2043type

Method summaryDefined inOverridesProperties
voidactivateListable
voiddesignEditor(WidgetWorkspace ws)Listable
voidgenerateScript(ScriptGenerationInfo info)
Prepare and generate initialization code
ScriptGenerator
voidinstanceScript(ScriptGenerationInfo info)
return either variable name (like 'ave1', found in info), or a constructor call (new ...)
ScriptGenerator
BooleanisResourceOf(Listable listable, Signature aspect)Mixabletype
ListablemixOn(Mixable mix)Mixable
ListablemixWith(Mixable mix)Mixable
voidregisterForTickTickReceiver
StringresourceStringListableintrospection
Booleantick(Int counter)TickReceiver
voidcom.nodelab.java.diagram.AddAxesAxDiagram
voidcom.nodelab.java.diagram.AddAxisWWWDInDiagram
Axescom.nodelab.java.diagram.AxesAtInDiagram
Intcom.nodelab.java.diagram.AxesCountDiagram
Axescom.nodelab.java.diagram.AxesForAcDiagram
voidcom.nodelab.java.diagram.ConstructorDiagram
voidcom.nodelab.java.diagram.DrawTopGrReDiagramGraphical
Booleancom.nodelab.java.diagram.PrepareAxisWDDiagram
voidcom.nodelab.java.graphical.ConstructorGraphical
voidcom.nodelab.java.graphical.DragMouseReReReReGraphicalView
voidcom.nodelab.java.graphical.DrawTopGrReGraphical
Booleancom.nodelab.java.graphical.IsSourceListenerGraphical
voidcom.nodelab.java.graphical.PaintGrPDReGraphical
Collection[Type]com.nodelab.java.graphical.RequiredDimensionsGraphicalView
voidcom.nodelab.java.graphical.RestoreDisplayGraphical
voidcom.nodelab.java.view.ActivateViewListable
Intcom.nodelab.java.view.ActorCountView
Actorcom.nodelab.java.view.ActorForSoView
Actorcom.nodelab.java.view.AddSourceSoView
voidcom.nodelab.java.view.ConstructorView
voidcom.nodelab.java.view.DesignViewWWView
Dimensioncom.nodelab.java.view.DimensionAtInView
Intcom.nodelab.java.view.DimensionCountView
Dimensioncom.nodelab.java.view.DimensionTypeTyView
voidcom.nodelab.java.view.DragMouseReReReReView
voidcom.nodelab.java.view.GenerateScriptSIViewScriptGenerator
Actorcom.nodelab.java.view.GetActorInView
voidcom.nodelab.java.view.InstallView
voidcom.nodelab.java.view.InstanceScriptSIViewScriptGenerator
Booleancom.nodelab.java.view.IsPerpetualView
voidcom.nodelab.java.view.PrepareView
Collection[Type]com.nodelab.java.view.RequiredDimensionsView
Scenecom.nodelab.java.view.SceneView
WidgetWorkspacecom.nodelab.java.view.WorkspaceView

Script summary
com.nodelab.0.10373
import 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);
  }
}