Fix wealth distribution chart functionality
- Add get_wealth_histogram() method to EconomicModel for histogram data - Add new API endpoint /simulation/<id>/distribution for chart data - Extend main data API with include_distribution parameter - Update real-time progress updates to include distribution data - Fix frontend updateCharts() to handle wealth distribution chart - Add distribution data processing in simulation.js - Update test_charts.py to verify histogram functionality Resolves issue where wealth distribution chart was not updating during simulations.
This commit is contained in:
@@ -15,7 +15,11 @@ let currentSimulation = {
|
||||
totalWealth: [],
|
||||
giniCoefficients: [],
|
||||
capitalShare: [],
|
||||
top10Share: []
|
||||
top10Share: [],
|
||||
distribution: {
|
||||
labels: [],
|
||||
counts: []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -445,7 +449,11 @@ function resetSimulation() {
|
||||
totalWealth: [],
|
||||
giniCoefficients: [],
|
||||
capitalShare: [],
|
||||
top10Share: []
|
||||
top10Share: [],
|
||||
distribution: {
|
||||
labels: [],
|
||||
counts: []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -596,6 +604,12 @@ function updateSimulationProgress(data) {
|
||||
currentSimulation.data.capitalShare.push(data.capital_share || 0);
|
||||
currentSimulation.data.top10Share.push(data.wealth_concentration_top10 || 0);
|
||||
|
||||
// Update distribution data if available
|
||||
if (data.distribution && data.distribution.labels && data.distribution.counts) {
|
||||
currentSimulation.data.distribution.labels = data.distribution.labels;
|
||||
currentSimulation.data.distribution.counts = data.distribution.counts;
|
||||
}
|
||||
|
||||
updateCharts();
|
||||
updateMetricsDisplay(data);
|
||||
}
|
||||
@@ -619,6 +633,13 @@ function updateCharts() {
|
||||
charts.inequality.data.datasets[1].data = currentSimulation.data.top10Share;
|
||||
charts.inequality.update('none');
|
||||
}
|
||||
|
||||
// Wealth Distribution Chart
|
||||
if (charts.distribution && currentSimulation.data.distribution.labels.length > 0) {
|
||||
charts.distribution.data.labels = currentSimulation.data.distribution.labels;
|
||||
charts.distribution.data.datasets[0].data = currentSimulation.data.distribution.counts;
|
||||
charts.distribution.update('none');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,7 +679,7 @@ async function onSimulationComplete(data) {
|
||||
// Fetch complete simulation data and populate charts
|
||||
try {
|
||||
const response = await window.MarkovEconomics.utils.apiRequest(
|
||||
`/api/simulation/${currentSimulation.id}/data?include_evolution=true`
|
||||
`/api/simulation/${currentSimulation.id}/data?include_evolution=true&include_distribution=true`
|
||||
);
|
||||
|
||||
if (response.evolution) {
|
||||
@@ -669,6 +690,12 @@ async function onSimulationComplete(data) {
|
||||
currentSimulation.data.top10Share = response.evolution.top10_shares || [];
|
||||
currentSimulation.data.capitalShare = response.evolution.capital_shares || [];
|
||||
|
||||
// Update distribution data
|
||||
if (response.distribution) {
|
||||
currentSimulation.data.distribution.labels = response.distribution.labels;
|
||||
currentSimulation.data.distribution.counts = response.distribution.counts;
|
||||
}
|
||||
|
||||
// Update charts with complete data
|
||||
updateCharts();
|
||||
|
||||
|
Reference in New Issue
Block a user