Fix Markov simulation chart display issue
- Fix circular import issue by moving simulation_manager to app/__init__.py - Enhance get_wealth_evolution to include inequality metrics data - Add get_inequality_evolution method for complete chart data - Update API to return top10_shares and capital_shares in evolution data - Modify onSimulationComplete to fetch and populate charts with complete data - Fix simulation threading to properly mark completion state - Add test script to verify chart data generation The charts now properly display simulation results by fetching complete evolution data when simulation completes, resolving the empty diagrams issue.
This commit is contained in:
@@ -651,14 +651,44 @@ function updateMetricsDisplay(data) {
|
||||
/**
|
||||
* Handle simulation completion
|
||||
*/
|
||||
function onSimulationComplete(data) {
|
||||
async function onSimulationComplete(data) {
|
||||
currentSimulation.isRunning = false;
|
||||
updateUIState('complete');
|
||||
|
||||
window.MarkovEconomics.utils.showNotification(
|
||||
`Simulation completed! ${data.total_snapshots} data points collected.`,
|
||||
'success'
|
||||
);
|
||||
// Fetch complete simulation data and populate charts
|
||||
try {
|
||||
const response = await window.MarkovEconomics.utils.apiRequest(
|
||||
`/api/simulation/${currentSimulation.id}/data?include_evolution=true`
|
||||
);
|
||||
|
||||
if (response.evolution) {
|
||||
// Clear and populate with complete data
|
||||
currentSimulation.data.iterations = response.evolution.iterations;
|
||||
currentSimulation.data.totalWealth = response.evolution.total_wealth;
|
||||
currentSimulation.data.giniCoefficients = response.evolution.gini_coefficients;
|
||||
currentSimulation.data.top10Share = response.evolution.top10_shares || [];
|
||||
currentSimulation.data.capitalShare = response.evolution.capital_shares || [];
|
||||
|
||||
// Update charts with complete data
|
||||
updateCharts();
|
||||
|
||||
// Update final metrics
|
||||
if (response.latest_snapshot) {
|
||||
updateMetricsDisplay(response.latest_snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
window.MarkovEconomics.utils.showNotification(
|
||||
`Simulation completed! ${data.total_snapshots} data points collected.`,
|
||||
'success'
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch simulation data:', error);
|
||||
window.MarkovEconomics.utils.showNotification(
|
||||
'Simulation completed but failed to load results',
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user