Coverage for .tox/p312/lib/python3.10/site-packages/scicom/knowledgespread/SimpleContinuousModule.py: 0%

1 import mesa

2

3

4 class SimpleCanvas(mesa.visualization.VisualizationElement):

5 """Display agents on a map background. No coordinates."""

6 local_includes = ["knowledgespread/simple_continuous_canvas.js"]

7 portrayal_method = None

8 canvas_height = 720

9 canvas_width = 1280

10

11 def __init__(self, portrayal_method, canvas_height=720, canvas_width=1280):

12 """

13 Instantiate a new SimpleCanvas

14 """

15 self.portrayal_method = portrayal_method

16 self.canvas_height = canvas_height

17 self.canvas_width = canvas_width

18 new_element = "new Simple_Continuous_Module({}, {})".format(

19 self.canvas_width, self.canvas_height

20 )

21 self.js_code = "elements.push(" + new_element + ");"

22

23 def render(self, model):

24 """Draw agents."""

25 space_state = []

26 for obj in model.schedule.agents:

27 portrayal = self.portrayal_method(obj)

28 x, y = obj.pos

29 x = (x - model.space.x_min) / (model.space.x_max - model.space.x_min)

30 y = (y - model.space.y_min) / (model.space.y_max - model.space.y_min)

31 portrayal["x"] = x

32 portrayal["y"] = y

33 space_state.append(portrayal)

34 return space_state