Ultronprime commited on
Commit
78d52ce
·
verified ·
1 Parent(s): 75e2df2

Update ui.js

Browse files
Files changed (1) hide show
  1. ui.js +35 -49
ui.js CHANGED
@@ -1,18 +1,15 @@
1
- // ui.js - Renders all UI components (Corrected Chart Logic)
2
 
3
  import { appState } from './state.js';
4
  import { attachAllListeners } from './events.js';
5
  import { getMonthlyProductionSummary, getMonthlyMaterialUsage } from './reportService.js';
6
 
7
- // Chart instances to prevent re-creation
8
  let productionChart = null;
9
  let inventoryChart = null;
10
 
11
- // Set Chart.js defaults for our dark theme
12
  Chart.defaults.color = 'hsl(210, 14%, 66%)';
13
  Chart.defaults.borderColor = 'hsl(220, 13%, 30%)';
14
 
15
- // Master function to update the entire UI
16
  export function refreshUI() {
17
  renderKpiCards();
18
  renderCharts();
@@ -112,39 +109,32 @@ function renderProductionHistoryChart() {
112
  data.push(totalProduced);
113
  }
114
 
115
- // ** BUG FIX STARTS HERE **
116
- // Instead of destroying, we now update the existing chart if it exists.
117
  if (productionChart) {
118
- productionChart.data.labels = labels;
119
- productionChart.data.datasets[0].data = data;
120
- productionChart.update();
121
- } else {
122
- // If it doesn't exist (first render), create it.
123
- productionChart = new Chart(ctx, {
124
- type: 'bar',
125
- data: {
126
- labels: labels,
127
- datasets: [{
128
- label: 'Complete Units Produced',
129
- data: data,
130
- backgroundColor: 'rgba(66, 153, 225, 0.5)',
131
- borderColor: 'rgba(66, 153, 225, 1)',
132
- borderWidth: 1,
133
- borderRadius: 4,
134
- }]
135
- },
136
- options: {
137
- responsive: true,
138
- maintainAspectRatio: false,
139
- plugins: { legend: { display: false } },
140
- scales: {
141
- y: { beginAtZero: true, grid: { color: 'hsl(220, 13%, 30%)' } },
142
- x: { grid: { display: false } }
143
- }
144
- }
145
- });
146
  }
147
- // ** BUG FIX ENDS HERE **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
149
 
150
  function renderInventoryStatusChart() {
@@ -168,22 +158,18 @@ function renderInventoryStatusChart() {
168
  }]
169
  };
170
 
171
- // ** BUG FIX STARTS HERE **
172
  if (inventoryChart) {
173
- inventoryChart.data.datasets[0].data = [okCount, warningCount, criticalCount];
174
- inventoryChart.update();
175
- } else {
176
- inventoryChart = new Chart(ctx, {
177
- type: 'doughnut',
178
- data: data,
179
- options: {
180
- responsive: true,
181
- maintainAspectRatio: false,
182
- plugins: { legend: { position: 'top', labels: { color: 'hsl(210, 14%, 66%)' } } }
183
- }
184
- });
185
  }
186
- // ** BUG FIX ENDS HERE **
 
 
 
 
 
 
 
 
187
  }
188
 
189
  function renderModals() {
 
1
+ // ui.js - Renders all UI components
2
 
3
  import { appState } from './state.js';
4
  import { attachAllListeners } from './events.js';
5
  import { getMonthlyProductionSummary, getMonthlyMaterialUsage } from './reportService.js';
6
 
 
7
  let productionChart = null;
8
  let inventoryChart = null;
9
 
 
10
  Chart.defaults.color = 'hsl(210, 14%, 66%)';
11
  Chart.defaults.borderColor = 'hsl(220, 13%, 30%)';
12
 
 
13
  export function refreshUI() {
14
  renderKpiCards();
15
  renderCharts();
 
109
  data.push(totalProduced);
110
  }
111
 
 
 
112
  if (productionChart) {
113
+ productionChart.destroy();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  }
115
+ productionChart = new Chart(ctx, {
116
+ type: 'bar',
117
+ data: {
118
+ labels: labels,
119
+ datasets: [{
120
+ label: 'Complete Units Produced',
121
+ data: data,
122
+ backgroundColor: 'rgba(66, 153, 225, 0.5)',
123
+ borderColor: 'rgba(66, 153, 225, 1)',
124
+ borderWidth: 1,
125
+ borderRadius: 4,
126
+ }]
127
+ },
128
+ options: {
129
+ responsive: true,
130
+ maintainAspectRatio: false,
131
+ plugins: { legend: { display: false } },
132
+ scales: {
133
+ y: { beginAtZero: true, grid: { color: 'hsl(220, 13%, 30%)' } },
134
+ x: { grid: { display: false } }
135
+ }
136
+ }
137
+ });
138
  }
139
 
140
  function renderInventoryStatusChart() {
 
158
  }]
159
  };
160
 
 
161
  if (inventoryChart) {
162
+ inventoryChart.destroy();
 
 
 
 
 
 
 
 
 
 
 
163
  }
164
+ inventoryChart = new Chart(ctx, {
165
+ type: 'doughnut',
166
+ data: data,
167
+ options: {
168
+ responsive: true,
169
+ maintainAspectRatio: false,
170
+ plugins: { legend: { position: 'top', labels: { color: 'hsl(210, 14%, 66%)' } } }
171
+ }
172
+ });
173
  }
174
 
175
  function renderModals() {