champion detail win rate chart
This commit is contained in:
@@ -18,18 +18,22 @@
|
||||
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
|
||||
import "phoenix_html"
|
||||
// Establish Phoenix Socket and LiveView configuration.
|
||||
import {Socket} from "phoenix"
|
||||
import {LiveSocket} from "phoenix_live_view"
|
||||
import { Socket } from "phoenix"
|
||||
import { LiveSocket } from "phoenix_live_view"
|
||||
import topbar from "../vendor/topbar"
|
||||
import { ChampionWinRate } from "./hooks/champion_win_rate_patch"
|
||||
|
||||
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
|
||||
let liveSocket = new LiveSocket("/live", Socket, {
|
||||
longPollFallbackMs: 2500,
|
||||
params: {_csrf_token: csrfToken}
|
||||
params: { _csrf_token: csrfToken },
|
||||
hooks: {
|
||||
ChampionWinRate,
|
||||
}
|
||||
})
|
||||
|
||||
// Show progress bar on live navigation and form submits
|
||||
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
|
||||
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" })
|
||||
window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
|
||||
window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import Chart from "chart.js/auto"
|
||||
|
||||
const ChampionWinRate = {
|
||||
mounted() {
|
||||
console.log("mounted")
|
||||
this.handleEvent("points", (event) => console.log("123"))
|
||||
|
||||
// this.props = { id: this.el.getAttribute("data-id") };
|
||||
this.handleEvent("win-rate", ({ winRates }) => {
|
||||
console.log(">>>>>>>")
|
||||
console.log(winRates);
|
||||
patches = winRates.map((winRate) => {
|
||||
return winRate.patch_number
|
||||
})
|
||||
winRateValues = winRates.map((winRate) => winRate.win_rate)
|
||||
setInterval(() => {
|
||||
const data = {
|
||||
labels: patches,
|
||||
datasets: [{
|
||||
label: 'Win rate',
|
||||
data: winRateValues,
|
||||
fill: false,
|
||||
borderColor: 'rgb(75, 192, 192)',
|
||||
tension: 0.1
|
||||
}]
|
||||
};
|
||||
this.chart = new Chart(document.getElementById("win-rate"), {
|
||||
type: 'line',
|
||||
data: data
|
||||
})
|
||||
this.chart.canvas.parentNode.style.height = '250px';
|
||||
this.chart.canvas.parentNode.style.width = '400px';
|
||||
}, 1000)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { ChampionWinRate };
|
||||
Reference in New Issue
Block a user