4 Commits

Author SHA1 Message Date
24d424bd90 Update bot project name to be a little less generic 2024-12-09 19:27:04 -08:00
1345b984d4 Link to the new TokenBot project 2024-12-08 20:20:40 -08:00
14b80dfea6 Add option to generate overlay URL
This is going to be expanded upon in future releases, for now it's hardcoded to use just the previous time overlay
2024-11-16 17:53:57 -08:00
24928c10fa Fix live token price updates 2024-11-16 17:53:14 -08:00
5 changed files with 68 additions and 20 deletions

View File

@@ -80,7 +80,11 @@
Copy URL to this Chart Copy URL to this Chart
</button> </button>
</div> </div>
<div> <div class="other-projects">
<p><em>
Get alerted when the Token hits certain thresholds using GoblinBot, find out more <a href="https://blog.emily.sh/token-bot/">here!</a>
</em></p>
<hr />
<p><em>Looking for the classic WoW Token price? Find it <a href="https://classic.wowtoken.app">here!</a></em></p> <p><em>Looking for the classic WoW Token price? Find it <a href="https://classic.wowtoken.app">here!</a></em></p>
</div> </div>
</div> </div>

View File

@@ -6,7 +6,7 @@ import fetchData from "./fetchData";
import {updateHighTime} from "./highTime"; import {updateHighTime} from "./highTime";
import {updateLowTime} from "./lowTime"; import {updateLowTime} from "./lowTime";
import {addLoader, removeLoader} from "./loader"; import {addLoader, removeLoader} from "./loader";
import {allowOverlay, forceOverlayOff, isOverlaySelected} from "./overlay"; import {allowOverlay, forceOverlayOff, forceOverlayOn, isOverlayAllowed, isOverlaySelected} from "./overlay";
import TokenChart from "./tokenChart"; import TokenChart from "./tokenChart";
import Datum from "./datum"; import Datum from "./datum";
@@ -212,6 +212,15 @@ function detectZeroQuery(urlSearchParams) {
toggleStartYAtZero(); toggleStartYAtZero();
} }
function detectOverlayQuery(urlSearchParams) {
const enableOverlay = urlSearchParams.get('overlay') === 'previous_time';
if (enableOverlay) {
forceOverlayOn();
} else {
forceOverlayOff();
}
}
function detectURLQuery() { function detectURLQuery() {
const urlSearchParams = new URLSearchParams(window.location.search); const urlSearchParams = new URLSearchParams(window.location.search);
if (urlSearchParams.has('region')) { if (urlSearchParams.has('region')) {
@@ -226,6 +235,9 @@ function detectURLQuery() {
if (urlSearchParams.has('startAtZero')) { if (urlSearchParams.has('startAtZero')) {
detectZeroQuery(urlSearchParams) detectZeroQuery(urlSearchParams)
} }
if (urlSearchParams.has('overlay')) {
detectOverlayQuery(urlSearchParams);
}
} }
function buildDeepLinksURL() { function buildDeepLinksURL() {
@@ -242,6 +254,9 @@ function buildDeepLinksURL() {
if (startYAtZero !== false){ if (startYAtZero !== false){
url += `startAtZero=${startYAtZero}&` url += `startAtZero=${startYAtZero}&`
} }
if (isOverlaySelected()){
url += `overlay=previous_time&`
}
return url return url
} }

View File

@@ -19,9 +19,22 @@ function forceOverlayOff(){
periodOverlayField.style.display = 'none'; periodOverlayField.style.display = 'none';
} }
function forceOverlayOn(){
const overlaySetting = document.getElementById("period-overlay");
const periodOverlayField = document.getElementById("period-overlay-options");
const advancedOptionsField = document.getElementById("advanced-options");
overlaySetting.checked = true;
advancedOptionsField.style.display = 'flex';
periodOverlayField.style.display = 'flex';
}
function isOverlayAllowed(timeSelection) {
return !(timeSelection === "all")
}
function allowOverlay(){ function allowOverlay(){
const periodOverlayField = document.getElementById("period-overlay-options"); const periodOverlayField = document.getElementById("period-overlay-options");
periodOverlayField.style.display = 'flex'; periodOverlayField.style.display = 'flex';
} }
export {isOverlaySelected, getOverlayTime, setOverlayLabelTime, forceOverlayOff, allowOverlay}; export {isOverlaySelected, getOverlayTime, setOverlayLabelTime, forceOverlayOff, forceOverlayOn, isOverlayAllowed, allowOverlay};

View File

@@ -420,6 +420,16 @@ details[open] summary {
margin: 10px; margin: 10px;
} }
.other-projects {
border: 1px solid silver;
margin-bottom: 10px;
font-size: 15px;
}
.other-projects > p {
line-height: 1em;
}
.data-header h1 { .data-header h1 {
margin-top: 24px; margin-top: 24px;
margin-bottom: 24px; margin-bottom: 24px;

View File

@@ -25,6 +25,7 @@ Chart.register(
import {updateHighVal} from "./highTime"; import {updateHighVal} from "./highTime";
import {updateLowVal} from "./lowTime"; import {updateLowVal} from "./lowTime";
import {isOverlaySelected, getOverlayTime, setOverlayLabelTime} from "./overlay"; import {isOverlaySelected, getOverlayTime, setOverlayLabelTime} from "./overlay";
import Datum from "./datum";
function lookupTimeUnit(query){ function lookupTimeUnit(query){
const lookup = { const lookup = {
@@ -77,6 +78,22 @@ export default class TokenChart {
this._chart = new Chart(this._context, chartConfig); this._chart = new Chart(this._context, chartConfig);
} }
async #updateHighLow(datum) {
if (this._highDatum === null) {
this._highDatum = new Datum(datum.getTime(), 0);
this._lowDatum = datum;
return;
}
if (datum.getPrice() > this._highDatum.getPrice()) {
this._highDatum = datum;
updateHighVal(this.highDatum);
}
else if (datum.getPrice() < this._lowDatum.getPrice()) {
this._lowDatum = datum;
updateLowVal(this.lowDatum);
}
}
async #createOverlayChart(region, time, yLevel, data){ async #createOverlayChart(region, time, yLevel, data){
const chartData = []; const chartData = [];
const overlayData = []; const overlayData = [];
@@ -91,15 +108,7 @@ export default class TokenChart {
}); });
} }
else { else {
await this.#updateHighLow(data[i]);
this._lastDatum = data[i];
if (this._highDatum === null || this._lastDatum.getPrice() > this._highDatum.getPrice()) {
this._highDatum = data[i];
}
if (this._lowDatum === null || this._lowDatum.getPrice() > this._lastDatum.getPrice()) {
this._lowDatum = data[i];
}
chartData.push({ chartData.push({
x: data[i].getX(), x: data[i].getX(),
@@ -174,13 +183,7 @@ export default class TokenChart {
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
this._lastDatum = data[i]; this._lastDatum = data[i];
if (this._highDatum === null || this._lastDatum.getPrice() > this._highDatum.getPrice()) { await this.#updateHighLow(data[i]);
this._highDatum = data[i];
}
if (this._lowDatum === null || this._lowDatum.getPrice() > this._lastDatum.getPrice()) {
this._lowDatum = data[i];
}
chartData.push({ chartData.push({
x: data[i].getX(), x: data[i].getX(),
@@ -289,7 +292,10 @@ export default class TokenChart {
this._lowDatum = datum; this._lowDatum = datum;
updateLowVal(this.lowDatum); updateLowVal(this.lowDatum);
} }
this._chart.data.datasets[0].data.push(datum); this._chart.data.datasets[0].data.push({
x: datum.getX(),
y: datum.getY(),
});
this._chart.update(); this._chart.update();
} }