var highlightCBBCMap = { chart : null, container : "", furtherData : null, view : "", topIndex : 1, init : function(wtype, callback){ var container = this.container; var self = this; this.view = $("body").attr("data-broswer-view"); if (this.view == "mobile" && screen && screen.orientation && screen.orientation.angle){ if (screen.orientation.angle == 90 || screen.orientation.angle == 270){ this.view = "pad"; } } $.getJSON('/'+lang+'/data/chart/highlightCBBCMap?wtype='+wtype+"&view="+this.view, function(_data) { self.furtherData = _data.furtherData; var data = self.decode(_data); if (data.length == 0){ $((container=='')?'#highlightCBBCMapContainer':'#'+container).html(""); if (callback!==undefined){ callback(_data); } }else{ $((container=='')?'#highlightCBBCMapContainer':'#'+container).highcharts(self.getJSON(data), function(chart){ self.chart = chart; self.redraw(); if (callback!==undefined){ callback(_data); } }); } }); }, decode : function(_data){ var self = this; var mainData = _data.mainData; var data = []; var min_x = 999999; var max_x = 0; var min_y = 999999; var max_y = 0; var _box_min = 999999; var _box_max = 0; //ulast = mainData[0].ulast; for (var i =0; i0){ return { x: -1000, y: -1000}; }else if (this.label.text.textStr.indexOf("tooltip_height78")>0){ return { x: point.plotX, y: point.plotY - 48}; }else{ return { x: point.plotX, y: point.plotY - 60}; } }, formatter: function(a){ //this.series.userOptions.zIndex = topIndex++; /*if (self.topIndex-1 != this.series.userOptions.zIndex){ try { this.series.update({zIndex:self.topIndex++}); return ""; }catch (e) {} //return; }*/ //console.log(this.series); //this.series.data[0].graphic.toFront(); //var imgheight = this.point.graphic.imgheight; var label = ""; var imgheight = this.point.graphic.imgheight; if (self.furtherData.wtype == "BEAR"){ if (this.x - self.furtherData.highest_from >0){ return self.labels[lang].call2future+": "+(this.x - self.furtherData.highest_from).toFixed(2)+self.labels[lang].unit+""; }else{ return ""; } }else{ if (self.furtherData.highest_to - this.x>0){ return self.labels[lang].call2future+": "+(self.furtherData.highest_to - this.x).toFixed(2)+self.labels[lang].unit+""; }else{ return ""; } } } }, }; }, setPeriod : function(_from,_to){ this.chart.xAxis[0].setExtremes(_from, _to); }, redraw: function(){ var chart = this.chart; var self = this; var px_last = chart.xAxis[0].toPixels(self.furtherData.ulast); //$("#chartBackground").remove(); $((self.container=='')?'#highlightCBBCMapContainer':'#'+self.container).find(".chartLegend").remove(); $((self.container=='')?'#highlightCBBCMapContainer':'#'+self.container).find(".chartBackgroundLine").remove(); chart.xAxis[0].removePlotBandOrLine("highfuture"); var textcss = { "color": '#000', "fontSize": "15px", "fontWeight": "bold", }; var textcss2 = { "color": '#000', "fontSize": "13px", "fontWeight": "bold", }; //_htmllabel1 = ""; _htmllabel2 = ""; _htmllabel1 = "
"+self.labels[lang].pclose+": "+addcomma(self.furtherData.ulast)+"
"; if (self.view == "desktop"){ _htmllabel2 = ""; } chart.renderer.path(['M', px_last, 20,'L', px_last, chart.margin[0]+ chart.plotHeight]).attr({ stroke: '#A8A8A8', 'stroke-width': 2, opacity: 1, class :'chartBackgroundLine', dashstyle:"Dash", zIndex: 2, }).add(); chart.renderer.text(_htmllabel1,px_last-50,12,true).css(textcss).attr({ class :'chartLegend', zIndex: 2, }).add(); if (self.view == "mobile"){ chart.renderer.text(self.labels[lang].yTitle, chart.margin[3]-55, 15).css(textcss2).attr({ class :'chartLegend', zIndex: 2, }).add(); }else{ chart.renderer.text(self.labels[lang].yTitle, chart.margin[3]-65, 15).css(textcss).attr({ class :'chartLegend', zIndex: 2, }).add(); } if (this.furtherData.wtype == "BEAR"){ chart.xAxis[0].addPlotLine({ label: { text: _htmllabel2, style: { "color": "#0072ce", "fontSize": "14px"}, x: -45, y: -24, useHTML:true, rotation: false, }, value: self.furtherData.highest_from, width: 2, color: "#0072ce", id: 'highfuture', zIndex: 2, }); }else{ chart.xAxis[0].addPlotLine({ label: { text: _htmllabel2, style: { "color": "#0072ce", "fontSize": "14px"}, x: -45, y: -24, useHTML:true, rotation: false, }, value: self.furtherData.highest_to, width: 2, color: "#0072ce", id: 'highfuture', zIndex: 2, }); } chart.renderer.text(self.labels[lang].xTitle, chart.plotWidth+chart.margin[1]+chart.margin[3]-65, chart.margin[0]+chart.plotHeight+20).css(textcss).attr({ class :'chartLegend', zIndex: 2, }).add(); chart.renderer.path(['M', chart.margin[3], 0 ,'L', chart.margin[3], chart.margin[0]+chart.plotHeight]).attr({ stroke: '#000', 'stroke-width': 1, opacity: 1, class :'chartBackgroundLine', zIndex: 2, }).add(); chart.renderer.path(['M', chart.margin[3], chart.margin[0]+ chart.plotHeight,'L', chart.plotWidth+chart.margin[1]+chart.margin[3], chart.margin[0]+ chart.plotHeight]).attr({ stroke: '#000', 'stroke-width': 1, opacity: 1, class :'chartBackgroundLine', zIndex: 2, }).add(); if (this.furtherData.wtype == "BEAR"){ var px_diff = chart.xAxis[0].toPixels(self.furtherData.ulast + self.furtherData.hsi_diff); var px_gap = chart.xAxis[0].toPixels(self.furtherData.ulast + self.furtherData.hsi_gap); var labeloffset = chart.renderer.text("00000.00", 0, -100).css(textcss).attr({class :'chartLegend'}).add().element.getBoundingClientRect().width; }else{ var px_diff = chart.xAxis[0].toPixels(self.furtherData.ulast - self.furtherData.hsi_diff); var px_gap = chart.xAxis[0].toPixels(self.furtherData.ulast - self.furtherData.hsi_gap); var labeloffset = 0; } chart.renderer.path(['M', px_last, chart.margin[0]+ chart.plotHeight - 48,'L', px_gap, chart.margin[0]+ chart.plotHeight - 48]).attr({ stroke: '#0072ce', 'stroke-width': 2, opacity: 1, class :'chartBackgroundLine', zIndex: 999, }).add(); chart.renderer.path(['M', px_last, chart.margin[0]+ chart.plotHeight - 15,'L', px_diff, chart.margin[0]+ chart.plotHeight - 15]).attr({ stroke: '#A8A8A8', 'stroke-width': 2, opacity: 1, class :'chartBackgroundLine', zIndex: 999, }).add(); chart.renderer.path(['M', px_gap, chart.margin[0]+ chart.plotHeight,'L', px_gap, chart.margin[0]+ chart.plotHeight+5]).attr({ stroke: '#0072ce', 'stroke-width': 1, opacity: 1, class :'chartBackgroundLine', zIndex: 999, }).add(); chart.renderer.path(['M', px_diff, chart.margin[0]+ chart.plotHeight,'L', px_diff, chart.margin[0]+ chart.plotHeight+5]).attr({ stroke: '#A8A8A8', 'stroke-width': 1, opacity: 1, class :'chartBackgroundLine', zIndex: 999, }).add(); chart.renderer.text("
"+(self.furtherData.ulast - self.furtherData.hsi_gap*((this.furtherData.wtype == "BEAR")?-1:1)).toFixed(2)+"
",px_gap - labeloffset,chart.margin[0]+ chart.plotHeight - 48,true).css(textcss).attr({ class :'chartLegend', zIndex: 2, }).add(); chart.renderer.text("
"+(self.furtherData.ulast - self.furtherData.hsi_diff*((this.furtherData.wtype == "BEAR")?-1:1)).toFixed(2)+"
",px_diff - labeloffset,chart.margin[0]+ chart.plotHeight - 15,true).css(textcss).attr({ class :'chartLegend', zIndex: 2, }).add(); /*hsi_diff hsi_gap*/ }, labels : { tc :{ xTitle : "收回價", yTitle : "槓桿比率", pclose : "現價", highfuture: "重貨區", call2future: "距重貨區", unit: "點", }, sc :{ xTitle : "收回价", yTitle : "杠杆比率", pclose : "現价", highfuture: "重货区", call2future: "距重货区", unit: "点", }, en :{ xTitle : "Call level", yTitle : "Gearing", pclose : "Last", highfuture: "Highest OS", call2future: "Call level to highest future", unit: "", }, }, }