mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2025-12-10 04:09:29 +02:00
added logic for graph in crash
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div v-if="crashdata.Status === 'WaitingForPlayers'"><h2>Игра не началась</h2></div>
|
||||||
<LineChart
|
<LineChart
|
||||||
:chart-data="data"
|
:chart-data="data"
|
||||||
:options="options"
|
:options="options"
|
||||||
css-classes="chart-container"
|
v-else
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -27,9 +28,16 @@ Chart.register(
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { LineChart },
|
components: { LineChart },
|
||||||
|
props: {
|
||||||
|
crashdata: Object
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.data = this.chartData;
|
||||||
|
this.updateData();
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
dataValues: [1, 2, 3],
|
dataValues: [],
|
||||||
labels: [""],
|
labels: [""],
|
||||||
data: null,
|
data: null,
|
||||||
options: {
|
options: {
|
||||||
@@ -38,37 +46,12 @@ export default {
|
|||||||
text: "Line",
|
text: "Line",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
animation: {
|
scales: {
|
||||||
duration: 200,
|
y: {
|
||||||
easing: "easeInOutQuad",
|
beginAtZero: true, // Устанавливаем начало оси Y с нуля
|
||||||
delay: 50,
|
|
||||||
onProgress: (animation) => {
|
|
||||||
const chart = animation.chart;
|
|
||||||
const ctx = chart.ctx;
|
|
||||||
const meta = chart.getDatasetMeta(0);
|
|
||||||
const points = meta.data;
|
|
||||||
const totalSteps = meta.total;
|
|
||||||
|
|
||||||
ctx.save();
|
|
||||||
ctx.beginPath();
|
|
||||||
|
|
||||||
points.forEach((point, index) => {
|
|
||||||
const prevPoint = meta.data[index - 1];
|
|
||||||
const progress = animation.progress;
|
|
||||||
|
|
||||||
if (index === 0 || progress * totalSteps > index) {
|
|
||||||
const x = prevPoint ? prevPoint.x + (point.x - prevPoint.x) * progress : point.x;
|
|
||||||
const y = prevPoint ? prevPoint.y + (point.y - prevPoint.y) * progress : point.y;
|
|
||||||
|
|
||||||
ctx.lineTo(x, y);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.lineWidth = 3;
|
|
||||||
ctx.stroke();
|
|
||||||
ctx.restore();
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
animation: false, // Отключаем анимацию
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -91,29 +74,35 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
watch: {
|
||||||
updateData() {
|
crashdata: {
|
||||||
const interval = 495;
|
handler: 'updateData',
|
||||||
let counter = 0;
|
immediate: true
|
||||||
|
}
|
||||||
const updateInterval = setInterval(() => {
|
|
||||||
const nextDataValue = this.dataValues[this.dataValues.length - 1] + 1;
|
|
||||||
this.dataValues.push(nextDataValue);
|
|
||||||
|
|
||||||
this.labels.push("");
|
|
||||||
this.data = this.chartData;
|
|
||||||
|
|
||||||
if (counter >= 6000 / interval) {
|
|
||||||
clearInterval(updateInterval);
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
}, interval);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
methods: {
|
||||||
this.data = this.chartData;
|
updateData() {
|
||||||
this.updateData();
|
let nextDataValue
|
||||||
|
if (this.crashdata.Status === 'WaitingForPlayers') {
|
||||||
|
this.data = this.chartData;
|
||||||
|
this.labels = [""];
|
||||||
|
this.dataValues = [0];
|
||||||
|
}
|
||||||
|
else if (this.crashdata.Status === 'InGame') {
|
||||||
|
nextDataValue = this.crashdata.CurrentX
|
||||||
|
|
||||||
|
this.data = this.chartData;
|
||||||
|
this.labels.push("");
|
||||||
|
this.dataValues.push(nextDataValue);
|
||||||
|
}
|
||||||
|
else if (this.crashdata.Status === 'GameEnd') {
|
||||||
|
this.dataValues = []
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('Error game')
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="crash-game__graph">
|
<div class="crash-game__graph">
|
||||||
<crash-graph-component></crash-graph-component>
|
<crash-graph-component :crashdata="crashObject"></crash-graph-component>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -81,9 +81,10 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
SaperNumbers,
|
SaperNumbers,
|
||||||
|
clickedBtn: null,
|
||||||
amountDeposit: 0,
|
amountDeposit: 0,
|
||||||
autoRatio: 0,
|
autoRatio: 0,
|
||||||
timerGame: ''
|
crashObject: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
@@ -94,8 +95,8 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const dataCrashParse = JSON.parse(dataCrash)
|
const dataCrashParse = JSON.parse(dataCrash)
|
||||||
|
|
||||||
this.timerGame = dataCrashParse.WaitingTime
|
this.crashObject = dataCrashParse
|
||||||
console.log(this.timerGame)
|
console.log(dataCrashParse)
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user