diff --git a/examples/Schelling/model.py b/examples/Schelling/model.py index fe9a6915068..c7147fc3b99 100644 --- a/examples/Schelling/model.py +++ b/examples/Schelling/model.py @@ -60,8 +60,6 @@ def __init__(self, height, width, density, minority_pc, homophily): # For testing purposes, agent's individual x and y {"x": lambda a: a.pos[0], "y": lambda a: a.pos[1]}) - self.running = True - # Set up agents # We use a grid iterator that returns # the coordinates of a cell as well as @@ -79,12 +77,16 @@ def __init__(self, height, width, density, minority_pc, homophily): self.grid.position_agent(agent, (x, y)) self.schedule.add(agent) + self.running = True + self.datacollector.collect(self) + def step(self): ''' Run one step of the model. If All agents are happy, halt the model. ''' self.happy = 0 # Reset counter of happy agents self.schedule.step() + # collect data self.datacollector.collect(self) if self.happy == self.schedule.get_agent_count(): diff --git a/examples/bank_reserves/bank_reserves/model.py b/examples/bank_reserves/bank_reserves/model.py index 2ad97b9f651..f54a0fec7f1 100644 --- a/examples/bank_reserves/bank_reserves/model.py +++ b/examples/bank_reserves/bank_reserves/model.py @@ -124,12 +124,13 @@ def __init__(self, height=grid_h, width=grid_w, init_people=2, rich_threshold=10 self.schedule.add(p) self.running = True + self.datacollector.collect(self) def step(self): - # collect data - self.datacollector.collect(self) # tell all the agents in the model to run their step function self.schedule.step() + # collect data + self.datacollector.collect(self) def run_model(self): for i in range(self.run_time): diff --git a/examples/bank_reserves/bank_reserves/server.py b/examples/bank_reserves/bank_reserves/server.py index 2c3547d3f38..818c3b6fe97 100644 --- a/examples/bank_reserves/bank_reserves/server.py +++ b/examples/bank_reserves/bank_reserves/server.py @@ -13,11 +13,11 @@ """ # Green -RICH_COLOR = "46FF33" +RICH_COLOR = "#46FF33" # Red -POOR_COLOR = "FF3C33" +POOR_COLOR = "#FF3C33" # Blue -MID_COLOR = "3349FF" +MID_COLOR = "#3349FF" def person_portrayal(agent): diff --git a/examples/boltzmann_wealth_model/wealth_model/model.py b/examples/boltzmann_wealth_model/wealth_model/model.py index 89a16a845aa..c9626932cc2 100644 --- a/examples/boltzmann_wealth_model/wealth_model/model.py +++ b/examples/boltzmann_wealth_model/wealth_model/model.py @@ -24,7 +24,6 @@ class MoneyModel(Model): def __init__(self, N, width, height): self.num_agents = N - self.running = True self.grid = MultiGrid(height, width, True) self.schedule = RandomActivation(self) self.datacollector = DataCollector( @@ -40,9 +39,13 @@ def __init__(self, N, width, height): y = random.randrange(self.grid.height) self.grid.place_agent(a, (x, y)) - def step(self): + self.running = True self.datacollector.collect(self) + + def step(self): self.schedule.step() + # collect data + self.datacollector.collect(self) def run_model(self, n): for i in range(n): diff --git a/examples/boltzmann_wealth_model_network/wealth_model/model.py b/examples/boltzmann_wealth_model_network/wealth_model/model.py index ff39212ef70..b7cdb1829d1 100644 --- a/examples/boltzmann_wealth_model_network/wealth_model/model.py +++ b/examples/boltzmann_wealth_model_network/wealth_model/model.py @@ -24,7 +24,6 @@ def __init__(self, num_agents, num_nodes): self.num_agents = num_agents self.num_nodes = num_nodes if num_nodes >= self.num_agents else self.num_agents self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=0.5) - self.running = True self.grid = NetworkGrid(self.G) self.schedule = RandomActivation(self) self.datacollector = DataCollector( @@ -41,8 +40,12 @@ def __init__(self, num_agents, num_nodes): # Add the agent to a random node self.grid.place_agent(a, list_of_random_nodes[i]) + self.running = True + self.datacollector.collect(self) + def step(self): self.schedule.step() + # collect data self.datacollector.collect(self) def run_model(self, n): diff --git a/examples/conways_game_of_life/game_of_life/model.py b/examples/conways_game_of_life/game_of_life/model.py index 72fcf29c562..5c5d4aeb666 100644 --- a/examples/conways_game_of_life/game_of_life/model.py +++ b/examples/conways_game_of_life/game_of_life/model.py @@ -37,6 +37,7 @@ def __init__(self, height, width): cell.state = cell.ALIVE self.grid.place_agent(cell, (x, y)) self.schedule.add(cell) + self.running = True def step(self): diff --git a/examples/epstein_civil_violence/civil_violence/model.py b/examples/epstein_civil_violence/civil_violence/model.py index 05dcc1592b9..50f4b8818f9 100644 --- a/examples/epstein_civil_violence/civil_violence/model.py +++ b/examples/epstein_civil_violence/civil_violence/model.py @@ -51,7 +51,6 @@ def __init__(self, height, width, citizen_density, cop_density, self.active_threshold = active_threshold self.arrest_prob_constant = arrest_prob_constant self.movement = movement - self.running = True self.max_iters = max_iters self.iteration = 0 self.schedule = RandomActivation(self) @@ -69,8 +68,8 @@ def __init__(self, height, width, citizen_density, cop_density, "arrest_probability": lambda a: getattr(a, "arrest_probability", None) } - self.dc = DataCollector(model_reporters=model_reporters, - agent_reporters=agent_reporters) + self.datacollector = DataCollector(model_reporters=model_reporters, + agent_reporters=agent_reporters) unique_id = 0 if self.cop_density + self.citizen_density > 1: raise ValueError( @@ -93,12 +92,16 @@ def __init__(self, height, width, citizen_density, cop_density, self.grid[y][x] = citizen self.schedule.add(citizen) + self.running = True + self.datacollector.collect(self) + def step(self): """ Advance the model by one step and collect data. """ self.schedule.step() - self.dc.collect(self) + # collect data + self.datacollector.collect(self) self.iteration += 1 if self.iteration > self.max_iters: self.running = False diff --git a/examples/forest_fire/forest_fire/model.py b/examples/forest_fire/forest_fire/model.py index a34bec8470b..f0f2921261d 100644 --- a/examples/forest_fire/forest_fire/model.py +++ b/examples/forest_fire/forest_fire/model.py @@ -44,13 +44,16 @@ def __init__(self, height, width, density): new_tree.condition = "On Fire" self.grid._place_agent((x, y), new_tree) self.schedule.add(new_tree) + self.running = True + self.datacollector.collect(self) def step(self): """ Advance the model by one step. """ self.schedule.step() + # collect data self.datacollector.collect(self) # Halt if no more fire diff --git a/examples/pd_grid/pd_grid/model.py b/examples/pd_grid/pd_grid/model.py index 421e28c8b3b..c4565540561 100644 --- a/examples/pd_grid/pd_grid/model.py +++ b/examples/pd_grid/pd_grid/model.py @@ -31,7 +31,6 @@ def __init__(self, height, width, schedule_type, payoffs=None): Determines the agent activation regime. payoffs: (optional) Dictionary of (move, neighbor_move) payoffs. ''' - self.running = True self.grid = SingleGrid(height, width, torus=True) self.schedule_type = schedule_type self.schedule = self.schedule_types[self.schedule_type](self) @@ -48,9 +47,13 @@ def __init__(self, height, width, schedule_type, payoffs=None): lambda m: len([a for a in m.schedule.agents if a.move == "C"]) }) - def step(self): + self.running = True self.datacollector.collect(self) + + def step(self): self.schedule.step() + # collect data + self.datacollector.collect(self) def run(self, n): ''' Run the model for n steps. ''' diff --git a/examples/shape_example/shape_model/model.py b/examples/shape_example/shape_model/model.py index 31209429a51..4e8afcb1d26 100644 --- a/examples/shape_example/shape_model/model.py +++ b/examples/shape_example/shape_model/model.py @@ -15,12 +15,12 @@ def __init__(self, unique_id, model, pos, heading=(1, 0)): class ShapesModel(Model): def __init__(self, N, width=20, height=10): - self.running = True self.N = N # num of agents self.headings = ((1, 0), (0, 1), (-1, 0), (0, -1)) # tuples are fast self.grid = SingleGrid(width, height, torus=False) self.schedule = RandomActivation(self) self.make_walker_agents() + self.running = True def make_walker_agents(self): unique_id = 0 diff --git a/examples/sugarscape_cg/sugarscape/model.py b/examples/sugarscape_cg/sugarscape/model.py index 2a997b23489..d82df33ed2f 100644 --- a/examples/sugarscape_cg/sugarscape/model.py +++ b/examples/sugarscape_cg/sugarscape/model.py @@ -65,9 +65,11 @@ def __init__(self, height=50, width=50, self.schedule.add(ssa) self.running = True + self.datacollector.collect(self) def step(self): self.schedule.step() + # collect data self.datacollector.collect(self) if self.verbose: print([self.schedule.time, diff --git a/examples/virus_on_network/virus_on_network/model.py b/examples/virus_on_network/virus_on_network/model.py index 7a0b7f14446..08215258b9a 100644 --- a/examples/virus_on_network/virus_on_network/model.py +++ b/examples/virus_on_network/virus_on_network/model.py @@ -47,7 +47,6 @@ def __init__(self, num_nodes, avg_node_degree, initial_outbreak_size, virus_spre self.virus_check_frequency = virus_check_frequency self.recovery_chance = recovery_chance self.gain_resistance_chance = gain_resistance_chance - self.running = True self.datacollector = DataCollector({"Infected": number_infected, "Susceptible": number_susceptible, @@ -66,6 +65,9 @@ def __init__(self, num_nodes, avg_node_degree, initial_outbreak_size, virus_spre for a in self.grid.get_cell_list_contents(infected_nodes): a.state = State.INFECTED + self.running = True + self.datacollector.collect(self) + def resistant_susceptible_ratio(self): try: return number_state(self, State.RESISTANT) / number_state(self, State.SUSCEPTIBLE) @@ -74,6 +76,7 @@ def resistant_susceptible_ratio(self): def step(self): self.schedule.step() + # collect data self.datacollector.collect(self) def run_model(self, n): diff --git a/examples/wolf_sheep/wolf_sheep/model.py b/examples/wolf_sheep/wolf_sheep/model.py index da6ab7c0751..7a73f9c5e39 100644 --- a/examples/wolf_sheep/wolf_sheep/model.py +++ b/examples/wolf_sheep/wolf_sheep/model.py @@ -115,9 +115,11 @@ def __init__(self, height=20, width=20, self.schedule.add(patch) self.running = True + self.datacollector.collect(self) def step(self): self.schedule.step() + # collect data self.datacollector.collect(self) if self.verbose: print([self.schedule.time, diff --git a/mesa/visualization/templates/js/ChartModule.js b/mesa/visualization/templates/js/ChartModule.js index f08e069aabf..99c3935c7e6 100644 --- a/mesa/visualization/templates/js/ChartModule.js +++ b/mesa/visualization/templates/js/ChartModule.js @@ -43,7 +43,7 @@ var ChartModule = function(series, canvas_width, canvas_height) { responsive: true, tooltips: { mode: 'index', - intersect: false, + intersect: false }, hover: { mode: 'nearest', @@ -53,13 +53,16 @@ var ChartModule = function(series, canvas_width, canvas_height) { xAxes: [{ display: true, scaleLabel: { - display: true, + display: true + }, + ticks: { + maxTicksLimit: 11 } }], yAxes: [{ display: true, scaleLabel: { - display: true, + display: true } }] } @@ -80,12 +83,10 @@ var ChartModule = function(series, canvas_width, canvas_height) { }; this.reset = function() { - chart.destroy(); - chartData.labels = []; - chart = new Chart(context, { - type: 'line', - data: chartData, - options: chartOptions + while (chart.data.labels.length) { chart.data.labels.pop(); } + chart.data.datasets.forEach(function(dataset) { + while (dataset.data.length) { dataset.data.pop(); } }); + chart.update(); }; -}; \ No newline at end of file +};