var css = document.createElement("style"); css.type = "text/css"; css.innerHTML = ".highcharts-data-labels { pointer-events:none;}"; css.innerHTML += ".highcharts-data-labels span{ text-decoration:none!important; }"; document.getElementsByTagName("head")[0].appendChild(css); let fromHome2 = ''; let chartTitle = `Sector chart by ${$('[name="sector_analysis_option"]:checked').next().text()}`; //if sectorHome is defined and true if (typeof sectorHome !== 'undefined' && sectorHome) { chartTitle = `Sector Chart`; fromHome2 = '&from=home'; } //Highcharts.setOptions({lang:{drillUpText:"Back to top "}}); var dnColors=['#A8384F','#C03954','#C03954','#F14E73','#F14E73','#E76E84']; var upColors=['#3E701A','#4C7C27','#4C7C27','#5D9438','#5D9438','#739F56']; var textColors = { '#A8384F' : '#ffffff', '#C03954' : '#ffffff', '#F14E73' : '#000000', '#E76E84' : '#000000', '#3E701A' : '#ffffff', '#4C7C27' : '#ffffff', '#5D9438' : '#000000', '#739F56' : '#000000', } dnColors = dnColors.reverse(); upColors = upColors.reverse(); var sectorTreeMap = { chart : null, hisMode : false, init : function(type,sid,sdate, callback){ var self = this; self.hisMode = (isNaN(sid*1) || sid=="" || sdate=="")?false:true; //console.log(isNaN(sid*1),sid); $.getJSON('/'+lang+'/data/chart/sectorTreeMap?type='+type+'&sdate='+sdate+'&sid='+sid+fromHome2, function(_data) { console.log(_data[0].stime) var data = self.decode(_data); $('#block_sector_stime').html(_data[0].stime) $('#sectorTreeMapContainer').highcharts(self.getJSON(data),function(chart){ self.chart = chart; if (callback!==undefined){ callback(chart,data); } if (!(isNaN(sid*1) || sid=="")){ //sectorTreeMap.chart.series[0].data[0].firePointEvent('click'); self.showSector(sid); }else{ $(".upper_btn").hide(); } //****************** //$('#sectorTreeMapContainer').find(".highcharts-container").attr("aria-hidden","true"); if($('#sectorTreeMapContainer').find(".link_table_a").length == 0){ var _text = []; if (lang == "tc"){ _text[0] = "查看圖表數據"; _text[1] = "於表單查看相關資產數據"; }else if (lang == "sc"){ _text[0] = "查看图表数据"; _text[1] = "於表单查看相关资产数据"; }else{ _text[0] = "View detailed data"; _text[1] = "View underlying detail from table"; } //$('#sectorTreeMapContainer').append(''+_text[1]+''); let url = '/'+lang+'/data/text-data/sectorTreeMap?type='+type+'&sdate='+sdate+'&sid='+sid; let chartName = { tc: "板塊圖表", sc: "板块图表", en: "Sector Chart" } genChartLink(url, $('.sector_chart_area_tip'), null, chartName[lang]); } let noDataWord = { tc: "無相關數據", sc: "无相关数据", en: "No Related Data" } setTimeout(function(){ $('#sectorTreeMapContainer').prepend(` `); }, 3000); //****************** }); }); }, decode : function(data){ var _data = []; var _underlying = []; var minValue = data[0].weight; var total = 0; var offset = 0.2; for (var i = 0; i < data.length; i++){ total += data[i].weight; } for (var i = 0; i < data.length; i++){ if (data[i].weight>0){ data[i].value = data[i].weight/total; data[i].value += (0.2/data.length); } } for (var i = 0; i < data.length; i++){ var colorIndex = Math.ceil(Math.min(Math.abs(data[i].pchng),6))-1; var color = "#D7D8D6"; var _textColor = "#ffffff"; var servicesData = []; if (data[i].pchng > 0){ color = upColors[colorIndex]; }else if (data[i].pchng < 0){ color = dnColors[colorIndex]; } //new code here let selectedDetail = { ...data[i].detail[0] }; if(!selectedDetail.focus){ let selectFocus = null; for (let j = 0; j < data[i].detail.length; j++){ if (data[i].detail[j].focus){ selectFocus = data[i].detail[j]; selectFocus.focus.name = data[i].detail[j].name; break; } } if (selectFocus){ selectedDetail.focus = selectFocus.focus; } }else{ selectedDetail.focus.name = data[i].detail[0].name; } _data.push({ id: "sector_"+ data[i].usector, drilldown: "drilldown_"+ data[i].usector, name: data[i].name+ ((data[i].pchng>0)?" +":" ")+(data[i].pchng*1).toFixed(2)+"%", value: data[i].value, color: color, dataLabels: { style: { color: _textColor, } }, //detail: data[i].detail[0] detail: selectedDetail }); /* console.log(selectedDetail); console.log(data[i].detail[0]); console.log('break'); */ total = 0; for(var j=0; j 0){ color = upColors[colorIndex]; }else if (data[i].detail[j].upchng < 0){ color = dnColors[colorIndex]; } servicesData.push({ id: data[i].detail[j].ucode, name: data[i].detail[j].name+ ((data[i].detail[j].upchng>0)?" +":" ")+data[i].detail[j].upchng+"%", value: data[i].detail[j].value, color: color, detail: data[i].detail[j], }); } _underlying.push({ id: "drilldown_"+ data[i].usector, type: 'treemap', layoutAlgorithm: 'squarified', data: servicesData, states: { hover:{ borderColor: '#ffffff', } }, }); } return {sectorData:_data,underlyingSerie:_underlying}; }, drillUp : function(){ return; console.log(this.chart.drillUpButton); if (this.chart.drillUpButton){ console.log('hi') $(this.chart.drillUpButton.element).trigger("click"); } /* if (typeof updateSectorNiceScroll === "function"){ updateSectorNiceScroll(); } */ }, showSector : function(sid){ for (var i = 0; i-1){ return ""; } if (detail.focus!=undefined && detail.focus){ var _focus = detail.focus; var space = lang=='en'?' ':''; var _type = _focus.wtype.replace("CBBC/","").replace("EU/",""); var html = "
"+this.key+"
"; //console.log((detail.upchng*1).toFixed(2)) html += "
"+detail.name+" ("+detail.ucode+") " + ((detail.upchng>0)?"+":"")+(detail.upchng*1).toFixed(2)+"%
"; html += "
"+" "+detail.focus.name+space+self.labels[lang][_type+'_short']+" ("+_focus.code+") " + ((self.hisMode)?"":(((_focus.pchng>0)?"+":"")+(_focus.pchng*1).toFixed(2)+"%"))+"
"; html += "
"; return html; }else{ var html = "
"+this.key+"
"; html += "
"+detail.name+" ("+detail.ucode+") " + ((detail.upchng>0)?"+":"")+(detail.upchng*1).toFixed(2)+"%
"; html += "
"; return html; } }else{ var html = "
"+this.key+"
"; html += "
"; return html; } }else{ var detail = this.point.detail; if (detail!=undefined && detail.focus!=undefined && detail.focus){ var _focus = detail.focus; var _type = _focus.wtype.replace("CBBC/","").replace("EU/",""); var html = "
"+this.key+"
"; if (_focus.isListing == "1"){ html += "
"+_focus.code+" ("+self.labels[lang][_type]+")
"; }else{ html += "
"+_focus.code+" ("+self.labels[lang][_type]+") " + ((self.hisMode)?"":(((_focus.pchng>0)?"+":"")+(_focus.pchng*1).toFixed(2)+"%"))+"
"; } html += "
"; return html; }else{ var html = "
"+this.key+"
"; //html += "
"+_focus.code+" ("+self.labels[lang][_type]+") " + ((self.hisMode)?"":(((_focus.pchng>0)?"+":"")+(_focus.pchng*1).toFixed(2)+"%"))+"
"; html += "
"; return html; } } } } } }, drilldown: { series:data.underlyingSerie, }, series: [{ type: 'treemap', allowPointSelect: true, alternateStartingDirection: true, layoutAlgorithm: 'squarified', data: data.sectorData, states: { hover:{ borderColor: '#ffffff' } }, drillUpButton: { position: { align: 'center', verticalAlign: 'bottom', className: 'hideDrillUp', y: 0, x: 0 } } }, ], exporting: { enabled: false } } }, labels : { tc :{ 'CALL' : "認購", 'PUT' : "認沽", 'BULL' : "牛證", 'BEAR' : "熊證", 'CALL_short' : "購", 'PUT_short' : "沽", 'BULL_short' : "牛", 'BEAR_short' : "熊", }, sc :{ 'CALL' : "认购", 'PUT' : "认沽", 'BULL' : "牛证", 'BEAR' : "熊证", 'CALL_short' : "购", 'PUT_short' : "沽", 'BULL_short' : "牛", 'BEAR_short' : "熊", }, en :{ 'CALL' : "Call", 'PUT' : "Put", 'BULL' : "Bull", 'BEAR' : "Bear", 'CALL_short' : "Call", 'PUT_short' : "Put", 'BULL_short' : "Bull", 'BEAR_short' : "Bear", }, }, }