Spaces:
Running
Running
Update rl_script.js
Browse files- rl_script.js +8 -2
rl_script.js
CHANGED
@@ -17,6 +17,7 @@ let agentState = { ...initialState };
|
|
17 |
let gridCells = [];
|
18 |
let stepCount = 0;
|
19 |
let stepHistory = [];
|
|
|
20 |
|
21 |
function createGrid() {
|
22 |
for (let row = 0; row < gridRows; row++) {
|
@@ -101,9 +102,14 @@ function resetRL() {
|
|
101 |
|
102 |
function updateLearningGraph() {
|
103 |
const ctx = learningGraphCanvas.getContext('2d');
|
104 |
-
ctx.clearRect(0, 0, learningGraphCanvas.width, learningGraphCanvas.height);
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
type: 'line',
|
108 |
data: {
|
109 |
labels: Array.from({ length: stepHistory.length }, (_, i) => i + 1),
|
|
|
17 |
let gridCells = [];
|
18 |
let stepCount = 0;
|
19 |
let stepHistory = [];
|
20 |
+
let myChart = null; // Global variable to hold the chart instance
|
21 |
|
22 |
function createGrid() {
|
23 |
for (let row = 0; row < gridRows; row++) {
|
|
|
102 |
|
103 |
function updateLearningGraph() {
|
104 |
const ctx = learningGraphCanvas.getContext('2d');
|
|
|
105 |
|
106 |
+
// Destroy the existing chart if it exists
|
107 |
+
if (myChart) {
|
108 |
+
myChart.destroy();
|
109 |
+
}
|
110 |
+
|
111 |
+
// Create a new chart
|
112 |
+
myChart = new Chart(ctx, {
|
113 |
type: 'line',
|
114 |
data: {
|
115 |
labels: Array.from({ length: stepHistory.length }, (_, i) => i + 1),
|