| |
| (function () { |
| "use strict"; |
| var el = document.getElementById("analyticsData"); |
| if (!el) return; |
| var data; |
| try { data = JSON.parse(el.textContent); } catch (e) { return; } |
| var TA = window.T_AN || { times: "次", sep: ":" }; |
|
|
| |
| var dc = document.getElementById("dailyChart"); |
| if (dc && typeof Chart !== "undefined") { |
| var series = data.series || { day: [], week: [], month: [] }; |
| var chart = null; |
| function render(range) { |
| var s = series[range] || []; |
| if (chart) chart.destroy(); |
| chart = new Chart(dc, { |
| type: "bar", |
| data: { |
| labels: s.map(function (x) { return x.label; }), |
| datasets: [{ data: s.map(function (x) { return x.hits; }), backgroundColor: "#8a1f2b" }] |
| }, |
| options: { |
| responsive: true, maintainAspectRatio: false, |
| plugins: { legend: { display: false }, tooltip: { callbacks: { label: function (c) { return c.parsed.y + " " + TA.times; } } } }, |
| scales: { x: { grid: { display: false } }, y: { beginAtZero: true, ticks: { precision: 0 } } } |
| } |
| }); |
| } |
| render("day"); |
| document.querySelectorAll(".range-btn").forEach(function (b) { |
| b.addEventListener("click", function () { |
| document.querySelectorAll(".range-btn").forEach(function (x) { x.classList.remove("active"); }); |
| b.classList.add("active"); |
| render(b.getAttribute("data-range")); |
| }); |
| }); |
| } |
|
|
| |
| var wm = document.getElementById("worldMap"); |
| if (wm && typeof jsVectorMap !== "undefined" && data.countries && data.countries.length) { |
| var byCode = {}, maxH = 0; |
| data.countries.forEach(function (c) { byCode[c.cc] = c; if (c.hits > maxH) maxH = c.hits; }); |
|
|
| function lerp(a, b, t) { return Math.round(a + (b - a) * t); } |
| function colorFor(hits) { |
| var t = 0.28 + 0.72 * (maxH ? hits / maxH : 1); |
| return "rgb(" + lerp(236, 138, t) + "," + lerp(202, 31, t) + "," + lerp(206, 43, t) + ")"; |
| } |
|
|
| try { |
| new jsVectorMap({ |
| selector: "#worldMap", |
| map: "world", |
| zoomButtons: true, |
| zoomOnScroll: false, |
| backgroundColor: "transparent", |
| regionStyle: { |
| initial: { fill: "#e6e4df", stroke: "#ffffff", "stroke-width": 0.4 }, |
| hover: { fillOpacity: 0.75 } |
| }, |
| onRegionTooltipShow: function (event, tooltip, code) { |
| var info = byCode[code]; |
| if (info) tooltip.text(info.country + TA.sep + info.hits + " " + TA.times, true); |
| } |
| }); |
| |
| |
| |
| |
| function colorize(tries) { |
| var svg = wm.querySelector("svg"); |
| var allDone = !!svg; |
| if (svg) { |
| data.countries.forEach(function (c) { |
| var el = svg.querySelector('[data-code="' + c.cc + '"]'); |
| if (el) el.style.setProperty("fill", colorFor(c.hits), "important"); |
| else allDone = false; |
| }); |
| } |
| if (!allDone && tries > 0) setTimeout(function () { colorize(tries - 1); }, 120); |
| } |
| colorize(25); |
| } catch (e) { |
| |
| } |
| } |
| })(); |
|
|