var today_profit = ""; var source; var chart; function initializeChart(datas) { chart = anychart.treeMap(datas, "as-tree"); let isDarkMode = false; let backgroundColor = isDarkMode ? "#000" : "#fff"; let strokeColor = isDarkMode ? "#000" : "#fff"; let textColor = isDarkMode ? "#fff" : "#000"; let customColorScale = anychart.scales.linearColor(); customColorScale.minimum(-3).maximum(3); customColorScale.colors(isDarkMode ? ["#b11b1b", "#111", "#1a9746"] : ["#b11b1b", "#eee", "#1a9746"]); chart.colorScale(customColorScale); chart.colorRange().enabled(true).length("90%"); chart.hovered().fill(isDarkMode ? "#000" : "#fff", isDarkMode ? 0.9 : 0.1); chart.headers().background().fill(backgroundColor).stroke(strokeColor); chart.background().fill(backgroundColor); chart.normal().stroke(strokeColor); chart.labels().fontFamily('GoyangDeogyang').adjustFontSize(true).useHtml(true).format(function() { return `${this.name}
${this.value}`; }); chart.tooltip().useHtml(true).format(function() { if (this.getData("price") === undefined) return ''; return `가격: ${this.getData("price")}$
시총: ${Math.round(this.getData("size") * 10)}억$`; }); chart.maxHeadersHeight("20%").maxDepth(2).headers(true); chart.container("container").draw(); //chart.autoRedraw(true); } function updateChartData(datas) { if (chart !== undefined) { chart.data(datas); // 데이터만 갱신 } else { initializeChart(datas); // 차트가 없으면 초기화 } } $(document).ready(function() { if (!window.EventSource) { alert("지원되지 않는 브라우저입니다."); return; } if (source !== undefined) source.close(); source = new EventSource('/map/sse'); source.addEventListener('message', function(e) { console.log(e); $('#sse_data').html(e.data); }); source.addEventListener('info', function(e) { $('#info').html(e.data); }); source.addEventListener('time', function(e) { $('#server_time').html(e.data); }); source.addEventListener('price_log', function(e) { $('#price_log').html(e.data); }); source.addEventListener('display_price', function(e) { $('#now_price').html(e.data); let now_price = e.data; document.title = `${now_price} ${today_profit}`; }); source.addEventListener('ndx_price', function(e) { $('#now_price_value').val(e.data); }); source.addEventListener('map', function(e) { let data_map = JSON.parse(e.data); if (data_map !== undefined) updateChartData(data_map); }); source.addEventListener('open', function() { // Connection was opened. }); source.addEventListener('error', function(e) { if (e.readyState == EventSource.CLOSED) { // Connection was closed. } }); });