Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions KTL/data/globalsAndInitial.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ data.options = {};
data.options.bonusRate = 3;
data.lastVisit = Date.now();
data.queuedReveals = {}
let chartData = []; // Stores { time: number, value: number }
let chartScale = 'linear'; // 'linear' or 'logarithmic'
let chartData = []; // Stores { time: number, value: number, HATL: number, MQ: number }
let graphType = "momentum"; //"momentum" or "magic"

// --- Core Settings ---
data.gameSettings = {
Expand Down
169 changes: 120 additions & 49 deletions KTL/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,28 +877,31 @@ function mouseOnActionTouch(event, actionVar) {
// }

function takeDataSnapshot(resourceValue, currentTime) {
if (currentTime <= 1) return;
if (chartData.length === 0) {
chartData.push({
time: currentTime,
value: resourceValue
value: resourceValue,
HATL: data.actions["hearAboutTheLich"].level,
MQ: actionData.awakenYourGrimoire.manaQuality()
});
return;
}

const lastStoredPoint = chartData[chartData.length - 1];
if (resourceValue === lastStoredPoint.value) {
return;
}
// if (resourceValue === lastStoredPoint.value) {
// return;
// }

const lastValue = lastStoredPoint.value;
const timeBeforeChange = currentTime - 1;

if (timeBeforeChange > lastStoredPoint.time) {
chartData.push({ time: timeBeforeChange, value: lastValue });
if ((currentTime - lastStoredPoint.time) > (currentTime > 21600 ? 239 : 119)) {
chartData.push({
time: currentTime,
value: resourceValue,
HATL: data.actions["hearAboutTheLich"].level,
MQ: actionData.awakenYourGrimoire.manaQuality()
});
}

chartData.push({ time: currentTime, value: resourceValue });

if (chartData.length > 200) {
chartData.splice(0, 2);
}
Expand All @@ -919,10 +922,11 @@ function drawChart() {

const canvasWidth = canvas.clientWidth;
const canvasHeight = canvas.clientHeight;
const padding = 40;
const padding = 50;

// Clear the canvas and fill with dark background
ctx.fillStyle = '#2d3748';
ctx.globalAlpha = 1;
ctx.fillRect(0, 0, canvas.width, canvas.height);

if (chartData.length < 2) {
Expand All @@ -936,8 +940,6 @@ function drawChart() {
// --- Determine Data Range ---
const minTime = chartData[0].time;
const maxTime = chartData[chartData.length - 1].time;
const values = chartData.map(d => d.value);
const maxValue = Math.max(...values);

// --- Draw Axes ---
ctx.strokeStyle = '#4a5568'; // Subtle gray for axes
Expand All @@ -951,53 +953,122 @@ function drawChart() {
ctx.lineTo(canvasWidth - padding, canvasHeight - padding);
ctx.stroke();

ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
ctx.textAlign = 'center';
// --- Draw Data Line ---
ctx.strokeStyle = '#63b3ed'; // Vibrant, contrasting blue for the line
ctx.lineWidth = 3; // Thicker line
ctx.lineJoin = 'round'; // Smoother corners
ctx.beginPath();

for (let i = 0; i < chartData.length; i++) {
const dataPoint = chartData[i];
const x = padding + ((dataPoint.time - minTime) / (maxTime - minTime)) * (canvasWidth - 2 * padding);
let y;
if (chartScale === 'logarithmic') {
let lastLabelX = -1000;
let lastHATL = 0;
if (graphType === "momentum") {
const values = chartData.map(d => d.value);
const minValue = Math.min(...values);
const maxValue = Math.max(...values);
for (let i = 0; i < chartData.length; i++) {
const dataPoint = chartData[i];
const HATL = dataPoint.HATL ? dataPoint.HATL : 0;
const x = padding + ((dataPoint.time - minTime) / (maxTime - minTime)) * (canvasWidth - 2 * padding);
if ((x - lastLabelX) >= ((canvasWidth - 2 * padding) / 8)) {
lastLabelX = x;
ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
ctx.fillText(secondsToTime(dataPoint.time), x, canvasHeight - padding + 20);
}
const logMinValue = Math.log1p(minValue);
const logMaxValue = Math.log1p(maxValue);
const logValue = Math.log1p(dataPoint.value);
y = (canvasHeight - padding) - ((logValue / logMaxValue) * (canvasHeight - 2 * padding));
} else {
y = (canvasHeight - padding) - ((dataPoint.value / maxValue) * (canvasHeight - 2 * padding));
const logValue = Math.log1p(dataPoint.value) - logMinValue;
let y = (canvasHeight - padding) - ((logValue / (logMaxValue - logMinValue)) * (canvasHeight - 2 * padding));
if (isNaN(y)) y = canvasHeight - padding;
if (HATL > 0 && HATL > lastHATL) {
lastHATL = HATL;
ctx.fillStyle = 'red'; // Light gray for labels
ctx.font = '14px sans-serif bold';
ctx.fillText(HATL, x, y - 4);
if (y < (canvasHeight - padding - 10)) {
ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
ctx.fillText(secondsToTime(dataPoint.time), x, y + 18);
}
}
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
if (isNaN(y)) y = canvasHeight - padding;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
ctx.stroke();

// --- Draw Labels and Grid ---
ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
ctx.textAlign = 'center';
const numYLabels = 5;
for (let i = 0; i <= numYLabels; i++) {
const yPos = padding + (i / numYLabels) * (canvasHeight - 2 * padding);
let labelValue;
if (chartScale === 'logarithmic') {
labelValue = Math.expm1(Math.log1p(maxValue) * (1 - (i / numYLabels)));
} else {
labelValue = maxValue * (1 - (i / numYLabels));
// --- Draw Labels and Grid ---
ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
const numYLabels = 5;
for (let i = 0; i <= numYLabels; i++) {
const yPos = padding + (i / numYLabels) * (canvasHeight - 2 * padding);
const labelValue = Math.expm1((Math.log1p(maxValue) - Math.log1p(minValue)) * (1 - (i / numYLabels)) + Math.log1p(minValue));
ctx.globalAlpha = 1;
ctx.fillText(intToString(labelValue, 1), padding - 20, yPos + 4);

// Horizontal grid line
ctx.strokeStyle = '#4a5568'; // Subtle gray for grid
ctx.globalAlpha = 0.25;
ctx.beginPath();
ctx.moveTo(padding, yPos);
ctx.lineTo(canvasWidth - padding, yPos);
ctx.stroke();
}
} else {
// Magic Quality graph
const values = chartData.map(d => d.MQ);
const minValue = Math.min(...values);
const maxValue = Math.max(...values);
for (let i = 0; i < chartData.length; i++) {
const dataPoint = chartData[i];
const HATL = dataPoint.HATL ? dataPoint.HATL : 0;
const x = padding + ((dataPoint.time - minTime) / (maxTime - minTime)) * (canvasWidth - 2 * padding);
if ((x - lastLabelX) >= ((canvasWidth - 2 * padding) / 8)) {
lastLabelX = x;
ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
ctx.fillText(secondsToTime(dataPoint.time), x, canvasHeight - padding + 20);
}
let y = (canvasHeight - padding) - ((dataPoint.MQ / maxValue) * (canvasHeight - 2 * padding));
if (isNaN(y)) y = canvasHeight - padding;
if (HATL > 0 && HATL > lastHATL) {
lastHATL = HATL;
ctx.fillStyle = 'red'; // Light gray for labels
ctx.font = '14px sans-serif bold';
ctx.fillText(HATL, x, y - 4);
if (y < (canvasHeight - padding - 10)) {
ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
ctx.fillText(secondsToTime(dataPoint.time), x, y + 18);
}
}
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.fillText(intToString(labelValue, 1), padding - 20, yPos + 4);

// Horizontal grid line
ctx.strokeStyle = '#4a5568'; // Subtle gray for grid
ctx.beginPath();
ctx.moveTo(padding - 5, yPos);
ctx.lineTo(canvasWidth - padding, yPos);
ctx.stroke();

// --- Draw Labels and Grid ---
ctx.fillStyle = '#a0aec0'; // Light gray for labels
ctx.font = '12px sans-serif';
const numYLabels = 5;
for (let i = 0; i <= numYLabels; i++) {
const yPos = padding + (i / numYLabels) * (canvasHeight - 2 * padding);
const labelValue = (maxValue - minValue) * (1 - (i / numYLabels)) + minValue;
ctx.globalAlpha = 1;
ctx.fillText(intToString(labelValue, 1), padding - 20, yPos + 4);

// Horizontal grid line
ctx.strokeStyle = '#4a5568'; // Subtle gray for grid
ctx.globalAlpha = 0.25;
ctx.beginPath();
ctx.moveTo(padding, yPos);
ctx.lineTo(canvasWidth - padding, yPos);
ctx.stroke();
}
}
ctx.fillText(secondsToTime(minTime), padding, canvasHeight - padding + 20);
ctx.fillText(secondsToTime(maxTime), canvasWidth - padding, canvasHeight - padding + 20);
}

function addLogMessage(text, type) {
Expand Down
42 changes: 21 additions & 21 deletions KTL/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//addMenuOptionsTab() adjust fps, saving
//addDataTab()
//addMenuTab("Previous Tips", <desc>) Adds a new tab that duplicates the toasts but can't
let canvas, ctx, linearBtn, logBtn;
let canvas, ctx, momentumBtn, magicBtn;

function initializeMenus() {
createMenu(); // makes the button | menu | title
Expand Down Expand Up @@ -43,24 +43,24 @@ function initializeMenus() {
function statChartInitial() {
canvas = document.getElementById('resourceChart');
ctx = canvas.getContext('2d');
linearBtn = document.getElementById('linearBtn');
logBtn = document.getElementById('logBtn');

linearBtn.addEventListener('click', () => {
chartScale = 'linear';
linearBtn.style.backgroundColor = '#4a5568';
linearBtn.style.color = 'white';
logBtn.style.backgroundColor = '#f7fafc';
logBtn.style.color = '#4a5568';
momentumBtn = document.getElementById('momentumBtn');
magicBtn = document.getElementById('magicBtn');

momentumBtn.addEventListener('click', () => {
graphType = "momentum";
momentumBtn.style.backgroundColor = '#4a5568';
momentumBtn.style.color = 'white';
magicBtn.style.backgroundColor = '#f7fafc';
magicBtn.style.color = '#4a5568';
drawChart();
});

logBtn.addEventListener('click', () => {
chartScale = 'logarithmic';
logBtn.style.backgroundColor = '#4a5568';
logBtn.style.color = 'white';
linearBtn.style.backgroundColor = '#f7fafc';
linearBtn.style.color = '#4a5568';
magicBtn.addEventListener('click', () => {
graphType = "magic";
magicBtn.style.backgroundColor = '#4a5568';
magicBtn.style.color = 'white';
momentumBtn.style.backgroundColor = '#f7fafc';
momentumBtn.style.color = '#4a5568';
drawChart();
});
}
Expand Down Expand Up @@ -192,16 +192,16 @@ function createDataMenu() {
</div>
<div id="chartContainer" style="width: 80%; max-width: 800px; background-color: #2d3748; border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.4); padding: 20px;">
<h2 style="text-align: center; margin-top: 0; color: #e2e8f0;">Recent 100 Overclock Amounts</h2>
<h2 style="text-align: center; margin-top: 0; color: #e2e8f0;">Progress and HATL lvl changes</h2>
<canvas id="resourceChart" style="width: 100%; height: 400px; border-radius: 4px;"></canvas>
<div style="text-align: center; margin-top: 15px;">
<button id="linearBtn" style="padding: 10px 20px; border: 1px solid #63b3ed; background-color: #63b3ed;
<button id="momentumBtn" style="padding: 10px 20px; border: 1px solid #63b3ed; background-color: #63b3ed;
color: #1a202c; border-radius: 5px; cursor: pointer; font-weight: bold; transition: background-color 0.2s;">
Linear
Total Momentum (log)
</button>
<button id="logBtn" style="padding: 10px 20px; border: 1px solid #4a5568; background-color: #4a5568;
<button id="magicBtn" style="padding: 10px 20px; border: 1px solid #4a5568; background-color: #4a5568;
color: #e2e8f0; border-radius: 5px; cursor: pointer; font-weight: bold; transition: background-color 0.2s;">
Logarithmic
Magic Quality
</button>
</div>
</div>
Expand Down