Reference 〉Hook

agentClick( list[Agent] agents, NetworkPlot plot, int t )

Runs when an agent is clicked in the NetworkPlot plot.

Required Parameters

  • agents list[Agent]

    The live agent(s) that were clicked on, possibly multiple if there are overlapping agents in the current map. Note that, if clicking on a historical map state (i.e. having scrubbed the time bar backward), the clicked agent may be dead, in which case None will be passed instead of an agent object.

  • plot NetworkPlot

    The NetworkPlot object that was clicked on.

  • t int

    The time currently displayed on the time slider. This may not match the current model time if the time slider has been scrubbed backward.

Notes and Examples

  1. charwick

    Feb 10, 2021 at 4:24

    Usually it will be desirable only to take an action if an agent is clicked while the current model time is displayed in the visualizer, since any actions taken will affect the current model state rather than the historical state. The third parameter can be used to ensure that the action is only taken when the visualization is current.

    @heli.hook
    def agentClick(agents, plot, t):
    	if t != heli.t: return
    
    	#Take an action here that affects the model state
  2. charwick

    Jun 13, 2021 at 19:10

    NetworkPlot does not automatically update its display when the model state changes. In order to update the visualization in place, it will be necessary to call the update() (to alert it to changed data and overwrite the existing data for the current period) and draw() (to refresh the display) methods of the NetworkPlot object passed as the plot argument. The latter must be called with the forceUpdate=True option; otherwise the plot only updates when the whole Charts visualizer updates.

    #Replace the agent clicked upon and create new replacement edges
    @heli.hook
    def agentClick(agents, plot, t):
    	if t != heli.t: return
    	
    	for agent in agents:
    		new = agent.reproduce()
    		enum = len(agent.edges[plot.kind]) if plot.kind in agent.edges else 0
    		agent.die()
    		for e in range(enum): newedge(heli)
    		print('Killing agent',agent.id,'and creating agent',new.id)
    	plot.update(heli.data.getLast(), t)
    	plot.draw(t, forceUpdate=True)
  3. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History