Question about how to capture when the tick changes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about how to capture when the tick changes

cnietocoria
Hello,

I was learning how to use the JFreeChart library that is included in RS. I managed to create a static chart. My agents have a double variable "value" that changes every tick. So, when I perform a double click over the agent I display the line chart of value.

So far, is good but I would like that the chart automatically refreshes the changes over the data set. As I explained my value changes with a new tick, so I was thinking that should listen to the Schedule instance to get where a new tick is performed, whit it update the data set.

It should be like in this example of a dynamic data set.

public void actionPerformed(final ActionEvent e) {
        if (e.getActionCommand().equals("ADD_DATA")) {
            final double factor = 0.90 + 0.2 * Math.random();
            this.lastValue = this.lastValue * factor;
            final Millisecond now = new Millisecond();
            System.out.println("Now = " + now.toString());
            this.series.add(new Millisecond(), this.lastValue);
        }
    }
Although, instead of performing an action with the mouse, like add data, I think that could use the scheduler instance.

Or maybe is other way to perform it on RS, for example the default charts.

Thanks in advance,

Cesar


--
Cesar Nieto Coria

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about how to capture when the tick changes

Tatara, Eric R.

I would schedule a simple action that updates the chart.  For example:

 

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

 

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

 

import repast.simphony.engine.environment.RunEnvironment;

import repast.simphony.engine.schedule.IAction;

import repast.simphony.engine.schedule.ISchedulableAction;

import repast.simphony.engine.schedule.ISchedule;

import repast.simphony.engine.schedule.ScheduleParameters;

import repast.simphony.visualization.ProbeEvent;

import repast.simphony.visualization.ProbeListener;

 

public class MyProbeListener2 implements ProbeListener {

 

       @Override

       public void objectProbed(ProbeEvent evt) {

              JFrame frame = new JFrame();

              JPanel panel = new JPanel();

             

              JLabel label = new JLabel("Tick: --");

 

              panel.add(label);

              frame.setContentPane(panel);

              frame.pack();

              frame.setVisible(true);

             

              ISchedule schedule = RunEnvironment.getInstance().getCurrentSchedule();

             

              double start = schedule.getTickCount() + 1;

              ISchedulableAction action = schedule.schedule(ScheduleParameters.createRepeating(start, 1), new IAction(){

                    

                     @Override

                     public void execute() {

                           double d = schedule.getTickCount();

                          

                           label.setText("Tick: " + d);

                     }

                    

              });

             

              frame.addWindowListener(new WindowAdapter() {

                     @Override

                     public void windowClosing(WindowEvent windowEvent) {

                           schedule.removeAction(action);

                     }

              });

       }

}

 

 

From: Cesar Nieto Coria [mailto:[hidden email]]
Sent: Thursday, June 15, 2017 10:27 AM
To: [hidden email]
Subject: [Repast-interest] Question about how to capture when the tick changes

 

Hello,

I was learning how to use the JFreeChart library that is included in RS. I managed to create a static chart. My agents have a double variable "value" that changes every tick. So, when I perform a double click over the agent I display the line chart of value.

So far, is good but I would like that the chart automatically refreshes the changes over the data set. As I explained my value changes with a new tick, so I was thinking that should listen to the Schedule instance to get where a new tick is performed, whit it update the data set.

It should be like in this example of a dynamic data set.


public void actionPerformed(final ActionEvent e) {
        if (e.getActionCommand().equals("ADD_DATA")) {
            final double factor = 0.90 + 0.2 * Math.random();
            this.lastValue = this.lastValue * factor;
            final Millisecond now = new Millisecond();
            System.out.println("Now = " + now.toString());
            this.series.add(new Millisecond(), this.lastValue);
        }
    }

Although, instead of performing an action with the mouse, like add data, I think that could use the scheduler instance.

Or maybe is other way to perform it on RS, for example the default charts.

Thanks in advance,

Cesar

 


--

Cesar Nieto Coria


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...