(function ($) { /*constant*/ var MINPANWIDTH = 110; var SLIDEHEIGHT = 30; var PANMAG = 5; var PANHEAD = 10; var INDICTWIDTH = 12; var PERMSEC = 10000; var PERSEC = 10000000; var PERMINUTE = (PERSEC * 60); var PERHOUR = (PERMINUTE * 60); var PERDAY = (PERHOUR * 24); var SPANPAD = 6; var SPANLINEHEIGHT = 16; var BOTTOMBUTTONLEFT = 80; var SHOWTHUMBSHEIGHT = 32; var SLIDHLIMIT = 160; var SHOWTHUMBSHLIMT = 200; var SHOWTOOLBARHLIMIT = 232; var SHOWLISTHLIMT = 250; var TOOLBARHEIGHT = 32; var TIMELABELHEIGHT = 32; var MINLISTHEIGHT = 80; var HSPLITHEIGHT = 10; var ButtonImage = $(new Image()).attr('src', 'htm/rtchart/chartbuttons.png'); var penColors = ['#00A8F0', '#5DB75D', '#FFFF00', '#FFA62F', '#E41B17', '#000066', '#A0D2FF', '#FF96FF', '#E0FFFF', '#388E8E', '#00EE00', '#CD3700', '#EEAD0E', '#6600CC', '#ADFF2F', '#663300']; var COLOR_NAMES = { aqua: [0, 255, 255], azure: [240, 255, 255], beige: [245, 245, 220], black: [0, 0, 0], blue: [0, 0, 255], brown: [165, 42, 42], cyan: [0, 255, 255], darkblue: [0, 0, 139], darkcyan: [0, 139, 139], darkgrey: [169, 169, 169], darkgreen: [0, 100, 0], darkkhaki: [189, 183, 107], darkmagenta: [139, 0, 139], darkolivegreen: [85, 107, 47], darkorange: [255, 140, 0], darkorchid: [153, 50, 204], darkred: [139, 0, 0], darksalmon: [233, 150, 122], darkviolet: [148, 0, 211], fuchsia: [255, 0, 255], gold: [255, 215, 0], green: [0, 128, 0], indigo: [75, 0, 130], khaki: [240, 230, 140], lightblue: [173, 216, 230], lightcyan: [224, 255, 255], lightgreen: [144, 238, 144], lightgrey: [211, 211, 211], lightpink: [255, 182, 193], lightyellow: [255, 255, 224], lime: [0, 255, 0], magenta: [255, 0, 255], maroon: [128, 0, 0], navy: [0, 0, 128], olive: [128, 128, 0], orange: [255, 165, 0], pink: [255, 192, 203], purple: [128, 0, 128], violet: [128, 0, 128], red: [255, 0, 0], silver: [192, 192, 192], white: [255, 255, 255], yellow: [255, 255, 0] }; dhtmlXCalendarObject.prototype.langData["cn"] = { dateformat: '%Y-%m-%d %H:%i:%s', monthesFNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], monthesSNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], daysFNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'], daysSNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], weekstart: 1, weekname: "d" }; var WebLink = function (weburl) { this.weburl = weburl; }; var TrendPen = function (rtchart, options) { this.rtChart = rtchart; this.options = $.extend( { URI: null, Num: 2, penColor: rtchart.getNextPenColor(), penWidth:2, linkReTryTime: 1000, hisReTryTime: 20000, lockRange: false, expandAll: false, stepLine: null, //true|false drawTag: false, drawLine:true, webURL: GoldenRtWeb.getWebURL() }, options || {}); this.hisRequestSeed = 1; if (this.options.rageMax != null) this.rageMax = this.options.rageMax; if (this.options.rageMin != null) this.rageMin = this.options.rageMin; var r = Math.abs(this.rageMax - this.rageMin); if (r < 1) { if (r > 0.1) { if(this.options.Num < 3) this.options.Num = 3; } else if (r > 0.01) { if (this.options.Num < 4) this.options.Num = 4; } else if (r > 0.001) { if (this.options.Num < 5) this.options.Num = 5; } else if (this.options.Num < 6) this.options.Num = 6; } }; var TrendColor = function (r, g, b, a) { this.rgba = ['r', 'g', 'b', 'a']; var x = 4; while (-1 < --x) { this[this.rgba[x]] = arguments[x] || ((x == 3) ? 1.0 : 0); } this.normalize(); } TrendColor.parse = function (color) { if (color instanceof TrendColor) return color; var result; // #a0b1c2 if ((result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))) return new TrendColor(parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)); // rgb(num,num,num) if ((result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))) return new TrendColor(parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10)); // #fff if ((result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))) return new TrendColor(parseInt(result[1] + result[1], 16), parseInt(result[2] + result[2], 16), parseInt(result[3] + result[3], 16)); // rgba(num,num,num,num) if ((result = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(color))) return new TrendColor(parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10), parseFloat(result[4])); // rgb(num%,num%,num%) if ((result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))) return new TrendColor(parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55); // rgba(num%,num%,num%,num) if ((result = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(color))) return new TrendColor(parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55, parseFloat(result[4])); // Otherwise, we're most likely dealing with a named color. var name = (color + '').replace(/^\s*([\S\s]*?)\s*$/, '$1').toLowerCase(); if (name == 'transparent') { return new TrendColor(255, 255, 255, 0); } return (result = COLOR_NAMES[name]) ? new TrendColor(result[0], result[1], result[2]) : new TrendColor(0, 0, 0, 0); }; TrendColor.processColor = function (color, options) { var opacity = options.opacity; if (!color) return 'rgba(0, 0, 0, 0)'; if (color instanceof TrendColor) return color.alpha(opacity).toString(); if (_.isString(color)) return TrendColor.parse(color).alpha(opacity).toString(); var grad = color.colors ? color : { colors: color }; if (!options.ctx) { if (!_.isArray(grad.colors)) return 'rgba(0, 0, 0, 0)'; return TrendColor.parse(_.isArray(grad.colors[0]) ? grad.colors[0][1] : grad.colors[0]).alpha(opacity).toString(); } grad = _.extend({ start: 'top', end: 'bottom' }, grad); if (/top/i.test(grad.start)) options.x1 = 0; if (/left/i.test(grad.start)) options.y1 = 0; if (/bottom/i.test(grad.end)) options.x2 = 0; if (/right/i.test(grad.end)) options.y2 = 0; var i, c, stop, gradient = options.ctx.createLinearGradient(options.x1, options.y1, options.x2, options.y2); for (i = 0; i < grad.colors.length; i++) { c = grad.colors[i]; if (_.isArray(c)) { stop = c[0]; c = c[1]; } else stop = i / (grad.colors.length - 1); gradient.addColorStop(stop, TrendColor.parse(c).alpha(opacity)); } return gradient; }; $.widget("rtinfo.trendChart", { options: { rtRefresh: true, showAxis:true, showGrid: true, showThumbs: true, showList:true, panShow: true, listExpand:true, reservePrevData: 10, spanSec: 10 * 60, //200s pointGroupName:null, freeRange: true, // 自由量程 panWidth: MINPANWIDTH + 50, listHeight: MINLISTHEIGHT + 50, activeShadowSize: 4, tooltipDelay: 1000, gridColor: 'rgba(91,91,91,1.0)', borderColor: 'rgba(120,120,120,1.0)', timeLabelColor: 'rgba(214,214,214,1.0)', indicatorColor: 'rgba(210,210,210,0.5)', bkColor:'rgba(0,0,0,1.0)', buttonImage: ButtonImage, resolution: 1// => resolution of the graph, to have printer-friendly graphs ! }, btipShow: false, tipShowPen: null, vIndicator: null, hIndicator: null, chartWidth: 0, chartHeight: 0, ftBeginTime: 0, ftTimeLabelBeg: null, ctx: null, canvas: null, buttonsDrawed: false, trendPens: null, webLinks: null, _create: function () { console.log('_create'); this.options.spanSec = this.options.spanSec || 1; if (!this.options.spanSec || this.options.spanSec < 1) this.options.spanSec = 1; var date = new Date(); date.setMilliseconds(0); date = this.DateToFileTime(date); date += PERSEC; date -= this.options.spanSec * PERSEC; this.setBeginTime(date); this._buildChart(); this.element.uniqueId(); $(window).resize(this, function (e) { e.data._onResize(); }); this.yScroll = 0; var rtchart = this; var X, Y; $(document).bind('mousemove.rtChart_' + this.element.attr('id'), function (e) { if (X === e.clientX && Y === e.clientY) return; X = e.clientX; Y = e.clientY; if (rtchart.mouseTimer) { window.clearTimeout(rtchart.mouseTimer); rtchart.mouseTimer = null; } if (rtchart.tooltipTimer && e.target != rtchart.vIndicator[0] && e.target != rtchart.hIndicator[0]) { window.clearTimeout(rtchart.tooltipTimer); rtchart.tooltipTimer = null; } if (e.target == rtchart.canvas[0]) { rtchart.mouseTimer = window.setTimeout(function () { window.clearTimeout(rtchart.mouseTimer); rtchart.mouseTimer = null; rtchart._onMouseMove(e); }, 200); } }); $(window).bind('keydown.rtChart_' + this.element.attr('id'), function (e) { rtchart._onKeyDown(e); }); var url = location.href; var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"); var paraObj = {} for (i = 0; j = paraString[i]; i++) { paraObj[decodeURIComponent(j.substring(0, j.indexOf("=")))] = decodeURIComponent(j.substring(j.indexOf("=") + 1, j.length)); } if (paraObj.pointGroupName != null) this.options.pointGroupName = paraObj.pointGroupName; if (this.options.pointGroupName == null) { if (paraObj.pointGroupName != null) this.options.pointGroupName = paraObj.pointGroupName; else if (paraObj.newPointGroup != null) { this.isNewPage = true; var d = dialog({ content: "可以在新打开的页中进行点组的设置操作,然后保存点组,
从而创建新的点组。", quickClose: true }); d.show(); window.setTimeout(function () { d.close().remove(); d = null;},2000); } } if(typeof(tagName)!="undefined" && tagName!=null || tagName!=""){ var itemDef=new GoldenRtWeb.RtItemDefine(0, 0, 0); this.AddPen({ URI: tagName,itemDef:itemDef}); this.requestHisData({ URI:tagName,itemDef:itemDef},100); } //if(!this.isNewPage) //this._loadPointGroup(); }, _loadPointGroup: function() { var groupName = ""; if (this.options.pointGroupName != null) groupName = this.options.pointGroupName; var rtchart = this; var configs = localStorage.getItem("goldenTrendConfig"); if(configs == null) return; if (configs) { try { configs = JSON.parse(configs); } catch (ex) { localStorage.removeItem("goldenTrendConfig"); configs = null; } } var config = configs[groupName]; if(config == null) { groupName = Object.keys(configs)[0]; config = configs[groupName]; } this.loadConfig(groupName,config); }, _init: function () { console.log('_init'); }, _destroy: function () { console.log('_destroy'); $(document).unbind('mousemove.rtChart_' + this.element.attr('id')); $(document).unbind('keydown.rtChart_' + this.element.attr('id')); this._clear(); if (this.webLinks) { for (i in this.webLinks) { var link = this.webLinks[i]; link.destroy(); delete link; } delete this.webLinks; } if (this.trendPens) { for (i in this.trendPens) { var pen = this.trendPens[i]; pen.destroy(); delete pen; } delete this.trendPens; } }, _isTouch: function () { return document.ontouchstart !== undefined; }, _buildChart: function () { this._clear(); this._bulidCanvas(); console.log('chartBuided'); }, _clear: function () { this.btipShow = false; if (this.artTooltip) this.artTooltip.close().remove(); if (this.tooltipTimer) { window.clearTimeout(this.tooltipTimer); this.tooltipTimer = null; } if (this.updateDataTimer) { window.clearTimeout(this.updateDataTimer); this.updateDataTimer = null; } if (this.updatePanTimer) { window.clearTimeout(this.updatePanTimer); this.updatePanTimer = null; } if (this.prepareTimer) { window.clearTimeout(this.prepareTimer); this.prepareTimer = null; } if (this.mouseTimer) { window.clearTimeout(this.mouseTimer); this.mouseTimer = null; } if (this.options.buttonImage) this.options.buttonImage.unbind(); if (this.tipShowPen) { this.tipShowPen.onTooltipHided(); this.tipShowPen = null; } if (this.activePen) { this.activePen.setActive(false); this.activePen = null; if(this.toolBar) this.toolBar.disableItem("deletePoint"); } if (this.colorPicker) { $('.colorpicker-ind', this.colorPicker).colorpicker('destroy'); this.colorPicker.draggable("destroy"); this.colorPicker.empty(); delete this.colorPicker; } if (this.vSplite) { if (this.vSplite.data('drag') === true) this.vSplite.draggable("destroy"); this.vSplite.unbind(); this.vSplite = null; } if (this.hSplite) { if (this.hSplite.data('drag') === true) this.hSplite.draggable("destroy"); this.hSplite.unbind(); this.hSplite = null; } if (this.vIndicator) { this.vIndicator.unbind(); this.vIndicator.draggable("destroy"); this.vIndicator = null; } if (this.hIndicator) { this.hIndicator.unbind(); this.hIndicator.draggable("destroy"); this.hIndicator = null; } if (this.ctx) delete this.ctx; if (this.canvas) { this.canvas.unbind(); delete this.canvas; } if (this.toolCalendar) { this.toolCalendar.unload(); delete this.toolCalendar; } if (this.toolBar) { this.toolBar.unload(); this.toolBar = null; } if (this.toolBarContainer) { this.toolBarContainer.remove(); this.toolBarContainer = null; } if (this.artTooltip) { this.artTooltip.remove(); delete this.artTooltip; } if (this.positionDiv) { this.positionDiv.unbind(); this.positionDiv.draggable("destroy"); this.positionDiv.remove(); this.positionDiv = null; } if (this.thumbBegDiv) { this.thumbBegDiv.unbind(); this.thumbBegDiv.draggable("destroy"); this.thumbBegDiv.remove(); this.thumbBegDiv = null; } if (this.thumbEndDiv) { this.thumbEndDiv.unbind(); this.thumbEndDiv.draggable("destroy"); this.thumbEndDiv.remove(); this.thumbEndDiv = null; } this.buttonsDrawed = false; if (this.listGrid) { this.listGrid.clearAll(true); this.listGrid.destructor(); delete this.listGrid; } if (this.listContainer) { this.listContainer.remove(); this.listContainer = null; } this.element.empty(); }, _bulidCanvas: function () { this.chartWidth = this.element.width(); this.chartHeight = this.element.height(); if (!this.chartWidth || !this.chartHeight) throw 'container not visable\'t exist'; var gw = this.getGridWidth(); var gh = this.getGridHeight(); var gt = this.toolBarCanShow() ? TOOLBARHEIGHT : 0; var cavansHight = gh; if(this.slidCanShow()) cavansHight += SLIDEHEIGHT; if (this.thumbsCanshow()) cavansHight += SHOWTHUMBSHEIGHT; if (this.listCanshow()) if (this.chartWidth < 100 + this.options.panWidth || this.options.panWidth < MINPANWIDTH) this.options.panShow = false; var rtchart = this; if (!this.canvas) { this.canvas = $(document.createElement('canvas')); this.element.append(this.canvas); this.canvas.bind('click', function (e) { rtchart._onClick(e); }); this.canvas.bind('dblclick', function (e) { rtchart._ondbClick(e); }); this.canvas.bind('mousedown', function (e) { rtchart._onMouseDown(e); }); this.canvas.bind('mousewheel', function (e) { e.preventDefault(); rtchart._onMouseWheel(e); }); if (this._isTouch()) { this.canvas.bind('touchstart', function (e) { rtchart._onTouchStart(e); }); } } this.canvas.css("position", "absolute") .css("left", 0) .css("top", gt) .css("right", 0) .css("height", cavansHight); if (this.options.bkColor != null) this.canvas.css('background-color',this.options.bkColor); this.canvas.attr("width", this.chartWidth * this.options.resolution); this.canvas.attr("height", cavansHight * this.options.resolution); var node = this.canvas.get(0); if (window.G_vmlCanvasManager) window.G_vmlCanvasManager.initElement(node); // For ExCanvas this.ctx = node.getContext('2d'); if (!window.G_vmlCanvasManager) this.ctx.scale(this.options.resolution, this.options.resolution); if (this.positionDiv) { this.positionDiv.draggable("destroy"); this.positionDiv.unbind(); this.positionDiv.remove(); this.positionDiv = null; } if (this.thumbBegDiv) { this.thumbBegDiv.draggable("destroy"); this.thumbBegDiv.unbind(); this.thumbBegDiv.remove(); this.thumbBegDiv = null; } if (this.thumbEndDiv) { this.thumbEndDiv.draggable("destroy"); this.thumbEndDiv.unbind(); this.thumbEndDiv.remove(); this.thumbEndDiv = null; } if (this.toolBarContainer == null) { this.toolBarContainer = $(document.createElement('div')); this.element.append(this.toolBarContainer); } this.toolBarContainer.css("position", "absolute") .css("left", 0) .css("top", -2) .css("right", 0) .css("height", TOOLBARHEIGHT) .addClass('unselectable'); this.calendarShowed = false; this.timerFocus = false; if (this.toolBar == null) { this.toolBar = new dhtmlXToolbarObject(this.toolBarContainer.get(0), "dhx_web"); this.toolBar.setIconsPath("htm/codebase/dhtmlxToolbar/codebase/icon/"); this.toolBar.addButton("addPoint", 0, null, "plus.png", "plus_dis.png"); this.toolBar.setItemToolTip("addPoint", "添加新点"); this.toolBar.addButton("deletePoint", 1, null, "deletepen.png", "deletepen_dis.png"); this.toolBar.setItemToolTip("deletePoint", "移除当前选定点"); this.toolBar.disableItem("deletePoint"); if (this.options.showAxis) { this.toolBar.addButtonTwoState("showAxis", 2, null, "axis.png", "axis_dis.png"); this.toolBar.setItemState("showAxis", true); this.toolBar.setItemToolTip("showAxis", "当前为值轴显示模式,单击转变为数据板显示模式"); } else { this.toolBar.addButtonTwoState("showAxis", 2, null, "datapan.png", "datapan_dis.png"); this.toolBar.setItemState("showAxis", false); this.toolBar.setItemToolTip("showAxis", "当前为数据板显示模式,单击转变为值轴显示模式"); } if (this.options.freeRange) { this.toolBar.addButtonTwoState("toggleRange", 3, null, "view_type_free.png", "view_type_free.png"); this.toolBar.setItemState("toggleRange", true); this.toolBar.setItemToolTip("toggleRange", "当前量程为自由量程,点击切换到固定量程"); } else { this.toolBar.addButtonTwoState("toggleRange", 3, null, "view_type.png", "view_type.png"); this.toolBar.setItemState("toggleRange", false); this.toolBar.setItemToolTip("toggleRange", "当前量程为固定量程,点击切换到自由量程"); } this.toolBar.addButton("colorPicker", 4, null, "colorpicker.png", "colorpicker_dis.png"); this.toolBar.setItemToolTip("colorPicker", "设置颜色"); this.toolBar.addButton("saveConfig", 5, null, "save.png", "save.png"); this.toolBar.setItemToolTip("saveConfig", "保存设置(如改变点组名称,可另存新建点组)"); var opts = [ ['newPiointGroup', 'obj', '新建点组', 'window_new.png'], ['editorPointGroup', 'obj', '编辑点组...', 'tag_blue_edit.png'], ['refreshPointGroup', 'obj', '刷新点组列表', 'reload.png'], ['idsep', 'sep'] ]; this.toolBar.addButtonSelect("pointGroup", 6, "点组", opts, "tag.png"); this.toolBar.addSeparator("rtSep", 7); //this.toolBar.addButtonTwoState("fullScreen", 7, null, "fullscreen.png", "fullscreen_dis.png"); //this.toolBar.setItemState("fullScreen", false); //this.toolBar.setItemToolTip("fullScreen", "单击进入全屏显示模式(F11)"); this.toolBar.addButton("zoomToool", 8, null, "zoom.png", "zoom_dis.png"); this.toolBar.setItemToolTip("zoomToool", "趋势缩放"); this.toolBar.addButton("zoomResume", 9, null, "zoom_resume.png", "zoom_resume_dis.png"); this.toolBar.setItemToolTip("zoomResume", "恢复缩放"); this.toolBar.disableItem("zoomResume"); this.toolBar.addSeparator("rtSep4", 10); if (this.options.rtRefresh) { this.toolBar.addButtonTwoState("reRefresh", 11, null, "refresh.png", "refresh_dis.png"); this.toolBar.setItemState("reRefresh", true); this.toolBar.setItemToolTip("reRefresh", "当前为实时刷新模式,单击转变为静态查询模式"); } else { this.toolBar.addButtonTwoState("reRefresh", 11, null, "query.png", "query_dis.png"); this.toolBar.setItemState("reRefresh", false); this.toolBar.setItemToolTip("reRefresh", "当前为静态查询模式,单击转变为实时刷新模式"); } this.toolBar.addSeparator("rtSep1", 12); this.toolBar.addButton("timePrev", 13, null, "previous.png", "previous_dis.png"); this.toolBar.setItemToolTip("timePrev", "前翻半个时间跨度"); var spanopts = [ ['b1m', 'obj', '当前时间 10分钟前', "left.png"], ['b3m', 'obj', '当前时间 30分钟前', "left.png"], ['b1h', 'obj', '当前时间 1小时前', "left.png"], ['b2h', 'obj', '当前时间 2小时前', "left.png"], ['b8h', 'obj', '当前时间 8小时前', "left.png"], ['b12h', 'obj', '当前时间 12小时前', "left.png"], ['spansep', 'sep'], ['b1d', 'obj', '当前时间 1天 前', "left.png"], ['b2d', 'obj', '当前时间 2天 前', "left.png"], ['b7d', 'obj', '当前时间 7天 前', "left.png"], // //['a1m', 'obj', '当前查询起始时间 10分钟后', "right.png"], //['a1h', 'obj', '当前查询起始时间 1小时后', "right.png"], //['a2h', 'obj', '当前查询起始时间 2小时后', "right.png"], //['a8h', 'obj', '当前查询起始时间 8小时后', "right.png"], //['a1d', 'obj', '当前查询起始时间 1天 后', "right.png"], //['a2d', 'obj', '当前查询起始时间 2天 后', "right.png"], //['a7d', 'obj', '当前查询起始时间 7天 后', "right.png"], ]; this.toolBar.addButtonSelect("timeSpan", 14, this.getTimeSpanString(), spanopts, null); this.toolBar.addButton("timeNext", 15, null, "next.png", "next_dis.png"); this.toolBar.setItemToolTip("timeNext", "后翻半个时间跨度"); this.toolBar.addSeparator("rtSep2", 16); this.toolBar.addInput("date_from", 17, "", 128); this.toolBar.addInput("date_to", 18, "", 128); this._updateTimeDisplay(); this.toolBar.addButton("goDate", 19, null, "find.png", "find_dis.png"); this.toolBar.setItemToolTip("goDate", "点击执行查询"); var from = this.toolBar.getInput("date_from"); var to = this.toolBar.getInput("date_to"); $(from).focusin(function () { rtchart.timerFocus = true; }); $(to).focusin(function () { rtchart.timerFocus = true; }); $(from).focusout(function () { rtchart.timerFocus = false; }); $(to).focusout(function () { rtchart.timerFocus = false; }); this.toolCalendar = new dhtmlXCalendarObject([from, to]); this.toolCalendar.setDateFormat("%Y-%m-%d %H:%i:%s");//.%u this.toolCalendar.setMinutesInterval(1); this.toolCalendar.loadUserLanguage("cn"); this._updateTimeDisplay(); this.toolCalendar.attachEvent("onShow", function(){ rtchart.calendarShowed = true; }); this.toolCalendar.attachEvent("onHide", function () { rtchart.calendarShowed = false; }); this.toolCalendar.attachEvent("onClick", function (date) { if (document.activeElement == $(from)[0]) { var button = document.activeElement.parentElement.nextElementSibling.nextElementSibling; var d = dialog({ content: "点击按钮进行查询操作或进行其他查询设置,\n点击工具条空白处取消文本框编辑状态。", quickClose: true }); d.show(button); window.setTimeout(function () { d.close().remove(); d = null; }, 2000); } else if (document.activeElement == $(to)[0]) { var button = document.activeElement.parentElement.nextElementSibling; var d = dialog({ content: "点击按钮进行查询操作或进行其他查询设置,\n点击工具条空白处取消文本框编辑状态。", quickClose: true }); d.show(button); window.setTimeout(function () { d.close().remove(); d = null; }, 2000); } }); var excelopts = [ ['exportToExcelInterpo', 'obj', '导出统一时间坐标的内插值', null], ['exportExcel', 'obj', '导出时间坐标不同的归档值', null] ]; this.toolBar.addButtonSelect("exportExceltool", 20, null, excelopts,"excel.png", "excel_dis.png"); this.toolBar.setItemToolTip("exportExceltool", "导出Excel"); this.toolBar.addButton("exportPng", 21, null, "mime_png.png", "mime_png.png"); this.toolBar.setItemToolTip("exportPng", "导出打印位图"); this.toolBar.addSeparator("rtSep3", 22); /*Button Command*/ this.toolBar.attachEvent("onClick", function (id) { rtchart.timerFocus = false; rtchart.calendarShowed = false; $(from).blur(); $(to).blur(); switch (id) { case "addPoint": rtchart._onAddPoint(); break; case "deletePoint": if (rtchart.listGrid.getSelectedRowId()) { var pens = rtchart.listGrid.getSelectedRowId(); pens = pens.split(','); if (pens) { for (var i = 0 ; i < pens.length; i++) { var rowid = pens[i]; var pen = rtchart.getPenByRowId(rowid); if(pen) rtchart.removePen(pen); } } } break; case "editorPointGroup": rtchart._onEditorPointGroup(); break; case "colorPicker": rtchart._onSetColors(); break; case "saveConfig": rtchart._onSaveConfig(); break; case "exportExcel": rtchart._onExportExcel(); break; case "exportToExcelInterpo": rtchart._onExportToExcelInterpo(); break; case "exportPng": rtchart._onExportPng(); break; case "mpass": rtchart._onModifyPassWord(); break; case "accmag": rtchart._onUserMagement(); break; case "login": rtchart.requestLogin("_login", true); break; case "logout": rtchart.logout(); break; case "goDate": rtchart._queryHisData($(from), $(to)); break; case "refreshPointGroup": rtchart._loadPointGroupNames(); break; case "newPiointGroup": var url = location.href; if (url.indexOf("?") > 0) url = url.substr(0, url.indexOf("?")); url += "?newPointGroup=1"; window.open(url, "_blank"); break; case "zoomToool": rtchart._toggleZoom(); break; case "zoomResume": rtchart._onReZoom(); break; case "timePrev": rtchart.updateBeginTime(rtchart.getBegTime() - 0.5 * rtchart.options.spanSec * PERSEC); break; case "timeNext": rtchart.updateBeginTime(rtchart.getBegTime() + 0.5 * rtchart.options.spanSec * PERSEC); break; case 'b1m': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 600 * PERSEC; rtchart.setBegTimeAndSpan(date, 600); break; case 'b3m': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 1800 * PERSEC; rtchart.setBegTimeAndSpan(date, 1800); break; case 'b1h': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 3600 * PERSEC; rtchart.setBegTimeAndSpan(date, 3600); break; case 'b2h': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 2 * 3600 * PERSEC; rtchart.setBegTimeAndSpan(date, 2 * 3600); break; case 'b8h': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 8 * 3600 * PERSEC; rtchart.setBegTimeAndSpan(date, 8 * 3600); break; case 'b12h': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 12 * 3600 * PERSEC; rtchart.setBegTimeAndSpan(date, 12 * 3600); break; case 'b1d': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 24 * 3600 * PERSEC; rtchart.setBegTimeAndSpan(date, 24 * 3600); break; case 'b2d': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 2*24 * 3600 * PERSEC; rtchart.setBegTimeAndSpan(date, 2*24 * 3600); break; case 'b7d': var date = new Date(); date.setMilliseconds(0); date = rtchart.DateToFileTime(date); date += PERSEC; date -= 7 * 24 * 3600 * PERSEC; rtchart.setBegTimeAndSpan(date, 7*24 * 3600); break; case 'a1m': rtchart.setTimeSpan(600, false); break; case 'a1h': rtchart.setTimeSpan(3600, false); break; case 'a2h': rtchart.setTimeSpan(2 * 3600, false); break; case 'a8h': rtchart.setTimeSpan(8 * 3600, false); break; case 'a1d': rtchart.setTimeSpan(24 * 3600, false); break; case 'a2d': rtchart.setTimeSpan(2 * 24 * 3600, false); break; case 'a7d': rtchart.setTimeSpan(7 * 24 * 3600, false); break; default: if (rtchart.pointGroups) { for (var n in rtchart.pointGroups) { var config = rtchart.pointGroups[n]; if (id == config.Id) { var gName = n; if (gName && gName.length) { var url = location.href; if (url.indexOf("?") > 0) url = url.substr(0, url.indexOf("?")); url += "?pointGroupName=" + encodeURI(gName); if (rtchart.isFullScreen() === true) window.location.href = url; else window.open(url, "_blank"); } break; } } } break; } }); this.toolBar.attachEvent("onStateChange", function (id) { switch (id) { case "reRefresh": if (rtchart.toolBar.getItemState("reRefresh")) rtchart.setRtrefresh(true); else rtchart.setRtrefresh(false); break; case "showAxis": if (rtchart.toolBar.getItemState("showAxis")) rtchart.setShowAxis(true); else rtchart.setShowAxis(false); break; case "fullScreen": rtchart.onFullScreenSet(); break; case "toggleRange": rtchart.toggleRangeMode(); break; } }); this._loadPointGroupNames(); var elem = document.documentElement; if (elem.requestFullscreen) { this.requestFullScreen = function() { var docElm = document.documentElement; docElm.requestFullscreen(); } this.isFullScreen = function () { return document.fullscreen; } } else if (elem.mozRequestFullScreen) { this.requestFullScreen = function () { var docElm = document.documentElement; docElm.mozRequestFullScreen(); } this.isFullScreen = function () { return document.mozFullScreen; } } else if (elem.webkitRequestFullScreen) { this.requestFullScreen = function () { var docElm = document.documentElement; docElm.webkitRequestFullScreen(); } this.isFullScreen = function () { return document.webkitIsFullScreen; } } else if (elem.msRequestFullscreen) { this.requestFullScreen = function () { var docElm = document.documentElement; docElm.msRequestFullscreen(); } this.isFullScreen = function () { return document.msFullscreenElement; } } if (document.exitFullscreen) { this.cancelFullScreen = function () { document.exitFullscreen(); } } else if (document.mozCancelFullScreen) { this.cancelFullScreen = function () { document.mozCancelFullScreen(); } } else if (document.webkitCancelFullScreen) { this.cancelFullScreen = function () { document.webkitCancelFullScreen(); } } else if (document.msExitFullscreen) { this.cancelFullScreen = function () { document.msExitFullscreen(); } } } this.positionDiv = $(document.createElement('div')); this.element.append(this.positionDiv); this.positionDiv.css("position", "absolute") .css("left", 0) .css("top", gt) .css("width", 6) .css("height", 6) .css(" z-index", 200) .addClass('unselectable') .draggable( { disabled: true, scroll:false, containment: [ this.canvas.offset().left - 2, this.canvas.offset().top + gt, this.canvas.offset().left + this.canvas.width() - 5, this.canvas.offset().top + gt + this.canvas.height() ] }); if (this.thumbsCanshow()) { gt += gh + TIMELABELHEIGHT; var h = SHOWTHUMBSHEIGHT - 3; this.thumbBegDiv = $(document.createElement('div')); this.element.append(this.thumbBegDiv); this.thumbBegDiv.css("position", "absolute") .css("left", -3) .css("top", gt) .css("width", 7) .css("height", h) .css("cursor", "e-resize") .css(" z-index", 200) .addClass('unselectable') .addClass('hspelit') .draggable( { containment: [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.chartWidth - 18, gh], axis: "x", scroll: false, drag: function (event, ui) { rtchart._onThumbsChanged(); } }); this.thumbEndDiv = $(document.createElement('div')); this.element.append(this.thumbEndDiv); this.thumbEndDiv.css("position", "absolute") .css("left", this.chartWidth - 3) .css("top", gt) .css("width", 7) .css("height", h) .css("cursor", "e-resize") .css(" z-index", 200) .addClass('unselectable') .addClass('hspelit') .draggable( { containment: [this.canvas.offset().left + 18, 0, this.canvas.offset().left + this.chartWidth - 3, gh], axis: "x", scroll: false, drag: function (event, ui) { rtchart._onThumbsChanged(); } }); gt += h; } if (this.listContainer) { this.listContainer.remove(); this.listContainer = null; } if (this.listCanshow() && this.options.listExpand) { gt += 4; this.listContainer = $(document.createElement('div')); this.element.append(this.listContainer); this.listContainer.css("position", "absolute") .css("left", 0) .css("right", 0) .css("top", gt) .css("bottom", 0) .css("border", "1px solid rgb(60,60,60)") .addClass('unselectable'); this.listGrid = new dhtmlXGridObject(this.listContainer.get(0)); this.listGrid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/"); //the path to images required by grid this.listGrid.setHeader ("点名称,线宽,描述,显示,数据时间,数据值,量程下限,量程上限,量程锁定,阶跃,标记,实时值,最大值,最小值,平均值");//the headers of columns this.listGrid.setColAlign("left,center,left,center,right,right,right,right,center,center,right,right,center,right,right"); //the alignment of columns this.listGrid.setInitWidths("160,50,180,45,140,120,100,100,65,45,45,110,110,110,110"); //the widths of columns this.listGrid.setColTypes("clrlabel,combo,ro,ch,ro,ro,edn,edn,ch,ch,ch,vqtcell,vqtcellclick,vqtcellclick,unitval"); //the types of columns this.listGrid.setColSorting("str,str,str,na,na,na,na,na,na,na,na,na,na,na,na"); //the sorting types this.listGrid.enableColumnMove(true); this.listGrid.enableDragAndDrop(true); this.listGrid.setSkin("dhx_web");//dhx_terrace this.listGrid.enableColumnAutoSize(true); this.listGrid.enableMultiselect(true); this.listGrid.init(); var combo = this.listGrid.getColumnCombo(1); combo.addOption("1", "1"); combo.addOption("2", "2"); combo.addOption("3", "3"); combo.addOption("4", "4"); combo.addOption("5", "5"); combo.addOption("6", "6"); combo.addOption("7", "7"); combo.addOption("8", "8"); this.listGrid.onSetLabelColor = function (e, rowid) { (e || event).cancelBubble = true; var pen = rtchart.getPenByRowId(rowid); if (pen) { rtchart.setPenColor(pen, e); } }; this.listGrid.onPosVQT = function (e, rowid,tip) { (e || event).cancelBubble = true; var pen = rtchart.getPenByRowId(rowid); if (pen) { pen.posVQT(tip); } }; this.listGrid.attachEvent("onSelectStateChanged", function (rowid) { if (rowid && rowid != "") { var pens = rowid.split(","); if (pens && pens.length) { var pen = rtchart.getPenByRowId(pens[0]); if (pen != rtchart.activePen) rtchart.requestActive(pen); } else rtchart.requestActive(null); } else rtchart.requestActive(null); }); this.listGrid.attachEvent("onAfterSorting", function (index, type, direction) { rtchart._onListSorted(); }); this.listGrid.attachEvent("onCheck", function (rowid, cInd, state) { var pen = rtchart.getPenByRowId(rowid); if (pen != null) { var col = rtchart.listGrid.getColumnLabel(cInd); switch (col) { case "显示": pen.setDisplay(state, false); break; case "阶跃": pen.setStepLine(state, false); break; case "标记": pen.setDrawTag(state, false); break; case "插值": pen.setInterpolate(state, false); break; case "量程锁定": pen.setRangeLock(state, false); break; } } }); this.listGrid.attachEvent("onDrop", function (sId, tId, dId, sObj, tObj, sCol, tCol) { rtchart._onListSorted(); }); this.listGrid.attachEvent("onCellChanged", function (rId, cInd, nValue) { var pen = rtchart.getPenByRowId(rId); if (pen != null) { var col = rtchart.listGrid.getColumnLabel(cInd); switch (col) { case "量程下限": pen.onSetMinRange(nValue); break; case "量程上限": pen.onSetMaxRange(nValue); break; case "线宽": pen.onSetLineWidth(nValue,true); break; } } }); this._synList(); } this._reDrawAll(); }, onFullScreenSet:function() { if (this.isFullScreen()) { this.cancelFullScreen(); this.toolBar.setItemState("fullScreen", false); this.toolBar.setItemToolTip("fullScreen", "单击进入全屏显示模式(F11)"); this.toolBar.setItemImage("fullScreen", "fullscreen.png"); } else { this.requestFullScreen(); this.toolBar.setItemState("fullScreen", true); //this.toolBar.setItemToolTip("fullScreen", "单击退出全屏显示模式(F11)"); this.toolBar.setItemImage("fullScreen", "leave_fullscreen.png"); } }, logout: function () { var xhr = $.ajax({ url: GoldenRtWeb.getWebURL() + '/Logout', type: "GET", processData: false, complete: function (xhr, ts) { var url = window.location.href; var index = url.lastIndexOf('?'); if (index > 0) url = url.substr(0, index); window.location = url; } }); }, _onExportPng: function() { var image = this.canvas[0].toDataURL("image/png").replace("image/png", "image/octet-stream"); window.location.href = image; }, _onExportToExcelInterpo: function () { if (!this.trendPens || !this.trendPens.length) { var d = dialog({ content: "目前尚未加载点信息,因此无法进行导出操作。", quickClose: true }); d.show(); window.setTimeout(function () { d.close(); d.remove(); d = null; }, 2000); return; } var pens = []; for (var i = 0 ; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; pens.push(pen.getURI()); } pens = pens.join(';'); var uri = "beginTime=" + this.getBegTime(); uri += "&endTime=" + this.getEndTime(); uri += "&point=" + pens; var link = document.createElement("a"); link.download = "exportExcel"; link.href = this.getWebURL() + "/ExportToExcelInterpo?" + encodeURI(uri); link.click(); }, _onExportExcel: function () { if (!this.trendPens || !this.trendPens.length) { var d = dialog({ content: "目前尚未加载点信息,因此无法进行导出操作。", quickClose: true }); d.show(); window.setTimeout(function () { d.close(); d.remove(); d = null; }, 2000); return; } var pens = []; for (var i = 0 ; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; pens.push(pen.getURI()); } pens = pens.join(';'); var uri = "beginTime=" + this.getBegTime(); uri += "&endTime=" + this.getEndTime(); uri += "&point=" + pens; var link = document.createElement("a"); link.download = "exportExcel"; link.href = this.getWebURL() + "/ExportToExcel?" + encodeURI(uri); link.click(); }, _queryHisData: function (from,to) { var beg = from.val(); beg = this.parseDate(beg); if (beg == null) { from.focus(); var d = dialog({ content: "查询起始时间设置有误,请重新设置。", quickClose: true }); window.setTimeout(function () { d.close().remove(); d = null; from.focus(); }, 2000); d.show(from[0]); return; } beg = this.DateToFileTime(beg); var end = to.val(); end = this.parseDate(end); if (end == null) { to.focus(); var d = dialog({ content: "查询截止时间设置有误,请重新设置。", quickClose: true }); window.setTimeout(function () { d.close().remove(); d = null; to.focus(); }, 2000); d.show(to[0]); return; } end = this.DateToFileTime(end); if (end <= beg) { to.focus(); var d = dialog({ content: "查询截止时间不能小于等于查询起始时间,请重新设置。", quickClose: true }); window.setTimeout(function () { d.close().remove(); d = null; to.focus(); }, 2000); d.show(to[0]); return; } this.setBegTimeAndSpan(beg, (end - beg) / PERSEC); }, getPenByRowId: function (rowId) { if (this.trendPens) { for (var k in this.trendPens) { var pen = this.trendPens[k]; if (pen.rowId == rowId) return pen; } } return null; }, _bindPenList: function (pen) { if (this.listGrid) { var rowId = this.listRowSeed++; this.listGrid.addRow(rowId, ""); pen._setListRowId(rowId); } }, _synList: function () { this.listGrid.clearAll(); this.listRowSeed = 1; if (this.trendPens && this.trendPens.length) { for (i in this.trendPens) this._bindPenList(this.trendPens[i]); } }, _updateList: function(rowId,colName,val) { if (this.listGrid && rowId && colName) { var num = this.listGrid.getColumnsNum(); for (var i = 0; i < num ; i++) { if (this.listGrid.getColumnLabel(i) == colName) { var cell = this.listGrid.cells(rowId, i); if (cell) cell.setValue(val); break; } } } }, getWebURL: function () { return GoldenRtWeb.getWebURL(); }, _reDrawAll: function () { var node = this.canvas.get(0); this.ctx.clearRect(0, 0, node.width, node.height); this.buttonsDrawed = false; this.updateDataArea(); this.UpdatePan(true); this._drawIndicator(); this._drawButtons(); }, _onResize: function () { if (this.artTooltip) this.artTooltip.close().reset().remove(); if (this.element.width() != this.chartWidth || this.element.height() != this.chartHeight) this._bulidCanvas(); }, _onListSorted: function() { var ids = this.listGrid.getAllRowIds(); var arry = ids.split(","); if (arry && arry.length) { var newPens = []; for (var i = 0; i < arry.length; i++) { var pen = this.getPenByRowId(arry[i]); if (pen) newPens.push(pen); } if (newPens.length) { this.trendPens = newPens; this.updateDataArea(); this.UpdatePan(); } } }, _drawIndicator: function () { var gw = this.getGridWidth(); var gh = this.getGridHeight(); var gt = this.toolBarCanShow() ? TOOLBARHEIGHT : 0; var rtchart = this; var hw; if (this.options.showAxis) hw = this.chartWidth; else hw = gw + 12; if (!this.hIndicator) { this.hIndicator = $(document.createElement('canvas')); this.element.append(this.hIndicator); bNew = true; } this.hIndicator.css("position", "absolute") .css("left", 0) .css("top", 60) .css("width", hw) .css("height", INDICTWIDTH) .css("cursor", "n-resize"); this.hIndicator.attr("width", (hw) * this.options.resolution); this.hIndicator.attr("height", INDICTWIDTH * this.options.resolution); var node = this.hIndicator.get(0); if (window.G_vmlCanvasManager) window.G_vmlCanvasManager.initElement(node); // For ExCanvas var hctx = node.getContext('2d'); if (!window.G_vmlCanvasManager) hctx.scale(this.options.resolution, this.options.resolution); hctx.save(); hctx.translate(0.5, 0.5); hctx.clearRect(0, 0, (hw), INDICTWIDTH); hctx.lineWidth = 3.0; hctx.strokeStyle = this.options.indicatorColor; hctx.beginPath(); hctx.moveTo(1, 5); hctx.lineTo(hw, 5); hctx.stroke(); hctx.restore(); if (bNew) this.hIndicator.draggable( { containment: [0, this.canvas.offset().top - 5, hw, this.canvas.offset().top + gh - 5], scroll: false, axis: "y", drag: function (event, ui) { rtchart._onhIndicatorMove(event); }, stop: function (event, ui) { rtchart._onhIndicatorMoveEnd(event); } }); else this.hIndicator.draggable('option', 'containment', [0, this.canvas.offset().top - 5, gw, this.canvas.offset().top + gh - 5]); this.hIndicator.hover( function (e) { rtchart.hIndicator.focus(); rtchart._onhIndicatorHover(e); }); if (this.vSplite) { if (this.vSplite.data('drag') === true) this.vSplite.draggable("destroy"); this.vSplite.unbind(); this.vSplite.remove(); this.vSplite = null; } if (this.hSplite) { if (this.hSplite.data('drag') === true) this.hSplite.draggable("destroy"); this.hSplite.unbind(); this.hSplite.remove(); this.hSplite = null; } bNew = false; if (!this.vIndicator) { this.vIndicator = $(document.createElement('canvas')); this.element.append(this.vIndicator); bNew = true; } this.vIndicator.css("position", "absolute") .css("left", 20) .css("top", gt) .css("width", INDICTWIDTH) .css("height", (gh + 16)) .css("cursor", "e-resize"); this.vIndicator.attr("width", INDICTWIDTH * this.options.resolution); this.vIndicator.attr("height", (gh + 16) * this.options.resolution); node = this.vIndicator.get(0); if (window.G_vmlCanvasManager) window.G_vmlCanvasManager.initElement(node); // For ExCanvas var vctx = node.getContext('2d'); if (!window.G_vmlCanvasManager) vctx.scale(this.options.resolution, this.options.resolution); vctx.save(); vctx.translate(0.5, 0.5); vctx.clearRect(0, 0, INDICTWIDTH, node.height); vctx.lineWidth = 3.0; vctx.strokeStyle = this.options.indicatorColor; vctx.beginPath(); vctx.moveTo(5, 1); vctx.lineTo(5, gh + 10); vctx.stroke(); vctx.restore(); if (bNew) this.vIndicator.draggable( { containment: [this.canvas.offset().left - 5, 0, this.canvas.offset().left + gw - 5, gh], axis: "x", scroll: false, drag: function (event, ui) { rtchart._onvIndicatorMove(event); }, stop: function (event, ui) { rtchart._onvIndicatorMoveEnd(event); } }); else this.vIndicator.draggable('option', 'containment', [this.canvas.offset().left - 5, 0, this.canvas.offset().left + gw - 5, gh]); this.vIndicator.hover( function (e) { rtchart.vIndicator.focus(); rtchart._onvIndicatorHover(e); }); if (this.options.panShow) { this.vSplite = $(document.createElement('canvas')); this.hIndicator.before(this.vSplite); this.vSplite.css("position", "absolute") .css("left", gw) .css("top", gt) .css("width", PANMAG * 2) .css("height", (gh + 1)) .css("cursor", "e-resize") .addClass('unselectable'); this.vSplite.attr("width", PANMAG * 2 * this.options.resolution); this.vSplite.attr("height", (gh + 1) * this.options.resolution); node = this.vSplite.get(0); if (window.G_vmlCanvasManager) window.G_vmlCanvasManager.initElement(node); // For ExCanvas var spctx = node.getContext('2d'); if (!window.G_vmlCanvasManager) spctx.scale(this.options.resolution, this.options.resolution); spctx.clearRect(0, 0, node.width, node.height); this.vSplite.draggable( { containment: [this.canvas.offset().left + 200, 0, this.chartWidth - 5, gh], axis: "x", scroll: false, start: function (event, ui) { var ctx = this.getContext('2d'); ctx.clearRect(0, 0, this.width, this.height); var gradient = ctx.createLinearGradient(0, 0, this.width, 0); gradient.addColorStop("0", "rgba(120,120,120,0.5)"); gradient.addColorStop(".50", "rgba(180,180,180,0.7)"); gradient.addColorStop("1.0", "rgba(120,120,120,0.5)"); ctx.fillStyle = gradient; ctx.fillRect(0, 0, this.width, this.height); ctx.beginPath(); ctx.lineWidth = "1"; ctx.strokeStyle = "rgb(30,30,30)"; ctx.rect(.5, .5, this.width - 1, this.height - 1); ctx.stroke(); }, stop: function (event, ui) { var ctx = this.getContext('2d'); ctx.clearRect(0, 0, this.width, this.height); var l = $(this).position().left; rtchart.setPanWidth(rtchart.chartWidth - l); } }); this.vSplite.data('drag', true); this.vSplite.hover( function (e) { var o = $(this).offset(); var x = e.pageX - o.left; var y = e.pageY - o.top; if (y > this.height / 2 - 18 && y < this.height / 2 - 18 + 35) { $(this).attr('title', '收回数据板'); $(this).css('cursor', 'pointer'); } else { $(this).attr('title', null); $(this).css('cursor', "e-resize"); } }, function (e) { $(this).css("cursor", "e-resize"); }); this.vSplite.click(function (e) { var o = $(this).offset(); var x = e.pageX - o.left; var y = e.pageY - o.top; if (y > this.height / 2 - 18 && y < this.height / 2 - 18 + 35) rtchart.setPanShow(false); }); } else if (this.panCanShow()) { this.vSplite = $(document.createElement('canvas')); this.hIndicator.before(this.vSplite); this.vSplite.css("position", "absolute") .css("left", this.chartWidth - 5) .css("top", gh / 2 + 15) .css("width", 5) .css("height", 35) .css("cursor", "pointer") .attr("title", "展开数据板"); this.vSplite.attr("width", 5 * this.options.resolution); this.vSplite.attr("height", 35 * this.options.resolution); node = this.vSplite.get(0); if (window.G_vmlCanvasManager) window.G_vmlCanvasManager.initElement(node); // For ExCanvas var spctx = node.getContext('2d'); if (!window.G_vmlCanvasManager) spctx.scale(this.options.resolution, this.options.resolution); spctx.clearRect(0, 0, node.width, node.height); this.vSplite.click(function (e) { rtchart.setPanShow(true); }); } if (this.listCanshow()) { this.hSplite = $(document.createElement('canvas')); this.element.append(this.hSplite); var t; if (this.listCanshow() && this.options.listExpand) t = this.chartHeight - this.options.listHeight; else t = this.chartHeight - 11; this.hSplite.css("position", "absolute") .css("left", 0) .css("top", t) .css("right", 0) .css("height", 10) .css("cursor", "n-resize") .css("z-index",1000) .addClass('unselectable'); this.hSplite.attr("width", this.chartWidth * this.options.resolution); this.hSplite.attr("height", 10 * this.options.resolution); node = this.hSplite.get(0); if (window.G_vmlCanvasManager) window.G_vmlCanvasManager.initElement(node); // For ExCanvas var hpctx = node.getContext('2d'); if (!window.G_vmlCanvasManager) hpctx.scale(this.options.resolution, this.options.resolution); hpctx.clearRect(0, 0, node.width, node.height); this.hSplite.draggable( { containment: [0, this.element.offset().top + 210, 0, this.element.offset().top + this.element.height() - 30], axis: "y", scroll: false, start: function (event, ui) { var ctx = this.getContext('2d'); ctx.clearRect(0, 0, this.width, this.height); var gradient = ctx.createLinearGradient(0, 0, 0, this.height); gradient.addColorStop("0", "rgba(120,120,120,0.5)"); gradient.addColorStop(".50", "rgba(200,200,200,0.7)"); gradient.addColorStop("1.0", "rgba(120,120,120,0.5)"); ctx.fillStyle = gradient; ctx.fillRect(0, 0, this.width - 3, this.height); ctx.beginPath(); ctx.lineWidth = "1"; ctx.strokeStyle = "rgb(30,30,30)"; ctx.rect(.5, .5, this.width - 3, this.height - 1); ctx.stroke(); }, stop: function (event, ui) { var ctx = this.getContext('2d'); ctx.clearRect(0, 0, this.width, this.height); var t = rtchart.chartHeight - $(this).offset().top + rtchart.element.offset().top; rtchart.setListHeight(t); } }); this.hSplite.data('drag', true); this.hSplite.hover( function (e) { var o = $(this).offset(); var x = e.pageX - o.left; var y = e.pageY - o.top; if (x > this.width / 2 - 18 && x < this.width / 2 + 18) { if (rtchart.options.listExpand) $(this).attr('title', '收回数据列表'); else $(this).attr('title', '展开数据列表'); $(this).css('cursor', 'pointer'); } else { $(this).attr('title', null); $(this).css('cursor', "n-resize"); } }, function (e) { $(this).css("cursor", "n-resize"); } ); this.hSplite.click(function (e) { var o = $(this).offset(); var x = e.pageX - o.left; var y = e.pageY - o.top; if (x > this.width / 2 - 18 && x < this.width / 2 + 18) { if (rtchart.options.listExpand) rtchart.setListExpand(false); else rtchart.setListExpand(true); } }); } }, _drawButtons: function () { if (this.buttonsDrawed === true || !this.options.buttonImage) return; if (this.options.buttonImage.get(0).complete === true) { var img = this.options.buttonImage.get(0); var gw = this.getGridWidth(); var gh = this.getGridHeight(); this.buttonsDrawed = true; var canvas = this.vIndicator.get(0); var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, 11, 11, 0, gh - 3, 11, 11); canvas = this.hIndicator.get(0); ctx = canvas.getContext("2d"); ctx.drawImage(img, 11, 0, 11, 11, gw - 3, 0, 11, 11); if (this.vSplite) { canvas = this.vSplite.get(0); ctx = canvas.getContext("2d"); if (this.options.panShow) ctx.drawImage(img, 0, 11, 5, 35, 0, canvas.height / 2 - 18, 5, 35); else ctx.drawImage(img, 5, 11, 5, 35, 0, 0, 5, 35); } if (this.hSplite) { canvas = this.hSplite.get(0); ctx = canvas.getContext("2d"); if(this.options.listExpand) ctx.drawImage(img, 10, 11, 35, 5, canvas.width / 2 - 18, 0, 35, 5); else ctx.drawImage(img, 10, 15, 35, 5, canvas.width / 2 - 18, 0, 35, 5); } } else { var me = this; this.options.buttonImage.load(function () { if (me) { me._drawButtons(); me.UpdateDataPan(true); me = null; } }); } }, updateDataArea: function() { if (this.updateDataAreaTimer == null) { var self = this; this.updateDataAreaTimer = window.setTimeout(function () { window.clearTimeout(self.updateDataAreaTimer) self.updateDataAreaTimer = null; self._drawDataArea(); self = null; }, 20); } }, _drawDataArea: function () { if (this.thumbsCanshow()) this._drawThumbs(); this._drawTimeLabel(); this._drawTrendLines(); }, _drawTrendLines:function() { var gw = this.getGridWidth(); var gh = this.getGridHeight(); var ctx = this.ctx; ctx.save(); ctx.clearRect(0, 0, gw, gh); ctx.translate(0.5, 0.5); var begTime = this.getDrawBegTime(); var endTime = this.getDrawEndTime(); var timeScale = gw / (endTime - begTime); if (this.options.showGrid) { var y = gh / 20.0; ctx.beginPath(); ctx.lineWidth = 1; ctx.strokeStyle = this.options.gridColor; for (var i = 0; i < 19; i++) { var iy = Math.floor(y ); ctx.moveTo(0, iy); ctx.lineTo(gw, iy); y += gh / 20.0; } var t = this.ftTimeLabelBeg; var x = (t - begTime) * timeScale; for (var i = 0; i < 4; i++) { var ix = Math.floor(x); ctx.moveTo(ix, 0); ctx.lineTo(ix, gh); t += (endTime - begTime) / 4; x = (t - begTime) * timeScale; } ctx.stroke(); } if (this.trendPens && this.trendPens.length) { ctx.rect(1, 1, gw - 1, gh - 1); ctx.clip(); ctx.lineWidth = 1; for (k in this.trendPens) { var pen = this.trendPens[k]; if (pen != this.activePen) pen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale); } if (this.activePen) { var shadowSize = this.options.activeShadowSize; var lineWidth = 2; ctx.lineWidth = shadowSize / 2; var offset = lineWidth / 2 + ctx.lineWidth / 2; ctx.strokeStyle = "rgba(0,0,0,0.4)"; this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale, offset + shadowSize / 2); ctx.strokeStyle = "rgba(0,0,0,0.5)"; this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale, offset); ctx.lineWidth = lineWidth; this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale); } } if (this.zoomRect) { ctx.lineWidth = 1; ctx.strokeStyle = "rgb(180,180,180)"; ctx.fillStyle = "rgba(10,10,10,0.2)"; ctx.beginPath(); ctx.rect(this.zoomRect.x, this.zoomRect.y, this.zoomRect.w, this.zoomRect.h); ctx.fill(); ctx.stroke(); } ctx.restore(); if (this.options.borderColor != null) { ctx.lineWidth = 1; ctx.beginPath(); ctx.strokeStyle = this.options.borderColor; ctx.rect(0.5, 0.5, gw, gh); ctx.stroke(); } }, _onThumbsChanged: function() { this.thumbBegDiv.draggable("option", "containment", [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.thumbEndDiv.position().left - 20, 0]); this.thumbEndDiv.draggable("option", "containment", [this.canvas.offset().left + this.thumbBegDiv.position().left + 20, 0, this.canvas.offset().left + this.chartWidth - 3, 0]); this._drawThumbs(); this._drawTimeLabel(); this._drawTrendLines(); }, _resetTumbs: function () { if (this.thumbBegDiv) { this.thumbBegDiv .css("left", -3) .draggable("option", "containment", [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.chartWidth - 18, 0]); } if (this.thumbEndDiv) { this.thumbEndDiv .css("left", this.chartWidth - 3) .draggable("option", "containment", [this.canvas.offset().left + 18, 0, this.canvas.offset().left + this.chartWidth - 18, 0]); } }, _drawThumbs: function () { var thw = this.chartWidth; var gh = this.getGridHeight(); var gt = gh + TIMELABELHEIGHT; var h = SHOWTHUMBSHEIGHT - 3; var ctx = this.ctx; ctx.save(); ctx.clearRect(0, gt, thw, h); ctx.translate(0.5, 0.5); if (this.trendPens && this.trendPens.length) { var begTime = this.getBegTime(); var endTime = this.getEndTime(); var timeScale = thw / this.options.spanSec / PERSEC; ctx.rect(1, gt, thw - 1, h - 1); ctx.clip(); ctx.lineWidth = 1; for (k in this.trendPens) { var pen = this.trendPens[k]; pen.drawThumbsTrendLine(ctx, begTime, endTime,gh, gt, h, timeScale); } } ctx.fillStyle = "rgba(100,100,100,0.7)"; var ix = this.thumbBegDiv.position().left + 6; ctx.fillRect(0, gt, ix, h); ix = this.thumbEndDiv.position().left; ctx.fillRect(ix, gt, thw - ix, h); ctx.restore(); if (this.options.borderColor != null) { ctx.lineWidth = 1; ctx.beginPath(); ctx.strokeStyle = this.options.borderColor; ctx.rect(0.5, 0.5 + gt, thw - 1, h); ctx.stroke(); } }, _drawTimeLabel: function () { if (!this.ctx || !this.slidCanShow()) return; var begTime = this.getDrawBegTime(); var endTime = this.getDrawEndTime(); var timeSpan = (endTime - begTime); var span = timeSpan / 4; var changed = false; if (this.ftTimeLabelBeg == null || Math.abs(this.ftTimeLabelBeg - this.ftBeginTime) > this.options.spanSec * PERSEC) { if (span >= PERDAY) { var ft = begTime + PERDAY; ft = this.FileTimeToDate(ft); ft.setHours(0); ft.setMinutes(0); ft.setSeconds(0); ft.setMilliseconds(0); this.ftTimeLabelBeg = this.DateToFileTime(ft); } else if (span > PERHOUR) { var ft = begTime + PERHOUR; ft = this.FileTimeToDate(ft); ft.setMinutes(0); ft.setSeconds(0); ft.setMilliseconds(0); this.ftTimeLabelBeg = this.DateToFileTime(ft); } else if (span > PERMINUTE) { var ft = begTime + PERMINUTE; ft = this.FileTimeToDate(ft); ft.setSeconds(0); ft.setMilliseconds(0); this.ftTimeLabelBeg = this.DateToFileTime(ft); } else if (span > PERSEC) { var ft = begTime + PERSEC; ft = this.FileTimeToDate(ft); ft.setMilliseconds(0); this.ftTimeLabelBeg = this.DateToFileTime(ft); } else this.ftTimeLabelBeg = begTime + span; changed = true; } while (begTime < this.ftTimeLabelBeg + span) { this.ftTimeLabelBeg -= span; changed = true; } while (begTime > this.ftTimeLabelBeg) { this.ftTimeLabelBeg += span; changed = true; } if(changed) this._updatevIndicatorTooltip(); var ctx = this.ctx; ctx.save(); ctx.translate(0.5, 0.5); ctx.fillStyle = this.options.timeLabelColor; ctx.textBaseline = "top"; ctx.textAlign = "left"; ctx.font = "12px sans-serif"; var gw = this.getGridWidth(); var gh = this.getGridHeight(); ctx.clearRect(0, gh + 0.5, gw, 13); var len = 60; var str; if (timeSpan/PERSEC > 10) str = this.FileTimeToTimeString(begTime, false); else { str = this.FileTimeToTimeString(begTime, true); len = 80; } ctx.fillText(str, 0, gh); str = this.FileTimeToDateString(begTime); ctx.clearRect(0, gh + 14, 70, 16); ctx.fillText(str, 0, gh + 16); var time = this.ftTimeLabelBeg; var x = (time - begTime) * gw / timeSpan; var px = 0; for (var i = 1; i < 5; i++) { var ix = Math.floor(x); if ((ix > px + len) && (ix + len < gw - len)) { if (this.options.spanSec > 10) str = this.FileTimeToTimeString(time, false); else str = this.FileTimeToTimeString(time, true); ctx.fillText(str, ix, gh); px = x; } time += timeSpan / 4; x += gw / 4; } if (timeSpan / PERSEC > 10) str = this.FileTimeToTimeString(endTime, false); else str = this.FileTimeToTimeString(endTime, true); ctx.textAlign = "right"; ctx.fillText(str, gw, gh); str = this.FileTimeToDateString(endTime); ctx.clearRect(gw - 70, gh + 14, 72, 16); ctx.fillText(str, gw, gh + 16); ctx.restore(); }, UpdatePan: function (bReDraw) { if (bReDraw) this.panReDraw = bReDraw; if (this.updatePanTimer == null) { var self = this; this.updatePanTimer = window.setTimeout(function () { window.clearTimeout(self.updatePanTimer) self.updatePanTimer = null; self._drawPan(); self = null; }, 100); } }, UpdateDataPan: function (bReDraw) { if (this.options.showAxis || !this.options.panShow) return; this.UpdatePan(bReDraw); }, UpdateAxisPan: function (bReDraw) { if (!this.options.showAxis || !this.options.panShow) return; this.UpdatePan(bReDraw); }, _drawPan: function (bReDraw) { if (this.options.panShow) { var l = this.getGridWidth() + PANMAG; var w = this.options.panWidth - PANMAG; if (this.options.showAxis) { var h = this.getGridHeight() + TIMELABELHEIGHT; var ctx = this.ctx; ctx.save(); ctx.font = "12px sans-serif"; ctx.textBaseline = "top"; ctx.lineWidth = 1.0; ctx.lineJoin = 'miter'; ctx.clearRect(l, 0, w + 1, h); ctx.rect(l, 0, w + 1, h - 2); ctx.clip(); ctx.translate(0.5, 0.5); if (this.trendPens) { for (var i = 0; i < this.trendPens.length; i++) this.trendPens[i].resetAxisDrawed(); var pl = this.getGridWidth() + PANMAG; var ph = this.getGridHeight(); var pw = this.options.panWidth - PANMAG; var begX = pl + 1; for (var i = 0; i < this.trendPens.length; i++) { ctx.strokeStyle = this.options.borderColor; ctx.fillStyle = this.options.timeLabelColor; var drawPen = this.trendPens[i]; var x = drawPen.drawAxis(begX, ph, ctx); if (isNaN(x)) x = 0; begX += x + 2; if (begX >= this.chartWidth) break; } } ctx.restore(); } else { var h = this.getGridHeight(); if (this.yScroll == null || this.yScroll < 0) this.yScroll = 0; else if (!this.trendPens || h > PANHEAD + this._getPanTotalHeight()) this.yScroll = 0; else if (this.yScroll + (h - PANHEAD) > this._getPanTotalHeight()) this.yScroll = this._getPanTotalHeight() - h + PANHEAD; var ctx = this.ctx; ctx.save(); ctx.font = "14px sans-serif"; ctx.textBaseline = "top"; bReDraw = this.panReDraw || bReDraw; this.panReDraw = false; if (bReDraw) ctx.clearRect(l + 0.5, 0.5, w, h + TIMELABELHEIGHT); ctx.rect(l, 0, w + 1, h - 2); ctx.clip(); if (this.trendPens) { var t = PANHEAD - this.yScroll; var pl = this.getGridWidth() + PANMAG; var ph = this.getGridHeight(); var pw = this.options.panWidth - PANMAG; for (var i = 0; i < this.trendPens.length; i++) { ctx.save(); ctx.translate(pl, t); if (this.newPenPos == i) { ctx.lineWidth = 4.0; ctx.lineJoin = 'round'; ctx.strokeStyle = "rgb(0,210,210)"; ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(pw, 0); ctx.stroke(); } var drawPen = this.trendPens[i]; drawPen.drawPan(bReDraw, ctx, t, pw); ctx.restore(); t += drawPen.getPanHeight(); if (t > ph) break; } } if (this._showAxisToggle === true) { this._showAxisToggle = false; ctx.clearRect(l + 0.5, h, w, TIMELABELHEIGHT); } ctx.restore(); ctx.beginPath(); ctx.lineWidth = 1; ctx.strokeStyle = this.options.borderColor; ctx.rect(l + 0.5, 0.5, w, h); ctx.stroke(); } } }, _setOption: function (key, value) { switch (key) { case "rtRefresh": this.setRtrefresh(value); break; } this._super(key, value); }, toggleRtRefresh: function () { this.setRtrefresh(!this.options.rtRefresh); }, setRtrefresh: function (brtRefresh) { if (this.options.rtRefresh == brtRefresh) return; this.options.rtRefresh = brtRefresh; if (this.options.rtRefresh) { this.toolBar.setItemImage("reRefresh","refresh.png"); this.toolBar.setItemState("reRefresh", true); this.toolBar.setItemToolTip("reRefresh", "当前为实时刷新模式,单击转变为静态查询模式"); } else { this.toolBar.setItemImage("reRefresh", "query.png"); this.toolBar.setItemState("reRefresh", false); this.toolBar.setItemToolTip("reRefresh", "当前为静态查询模式,单击转变为实时刷新模式"); } if (this.options.rtRefresh) { if (Math.abs(this.DateToFileTime(new Date()) - this.getEndTime()) > this.options.spanSec * PERSEC) { var begTime = new Date(); begTime.setMilliseconds(0); begTime = this.DateToFileTime(begTime); begTime += PERSEC; begTime -= this.options.spanSec * PERSEC; this.ftTimeLabelBeg = null; if (this.ftBeginTime == begTime) this.ftBeginTime = 0; this.setBeginTime(begTime); } else if (this.webLinks) { for (var i in this.webLinks) this.webLinks[i].requestHisData(); } } }, toggleShowAxis: function () { this.setShowAxis(!this.options.showAxis); }, setShowAxis: function (bShowAxis) { if (this.options.showAxis == bShowAxis) return; this.options.showAxis = bShowAxis; if (this.options.showAxis) { this.toolBar.setItemImage("showAxis", "axis.png"); this.toolBar.setItemState("showAxis", true); this.toolBar.setItemToolTip("showAxis", "当前为值轴显示模式,单击转变为数据板显示模式"); } else { this.toolBar.setItemImage("showAxis", "datapan.png"); this.toolBar.setItemState("showAxis", false); this.toolBar.setItemToolTip("showAxis", "当前为数据板显示模式,单击转变为值轴显示模式"); } this._showAxisToggle = true; var gw = this.getGridWidth(); var hw; if (this.options.showAxis) hw = this.chartWidth; else hw = gw + 12; this.hIndicator.css("width", hw); this.hIndicator.attr("width", (hw) * this.options.resolution); var node = this.hIndicator.get(0); if (window.G_vmlCanvasManager) window.G_vmlCanvasManager.initElement(node); // For ExCanvas var hctx = node.getContext('2d'); if (!window.G_vmlCanvasManager) hctx.scale(this.options.resolution, this.options.resolution); hctx.save(); hctx.translate(0.5, 0.5); hctx.clearRect(0, 0, (hw), INDICTWIDTH); hctx.lineWidth = 3.0; hctx.strokeStyle = this.options.indicatorColor; hctx.beginPath(); hctx.moveTo(1, 5); hctx.lineTo(hw, 5); hctx.stroke(); if (this.options.buttonImage && this.options.buttonImage.get(0).complete === true) { var img = this.options.buttonImage.get(0); hctx.drawImage(img, 11, 0, 11, 11, gw - 3, -0.5, 11, 11); } hctx.restore(); this.UpdatePan(true); }, toggleRangeMode: function () { this.setRangeMode(!this.options.freeRange); }, setRangeMode: function (rangeMode) { if (this.options.freeRange === rangeMode) return; this.options.freeRange = rangeMode; if (this.options.freeRange) { this.toolBar.setItemImage("toggleRange", "view_type_free.png"); this.toolBar.setItemState("toggleRange", true); this.toolBar.setItemToolTip("toggleRange", "当前量程为自由量程,点击切换到固定量程"); } else { this.toolBar.setItemImage("toggleRange", "view_type.png"); this.toolBar.setItemState("toggleRange", false); this.toolBar.setItemToolTip("toggleRange", "当前量程为固定量程,点击切换到自由量程"); } // 如果是固定量程 var pen if (!rangeMode) { for (var i = 0, len = this.trendPens.length; i < len; i++) { pen = this.trendPens[i]; pen.setRange(0, 1000, null); } } }, setCursor: function (cursor) { this.canvas.css("cursor", cursor); }, showTooltip: function (opt, pen) { if (this.artTooltip) this.artTooltip.close().remove(); if (this.tipShowPen) this.tipShowPen.onTooltipHided(); if (this.tooltipTimer) { window.clearTimeout(this.tooltipTimer); this.tooltipTimer = null; } var rtChart = this; this.tooltipTimer = window.setTimeout( function () { var o = rtChart.getOffset(); if (opt.x == null || opt.x < 0) opt.x = 0; else if (opt.x + rtChart.positionDiv.width() + 2 > o.left + rtChart.chartWidth) opt.x = o.left + rtChart.chartWidth - rtChart.positionDiv.width() - 2; if (opt.y == null || opt.y < 0) opt.y = 0; else if (opt.y + rtChart.positionDiv.height() + 2 > o.top + rtChart.chartHeight) opt.y = o.top + rtChart.chartHeight - rtChart.positionDiv.height() - 2; rtChart.positionDiv.offset({ left: opt.x, top: opt.y }); $.extend(opt, { padding: 10, onremove: function () { rtChart._onTootipHided(); rtChart = null; } }); rtChart.artTooltip = dialog(opt); rtChart.artTooltip.show(rtChart.positionDiv.get(0)); rtChart.btipShow = true; rtChart.tipShowPen = pen; if (rtChart.tipShowPen) rtChart.tipShowPen.onTooltipShowed(); }, this.options.tooltipDelay || 200); }, UpdateTooltip: function (content) { if (this.artTooltip) this.artTooltip.content(content) }, _onTootipHided: function () { this.btipShow = false; if (this.tipShowPen) { this.tipShowPen.onTooltipHided(); this.tipShowPen = null; } this.tootipAt = null; if (this.artTooltip) delete this.artTooltip; this.positionDiv.offset({ left: this.canvas.offset().left, top: this.canvas.offset().top }); }, getTooltipPen: function () { return this.tipShowPen; }, _onhIndicatorHover: function (e) { if (this.loginning === true) return; if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) return; if (this.artTooltip) this.artTooltip.close().remove(); if (this.tooltipTimer) { window.clearTimeout(this.tooltipTimer); this.tooltipTimer = null; } var rtChart = this; this.tooltipTimer = window.setTimeout( function () { if (rtChart.tooltipTimer) { window.clearTimeout(rtChart.tooltipTimer); rtChart.tooltipTimer = null; } var gh = rtChart.getGridHeight(); var o = rtChart.canvas.offset(); var y = e.pageY - o.top; var ta = (y > gh / 2) ? 'bottom' : 'top'; var opt = { title: "值线", content: rtChart._gethIndicatorTooltipContent(), align: ta, padding: 10, width: 300, skin: 'tooltipTans' }; rtChart.artTooltip = dialog(opt); rtChart.artTooltip.show(rtChart.hIndicator.get(0)); rtChart.btipShow = true; rtChart.tootipAt = "HI"; rtChart = null; }, this.options.tooltipDelay || 1000); }, _onhIndicatorMove: function (event) { if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) this.artTooltip.content(this._gethIndicatorTooltipContent()); }, _onhIndicatorMoveEnd: function (event) { if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) this.artTooltip.content(this._gethIndicatorTooltipContent()); }, _gethIndicatorTooltipContent: function() { var gh = this.getGridHeight(); var iy = this.hIndicator.offset().top - this.canvas.offset().top + 5; var content = null; if (this.trendPens) { var arr = []; for (var i in this.trendPens) arr.push(this.trendPens[i].getValueLine(iy)); if (arr.length) content = arr.join(""); } return content; }, _onvIndicatorHover: function (e) { if (this.loginning === true) return; if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) return; if (this.artTooltip) this.artTooltip.close().remove(); if (this.tooltipTimer) { window.clearTimeout(this.tooltipTimer); this.tooltipTimer = null; } var rtChart = this; this.tooltipTimer = window.setTimeout( function () { if (rtChart.tooltipTimer) { window.clearTimeout(rtChart.tooltipTimer); rtChart.tooltipTimer = null; } var gw = rtChart.getGridWidth(); var o = rtChart.canvas.offset(); var x = e.pageX - o.left; var ta = (x > gw / 2) ? 'left top' : 'left top'; var currentTime = {}; var opt = { title: rtChart._getvIndicatorTooltipTitle(currentTime), content: rtChart._getvIndicatorTooltipContent(currentTime), align: ta, padding: 10, width: 320, skin: 'tooltipTans' }; rtChart.artTooltip = dialog(opt); rtChart.artTooltip.show(rtChart.vIndicator.get(0)); rtChart.btipShow = true; rtChart.tootipAt = "VI"; rtChart = null; }, this.options.tooltipDelay || 1000); }, _onvIndicatorMove: function(e) { if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) { this.artTooltip.reset(); this._updatevIndicatorTooltip(); } }, _onvIndicatorMoveEnd: function (e) { this._updatevIndicatorTooltip(); }, _updatevIndicatorTooltip: function () { if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) { if (this.vTooltipTimer == null) { var rtChart = this; this.vTooltipTimer = window.setTimeout(function () { window.clearTimeout(rtChart.vTooltipTimer); rtChart.vTooltipTimer = null; var currTime = {}; rtChart.artTooltip.title(rtChart._getvIndicatorTooltipTitle(currTime)); rtChart.artTooltip.content(rtChart._getvIndicatorTooltipContent(currTime)); rtChart = null; }, 100); } } if (this.trendPens) { for (var i in this.trendPens) this.trendPens[i].updateDataReader(); } }, _getvIndicatorTooltipTitle: function (currTime) { var gw = this.getGridWidth(); var ix = this.vIndicator.position().left + 5; var begTime = this.getDrawBegTime(); var endTime = this.getDrawEndTime(); var span = endTime - begTime; var timeScale = span / gw; var ft = begTime + ix * timeScale; var title = ""; var date = this.FileTimeToDate(ft); if (span > 28 * PERDAY) title += date.getFullYear() + "年"; if (span > PERDAY) title += (date.getMonth() + 1) + "月"; if (span > PERHOUR) title += date.getDate() + "日"; title += this.FileTimeToTimeString(ft, true); title += " 附近的值"; currTime.ft = ft; return title; }, _getvIndicatorTooltipContent: function (currentTime) { var ft = currentTime.ft; if (this.trendPens) { var content = []; for (var i in this.trendPens) content.push(this.trendPens[i].getValueTooltipAtTime(ft)); if (content.length) return content.join(""); else return null; } else return null; }, posvIndicator:function(ft) { if (ft >= this.getBegTime() && ft <= this.getEndTime()) { if (this.options.rtRefresh) this.setRtrefresh(false); if (ft <= this.getDrawBegTime() || ft >= this.getDrawEndTime()) { this._resetTumbs(); this.updateDataArea(); } var begTime = this.getDrawBegTime(); var endTime = this.getDrawEndTime(); var gw = this.getGridWidth(); var span = endTime - begTime; var timeScale = span / gw; var posX = Math.floor((ft - this.getDrawBegTime()) / timeScale) - 6; while(1){ this.vIndicator.css("left", posX - 5); var ix = this.vIndicator.position().left + 5; if (begTime + ix * timeScale >= ft) break; posX++; } } }, getReaderTimer:function() { var gw = this.getGridWidth(); var ix = this.vIndicator.position().left + 5; var begTime = this.getDrawBegTime(); var endTime = this.getDrawEndTime(); var span = endTime - begTime; var timeScale = span / gw; var ft = begTime + ix * timeScale; return ft; }, getHisRefreshing: function () { return this.options.rtRefresh; }, panCanShow: function () { if (!this.options.panWidth || this.options.panWidth < MINPANWIDTH) this.options.panWidth = MINPANWIDTH; if (this.chartWidth < 100 + this.options.panWidth) return false; else return true; }, thumbsCanshow: function() { if (this.options.showThumbs && this.chartHeight > SHOWTHUMBSHLIMT) return true; else return false; }, thumbsShow: function() { if (this.options.showThumbs && this.chartHeight > SHOWTHUMBSHLIMT) { var beg = this.thumbBegDiv.position().left + 3; var end = this.thumbEndDiv.position().left + 3; if (beg > 0 || end < this.chartWidth) return true; else return false; } else return false; }, _tumbsCanDrag: function (x) { var beg = this.thumbBegDiv.position().left + 3; var end = this.thumbEndDiv.position().left + 3; if ((x > beg && x < end) && (beg > 0 || end < this.chartWidth)) return true; else return false; }, listCanshow: function () { if (this.options.showList && (this.chartHeight - this.options.listHeight) > 200) return true; else return false; }, toolBarCanShow: function () { if (this.chartHeight > SHOWTOOLBARHLIMIT) return true; else return false; }, slidCanShow: function () { if (this.chartHeight > SLIDHLIMIT) return true; else return false; }, setListHeight: function(h) { if (this.options.listHeight == h) { if (this.hSplite) { var canvas = this.hSplite.get(0); var ctx = canvas.getContext("2d"); if (this.options.buttonImage && this.options.buttonImage.get(0).complete === true) { var img = this.options.buttonImage.get(0); if (this.options.listExpand) ctx.drawImage(img, 10, 11, 35, 5, canvas.width / 2 - 18, 0, 35, 5); else ctx.drawImage(img, 10, 15, 35, 5, canvas.width / 2 - 18, 0, 35, 5); } } return; } this.options.listHeight = h; if (this.options.listHeight < 30) this.options.listExpand = false; else this.options.listExpand = true; if (this.artTooltip) this.artTooltip.close().reset().remove(); this._bulidCanvas(); }, setListExpand: function(bExpand) { if (this.options.listExpand == bExpand) return; if (bExpand) { if (!this.listCanshow()) return; } this.options.listExpand = bExpand; if (this.artTooltip) this.artTooltip.close().reset().remove(); this._bulidCanvas(); }, getPanShow: function () { return this.options.panShow; }, setPanShow: function (bShow) { if (this.options.panShow == bShow) return; if (bShow) { if (!this.panCanShow()) return; } this.options.panShow = bShow; this._reDrawAll(); }, setPanWidth: function (w) { if (this.options.panWidth == w) return; this.options.panWidth = w; if (this.chartWidth < 100 + this.options.panWidth || this.options.panWidth < MINPANWIDTH) this.options.panShow = false; this._reDrawAll(); }, getPanWidth: function () { return this.options.panWidth - PANMAG; }, getOffset: function () { return this.canvas.offset(); }, getGridWidth: function () { return this.chartWidth - (this.options.panShow ? this.options.panWidth : 0) - 1; }, getGridHeight: function () { var h = this.chartHeight; if (this.toolBarCanShow()) h -= TOOLBARHEIGHT; if (this.listCanshow()) { if (this.options.listExpand) h -= this.options.listHeight; else h -= HSPLITHEIGHT; } if(this.slidCanShow()) h -= SLIDEHEIGHT; if (this.thumbsCanshow()) h -= SHOWTHUMBSHEIGHT; h--; return h; }, getNextPenColor: function () { var i = 0; if (this.trendPens) { if (this.trendPens.length < penColors.length) { i = this.trendPens.length; return penColors[i]; } else { i = this.trendPens.length % penColors.length; var c = TrendColor.parse(penColors[i]); var sign = (this.trendPens.length % 2 == 1 ? -1 : 1); var factor = 1 + sign * Math.ceil(this.trendPens.length / 2) * 0.2; c.scale(factor, factor, factor); return c.toString(); } } else return penColors[i]; }, getButtonImage: function () { if (this.options.buttonImage) return this.options.buttonImage.get(0); else return null; }, _updateTimeDisplay: function() { if (!this.toolBar || this.calendarShowed === true || this.timerFocus === true) return; this.toolBar.setValue("date_from", this.FileTimeToDateString(this.getBegTime()) + " " + this.FileTimeToTimeString(this.getBegTime(), this.options.spanSec < 10)); this.toolBar.setValue("date_to", this.FileTimeToDateString(this.getEndTime()) + " " + this.FileTimeToTimeString(this.getEndTime(), this.options.spanSec < 10)); }, getTimeSpanString: function() { var spanStr = "时间跨度:"; var span = this.options.spanSec * PERSEC; if (this.options.spanSec > PERDAY) { var d = Math.floor(span / PERDAY); span -= d * PERDAY; spanStr += d + "天"; } if (this.options.spanSec * PERSEC > PERHOUR) { var h = Math.floor(span / PERHOUR); span -= h * PERHOUR; spanStr += h + "时"; } if (this.options.spanSec * PERSEC > PERMINUTE) { var m = Math.floor(span / PERMINUTE); span -= m * PERMINUTE; spanStr += m + "分"; } var s = Math.floor(span / PERSEC); span -= s * PERSEC; spanStr += s + "秒"; if (this.options.spanSec <= 10) { var ms = (span / PERMSEC).toFixed(2); spanStr += ms + "毫秒"; } return spanStr; }, setBegTimeAndSpan: function (begTime, span) { span = span || 1; if (this.options.spanSec == span && this.ftBeginTime == begTime) return; this.ftTimeLabelBeg = null; this.options.spanSec = span; if (this.ftBeginTime == begTime) this.ftBeginTime = 0; this.updateBeginTime(begTime); if(this.toolBar) this.toolBar.setItemText("timeSpan", this.getTimeSpanString()); this._updateTimeDisplay(); }, setTimeSpan: function (span, fixEnd) { span = span || 1; if (this.options.spanSec == span) return; var newBeginTime; if (fixEnd) newBeginTime = this.getEndTime() - span * PERSEC; else newBeginTime = this.getBegTime(); this.ftTimeLabelBeg = null; this.options.spanSec = span; if (this.ftBeginTime == newBeginTime) this.ftBeginTime = 0; this.updateBeginTime(newBeginTime); if (this.toolBar) this.toolBar.setItemText("timeSpan", this.getTimeSpanString()); this._updateTimeDisplay(); }, updateBeginTime: function(ft) { this.setBeginTime(ft); if (this.dataLoadTimer) { window.clearTimeout(this.dataLoadTimer); this.dataLoadTimer = null; } var rtchart = this; this.dataLoadTimer = window.setTimeout(function () { window.clearTimeout(rtchart.dataLoadTimer); rtchart.dataLoadTimer = null; if (rtchart.trendPens) { for (i in rtchart.trendPens) { var pen = rtchart.trendPens[i]; pen.refreshHisData(true); } } rtchart = null; }, 500); this.updateDataArea(); this._updatevIndicatorTooltip(); }, setBeginTime: function (ft) { if (this.ftBeginTime == ft) return; var old = this.ftBeginTime; this.ftBeginTime = ft; if (this.getHisRefreshing()) { if (ft < old) { this.autoRefresh = true; this.setRtrefresh(false); } } this._updateTimeDisplay(); }, setBegTime: function(begTime, fixEnd) { var ft = this.DateToFileTime(begTime); if (fixEnd ) { if(this.getEndTime() > ft) { var span = this.getEndTime() - ft; span /= PERSEC; this.setBegTimeAndSpan(ft, span); } else { var d = dialog({ content: '设置的起始时间不能大于截至时间' }); d.show(); setTimeout(function () { d.close().remove(); d = null; }, 2000); } } else { this.ftTimeLabelBeg = null; if (this.ftBeginTime == ft) this.ftBeginTime = 0; this.updateBeginTime(ft); } }, setEndTime: function(endTime, fixBeg) { var ft = this.DateToFileTime(endTime); if(fixBeg) { if(ft > this.getBegTime()) { var span = ft - this.getBegTime(); span /= PERSEC; ft -= this.options.spanSec * PERSEC; this.setBegTimeAndSpan(ft, span); } else { var d = dialog({ content: '设置的截至时间不能大于起始时间' }); d.show(); setTimeout(function () { d.close().remove(); d = null; }, 2000); } } else { ft -= this.options.spanSec * PERSEC; this.ftTimeLabelBeg = null; if (this.ftBeginTime == ft) this.ftBeginTime = 0; this.updateBeginTime(ft); } }, getBegTime: function () { return this.ftBeginTime; }, getEndTime: function () { return this.ftBeginTime + (this.options.spanSec * PERSEC); }, getTimeSlot: function () { var slotTime = this.options.spanSec * PERSEC; slotTime /= this.getGridWidth(); return slotTime; }, getTimeSpan: function () { return this.options.spanSec * PERSEC; }, getDrawBegTime: function() { var begTime = this.getBegTime(); if (this.thumbsShow()) { var beg = this.thumbBegDiv.position().left + 3; if (beg > 0) { var w = this.chartWidth - 1; begTime += beg * this.options.spanSec * PERSEC / w; } } return begTime; }, getDrawEndTime: function() { var endTime = this.getEndTime(); if (this.thumbsShow()) { var end = this.thumbEndDiv.position().left + 3; var w = this.chartWidth - 1; if (end < w) { endTime -= (w - end) * this.options.spanSec * PERSEC / w; } } return endTime; }, _setNewLastTime: function (lastft) { if (lastft <= this.getEndTime()) return; var newTimeBegin = lastft - (this.options.spanSec * PERSEC); if (!this.newTimeBegin || this.newTimeBegin < newTimeBegin) this.newTimeBegin = newTimeBegin; }, _onNewHisData: function () { if (!this.prepareTimer) { var me = this; this.prepareTimer = window.setTimeout(function () { window.clearTimeout(me.prepareTimer); me.prepareTimer = null; me._prepareHisData(); me = null; }, 10); } }, _prepareHisData: function () { if (!this.trendPens || !this.trendPens.length) return; var begTime, endTime; var baseChanged = false; var newTimeBeg = this.newTimeBegin; if (newTimeBeg > this.getBegTime()) { baseChanged = true; begTime = this.newTimeBegin; endTime = begTime + (this.options.spanSec * PERSEC); this.newTimeBegin = null; } if (!baseChanged) { begTime = this.getBegTime(); endTime = this.getEndTime(); } for (k in this.trendPens) { var pen = this.trendPens[k]; pen.prepareHisData(begTime, endTime); } if (baseChanged) { this.setBeginTime(begTime); if (!this.getHisRefreshing()) this.setRtrefresh(true); this._drawTimeLabel(); } else if (!this.getHisRefreshing()) { if(newTimeBeg >= this.getBegTime() - (this.options.spanSec * PERSEC) * 20/this.getGridWidth()) this.setRtrefresh(true); } this.updateDataArea(); }, _getPanTotalHeight: function () { if (!this.trendPens || !this.trendPens.length) return 0; var t = 0; for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; t += pen.getPanHeight(); } return t; }, _findDragThing: function (e) { this.dargWho = null; var gw = this.getGridWidth(); var gh = this.getGridHeight(); var o = this.getOffset(); var dragEvent = e; if (e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) dragEvent = e.originalEvent.changedTouches[0]; var x = dragEvent.pageX - o.left; var y = dragEvent.pageY - o.top; if (this.options.panShow && !this.options.showAxis && x > gw + PANMAG && y < gh)//@pan { var t = PANHEAD; x -= (gw + PANMAG); if (y < t) { } else if (this.trendPens) { y -= t; y += this.yScroll; t = 0; var dargPen = null; for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; if (y >= t && y <= t + pen.getPanHeight() && pen == this.activePen) { dargPen = pen; break; } else t += pen.getPanHeight(); } if (dargPen) { this.dargWho = "penPan"; this.origVal = this.getPenIndex(dargPen); } else if (t > gh - PANHEAD) { this.dargWho = "pan"; this.origVal = this.yScroll; } } } else if (x > 0 ) { var activeDrag = false; if (y >= 0 && y <= gh) { if (this.trendPens) { var ft = this._getXTime(x); for (var i in this.trendPens) { var pen = this.trendPens[i]; if (pen == this.activePen && pen.hasDataAtTime(ft, y)) { activeDrag = true; break; } } } if (this.zooming === true) { this.dargWho = "dataArea"; this.origVal = this.getBegTime(); } else if (activeDrag) { this.origSecVal = dragEvent.pageY; this.dargWho = "activePen"; this.origVal = this.getBegTime(); } else { this.dargWho = "dataArea"; this.origVal = this.getBegTime(); } } else if (y > gh && y < gh + TIMELABELHEIGHT) { this.dargWho = "timeLabel"; this.origVal = this.getBegTime(); } else if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow(x)) { if (this._tumbsCanDrag(x)) { this.dargWho = "tumbsDrag"; } } } }, _getPanPenAtMouse: function (e) { if (this.options.panShow) { if (this.trendPens) { var gw = this.getGridWidth(); var gh = this.getGridHeight(); var o = this.getOffset(); var dragEvent = e; if (e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) dragEvent = e.originalEvent.changedTouches[0]; var x = dragEvent.pageX - o.left; var y = dragEvent.pageY - o.top; if (this.options.panShow && x > gw + PANMAG && y < gh)//@pan { var t = PANHEAD; x -= (gw + PANMAG); if (y < t) { } else { y -= t; y += this.yScroll; t = 0; for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; if (y >= t && y <= t + pen.getPanHeight()) return pen; else t += pen.getPanHeight(); } } } } } return null; }, _getXTime: function (x) { return this.getDrawBegTime() + (this.getDrawEndTime() - this.getDrawBegTime()) * x / this.getGridWidth(); }, _onMouseWheel: function (e) { var gw = this.getGridWidth(); var gh = this.getGridHeight(); var o = this.getOffset(); var x = e.pageX - o.left; var y = e.pageY - o.top; if (this.options.panShow && x > gw + PANMAG && y < gh)//@pan { if (gh < PANHEAD + this._getPanTotalHeight()) { this.yScroll += ((e.deltaY * 10) * -1); this.UpdateDataPan(true); } } else if (x > 0 && x < gw) { if (y >= 0 && y <= gh) { if (this.trendPens) { var ft = this._getXTime(x); for (var i in this.trendPens) { var pen = this.trendPens[i]; if (pen == this.activePen) { pen.expendY(e.deltaY * -2); break; } } } } } }, _onMouseDown: function (e) { if (this._isTouch()) return; if (this.artTooltip) this.artTooltip.close().remove(); if (this.tooltipTimer) { window.clearTimeout(this.tooltipTimer); this.tooltipTimer = null; } var rtchart = this this._findDragThing(e); if (this.dargWho) { this.dragStartEvent = e; this.positionDiv.draggable("option", "disabled", false); this.positionDiv.bind("drag", function (event, ui) { rtchart._dragMove(event); }); this.positionDiv.bind("dragstop", function (event, ui) { rtchart._unDarg(); rtchart = null; }); this.positionDiv.offset({ left: e.pageX - 2, top: e.pageY - 2 }); this.positionDiv.trigger(e); if (this.dargWho == 'dataArea' && this.zooming) this.positionDiv.addClass('zoomcur'); this.dragTimer = window.setTimeout(function () { var dargWho = rtchart.dargWho; window.clearTimeout(rtchart.dragTimer); rtchart.dragTimer = null; rtchart._unDarg(); if (dargWho == "tumbsDrag") rtchart._ondbClick(e); else rtchart._onClick(e); rtchart = null; }, 200); } }, _dragMove: function (e) { if (this.dragTimer) { window.clearTimeout(this.dragTimer); this.dragTimer = null; } if (this.dragStartEvent && this.dargWho) { var gw = this.getGridWidth(); var gh = this.getGridHeight(); var startEvent = this.dragStartEvent; var detX = e.clientX - startEvent.clientX; var detY = e.clientY - startEvent.clientY; switch (this.dargWho) { case 'pan': this.yScroll = this.origVal - detY; this.UpdateDataPan(true); break; case 'penPan': var pen = this._getPanPenAtMouse(e); if (pen) { var newPos = this.getPenIndex(pen) if (newPos != this.origVal && newPos != this.newPenPos) { this.newPenPos = newPos; this.UpdateDataPan(true); } else if (this.trendPens && this.getGridHeight() < PANHEAD + this._getPanTotalHeight()) { var gh = this.getGridHeight(); var o = this.getOffset(); var y = e.pageY - o.top; if (y < 20) { if (this.yScroll > 0) { this.yScroll -= pen.getPanHeight(); this.UpdateDataPan(true); } } else if (y > gh - 10) { this.yScroll += pen.getPanHeight(); this.UpdateDataPan(true); } } } break; case 'timeLabel': this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw); this.updateDataArea(); break; case 'activePen': if (this.activePen && this.origSecVal) { var dY = e.pageY - this.origSecVal; if (Math.abs(detY) > 5) { this.activePen.moveY(dY); this.origSecVal = e.pageY; } } if (Math.abs(detX) > 30) { this.acvtimePenTimeOffset = true; this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw); this.updateDataArea(); } break; case 'dataArea': if (this.zooming) { var o = this.canvas.offset(); var x = startEvent.pageX - o.left; var y = startEvent.pageY - o.top; var gw = this.getGridWidth(); var gh = this.getGridHeight(); if (x > 0 && x < gw && y > 0 && y < gh) { this.zoomRect = { x: x, y: y, w: detX, h: detY }; var x = this.zoomRect.x; if (this.zoomRect.w < 0) x += this.zoomRect.w; this.zoomRect.begTime = this._getXTime(x); this.updateDataArea(); } } else { this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw); this.updateDataArea(); } break; case 'tumbsDrag': if (detX > 0) { var end = this.thumbEndDiv.position().left + 3; if (end < this.chartWidth - 3) { var l = parseInt(this.thumbEndDiv.css('left')) + detX; if (l > this.chartWidth - 3) l = this.chartWidth - 3; this.thumbEndDiv.css('left', l); l = parseInt(this.thumbBegDiv.css('left')) + detX; this.thumbBegDiv.css('left', l ); this._onThumbsChanged(); } } else if (detX < 0) { var beg = this.thumbBegDiv.position().left + 3; if (beg > 0) { var l = parseInt(this.thumbBegDiv.css('left')) + detX; if (l < -3) l = -3; this.thumbBegDiv.css('left', l); l = parseInt(this.thumbEndDiv.css('left')) + detX; this.thumbEndDiv.css('left', l); this._onThumbsChanged(); } } this.dragStartEvent = e; break; } } else this._unDarg(); }, _unDarg: function () { if (this.dragTimer) { window.clearTimeout(this.dragTimer); this.dragTimer = null; } switch (this.dargWho) { case 'penPan': if (this.newPenPos != null) { var pen = this.trendPens[this.newPenPos]; this.trendPens[this.newPenPos] = this.getPenByIndex(this.origVal); this.trendPens[this.origVal] = pen; this.newPenPos = null; this.UpdateDataPan(true); this._synList(); } break; case 'timeLabel': if (this.trendPens) { for (i in this.trendPens) { var pen = this.trendPens[i]; pen.refreshHisData(); } } break; case 'dataArea': if (this.zooming) { this._toggleZoom(); this.positionDiv.removeClass('zoomcur'); if (this.zoomRect) { if (this.zoomRect.w < 0) { this.zoomRect.x += this.zoomRect.w; this.zoomRect.w *= -1; } if (this.zoomRect.h < 0) { this.zoomRect.y += this.zoomRect.h; this.zoomRect.h *= -1; } if (this.zoomStack == null) this.zoomStack = []; var zoomItem = {}; zoomItem.begTime = this.getBegTime(); zoomItem.spanTime = this.options.spanSec; this.zoomStack.push(zoomItem); this._updateReZoom(); var begTime = this.zoomRect.begTime; var span = (this.getDrawEndTime() - this.getDrawBegTime()) * this.zoomRect.w / this.getGridWidth(); if (span < 1) span = 1; var endTime = begTime + span ; if (this.trendPens) { for (i in this.trendPens) { var pen = this.trendPens[i]; if (pen.hasDataBetweenTime(begTime, endTime)) { if (zoomItem.pens == null) zoomItem.pens = []; zoomItem.pens.pushpen } } } this.zoomRect = null; this._resetTumbs(); this.setBegTimeAndSpan(begTime, span/PERSEC); } } else if (this.trendPens) { for (i in this.trendPens) { var pen = this.trendPens[i]; pen.refreshHisData(); } } break; case 'activePen': if (this.acvtimePenTimeOffset && this.trendPens) { for (i in this.trendPens) { var pen = this.trendPens[i]; pen.refreshHisData(); } } break; } this.origSecVal = null; this.dargWho = null; this.origVal = null; this.dragStartEvent = null; this.positionDiv.draggable("option", "disabled", true); this.positionDiv.unbind("drag"); this.positionDiv.unbind("dragstop"); this.positionDiv.offset({ left: this.canvas.offset().left, top: this.canvas.offset().top }); }, _onTouchStart: function (e) { if (this.artTooltip) this.artTooltip.close().remove(); if (this.tooltipTimer) { window.clearTimeout(this.tooltipTimer); this.tooltipTimer = null; } this._findDragThing(e); if (this.dargWho) { this.dragStartEvent = e; var rtchart = this; this.canvas.bind('touchmove', function (e) { rtchart._onTouchMove(e); }); this.canvas.bind('touchend', function (e) { rtchart._onTouchEnd(e); rtchart = null; }); this.dragTimer = window.setTimeout(function () { window.clearTimeout(rtchart.dragTimer); rtchart.dragTimer = null; if (rtchart.tooltipTimer) { window.clearTimeout(rtchart.tooltipTimer); rtchart.tooltipTimer = null; } rtchart._onTouchEnd(); rtchart = null; }, 800); } }, _onTouchMove: function (e) { if (this.dragTimer) { window.clearTimeout(this.dragTimer); this.dragTimer = null; } if (this.dragStartEvent && this.dargWho) { var startEvent = this.dragStartEvent.originalEvent.changedTouches[0]; var currEvent = e.originalEvent.changedTouches[0]; var detX = currEvent.clientX - startEvent.clientX; var detY = currEvent.clientY - startEvent.clientY; switch (this.dargWho) { case 'pan': this.yScroll = this.origVal - detY; this.UpdateDataPan(true); break; case 'penPan': var pen = this._getPanPenAtMouse(e); if (pen) { var newPos = this.getPenIndex(pen) if (newPos != this.origVal && newPos != this.newPenPos) { this.newPenPos = newPos; this.UpdateDataPan(true); } else if (this.trendPens && this.getGridHeight() < PANHEAD + this._getPanTotalHeight()) { var gh = this.getGridHeight(); var o = this.getOffset(); var y = currEvent.pageY - o.top; if (y < 20) { if (this.yScroll > 0) { this.yScroll -= pen.getPanHeight(); this.UpdateDataPan(true); } } else if (y > gh - 10) { this.yScroll += pen.getPanHeight(); this.UpdateDataPan(true); } } } break; default: this._onTouchEnd(); return; } } else this._onTouchEnd(); }, _onTouchEnd: function (e) { if (this.dragTimer) { window.clearTimeout(this.dragTimer); this.dragTimer = null; } if (this.newPenPos != null) { var pen = this.trendPens[this.newPenPos]; this.trendPens[this.newPenPos] = this.getPenByIndex(this.origVal); this.trendPens[this.origVal] = pen; this.newPenPos = null; this.UpdateDataPan(true); } this.canvas.unbind('touchmove'); this.canvas.unbind('touchend'); this.dargWho = null; this.origVal = null; this.dragStartEvent = null; }, _onKeyDown: function (e){ switch(e.which) { case 39://right if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) { if (this.thumbsShow()) { var x = this.vIndicator.position().left + 5; var endTime = this._getXTime(x + 2); var limit = this.getDrawEndTime(); if (endTime >= limit) { var l = parseInt(this.thumbEndDiv.css('left')); var s = l + 10; if (s > this.chartWidth - 3) s = this.chartWidth - 3; if (s > l) { this.thumbEndDiv.css('left', s); s = parseInt(this.thumbBegDiv.css('left')) + s - l; if (s > this.chartWidth - 13) s = this.chartWidth - 13; this.thumbBegDiv.css('left', s); this._onThumbsChanged(); } } } var gw = this.getGridWidth(); var off = this.vIndicator.offset(); if (off.left + 1 <= this.canvas.offset().left + gw - 5) { this.vIndicator.offset({ left: off.left + 1, top: off.top }); this.artTooltip.reset(); this._updatevIndicatorTooltip(); } } else { var gw = this.getGridWidth(); var begTime = this.getDrawBegTime(); var endTime = this.getDrawEndTime(); var det = (endTime - begTime) / gw; this.updateBeginTime(this.getBegTime() - det); } break; case 37://left if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) { if (this.thumbsShow()) { var x = this.vIndicator.position().left + 5; var begTime = this._getXTime(x - 2); var limit = this.getDrawBegTime(); if (begTime <= limit) { var l = parseInt(this.thumbBegDiv.css('left')); var s = l - 10; if (s < -3) s = -3; if (s < l) { this.thumbBegDiv.css('left', s); s = parseInt(this.thumbEndDiv.css('left')) - (l - s); if (s < 13) s = 13; this.thumbEndDiv.css('left', s); this._onThumbsChanged(); } } } var gw = this.getGridWidth(); var off = this.vIndicator.offset(); if (off.left - 1 >= this.canvas.offset().left - 5) { this.vIndicator.offset({ left: off.left - 1, top: off.top }); this.artTooltip.reset(); this._updatevIndicatorTooltip(); } } else { var gw = this.getGridWidth(); var begTime = this.getDrawBegTime(); var endTime = this.getDrawEndTime(); var det = (endTime - begTime) / gw; this.updateBeginTime(this.getBegTime() + det); } break; case 38://up if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) { var gh = this.getGridHeight(); var off = this.hIndicator.offset(); if (off.top - 1 >= this.canvas.offset().top - 5) { this.hIndicator.offset({ left: off.left, top: off.top - 1}); this.artTooltip.content(this._gethIndicatorTooltipContent()); this.artTooltip.reset(); } } else if (this.activePen) this.activePen.moveY(-1); break; case 40://down if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) { var gh = this.getGridHeight(); var off = this.hIndicator.offset(); if (off.top + 1 <= this.canvas.offset().top + gh - 5) { this.hIndicator.offset({ left: off.left, top: off.top + 1 }); this.artTooltip.content(this._gethIndicatorTooltipContent()); this.artTooltip.reset(); } } else if (this.activePen) this.activePen.moveY(1); break; } }, _ondbClick: function (e) { var gw = this.getGridWidth(); var gh = this.getGridHeight(); var o = this.getOffset(); var x = e.pageX - o.left; var y = e.pageY - o.top; if(y > gh + TIMELABELHEIGHT && this.thumbsCanshow()) { this._resetTumbs(); this.updateDataArea(); } }, _onClick: function (e) { this.canvas.attr("title", null); this.canvas.css("cursor", "default"); if (this.btipShow === true && this.tipShowPen && this.tipShowPen.getpreventTooltipUpdate() === true) { if (this.artTooltip) this.artTooltip.close().remove(); return; } if (!this.trendPens || !this.trendPens.length) return; if (this.zooming) this._toggleZoom(e); var gw = this.getGridWidth(); var gh = this.getGridHeight(); var o = this.getOffset(); var x = e.pageX - o.left; var y = e.pageY - o.top; var clientx = x; var clienty = y if (this.options.panShow && x > gw + PANMAG && y < gh)//@pan { if (!this.options.showAxis) { var t = PANHEAD; x -= (gw + PANMAG); if (y < t) { } else { y -= t; y += this.yScroll; t = 0; for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; if (y >= t && y <= t + pen.getPanHeight()) { if (pen.onClick(x, y - t, e) === true) { } break; } else t += pen.getPanHeight(); } } } else { for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; var beg = pen.axisBeg; var end = pen.axisEnd; if (clientx >= beg && clientx <= end) { if (this.btipShow) { if (this.artTooltip) this.artTooltip.close().remove(); } pen.onSetCommAxis(e); break; } } } } else if (y >= 0 && y < gh) { if (this.trendPens) { var ft = this._getXTime(x); var oldActive = this.activePen; var bFind = false; var first = null; for (var i in this.trendPens) { pen = this.trendPens[i]; if (pen == oldActive) { bFind = true; this.requestActive(null); } else if (pen.hasDataAtTime(ft, y)) { if (bFind || oldActive == null) { pen.activePen(); return; } else if (first == null) first = pen; } } if(first) first.activePen(); } } else if (y > gh && y < gh + TIMELABELHEIGHT) { if (x < 70) this._onSetBegTime(e); else if (x > gw - 80 && x < gw) this._onSetEndTime(e); } }, _onMouseMove: function (e) { if (this.colorPicker && this.colorPicker.is(":visible")) return; if (this.btipShow === true && this.tipShowPen && this.tipShowPen.getpreventTooltipUpdate() === true) return; if (!this.trendPens || !this.trendPens.length) return; if (this.tooltipTimer) { window.clearTimeout(this.tooltipTimer); this.tooltipTimer = null; } var oldShow = this.btipShow; var bClearCursor = true; var bClearNativeTooltip = true; this.btipShow = false; var gw = this.getGridWidth(); var gh = this.getGridHeight(); var o = this.getOffset(); var x = e.pageX - o.left; var y = e.pageY - o.top; var clientx = x; var clienty = y if (clientx > 0 && clientx < this.chartWidth && clienty > 0 && clienty < this.chartHeight) { if (this.options.panShow && x > gw + PANMAG && y < gh)//@pan { if (this.zooming) this.canvas.removeClass('zoomcur'); if (!this.options.showAxis) { var t = PANHEAD; x -= (gw + PANMAG); if (y < t) { } else { y -= t; y += this.yScroll; t = 0; for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; if (y >= t && y <= t + pen.getPanHeight()) { if (pen.onMouseMove(x, y - t, e, clientx, clienty, gh) === true) bClearCursor = false; break; } else t += pen.getPanHeight(); } } } else { for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; var beg = pen.axisBeg; var end = pen.axisEnd; if (clientx >= beg && clientx <= end) { bClearCursor = false; bClearNativeTooltip = false; this.canvas.css("cursor", "pointer"); this.canvas.attr("title", "点击进行 " + pen.getLabel() +" 的共轴设置"); break; } } } } else if (y >= 0 && y < gh) { if (this.zooming) this.canvas.addClass('zoomcur'); } else if (y > gh && y < gh + TIMELABELHEIGHT) { if (this.zooming) this.canvas.removeClass('zoomcur'); if (x < 70) { bClearCursor = false; bClearNativeTooltip = false; this.canvas.css("cursor", "pointer"); this.canvas.attr("title", "点击设置查询起始时间"); } else if (x > gw - 80 && x < gw) { bClearCursor = false; bClearNativeTooltip = false; this.canvas.css("cursor", "pointer"); this.canvas.attr("title", "点击设置查询截至时间"); } } else if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow()) { if (this._tumbsCanDrag(x) ) { bClearCursor = false; this.canvas.css("cursor", "e-resize"); } } } if (bClearNativeTooltip) this.canvas.attr("title", null); if (bClearCursor && !this.zooming) this.canvas.css("cursor", "default"); if (oldShow && !this.btipShow) { if (this.artTooltip) this.artTooltip.close().remove(); } if (!this.btipShow && this.tipShowPen) { this.tipShowPen.onTooltipHided(); this.tipShowPen = null; } }, _linkData: function (pen) { if (!this.webLinks) this.webLinks = []; var url = pen.getWebURL().toLowerCase(); var webLink = this.webLinks[url]; if (webLink == null) { webLink = new WebLink(url); this.webLinks[url] = webLink; } webLink.addPen(pen); }, _buildColorPicker: function () { if (this.colorPicker) return; this.colorPicker = $(document.createElement('div')); this.colorPicker.css("position", "absolute") .addClass("dropdown-menu") .addClass("colorpicker-title"); this.element.append(this.colorPicker); this.colorPicker.append(document.createElement('div')); $('div:first', this.colorPicker) .attr("data-color", "rgb(255, 255, 255)") .addClass("colorpicker-ind") .colorpicker( { align: 'left' }); this.colorPicker.draggable({ drag: function (event, ui) { $('.colorpicker-ind', this).colorpicker('reposition'); } }); var label = $(document.createElement('span')); this.colorPicker.append(label); label.addClass("colorpicker-label"); var prev = $(document.createElement('div')); prev.html('
') this.colorPicker.append(prev); prev .addClass("colorpicker-prev") .attr('title', '点击恢复到上次设置'); var resume = $(document.createElement('div')); resume.html('
') this.colorPicker.append(resume); resume .addClass("colorpicker-resume") .attr('title', '点击恢复初始设置'); }, AddPen: function (options) { if (!this.trendPens) this.trendPens = []; var pen = new TrendPen(this, options); this.trendPens.push(pen); this._bindPenList(pen); this._linkData(pen); this._drawPan(false); }, removePen: function (pen) { if (this.tipShowPen == pen) { if (this.artTooltip) this.artTooltip.close().remove(); } if (this.activePen) { this.activePen.setActive(false); this.activePen = null; if (this.toolBar) this.toolBar.disableItem("deletePoint"); } var bFind = false; if (this.trendPens) { var len = this.trendPens.length; for (var i = 0; i < len; i++) { if (this.trendPens[i] == pen) { bFind = true; this.trendPens.splice(i, 1); break; } } } if (pen.rowId != null && this.listGrid) { this.listGrid.deleteRow(pen.rowId); } pen.destroy(); if (bFind) { this.UpdatePan(true); this.updateDataArea(); } }, getPenIndex: function (pen) { if (this.trendPens) { for (var i = 0; i < this.trendPens.length; i++) { if (this.trendPens[i] == pen) return i; } } return -1; }, getPenByIndex: function (i) { if (!this.trendPens) return null; else return this.trendPens[i]; }, requestLogin: function (from, notCloseAutoLogClose) { if (this.artTooltip) this.artTooltip.close().remove(); if (this.loginning === true) return; this.loginning = true; var rtChart = this; }, getActivePen: function () { return this.activePen; }, ensurePenPanVisble: function (pen) { if (this.options.panShow && !this.options.showAxis) { var t = 0; var gh = this.getGridHeight(); for (var i = 0; i < this.trendPens.length; i++) { var findPen = this.trendPens[i]; if (findPen == pen) { if (t < this.yScroll) { this.yScroll = t; this.UpdateDataPan(true); } else if (t - this.yScroll + pen.getPanHeight() + PANHEAD > gh) { this.yScroll = t + pen.getPanHeight() + PANHEAD - gh; this.UpdateDataPan(true); } break; } else t += pen.getPanHeight(); } } }, requestActive: function (pen) { if (this.activePen == pen) return; if (this.activePen) this.activePen.setActive(false); this.activePen = pen; if (this.activePen) { this.activePen.setActive(true); this.ensurePenPanVisble(this.activePen); if (this.activePen.rowId && this.listGrid && this.activePen.rowId != this.listGrid.getSelectedRowId()) this.listGrid.selectRow(this.listGrid.getRowIndex(this.activePen.rowId), false, false, true); if (this.toolBar) this.toolBar.enableItem("deletePoint"); } else { if (this.toolBar) this.toolBar.disableItem("deletePoint"); if (this.listGrid && this.listGrid.getSelectedRowId() != null) this.listGrid.clearSelection(); } this._drawDataArea(); }, setPenColor: function (pen, e) { if (this.btipShow) { if (this.artTooltip) this.artTooltip.close().remove(); } if (!this.colorPicker) this._buildColorPicker(); var colorpicker = this.colorPicker; if (colorpicker.prevColor != null) { $('.colorpicker-prev', colorpicker).show(); $('.colorpicker-prevbk', colorpicker).css('background-color', colorpicker.prevColor); $('.colorpicker-prev', colorpicker).bind("click", function () { if (colorpicker) { $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.prevColor); } }); } else $('.colorpicker-prev', colorpicker).hide(); colorpicker.resumeColor = pen.getPenColor(); $('.colorpicker-resume', colorpicker).bind("click", function () { if (colorpicker) { $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.resumeColor); } }); var o = this.getOffset(); var x = e.pageX - o.left; var y = e.pageY - o.top; var at; if (x < this.chartWidth / 2) at = "left+15"; else at = "right-10"; if (y < this.chartHeight / 2) at += " top+15"; else at += " bottom-140"; $('.colorpicker-label', colorpicker).text("设置趋势笔颜色:" + pen.getLabel()); colorpicker.show() .position({ my: at, of: e, collision: "fit" }); $('.colorpicker-resumebk', colorpicker).css('background-color', pen.getPenColor()); $('.colorpicker-ind', colorpicker) .colorpicker('setValue', pen.getPenColor()) .colorpicker('show') .off() .on('changeColor.colorpicker', function (event) { if (pen) pen.setPenColor(event.color.toString()); }) .on('hidePicker.colorpicker', function (event) { if (colorpicker) { colorpicker.prevColor = $(this).data('colorpicker').color.toString(); colorpicker.hide(); $('.colorpicker-ind', colorpicker).off(); $('.colorpicker-resume', colorpicker).unbind(); $('.colorpicker-prev', colorpicker).unbind(); colorpicker = null; } if (pen) pen = null; }); }, setColors: function (who, clr) { switch (who) { case 'bkColor': this.options.bkColor = clr; this.canvas.css('background-color', clr); break; case 'gridColor': if (this.options.gridColor != clr) { this.options.gridColor = clr; this.updateDataArea(); this.UpdateAxisPan(true); } break; case 'indColor': if (this.options.indicatorColor != clr) { var img = this.options.buttonImage; if (img) { img = img.get(0); if (img.complete !== true) img = null; } var gw = this.getGridWidth(); var gh = this.getGridHeight(); var hw; if (this.options.showAxis) hw = this.chartWidth; else hw = gw + 12; this.options.indicatorColor = clr; var node = this.hIndicator.get(0); var hctx = node.getContext('2d'); hctx.clearRect(0, 0, node.width, node.height); hctx.save(); hctx.translate(0.5, 0.5); hctx.lineWidth = 3.0; hctx.strokeStyle = this.options.indicatorColor; hctx.beginPath(); hctx.moveTo(1, 5); hctx.lineTo(hw, 5); hctx.stroke(); hctx.restore(); if (img) hctx.drawImage(img, 11, 0, 11, 11, gw - 3, 0, 11, 11); node = this.vIndicator.get(0); var vctx = node.getContext('2d'); vctx.clearRect(0, 0, node.width, node.height); vctx.save(); vctx.translate(0.5, 0.5); vctx.lineWidth = 3.0; vctx.strokeStyle = this.options.indicatorColor; vctx.beginPath(); vctx.moveTo(5, 1); vctx.lineTo(5, gh + 10); vctx.stroke(); vctx.restore(); if (img) vctx.drawImage(img, 0, 0, 11, 11, 0, gh - 3, 11, 11); } break; case 'bordrColor': if (this.options.borderColor != clr) { this.options.borderColor = clr; this._reDrawAll(); } break; case 'timeLabelColor': if (this.options.timeLabelColor != clr) { this.options.timeLabelColor = clr; this._drawTimeLabel(); } break; } }, parseDate: function (datestr) { var date = null; var indate = datestr.split(" "); if (indate.length > 0) { var d = indate[0].split("-"); if (d.length == 3) { do { var y = parseInt(d[0]); if (isNaN(y) || y < 0) break; if (d[0].length <= 2) y += 2000; var m = parseInt(d[1]); if (isNaN(m)) break; if (m < 1 || m > 12) break; m--; var day = parseInt(d[2]); if (isNaN(day)) break; if (day < 1 || day > 31) break; date = new Date(y, m, day, 0, 0, 0, 0); if (indate.length < 2) break; d = indate[1].split(":"); if (d.length == 3) { var h = parseInt(d[0]); if (isNaN(h) || h < 0 || h > 23) break; date.setHours(h); var m = parseInt(d[1]); if (isNaN(m) || m < 0 || h > 59) break; date.setMinutes(m); var s = parseInt(d[2]); if (isNaN(s) || s < 0 || s > 59) break; date.setSeconds(s); var ms = parseFloat(d[2]); if (ms != s) { ms -= s; ms *= 1000; ms = ms.toFixed(0); date.setMilliseconds(ms); } } } while (false); } } return date; }, _onSetBegTime: function (e) { if (this.btipShow) { if (this.artTooltip) this.artTooltip.close().remove(); } var rtChart = this; var d = dialog( { title: '设置查询起始时间', quickClose: true, content: '
', onshow: function () { var set = $('input[name=dateSet]', this.__popup) .val(rtChart.FileTimeToDateString(rtChart.getBegTime()) + " " + rtChart.FileTimeToTimeString(rtChart.getBegTime())) .datetimepicker({ changeMonth: true, changeYear: true }); $('input[name=dateSet]', this.__popup).keydown(this, function (e) { switch (e.which) { case 13: d.ok(); break; case 27: d.close().remove(); d = null; rtChart = null; break; } }); $('#ui-datepicker-div').draggable(); }, okValue: '确定', ok: function () { var date = rtChart.parseDate($('input[name=dateSet]', this.__popup).val()); if (date != null) { var fixEnd = $('input[name=fixEnd]', this.__popup)[0].checked; rtChart.setBegTime(date, fixEnd); } d.close().remove(); d = null; }, onclose: function () { $('input[name=dateSet]', this.__popup) .datetimepicker("hide"); $('#ui-datepicker-div').draggable("destroy"); rtChart = null; } }); e.pageX += 10; e.pageY -= 30; d.show(e); }, _onSetEndTime: function (e) { if (this.btipShow) { if (this.artTooltip) this.artTooltip.close().remove(); } var rtChart = this; var d = dialog( { title: '设置查询截至时间', quickClose: true, content: '
', onshow: function () { var set = $('input[name=dateSet]', this.__popup) .val(rtChart.FileTimeToDateString(rtChart.getEndTime()) + " " + rtChart.FileTimeToTimeString(rtChart.getEndTime())) .datetimepicker({ changeMonth: true, changeYear: true }); $('input[name=dateSet]', this.__popup).keydown(this, function (e) { switch (e.which) { case 13: d.ok(); break; case 27: d.close().remove(); d = null; rtChart = null; break; } }); $('#ui-datepicker-div').draggable(); }, okValue: '确定', ok: function () { var date = rtChart.parseDate($('input[name=dateSet]', this.__popup).val()); if (date != null) { var fixBeg = $('input[name=fixBeg]', this.__popup)[0].checked; rtChart.setEndTime(date, fixBeg); } d.close().remove(); d = null; }, onclose: function () { $('input[name=dateSet]', this.__popup) .datetimepicker("hide"); $('#ui-datepicker-div').draggable("destroy"); rtChart = null; } }); e.pageX += 10; e.pageY -= 30; d.show(e); }, _loadPoints: function (dia, grid, info, start, count, tabfilter,tagfilter, totalCount) { info.css("color", "rgb(0,0,100)"); info.text("正在获取数据..."); var rtchart = this; this._loadAddPoints = true; //注意标签点中有#号问题 var str="http://" + webServiceIP + ":" + webServicePort + "/api/Point?start="+start+"&count="+count+"&filter="+tagfilter+"&tabfilter="+tabfilter; $.ajax({ url: str, type: 'GET', dataType: 'json', cache: false, success: function (data) { if(data==null) return; totalCount.Num = data.Count; var ind=start; if(data.PointsPros&&data.PointsPros.length>0){ info.css("color", "rgb(0,0,100)"); info.text("请选择一个或多个数据点:(总共:" + totalCount.Num + " 个数据点)"); info.attr("title", "(共有:" + totalCount.Num + " 个数据点)"); var pointspros=data.PointsPros; var len =data.PointsPros.length; var newind = 1; var append = false; if(grid.getRowsNum() == 0) append = true; for (var i = 0; i < len; i++) { var id, name, des, unit, type; id=pointspros[i].Id; name=pointspros[i].TagName; des=pointspros[i].Desc; unit=pointspros[i].Uint; type=pointspros[i].Type; if (append === true){ grid.addRow(i, [false, newind++, id, name, des, unit, type]); } else { var pid = 'p_' + ind; grid.cells(pid, 2).setValue(id); grid.cells(pid, 3).setValue(name); grid.cells(pid, 4).setValue(des); grid.cells(pid, 5).setValue(unit); grid.cells(pid, 6).setValue(type); grid.changeRowId(pid,id); ind++; } } } else{ info.css("color", "rgb(0,0,100)"); info.text("没有符合搜索条件的数据点"); info.attr("title", null); } } }) }, _loadTableNames: function(comBox) { if(tableNameStr.length>0){ for(var i=0;i this.canvas.width() - 60) w = this.canvas.width() - 60; if (h > this.canvas.height() - 110) h = this.canvas.height() - 110; var content = '
'; content += '
'; content += '
'; content += '
' var rowHeight = null; var tabRowCount = null; var containdiv = null; var info = null; var grid = null; var comBox = null; var totalCount = {}; var tabfilter = null; var tagfilter = null; var dia = dialog( { title: '添加新点', quickClose: true, content: content, onshow: function () { containdiv = $('div[name=gridlist]', this.__popup)[0]; var skin = "dhx_web"; grid = new dhtmlXGridObject(containdiv); grid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/"); grid.setHeader("选择,序号,Id,点名称,描述,单位,数据类型"); grid.setColumnsVisibility("false,false,true,false,false,false,false"); grid.setInitWidths("50,50,45,230,300,60,60"); grid.setColAlign("center,right,right,left,left,left,left"); grid.setColTypes("ch,ro,ro,ro,ro,ro,ro"); grid.setColSorting("na,na,na,na,na,na,na"); grid.setSkin(skin); grid.enableColumnMove(true); grid.attachEvent("onScroll", function (sLeft, sTop) { var rowCount = grid.getRowsNum(); if (rowCount == 0) { console.log("return"); return; } if (tabRowCount == null) { rowHeight = $('tr.ev_' + skin, containdiv).height(); var tabH = $('div.objbox', containdiv).height(); tabRowCount = Math.ceil(tabH/rowHeight) } if (rowHeight != null && tabRowCount) { var ind = Math.floor(sTop/rowHeight); ind += tabRowCount; if (ind + 1 >= rowCount && rowCount < totalCount.Num) { var count = totalCount.Num - rowCount; if (count > 200) count = 200; var pid = rowCount; for (var i = 0; i < count; i++) { grid.addRow("p_" + pid, [false, pid + 1]); pid++; } rtChart._loadPoints(dia, grid, info, rowCount, count, tabfilter,tagfilter, totalCount); } } }); var button = $("input[type=button]", this.__popup); button.click(function () { var idsstr = grid.getCheckedRows(0); if (idsstr != null) { var ids = idsstr.split(','); if (ids && ids.length && ids[0] != "") { for (var i = 0; i < ids.length; i++) { var rowId = parseInt(ids[i]); var cell = grid.cells(rowId, 3); if(cell) var itemDef=new GoldenRtWeb.RtItemDefine(0, 0, 0); rtChart.AddPen({ URI: cell.getValue(),itemDef:itemDef}); rtChart.requestHisData({ URI: cell.getValue(),itemDef:itemDef},100); } } } dia.close().remove(); dia = null; }) grid.attachEvent("onCheck", function (rId, cInd, state) { var idsstr = grid.getCheckedRows(0); if (idsstr == null) button.attr("disabled", "disabled"); else { var ids = idsstr.split(','); if (ids && ids.length && ids[0] != "") button.removeAttr("disabled"); else button.attr("disabled", "disabled"); } }); grid.init(); info = $("span", this.__popup); comBox = new dhtmlXCombo($("div[name=tabfileter]", this.__popup).get(0), "combo", 170); //comBox.addOption("所有(*)", "所有(*)"); /*comBox.setComboText("U2"); tabfilter = "U2";*/ if (rtChart.options.perfectGroup) { comBox.setComboText(rtChart.options.perfectGroup); if(rtChart.options.perfectGroup == "所有(*)") tabfilter = "*"; else tabfilter = rtChart.options.perfectGroup; } else { //comBox.setComboText("所有(*)"); tabfilter = "*"; } comBox.attachEvent("onChange", function () { var val = comBox.getComboText(); rtChart.options.perfectGroup = val; if (val == "所有(*)") val = "*"; if (val != tabfilter) { tabfilter = val; grid.clearAll(); button.attr("disabled", "disabled"); rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount); } }); var kTimer = null; comBox.attachEvent("onKeyPressed", function () { if (kTimer) { window.clearTimeout(kTimer); kTimer = null; } kTimer = window.setTimeout(function () { if (kTimer) { window.clearTimeout(kTimer); kTimer = null; } var val = comBox.getComboText(); if (val == "所有(*)") val = "*"; if (val != tabfilter) { tabfilter = val; grid.clearAll(); button.attr("disabled", "disabled"); rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount); } }, 1000); }); rtChart._loadTableNames(comBox); tabfilter = comBox.getComboText(); if(tabfilter.length!=0){ rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount); }; var fTimer = null; $("input[name=tagfileter]", this.__popup).keyup(function () { var input = $(this); if (fTimer) { window.clearTimeout(fTimer); fTimer = null; } fTimer = window.setTimeout(function () { if (fTimer) { window.clearTimeout(fTimer); fTimer = null; } if (input.val() != tagfilter) { tagfilter = input.val(); grid.clearAll(); button.attr("disabled", "disabled"); rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount); } }, 1000); }); }, onremove: function () { info = null; containdiv = null; if (grid) { grid.destructor(); grid = null; } if (comBox) { comBox.unload(); delete comBox; } rtChart = null; } }); dia.show($('.dhx_toolbar_btn', this.element)[0]); }, _onEditorPointGroup: function () { if (!this.pointGroups) { var d = dialog({ content: "当前没有可用的点组,可以尝试保存点组,
从而创建新的点组。", quickClose: true }); return; } var rtChart = this; var content = '
可以拖动表格以改变点组的列表顺序' var grid = null; var dia = dialog( { title: '编辑点组', quickClose: true, content: content, onshow: function () { var containdiv = $('div[name=gridlist]', this.__popup)[0]; var info = $('span[name=info]', this.__popup); grid = new dhtmlXGridObject(containdiv); grid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/"); grid.setHeader("删除,名称,缺省"); grid.setInitWidths("50,130,60"); grid.setColAlign("center,left,center"); grid.setColTypes("ch,ed,ch"); grid.setColSorting("na,na,na"); grid.setSkin("dhx_web"); grid.enableDragAndDrop(true); var commitButton = $("input[name=save]", this.__popup); commitButton.click(function () { var groups = []; var i = 0; var ids = grid.getAllRowIds(); if (ids) { ids = ids.split(","); if (ids && ids.length && ids[0] != "") { for (var i = 0; i < ids.length; i++) { var rid = ids[i]; var set = { Id: rid, name: grid.cells(rid, 1).getValue(), default_: grid.cells(rid, 2).isChecked(), seq: i }; groups.push(set); } } } rtChart._submitPointGroup(dia, groups, info); }); var delteButton = $("input[name=delete]", this.__popup); delteButton.click(function () { var idsstr = grid.getCheckedRows(0); var ids = idsstr.split(','); if (ids && ids.length && ids[0] != "") { for (var i = 0; i < ids.length; i++) grid.deleteRow(ids[i]); } }); grid.attachEvent("onCheck", function (rId, cInd, state) { if (cInd == 0) { var idsstr = grid.getCheckedRows(0); if (idsstr == null) delteButton.attr("disabled", "disabled"); else { var ids = idsstr.split(','); if (ids && ids.length && ids[0] != "") delteButton.removeAttr("disabled"); else delteButton.attr("disabled", "disabled"); } } else if (cInd == 2 && state) { var ids = grid.getCheckedRows(2); ids = ids.split(','); for (var i = 0; i < ids.length; i++) { if (ids[i] != rId) grid.cells(ids[i], 2).setValue(false); } } }); grid.init(); for (var i in rtChart.pointGroups) { var pg = rtChart.pointGroups[i]; grid.addRow(pg.Id, [false, pg.name, pg.bDefault]); } }, onremove: function () { if (grid) { grid.destructor(); grid = null; } rtChart = null; } }); dia.show($('.dhx_toolbar_btn', this.element)[4]); }, _onSetColors: function (clrName) { if (!clrName) { var rtChart = this; var d = dialog( { title: '设置颜色', quickClose: true, content: '
什么颜色?
', onshow: function () { $('input[type=radio]', this.__popup).change(function () { rtChart._onSetColors($(this).val()); rtChart = null; d.close().remove(); d = null; }); } }); d.show($('.dhx_toolbar_btn', this.element)[2]); return; } else { var clrLabel; var clr; switch (clrName) { case 'bkColor': clrLabel = '背景色'; clr = this.canvas.css('background-color'); break; case 'gridColor': clrLabel = '格线色'; clr = this.options.gridColor; break; case 'indColor': clrLabel = '指示线颜色'; clr = this.options.indicatorColor; break; case 'bordrColor': clrLabel = '边框色'; clr = this.options.borderColor; break; case 'timeLabelColor': clrLabel = '时间标签颜色'; clr = this.options.timeLabelColor; break; default: return; } if (this.btipShow) { if (this.artTooltip) this.artTooltip.close().remove(); } if (!this.colorPicker) this._buildColorPicker(); var colorpicker = this.colorPicker; if (colorpicker.prevColor != null) { $('.colorpicker-prev', colorpicker).show(); $('.colorpicker-prevbk', colorpicker).css('background-color', colorpicker.prevColor); $('.colorpicker-prev', colorpicker).bind("click", function () { if (colorpicker) { $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.prevColor); } }); } else $('.colorpicker-prev', colorpicker).hide(); colorpicker.resumeColor = clr; var rtchart = this; $('.colorpicker-resume', colorpicker).bind("click", function () { if (colorpicker) { $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.resumeColor); } }); $('.colorpicker-label', colorpicker).text("设置 " + clrLabel); colorpicker.show() .position({ my: "left+10 top+20", of: $('.dhx_toolbar_btn', this.element)[0], collision: "fit" }); $('.colorpicker-resumebk', colorpicker).css('background-color', clr); $('.colorpicker-ind', colorpicker) .colorpicker('setValue', clr) .colorpicker('show') .off() .on('changeColor.colorpicker', function (event) { rtchart.setColors(clrName, event.color.toString()); }) .on('hidePicker.colorpicker', function (event) { if (colorpicker) { colorpicker.prevColor = $(this).data('colorpicker').color.toString(); colorpicker.hide(); $('.colorpicker-ind', colorpicker).off(); $('.colorpicker-resume', colorpicker).unbind(); $('.colorpicker-prev', colorpicker).unbind(); colorpicker = null; } if (rtchart) rtchart = null; }); } }, setPointGroupName: function (gName, bDefault) { if(gName != null) window.document.title = gName; this.bDeafultGroup = bDefault; this.options.pointGroupName = gName; }, loadConfig: function (groupName, config) { if (config == null) return; this.setPointGroupName(groupName, (config.bDefault != null ? config.bDefault : false)); var pensConfig = null; var bRtRefresh = false; var bShowAxis = false; if (config.spanSec != null) this.setTimeSpan(parseInt(config.spanSec), true); if (config.bkColor != null) this.options.bkColor = config.bkColor; if (config.showAxis != null) bShowAxis = config.showAxis; if (config.rtRefresh != null) bRtRefresh = config.rtRefresh; if (config.listExpand != null) this.options.listExpand = config.listExpand; if (config.perfectGroup != null) this.options.listExpand = config.perfectGroup; if (config.indicatorColor != null) this.options.indicatorColor = config.indicatorColor; if (config.timeLabelColor != null) this.options.timeLabelColor = config.timeLabelColor; if (config.panShow != null) this.options.panShow = config.panShow; if (config.listHeight != null) this.options.listHeight = parseInt(config.listHeight); if (config.showGrid != null) this.options.showGrid = config.showGrid; if (config.borderColor != null) this.options.borderColor = config.borderColor; if (config.timeLabelColor != null) this.options.timeLabelColor = config.timeLabelColor; if (config.gridColor != null) this.options.gridColor = config.gridColor; if (config.tooltipDelay != null) this.options.tooltipDelay = config.tooltipDelay; if (config.panWidth != null) this.options.panWidth = config.panWidth; if (config.showThumbs != null) this.options.showThumbs = config.showThumbs; if (config.showList != null) this.options.showList = config.showList; if (config.trendPens != null) { if (pensConfig == null) pensConfig = []; for (var i = 0 ; i < config.trendPens.length; i++) { var penOption = {}; pensConfig.push(penOption); var pen = config.trendPens[i]; if (pen.URI != null) penOption.URI = pen.URI; if (pen.linkReTryTime != null) penOption.linkReTryTime = pen.linkReTryTime; if (pen.penColor != null) penOption.penColor = pen.penColor; if (pen.Num != null) penOption.Num = pen.Num; if (pen.drawLine != null) penOption.drawLine = pen.drawLine; if (pen.stepLine != null) penOption.stepLine = pen.stepLine; if (pen.drawTag != null) penOption.drawTag = pen.drawTag; if (pen.interpolate != null) penOption.interpolate = pen.interpolate; if (pen.hisReTryTime != null) penOption.hisReTryTime = pen.hisReTryTime; if (pen.lockRange != null) penOption.lockRange = pen.lockRange; if (pen.penWidth != null) penOption.penWidth = pen.penWidth; if (pen.rageMax != null) penOption.rageMax = pen.rageMax; if (pen.rageMin != null) penOption.rageMin = pen.rageMin; } } if (this.trendPens) { var pens = []; for (var i = 0; i < this.trendPens.length ; i++) pens.push(this.trendPens[i]); for (var i = 0 ; i < pens.length; i++) this.removePen(pens[i]); } if (this.listGrid) this.listGrid.clearAll(); this.trendPens = []; if (pensConfig) { for (var i = 0; i < pensConfig.length; i++) this.trendPens.push(new TrendPen(this, pensConfig[i])); } for (var i = 0; i < this.trendPens.length; i++) { var pen = this.trendPens[i]; if (pen.options.commAxis) { for (var j = 0; j < pen.options.commAxis.length ; j++) { var uri = pen.options.commAxis[j]; for (var k = 0; k < this.trendPens.length; k++) { var commpen = this.trendPens[k]; if (commpen.getURI() == uri) { if (pen.commAxis == null) pen.commAxis = []; pen.commAxis.push(commpen); } } } } this._linkData(pen); } this._resetTumbs(); this._bulidCanvas(); this.setRtrefresh(bRtRefresh); this.setShowAxis(bShowAxis); if (this.toolBar) this.toolBar.setItemText("timeSpan", this.getTimeSpanString()); }, _onSaveConfig: function () { var rtChart = this; var d = dialog( { title: '保存设置', quickClose: true, content: '
点组名称:
', onshow: function () { $('input[name=groupName]', this.__popup).val(rtChart.options.pointGroupName == null ? "" : rtChart.options.pointGroupName); $('form', this.__popup).keydown(this, function (e) { switch (e.which) { case 13: d.ok(); break; case 27: d.close().remove(); d = null; rtChart = null; break; } }); }, okValue: '确定', ok: function () { var gName = $('input[name=groupName]', this.__popup).val(); var bDefault = $('input[type=checkbox]', this.__popup)[0].checked; if (gName == null || gName.length == 0) { var pd = dialog({ quickClose: true, content: "点组名称不能为空" }); pd.show(); window.setTimeout(function () { pd.close().remove(); }, 2000); $('input[name=groupName]', this.__popup).focus(); return false; } rtChart.setPointGroupName(gName, bDefault); rtChart.saveConfig(bDefault); d.close().remove(); d = null; rtChart = null; } }); d.show($('.dhx_toolbar_btn', this.element)[3]); }, saveConfig: function (bDefault) { if (this.options.pointGroupName == null || this.options.pointGroupName.length == 0) { var pd = dialog({ quickClose: true, content: "点组名称不能为空" }); pd.show(); window.setTimeout(function () { pd.close().remove(); }, 2000); return; } var config = {}; config.name = this.options.pointGroupName; config.spanSec = this.options.spanSec; config.bkColor = this.options.bkColor; config.showAxis = this.options.showAxis; config.rtRefresh = this.options.rtRefresh; config.listExpand = this.options.listExpand; if (this.options.perfectGroup) { config.perfectGroup = this.options.perfectGroup; } config.indicatorColor = this.options.indicatorColor; config.timeLabelColor = this.options.timeLabelColor; config.spanSec = this.options.spanSec; config.panShow = this.options.panShow; config.listHeight = this.options.listHeight; config.showGrid = this.options.showGrid; config.borderColor = this.options.borderColor; config.timeLabelColor = this.options.timeLabelColor; config.gridColor = this.options.gridColor; config.tooltipDelay = this.options.tooltipDelay; config.panWidth = this.options.panWidth; config.showThumbs = this.options.showThumbs; config.showList = this.options.showList; config.bDefault = (bDefault ? true : false); if (this.trendPens) { var len = this.trendPens.length; config.trendPens = []; for (var i = 0; i < len; i++) { var pen = this.trendPens[i]; config.trendPens.push(pen.getConfig()); } } var configs = localStorage.getItem("goldenTrendConfig"); if (configs) { try { configs = JSON.parse(configs); } catch(ex) { localStorage.removeItem("goldenTrendConfig"); configs = null; } } if(configs) { if (config.bDefault) { for(var i in configs) { var setconfig = configs[i]; setconfig.bDeafult = false; } } } else { configs = {}; } configs[this.options.pointGroupName] = config; var id = 0; for (var i in configs) { var setconfig = configs[i]; setconfig.Id = id++; } localStorage.setItem("goldenTrendConfig", JSON.stringify(configs)); var d = dialog({ content: "点组设置保存已成功!", quickClose: true }); d.show(); window.setTimeout(function () { d.close().remove(); d = null; }, 2000); this._loadPointGroupNames(); }, _loadPointGroupNames: function() { var dia = null; if (this.initDialogShow !== true) { this.initDialogShow = true; } var pointGroups = localStorage.getItem("goldenTrendConfig"); if (pointGroups) { try { pointGroups = JSON.parse(pointGroups); } catch(ex) { localStorage.removeItem("goldenTrendConfig"); pointGroups = null; } } this._onPointGroupNamesLoaded(pointGroups); }, _onPointGroupNamesLoaded: function (pointGroups) { if (!this.toolBar || !pointGroups) return; this.pointGroups = pointGroups; var opts = [ //['newPiointGroup', 'obj', '新建点组', 'window_new.png'], ['editorPointGroup', 'obj', '编辑点组...', 'tag_blue_edit.png'], ['refreshPointGroup', 'obj', '刷新点组列表', 'reload.png'], ['idsep', 'sep'] ]; this.toolBar.removeItem("pointGroup"); for (var n in this.pointGroups) { var pg = this.pointGroups[n]; if (!this.isNewPage && pg.bDefault === true && this.options.pointGroupName == null) { this.options.pointGroupName = n; this._loadPointGroup(); } var opt = [pg.Id, 'obj', n, 'tags.png']; opts.push(opt); } this.toolBar.addButtonSelect("pointGroup", 4, "点组", opts, "tag.png"); }, _onSetTimeSpan: function (e) { var rtChart = this; var d = dialog( { title: '设置时间跨度', quickClose: true, content: '
时间跨度:
时间单位:', onshow: function () { $('form', this.__popup).keydown(this, function (e) { switch (e.which) { case 13: d.ok(); break; case 27: d.close().remove(); d = null; rtChart = null; break; } }); }, okValue: '确定', ok: function () { var span = $('input[ name="timespan"]', d.__popup).val(); span = parseInt(span, 10); if (!span || isNaN(span) || span < 1) span = 1; switch ($('input:radio:checked', this.__popup).val()) { case 'm': span *= 60; break; case 'h': span *= 3600; break; } d.close().remove(); d = null; if (!rtChart.getHisRefreshing()) { d = dialog( { title: '固定哪个时间?', quickClose: true, content: '', onshow: function () { $('input[type=radio]', this.__popup).change(function () { var fixEnd = false; if ($(this).val() == 'fixEnd') fixEnd = true; d.close().remove(); d = null; rtChart.setTimeSpan(span, fixEnd); rtChart = null; }); } }); d.show(e); } else { rtChart.setTimeSpan(span); rtChart = null; } } }); e.pageX += 10; e.pageY -= 30; d.show(e); }, _toggleZoom: function () { this.zooming = this.zooming ? false : true; if (this.zooming) this.canvas.addClass('zoomcur'); else this.canvas.removeClass('zoomcur'); }, _updateReZoom: function () { if (this.zoomStack && this.zoomStack.length) this.toolBar.enableItem("zoomResume"); else this.toolBar.disableItem("zoomResume"); }, _onReZoom: function () { if (this.zoomStack && this.zoomStack.length) { var zoomItem = this.zoomStack.pop(); this._updateReZoom(); if (zoomItem.pens) { for (var i in zoomItem.pens) { var zoomPen = zoomItem.pens[i]; } } this.setBegTimeAndSpan(zoomItem.begTime, zoomItem.spanTime); } }, RegistRtPt: function (pen, rtDef, callback, opt) { var url = pen.getWebURL().toLowerCase(); var webLink = this.webLinks[url]; if (webLink) { return webLink.RegistRtPt(rtDef, pen, callback, opt); } else return null; }, UnRegistRtPt: function (pen, rtRefreshKey) { if (!this.webLinks) return; var url = pen.getWebURL().toLowerCase(); var webLink = this.webLinks[url]; if (webLink) webLink.UnRegistRtPt(pen, rtRefreshKey); }, requestHisData: function (pen, delay) { var url = GoldenRtWeb.getWebURL(); var webLink =this.webLinks[url]; if (webLink) return webLink.requestHisData(delay); else return false; }, DateToFileTime: function (date) { var epoch_diff = 116444736000000000; var rate_diff = 10000; var ut = date.getTime(); var ft = ut * rate_diff + epoch_diff; return ft; }, FileTimeToDate: function (fTime) { var epoch_diff = 116444736000000000; var rate_diff = 10000; var ut = (fTime - epoch_diff) / rate_diff; return new Date(ut); }, FileTimeToDateString: function (fTime) { if (isNaN(fTime) || fTime == 0) return ""; var date = this.FileTimeToDate(fTime); var dstr = date.getFullYear().toString(); dstr += "-"; if (date.getMonth() + 1 < 10) dstr += "0" + (date.getMonth() + 1).toString(); else dstr += (date.getMonth() + 1).toString(); dstr += "-"; if (date.getDate() < 10) dstr += "0" + date.getDate(); else dstr += date.getDate(); return dstr; }, FileTimeToTimeString: function (fTime, ms) { if (isNaN(fTime) || fTime == 0) return ""; var date = this.FileTimeToDate(fTime); var time; if (date.getHours() < 10) time = "0" + date.getHours(); else time = date.getHours().toString(); time += ":"; if (date.getMinutes() < 10) time += "0" + date.getMinutes().toString(); else time += date.getMinutes(); time += ":"; if (date.getSeconds() < 10) time += "0" + date.getSeconds().toString(); else time += date.getSeconds(); if (ms === true) { time += "."; if (date.getMilliseconds() < 10) time += "00" + date.getMilliseconds().toString(); else if (date.milliseconds < 100) time += "0" + date.getMilliseconds().toString(); else time += date.getMilliseconds().toString(); } return time; } }); WebLink.prototype = { addPen: function (pen) { if (!this.Pens) this.Pens = []; this.Pens.push(pen); this.startLink(); }, destroy: function () { if (this.hisTimer) { window.clearTimeout(this.hisTimer); this.hisTimer = null; } if (this.linkTimer) { window.clearTimeout(this.linkTimer); this.linkTimer = null; } if (this.rtRefresher) { this.rtRefresher.clear(); delete this.rtRefresher; } if (this.Pens) delete this.Pens; }, startLink: function (delay) { if (this.linkTimer) { window.clearTimeout(this.linkTimer); this.linkTimer = null; } var self = this; this.linkTimer = window.setTimeout(function () { window.clearTimeout(self.linkTimer); self.linkTimer = null; self._beginLink(); self = null; }, delay || 10); }, _beginLink: function () { if (!this.Pens || !this.Pens.length) return; var self = this; for (var i in this.Pens) { var pen = this.Pens[i]; if (pen.isLinkRq()) { self._addpenClosure(pen); } pen.setLinkStatus("linking", "正在连接..."); } }, _addpenClosure:function(pen) { var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point?tagName=" + pen.getURI(); $.ajax({ url: str, type: 'GET', dataType: 'json', cache: false, success: function (data) { if(data) pen.onLinkTab(data); } }); }, RegistRtPt: function (rtDef, scope, callback, opt) { if (!this.rtRefresher) this.rtRefresher = new GoldenRtWeb.RtRefresher(this.weburl); return this.rtRefresher.RegistRtPt(rtDef, scope, callback, opt); }, UnRegistRtPt: function (pen, rtRefreshKey) { if (this.rtRefresher) this.rtRefresher.UnRegistRtPt(rtRefreshKey); if (this.Pens) { for (i in this.Pens) { if (this.Pens[i] == pen) { this.Pens.splice(i, 1); break; } } } }, requestHisData: function (delay) { if (this.hisTimer) { window.clearTimeout(this.hisTimer); this.hisTimer = null; } var self = this; this.hisTimer = window.setTimeout(function () { window.clearTimeout(self.hisTimer); self.hisTimer = null; self._pullHisData(); self = null; }, delay || 10); return true; }, _pullHisData: function () { if (!this.Pens || !this.Pens.length) return; var reqInfoset = null; var tagName=[]; var metaId=""; var beginTime=""; var endTime=""; var tabs=[]; for (i in this.Pens) { var pen = this.Pens[i]; if (pen.isHisRq()) { var tab = pen.getHisRequestTab(); tab.reqHisPen = pen; tab.clientHandle = i; pen.setHisStatus("getting", "正在获取历史数据..."); tabs.push(tab); tab.reqHisPen = pen; tab.clientHandle = i; if(beginTime==""){ if(pen.options.itemDef.beginTime!=null){ beginTime=pen.options.itemDef.beginTime; } else{ beginTime=0; } } if(endTime==""){ if(pen.options.itemDef.endTime!=null){ endTime=pen.options.itemDef.endTime; }else{ endTime=0; } } var item = pen.options.URI; item += "&beginTime=" + beginTime + "&endTime=" + endTime + "&interval=1000"; tagName.push(item); } } if (tagName.length>0) { for (var i = 0; i < tagName.length; i++) { { var str = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryPlot?tagNames=" + tagName[i]; var self = this; var tab = tabs[i]; $.ajax({ url: str, type: 'GET', dataType: 'json', cache: false, complete: function (xhr, ts) { if (xhr.tab) { var data = xhr.responseJSON; if (data.length > 0) self._onHisEnd(xhr.tab, data); delete xhr.tab; } } }).tab = tab; } } } else this._onHisEnd(); }, _onHisEnd: function (tab,data) { if (tab && data && data.length > 0) { if (tab.reqHisPen) { tab.hisData = data[0]; tab.reqHisPen.onHisTab(tab); tab.reqHisPen = null; } } if (!this.Pens || !this.Pens.length) return; this.requestHisData(3000); } }; TrendPen.prototype = { destroy: function () { if (this.linkingTime) { window.clearTimeout(this.linkingTime); this.linkingTime = null; } if (this.hisingTime) { window.clearTimeout(this.hisingTime); this.hisingTime = null; } if (this.rtRefreshKey) { this.rtChart.UnRegistRtPt(this, this.rtRefreshKey); this.rtRefreshKey = null; } var oldComm = this.commAxis; this.commAxis = null; if (oldComm) { for (var i = 0; i < oldComm.length; i++) oldComm[i].removeCommAxis(this); } this.rtChart = null; }, hisDatRemove: function (array, from, to) { var rest = array.slice((to || from) + 1 || array.length); array.length = from < 0 ? array.length + from : from; return array.push.apply(array, rest); }, updateRangeList:function() { if (this.rageMax != null && this.rageMin != null ) { this.setGridSelf = true; this.rtChart._updateList(this.rowId, "量程下限", this.rageMin.toFixed(this.options.Num)); this.rtChart._updateList(this.rowId, "量程上限", this.rageMax.toFixed(this.options.Num)); this.setGridSelf = false; } else { this.setGridSelf = true; this.rtChart._updateList(this.rowId, "量程下限", null); this.rtChart._updateList(this.rowId, "量程上限", null); this.setGridSelf = false; } }, setDataReader: function() { if (this.rtChart == null) return; var ft = this.rtChart.getReaderTimer(); var vqt = null; var prev = null; var next = null; if (this.hisData) { var len = this.hisData.length; for (var i = 0; i < len; i++) { var findVQT = this.hisData[i]; if (findVQT.StampTime == ft) { vqt = findVQT; break; } else if (findVQT.StampTime > ft) { if (prev) { vqt = prev; next = findVQT; } else vqt = findVQT; break; } else prev = findVQT; } } if (vqt) { if (vqt.Value != null) { if (next && next.StampTime > vqt.StampTime && next.Value != null) { var val; if (this.isString(vqt)) val = vqt.Value ? vqt.Value : ""; else if (this.isBoolen(vqt)) { if (vqt.Value) val = "1"; else val = "0"; } else { val = vqt.Value + (next.Value - vqt.Value) * (ft - vqt.StampTime) / (next.StampTime - vqt.StampTime); val = val.toFixed(this.options.Num); } if (this.unit) val += " " + this.unit; var time = this.rtChart.FileTimeToDateString(ft) + " " + this.rtChart.FileTimeToTimeString(ft); this.rtChart._updateList(this.rowId, "数据时间", time); this.rtChart._updateList(this.rowId, "数据值", val); } else { var time = this.getFullStampTimeStr(vqt); var val ; if (this.isString(vqt)) val = vqt.Value ? vqt.Vvalue : ""; else if (this.isBoolen(vqt)) { if (vqt.Value) val = "1"; else val = "0"; } else val = (this.isFloat(vqt) ? vqt.Value.toFixed(this.options.Num) : vqt.Value); if (this.unit) val += " " + this.unit; this.rtChart._updateList(this.rowId, "数据时间", time); this.rtChart._updateList(this.rowId, "数据值", val); } } } else { var time = this.rtChart.FileTimeToDateString(ft) + " " + this.rtChart.FileTimeToTimeString(ft); var val = '[!!无历史数据]'; this.rtChart._updateList(this.rowId, "数据时间", time); this.rtChart._updateList(this.rowId, "数据值", val); } }, updateDataReader:function() { if (this.rtChart == null) return; if (this.dataReaderTime == null) { var me = this; this.dataReaderTime = window.setTimeout(function () { window.clearTimeout(me.dataReaderTime); me.dataReaderTime = null; me.setDataReader(); me = null; }, 100); } }, setRangeLock: function (lock, updateList) { if (this.options.lockRange === lock) return; this.options.lockRange = lock; if (!lock) { var gh = this.rtChart.getGridHeight(); } if (updateList !== false) this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange); }, onSetMinRange: function (nValue) { if (!this.setGridSelf) { var minset = parseFloat(nValue); if (this.rageMax > minset) { this.options.lockRange = true; this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange); this.setRange(minset, this.rageMax, null); } this.updateRangeList(); } }, onSetMaxRange: function (nValue) { if (!this.setGridSelf) { var maxset = parseFloat(nValue); var gh = this.rtChart.getGridHeight(); if (maxset > this.rageMin) { this.options.lockRange = true; this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange); this.setRange(this.rageMin, maxset, null); } this.updateRangeList(); } }, log10: function (val) { return Math.log(val) / Math.LN10; }, setRange: function (rageMin, rageMax, calls) { if (this.rageMin != rageMin || this.rageMax != rageMax) { this.rageMin = rageMin; this.rageMax = rageMax; if ((this.maxVqt && this.isFloat(this.maxVqt)) || (this.minVqt && this.isFloat(this.minVqt))) { var r = Math.abs(this.rageMax - this.rageMin); if (r < 1) { var bSet = false; if (r > 0.1) { if (this.options.Num < 3) { this.options.Num = 3; bSet = true; } } else if (r > 0.01) { if (this.options.Num < 4) { this.options.Num = 4; bSet = true; } } else if (r > 0.001) { if (this.options.Num < 5) { this.options.Num = 5; bSet = true; } } else if (this.options.Num < 6) { this.options.Num = 6; bSet = true } if (bSet) this.updateListGrid(); } } this.rtChart.updateDataArea(); this.rtChart.UpdateAxisPan(true); this.updateRangeList(); } if (this.commAxis && this.commAxis.length) { if (calls == null) calls = []; calls.push(this); for (var i = 0; i < this.commAxis.length; i++) { var pen = this.commAxis[i]; var seted = false; for (var k in calls) { if (calls[k] == pen) { seted = true; break; } } if (!seted) pen.setRange(rageMin, rageMax, calls); } } }, moveY: function (deltY) { if(this.rageMin == null || this.rageMax == null || this.rageMax == this.rageMin) return; var gh = this.rtChart.getGridHeight(); var delt = (this.rageMax - this.rageMin) * deltY / gh; this.setRange(this.rageMin + delt,this.rageMax + delt); }, isGood: function(vqt) { if (!vqt) return false; return (vqt.Qua == 0 || ((vqt.Qua & 0x100) && (vqt.Qua & 0xc0) == 0xc0)); }, isBad: function(vqt) { return !this.isGood(vqt); }, isUncertain: function(vqt) { return false; }, isFloat: function(vqt) { if (!vqt || !vqt.Value) return false; var num = parseFloat(vqt.Value); if (isNaN(num)) return false; else { if (num.toString().indexOf(".") > 0) return true; else return false; } }, GetNumber: function (vqt) { if (!vqt) return 0; var num = parseFloat(vqt.Value); if (num == null) return 0; if (!isNaN(num)) return num; else if (num.toString().toLowerCase() == "true") return 1; else if (num.toString().toLowerCase() == "false") return 0; var hash = 0; if (!this.value || !this.value.length) return hash; for (i = 0; i < this.value.length; i++) { char = this.value.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash = hash & hash; } return hash; }, isBoolen:function(vqt) { if (!vqt) return false; else if (vqt.Value == "true" || vqt.Value == "false") return true; else return false; }, isString:function(vqt) { if (!vqt) return false; else if (vqt.Value == null) return false; else if (typeof vqt.Value == 'string') return true; else return false; }, getQuaStr: function(vqt) { var re = ""; if (!vqt || vqt.Qua == null) return re; switch (vqt.Qua) { case 0: // re = "正常"; break; case 1: re = "无数据"; break; case 2: re = "创建"; break; case 3: re = "停机"; break; case 4: re = "计算停止"; break; case 5: re = "坏点"; break; case 6: re = "被零除"; break; case 7: re = "已被删除"; break; default: if (this.qua & 0x0100) // 从0x0100至0x01FF为OPC质量码 { switch (this.qua & 0xFC) { case 0x00: re = "坏值"; break; case 0x04: re = "坏值(组态错误)"; break; case 0x08: re = "坏值(没有连接)"; break; case 0x0C: re = "坏值(设备故障)"; break; case 0x10: re = "坏值(传感器故障)"; break; case 0x14: re = "坏值(最后值)"; break; case 0x18: re = "坏值(通讯故障)"; break; case 0x1C: re = "坏值(退出服务)"; break; case 0x20: re = "坏值(不被许可)"; break; case 0x24: re = "坏值(超出量程)"; break; case 0x2C: re = "坏值(未定义值)"; break; case 0x28: re = "坏值(计算错误)"; break; case 0x30: re = "坏值(输出开路)"; break; case 0x34: re = "坏值(输入开路)"; break; case 0x3C: re = "坏值(转换错误)"; break; case 0x40: re = "坏值(可疑值)"; break; case 0x44: re = "可疑值(最后值)"; break; case 0x48: re = "可疑值(输出开路)"; break; case 0x4C: re = "可疑值(等待同步)"; break; case 0x50: re = "可疑值(传感器校正)"; break; case 0x54: re = "可疑值(超出量程)"; break; case 0x58: re = "可疑值(子故障)"; break; case 0x5C: re = "可疑值(输入开路)"; break; case 0x60: re = "可疑值(转换错误)"; break; case 0xC0: re = "正常"; break; case 0xC4: re = "正常(初始化)"; break; case 0xC4: re = "正常(无状态)"; break; case 0xD8: re = "正常(当地重载)"; break; } } else { re = "用户自定义"; } break; } return re; }, getFullStampTimeStr: function(vqt) { return GoldenRtWeb.FileTimeToString(vqt.StampTime, false); }, getStampTimeStr: function(vqt) { return GoldenRtWeb.FileTimeToString(vqt.StampTime, false); }, expendY: function (deltaY) { if (this.rageMin == null || this.rageMax == null || this.rageMax == this.rageMin) return; var gh = this.rtChart.getGridHeight(); var delt = (this.rageMax - this.rageMin) * deltaY / gh; var M = null; if (this.minVqt && this.isGood(this.minVqt) && this.maxVqt && this.isGood(this.maxVqt)) { if (this.isBoolen(this.minVqt)) M = 0.5; else if (this.GetNumber(this.minVqt) != this.GetNumber(this.maxVqt)) M = 0.5 * (this.GetNumber(this.maxVqt) - this.GetNumber(this.minVqt)) + this.GetNumber(this.minVqt); else M = 0.5 * this.GetNumber(this.maxVqt); } else if (this.minVqt && this.isGood(this.minVqt)) { if (this.isBoolen(this.minVqt)) M = 0.5; else M = 0.5 * this.GetNumber(this.minVqt); } else if (this.maxVqt && this.isGood(this.maxVqt)) { if (this.isBoolen(this.maxVqt)) M = 0.5; else M = 0.5 * this.GetNumber(this.maxVqt); } else return; var K = (M - this.rageMin) / (this.rageMax - this.rageMin); var max = this.rageMax + delt; var min = (M - K * max) / (1 - K); if (max <= min) return; this.setRange(min, max); }, getY: function(val) { if (this.rageMin == null || this.rageMax == null || this.rageMin == this.rageMax) return null; var gh = this.rtChart.getGridHeight(); var y = gh - gh * (val - this.rageMin) / (this.rageMax - this.rageMin); return y; }, getVal: function(y) { if (this.rageMin == null || this.rageMax == null || this.rageMin == this.rageMax) return null; var gh = this.rtChart.getGridHeight(); var v = this.rageMin + (gh - y) * (this.rageMax - this.rageMin) / gh; return v; }, hasDataAtTime: function (ft, y) { if (this.hisData) { var yVal = this.getVal(y); if (yVal == null) return false; if (this.minVqt && this.isGood(this.minVqt) && this.GetNumber(this.minVqt) > yVal) { if (this.isBoolen(this.minVqt) && yVal < 0) return false; if (this.maxVqt && this.isGood(this.maxVqt) && this.GetNumber(this.maxVqt) == this.GetNumber(this.minVqt)) { if (this.rageMin > yVal) return false; } else return false; } if (this.maxVqt && this.isGood(this.maxVqt) && this.GetNumber(this.maxVqt) < yVal) { if (this.isBoolen(this.maxVqt) && yVal > 1) return false; else if (this.minVqt && this.isGood(this.minVqt) && this.GetNumber(this.maxVqt) == this.GetNumber(this.minVqt)) { if (this.rageMax < yVal) return false; } else return false; } var prev = null; var len = this.hisData.length; for (var i = 0; i < len; i++) { var vqt = this.hisData[i]; if (vqt.StampTime == ft) return true; else if (vqt.StampTime > ft) { if (prev) return true; else return false; } else prev = vqt; } return false; } else return false; }, hasDataBetweenTime: function (begTime, endTime) { if (this.hisData) { var len = this.hisData.length; for (var i = 0; i < len; i++) { var vqt = this.hisData[i]; if (vqt.StampTime >= begTime && vqt.StampTime <= endTime) return true; } return false; } else return false; }, getPanHeight: function () { var h = 55; if (this.vqt) h += SPANLINEHEIGHT; if (this.avg != null) h += SPANLINEHEIGHT; if (this.maxVqt) h += SPANLINEHEIGHT if (this.minVq) h += SPANLINEHEIGHT; return h; }, isLinkRq: function () { if (this.itemDef) return false; else if (this.linkTime && (new Date() - this.linkTime < this.options.linkReTryTime)) return false; else return true; }, isLinked: function () { return this.itemDef != null; }, getConfig: function() { var config = {}; config.URI = this.getURI(); config.linkReTryTime = this.options.linkReTryTime; config.penColor = this.options.penColor; config.Num = this.options.Num; config.penWidth = this.options.penWidth || 1; config.drawLine = this.options.drawLine; config.stepLine = this.options.stepLine == null ? false : this.options.stepLine; config.drawTag = this.options.drawTag; config.interpolate = this.options.interpolate == null ? false : this.options.interpolate; config.hisReTryTime = this.options.hisReTryTime; config.lockRange = this.options.lockRange; config.rageMax = this.options.rageMax; config.rageMin = this.options.rageMin; if (this.commAxis) { var axis = []; for (var i = 0; i < this.commAxis.length; i++) { var pen = this.commAxis[i]; axis.push(pen.getURI()); } config.commAxis = axis; } return config; }, setDes: function(des) { this.des = des; if (this.rtChart && this.rowId) this.rtChart._updateList(this.rowId, "描述", this.getDes()); }, getDes: function() { return this.des; }, getWebURL: function () { return GoldenRtWeb.getWebURL(); }, getURI: function () { return this.options.URI; }, getLabel: function () { var uri = this.getURI(); var i = uri.lastIndexOf("."); if (i > 0) return uri.substring(i + 1); else return uri; }, getPenColor: function () { return this.options.penColor; }, onSetLineWidth: function(nValue,fromgrid) { this.options.penWidth = parseInt(nValue); this.rtChart.updateDataArea(); if(!fromgrid) this.rtChart._updateList(this.rowId, "线宽", this.options.penWidth); }, setPenColor: function (rgba) { this.options.penColor = rgba; this.panPos = null; this.rtChart.UpdatePan(false); this.rtChart.updateDataArea(); this.rtChart._updateList(this.rowId, "点名称", { uri: this.getURI(), color: this.getPenColor() }); }, drawPan: function (bredraw, ctx, t, w) { var bReDaw = this.activeChanged || bredraw || ((t === this.panPos) ? false : true); var cleared = false; var dt = SPANPAD; var h = SPANLINEHEIGHT; if (bReDaw) { this.activeChanged = false; this.panPos = t; ctx.clearRect(1, 0, w - 2, this.getPanHeight()); cleared = true; ctx.translate(0.5, 0.5); ctx.lineWidth = 1; ctx.beginPath(); ctx.strokeStyle = "rgb(30,30,30)"; ctx.moveTo(1, 1) ctx.lineTo(w - 2, 1); ctx.stroke(); ctx.beginPath(); ctx.strokeStyle = "rgb(220,220,220)"; ctx.moveTo(1, 2) ctx.lineTo(w - 2, 2); ctx.stroke(); ctx.beginPath(); ctx.fillStyle = this.options.penColor; ctx.strokeStyle = this.options.penColor; ctx.rect(6.5, 9.5, 8, 8); ctx.fill(); ctx.textAlign = "left"; ctx.fillText(this.getLabel(), 18, dt, w - 12); if (this.bActive) { ctx.rect(2, 3, w - 4, this.getPanHeight() - 4); ctx.stroke(); } var r = w - 10; ctx.beginPath(); ctx.moveTo(r, 6) ctx.lineTo(r + 6, 12); ctx.moveTo(r + 6, 6) ctx.lineTo(r, 12); ctx.stroke(); } var img = this.rtChart.getButtonImage(); if (img && !img.complete) img = null; var likdarwed = false; dt += h; if ((bReDaw || this.linkChanged) && this.linkStatus != null) { this.linkChanged = false; if (!cleared) ctx.clearRect(3, dt, w - 5, h); likdarwed = true; if (img) { switch (this.linkStatus) { case 'linking': ctx.drawImage(img, 22, 0, 5, 6, 8, dt, 5, 6); break; case 'linked': ctx.drawImage(img, 36, 0, 10, 7, 8, dt, 10, 7); break; case 'error': ctx.drawImage(img, 27, 0, 5, 5, 8, dt, 5, 5); break; default: ctx.drawImage(img, 32, 0, 4, 5, 8, dt, 4, 5); break; } } if (this.unit) { ctx.fillStyle = this.options.penColor; ctx.textAlign = "right"; ctx.textBaseline = "top"; ctx.fillText(this.unit, w - 2, dt, w - 50); } } if ((bReDaw || this.hisChanged || likdarwed) && this.hisGetStaus != null) { this.hisChanged = false; if (!likdarwed && !cleared) ctx.clearRect(20, dt, 10, h); if (img) { switch (this.hisGetStaus) { case 'getting': ctx.drawImage(img, 22, 0, 5, 6, 20, 23, 5, 6); break; case 'error': ctx.drawImage(img, 27, 0, 5, 5, 20, 23, 5, 5); break; case 'linked': ctx.drawImage(img, 22, 6, 8, 5, 20, 24, 8, 5); break; case "nodata": case "wait": ctx.drawImage(img, 46, 0, 10, 10, 20, 23, 10, 10); break; default: ctx.drawImage(img, 32, 0, 4, 5, 20, 23, 4, 5); break; } } } dt += h; if (bReDaw || this.vqtChanged) { this.vqtChanged = false; if (!cleared) ctx.clearRect(3, dt, w - 5, h); if (this.vqt) { ctx.fillStyle = this.options.penColor; ctx.textAlign = "left"; ctx.textBaseline = "top"; ctx.fillText("实时", 5, dt, 30); if (this.vqt.isBad()) ctx.fillStyle = "rgb(200,0,0)"; else if (this.vqt.isUncertain()) ctx.fillStyle = "rgb(160,150,0)"; ctx.textAlign = "right"; if (this.vqt.value != null) ctx.fillText((this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value), w - 3, dt, w - 30); else if (this.vqt.isBad()) ctx.fillText("####", w - 3, dt, w - 30); else if (this.vqt.isUncertain()) ctx.fillText("????", w - 3, dt, w - 30); } } if (this.vqt) dt += h; if (bReDaw || this.avgChanged) { this.avgChanged = false; if (!cleared) ctx.clearRect(3, dt, w - 5, h); if (this.avg != null) { ctx.fillStyle = this.options.penColor; ctx.textAlign = "left"; ctx.textBaseline = "top"; ctx.fillText("平均", 5, dt, 30); ctx.textAlign = "right"; ctx.fillText(this.avg.toFixed(this.options.Num), w - 3, dt, w - 30); } } if (this.avg != null) dt += h; if (bReDaw || this.minChanged) { this.minChanged = false; if (!cleared) ctx.clearRect(3, dt, w - 5, h); if (this.minVqt) { ctx.fillStyle = this.options.penColor; ctx.textAlign = "left"; ctx.textBaseline = "top"; ctx.fillText("最小", 5, dt, 30); if (!this.isGood(this.minVqt)) { ctx.fillStyle = "rgb(120,0,0)"; } ctx.textAlign = "right"; if (this.minVqt.Value != null) ctx.fillText((this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value), w - 3, dt, w - 30); else if (!this.isGood(this.minVqt)) ctx.fillText("####", w - 3, dt, w - 30); } } if (this.minVqt) dt += h; if (bReDaw || this.maxChanged) { this.maxChanged = false; if (!cleared) ctx.clearRect(3, dt, w - 5, h); if (this.maxVqt) { ctx.fillStyle = this.options.penColor; ctx.textAlign = "left"; ctx.textBaseline = "top"; ctx.fillText("最大", 5, dt, 30); if (!this.isGood(this.maxVqt)) { ctx.fillStyle = "rgb(120,0,0)"; } ctx.textAlign = "right"; if (this.maxVqt.Value != null) ctx.fillText((this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value), w - 3, dt, w - 30); else if (!this.isGood(this.maxVqt)) ctx.fillText("####", w - 3, dt, w - 30); } } }, setLinkStatus: function (status, info, nodelay) { if (!this.rtChart) return; if (status == "linking") this.linkTime = new Date(); else if (this.linkStatus == "linking" && !(nodelay === true)) { var self = this; if (this.linkingTime) window.clearTimeout(this.linkingTime); this.linkingTime = window.setTimeout(function () { window.clearTimeout(self.linkingTime); self.linkingTime = null; self.setLinkStatus(status, info, true); self = null; }, 100); return; } if (this.linkStatus != status || this.linkInfo != info) { this.linkStatus = status; this.linkInfo = info; if (this.linkStatus == "error" && this.linkInfo && this.linkInfo.lastIndexOf("E_AUTHENERR") >= 0) { this.requestLogin = true; this.rtChart.requestLogin(); } else if (this.linkStatus != 'linking') this.requestLogin = false; this.linkChanged = true; this.rtChart.UpdateDataPan(false); if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "linkStatus" && !(this.requestLogin === true)) this.rtChart.UpdateTooltip(this.getLinkStatus()); } }, getLinkStatus: function () { var st; switch (this.linkStatus) { case "linking": st = '正在连接...'; break; case "error": st = '连接故障!'; break; case "linked": st = '已连接'; break; default: st = '状态码未知!'; } if (this.linkInfo) { st += "
"; st += this.linkInfo; } return st; }, resetAxisDrawed: function () { this.axisDrawed = false; this.axisBeg = null; this.axisEnd = null; }, setAxisDrawed: function (calls) { this.axisDrawed = true; if (this.commAxis && this.commAxis.length) { if (calls == null) calls = []; calls.push(this); for (var i = 0; i < this.commAxis.length; i++) { var pen = this.commAxis[i]; var seted = false; for (var k in calls) { if (calls[k] == pen) { seted = true; break; } } if (!seted) pen.setAxisDrawed(calls); } } }, drawAxis: function (begX, h, ctx) { if (this.axisDrawed || !this.options.drawLine) return 0; var maxW = 30; ctx.beginPath(); if (this == this.rtChart.getActivePen()) ctx.strokeStyle = this.getPenColor(); else if (this.commAxis && this.commAxis.length) { for (var i = 0; i < this.commAxis.length; i++) { var pen = this.commAxis[i]; if (pen == this.rtChart.getActivePen()) { ctx.strokeStyle = pen.getPenColor(); break; } } } if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) { var t = this.getY(1); if (t == null) return 0; var b = this.getY(0); ctx.moveTo(begX, t); ctx.lineTo(begX, b); ctx.moveTo(begX, t); ctx.lineTo(begX + 3, t); ctx.textBaseline = "top"; ctx.fillText("1", begX+ 2,t); ctx.moveTo(begX, b); ctx.lineTo(begX + 3, b); ctx.textBaseline = "bottom"; ctx.fillText("0", begX + 2, b); ctx.stroke(); maxW -= 22; } else { if (this.rageMax == null || this.rageMin == null || this.rageMax == this.rageMin ) return 0; var r = Math.abs(this.rageMax - this.rageMin)/20; var Num =0; if (r < 1) { r = 1.0 / r; Num = Math.ceil(this.log10(r)); } ctx.moveTo(begX, 0); ctx.lineTo(begX, h); ctx.moveTo(begX - 2, 0) ctx.lineTo(begX + 2, 0); ctx.textBaseline = "top"; var str = this.rageMax.toFixed(Num).toString(); if(str.length > 5) { var d = (str.length - 5) * 5; if(d > 20) d = 20; maxW += d; } ctx.fillText(str, begX + 2, -2, maxW - 2); ctx.moveTo(begX - 2, h) ctx.lineTo(begX + 2, h); ctx.textBaseline = "middle"; ctx.fillText(this.rageMin.toFixed(Num), begX + 2, h, maxW - 2); ctx.textBaseline = "middle"; var y = h / 20.0; for (var i = 1; i < 20; i++) { var iy = Math.floor(y); ctx.moveTo(begX - 2, iy) ctx.lineTo(begX + 1, iy); ctx.fillText((this.rageMax - i * (this.rageMax - this.rageMin) / 20).toFixed(Num), begX + 3, iy, maxW - 2); y += h / 20.0; } ctx.stroke(); } var x = begX; var y; if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) y = this.getY(0) + 6; else y = h + 6; ctx.beginPath(); ctx.fillStyle = this.getPenColor(); ctx.rect(x, y, 5,5); ctx.fill(); x += 7; if (x + 5 > begX + maxW) { x = begX; y += 7; } this.setAxisDrawed(); if (this.commAxis && this.commAxis.length) { for (var i = 0; i < this.commAxis.length; i++) { var pen = this.commAxis[i]; ctx.beginPath(); ctx.fillStyle = pen.getPenColor(); ctx.rect(x, y, 5, 5); ctx.fill(); x += 7; if (x + 5 > begX + maxW) { x = begX; y += 7; } } } this.axisBeg = begX; this.axisEnd = begX + maxW; return maxW; }, removeCommAxis: function(pen) { if (this.commAxis) { var len = this.commAxis.length; for (var i = 0; i < len; i++) { if (this.commAxis[i] == pen) { this.commAxis.splice(i, 1); break; } } } }, addCommAxis: function(pen) { var oldComm = this.commAxis; this.commAxis = null; if (oldComm) { for (var i = 0; i < oldComm.length; i++) oldComm[i].removeCommAxis(this); } this.setRange(pen.rageMin, pen.rageMax); this.commAxis = []; this.commAxis.push(pen); }, onCommAxisSet: function(arr) { var newComm = null; for (var i = 0; i < arr.length; i++) { var ind = arr[i]; var pen = this.rtChart.trendPens[ind]; if (pen && pen != this) { if (newComm == null) newComm = []; newComm.push(pen); } } var oldComm = this.commAxis; this.commAxis = null; if (oldComm) { for (var i = 0; i < oldComm.length; i++) { var pen = oldComm[i]; pen.removeCommAxis(this); } } if (newComm) { for (var i = 0; i < newComm.length; i++) newComm[i].addCommAxis(this); } this.commAxis = newComm; this.rtChart.UpdateAxisPan(true); }, onSetCommAxis: function(e) { this.rtChart.requestActive(this); var pen = this; var content = '选择共轴位号:'; var bIsBool = false; if(this.minVqt && this.isBoolen(this.minVqt)) bIsBool = true; else if(this.maxVqt && this.isBoolen(this.maxVqt)) bIsBool = true; var pens = this.rtChart.trendPens; for(var i = 0;i < pens.length;i++) { var pen = pens[i]; if (pen == this) content += '
'; else { var bIsComm = false; if (this.commAxis && this.commAxis.length) { for (var k = 0; k < this.commAxis.length; k++) { if (this.commAxis[k] == pen) { bIsComm = true; break; } } } if (bIsComm) { content += '
'; } else { var bpenIsBool = false; if (pen.minVqt && pen.isBoolen( pen.minVqt)) bpenIsBool = true; else if (pen.maxVqt && pen.isBoolen(pen.maxVqt)) bpenIsBool = true; if (bpenIsBool == bIsBool) { content += '
'; } } } } content += '
'; var pen = this; var d = dialog( { title: '设置 ' + this.getLabel() + ' 的共轴显示', quickClose: true, content: content, padding: 10, okValue: '确定', ok: function () { var arr = []; var sel = $('input[type=checkbox]', this.__popup); for (var i = 0; i < sel.length ; i++) { if(sel[i].checked) arr.push(parseInt(sel[i].value)); } pen.onCommAxisSet(arr); pen = null; d.close().remove(); d = null; } }); e.pageX += 10; e.pageY -= 30; d.show(e); }, getCommGroup: function(penGroup) { penGroup.push(this); if (this.commAxis && this.commAxis.length) { for (var i = 0; i < this.commAxis.length; i++) { var pen = this.commAxis[i]; var find = false; for (var k in penGroup) { if (penGroup[k] == pen) { find = true; break; } } if (!find) pen.getCommGroup(penGroup); } } }, setHisStatus: function (status, info, nodelay) { if (!this.rtChart) return; if (status == "getting") this.hisTime = new Date(); else if (this.hisGetStaus == "getting" && !(nodelay === true)) { var self = this; if (this.hisingTime) window.clearTimeout(this.hisingTime); this.hisingTime = window.setTimeout(function () { window.clearTimeout(self.hisingTime); self.hisingTime = null; self.setHisStatus(status, info, true); self = null; }, 100); return; } if (this.hisGetStaus != status || this.hisInfo != info) { this.hisGetStaus = status; this.hisInfo = info; this.hisChanged = true; this.rtChart.UpdateDataPan(false); if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "hisStatus" && !(this.requestLogin === true)) this.rtChart.UpdateTooltip(this.getHisStatus()); } }, getHisStatus: function () { var st; switch (this.hisGetStaus) { case "getting": st = '正在获取...'; break; case "wait": st = '正在等待...'; break; case "error": st = '连接故障!'; break; case "linked": st = '已获得历史数据'; break; case "nodata": st = '无历史数据'; break; default: st = '状态码未知!'; } if (this.hisInfo) { st += "
"; st += this.hisInfo; } return st; }, getpreventTooltipUpdate: function () { return this.preventTooltipUpdate; }, onTooltipShowed: function () { this.showTolltip = true; }, onTooltipHided: function () { this.showTolltip = false; this.preventTooltipUpdate = false; this.toolTipAt = null; }, isActive: function() { return this.bActive; }, setActive: function (bActive) { if (this.bActive == bActive || !this.rtChart) return; this.bActive = bActive; this.activeChanged = true; this.rtChart.UpdatePan(false); }, activePen: function () { var nowActived = this.rtChart.getActivePen() == this; if (nowActived) this.bActive = true; else this.rtChart.requestActive(this); }, onMouseMove: function (x, y, e, clientX, clientY, panH) { var w = this.rtChart.getPanWidth(); var ta = (clientY > panH / 2) ? 'top right' : 'bottom right'; var ty = e.pageY + ((clientY > panH / 2) ? -8 : 8); var t = SPANPAD; var h = SPANLINEHEIGHT; if (y >= 0 && y < t + h) { if (x < 20) { var opt = { content: "点击设置趋势笔颜色", align: ta, skin: 'tooltipTans', x: e.pageX + 10, y: ty } this.toolTipAt = null; this.rtChart.showTooltip(opt, this); this.rtChart.setCursor("pointer"); return true; } else if (x < w - 10) { if (this.rtChart && this.rtChart.getLoginPen && this.rtChart.getLoginPen() != this) { var opt = { title: this.getLabel(), content: "存取路径:
" + this.getURI() + (this.des && this.des.length ? ("
描 述:
" + this.des) : "") + "
Web服务:
" + this.getWebURL(), skin: 'tooltipTans', align: ta, x: e.pageX + 20, y: ty } this.toolTipAt = null; this.rtChart.showTooltip(opt, this, e); this.rtChart.setCursor("pointer"); return true; } } else { var opt = { content: "单击移除趋势笔", skin: 'tooltipTans', align: ta, x: e.pageX, y: ty } this.toolTipAt = null; this.rtChart.showTooltip(opt, this); this.rtChart.setCursor("pointer"); return true; } } else if (y >= t + h && y < t + 2 * h) { if (x >= 0 && x < 18) { var st; var bHook = false; if (this.requestLogin === true) { st = '实时信息网站:
' + this.getWebURL() + "
需要登录,点击这里进行操作"; this.preventTooltipUpdate = true; bHook = true; } else { st = this.getLinkStatus(); this.preventTooltipUpdate = false; } var opt = { title: '连接状态', content: st, skin: 'tooltipTans', align: ta, x: e.pageX + 20, y: ty } if (bHook) { var trendPen = this; var showed = false; opt.onshow = function () { if (showed === false) { showed = true; $('a', this.__popup).click(function () { $(this).unbind('click'); trendPen.rtChart.requestLogin(); trendPen = null; }); } }; } else opt.width = 180; this.rtChart.showTooltip(opt, this); this.toolTipAt = "linkStatus"; } else if (x >= 20 && x < 30 && this.hisGetStaus != null) { var opt = { title: '历史数据获取状态', content: this.getHisStatus(), skin: 'tooltipTans', width: 180, align: ta, x: e.pageX + 20, y: ty } this.rtChart.showTooltip(opt, this); this.toolTipAt = "hisStatus"; } else if (x > w - 22) { if (this.unit) { var opt = { content: '工程单位:' + this.unit, skin: 'tooltipTans', align: ta, x: e.pageX + 10, y: ty } this.rtChart.showTooltip(opt, this); this.toolTipAt = null; } } } else if (y >= t + 2 * h && y < t + 3 * h) { if (this.vqt) { var opt = { title: this.getLabel() + ' 的实时数据', content: this.getVQTTooltip(), align: ta, skin: 'tooltipTans', width: 250, x: e.pageX + 10, y: ty } this.rtChart.showTooltip(opt, this); this.toolTipAt = "vqt"; } } else if (y >= t + 3 * h && y < t + 4 * h) { if (this.avg != null) { var opt = { title: this.getLabel() + ' 的平均值(中值)', content: this.getAVGTooltip(), align: ta, skin: 'tooltipTans', width: 250, x: e.pageX + 10, y: ty } this.rtChart.showTooltip(opt, this); this.toolTipAt = "avg"; } } else if (y >= t + 4 * h && y < t + 5 * h) { if (this.minVqt != null) { var opt = { title: this.getLabel() + ' 的最小值', content: this.getMinVQTTooltip(), align: ta, skin: 'tooltipTans', width: 250, height: 90, x: e.pageX + 10, y: ty } this.rtChart.showTooltip(opt, this); this.toolTipAt = "minVQT"; this.rtChart.setCursor("pointer"); return true; } } else if (y >= t + 5 * h && y < t + 6 * h) { if (this.maxVqt != null) { var opt = { title: this.getLabel() + ' 的最大值', content: this.getMaxVQTTooltip(), align: ta, skin: 'tooltipTans', width: 250, height: 90, x: e.pageX + 10, y: ty } this.rtChart.showTooltip(opt, this); this.toolTipAt = "maxVQT"; this.rtChart.setCursor("pointer"); return true; } } }, onClick: function (x, y, e) { var w = this.rtChart.getPanWidth(); var t = SPANPAD; var h = SPANLINEHEIGHT; if (x > 20 && x < w - 10 && this.requestLogin !== true && !this.bActive) { this.rtChart.requestActive(this); return; } if (y >= 0 && y < t + h) { if (x < 20) { this.rtChart.setPenColor(this, e); } else if (x < w - 10) { if (this.requestLogin === true) { this.rtChart.requestLogin(); } else { if (this.bActive) this.rtChart.requestActive(null); else this.rtChart.requestActive(this); } } else this.rtChart.removePen(this); } else if (y >= t + 4 * h && y < t + 5 * h) this.posVQT("min"); else if (y >= t + 5 * h && y < t + 6 * h) this.posVQT("max"); }, onLinkTab: function (data) { if (!data || !data.length || !this.rtChart) return; var base = data[0].BasePointInfo; if (base && base.Unit) this.unit = base.Unit; if (base && base.Desc) this.setDes(base.Desc); this.rtRefreshKey = this.rtChart.RegistRtPt(this, this.getURI(), this.onRtRefresh); if (!this.rtRefreshKey) this.setLinkStatus("error", "实时刷新注册失败!"); if (!this.rtChart.requestHisData(this)) this.setHisStatus("error", "历史数据查询请求失败!"); }, setRtVQT: function (vqt) { if (!this.rtChart) return; var bReDraw = (this.vqt && !vqt) || (!this.vqt && vqt); this.vqt = vqt; this.vqtChanged = true; if(this.rowId) this.rtChart._updateList(this.rowId, "实时值", this.getVQTList()); this.rtChart.UpdateDataPan(bReDraw); if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "vqt") this.rtChart.UpdateTooltip(this.getVQTTooltip()); }, getVQTList: function () { if (!this.vqt) { return { title: "尚未获取实时值", color: "rgb(160,0,0)", value: "[!!尚未获取实时值]" }; } else { var vqt = {}; vqt.title = "质量码:" + this.vqt.getQuaStr() + "\n" + "时间戳:" + this.vqt.getFullStampTimeStr(); if (this.vqt.isGood()) vqt.color = "rgb(0,30,0)"; else if (this.vqt.isUncertain()) vqt.color = "rgb(100,100,0)"; else vqt.color = "rgb(180,0,0)"; vqt.value = (this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value); if (this.unit && this.unit.length) { vqt.unit = this.unit; } vqt.numberVal = this.vqt.GetNumber(); return vqt; } }, getMaxVQTList: function () { if (!this.maxVqt) { return { title: "尚未获得最大值", color: "rgb(160,0,0)", value: "[!!尚未获得最大值]" }; } else { var vqt = {}; vqt.tip = "max"; vqt.title = "质量码:" + this.getQuaStr(this.maxVqt) + "\n" + "时间戳:" + this.getFullStampTimeStr(this.maxVqt); if (this.isGood(this.maxVqt)) vqt.color = "rgb(0,80,0)"; else if (this.isUncertain(this.maxVqt)) vqt.color = "rgb(100,100,0)"; else vqt.color = "rgb(180,0,0)"; vqt.value = (this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value); if (this.unit && this.unit.length) { vqt.unit = this.unit; } return vqt; } }, getMinVQTList: function () { if (!this.minVqt) { return { title: "尚未获得最小值", color: "rgb(160,0,0)", value: "[!!尚未获得最小值]" }; } else { var vqt = {}; vqt.tip = "min"; vqt.title = "质量码:" + this.getQuaStr(this.minVqt) + "\n" + "时间戳:" + this.getFullStampTimeStr(this.minVqt); if (this.isGood(this.minVqt)) vqt.color = "rgb(0,80,0)"; else if (this.isUncertain(this.minVqt)) vqt.color = "rgb(100,100,0)"; else vqt.color = "rgb(180,0,0)"; vqt.value = (this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value); if (this.unit && this.unit.length) { vqt.unit = this.unit; } return vqt; } }, getVQTTooltip: function () { if (!this.vqt) return null; var tip = '
'; else tip += 'tooltpbadval">'; tip += '实时值:'; if (this.vqt.value != null) { tip += (this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value); if (this.unit && this.unit.length) { tip += " " + this.unit; } } tip += '
'; if (this.vqt.isGood()) tip += '
'; else tip += '
'; tip += '质量码:'; tip += this.vqt.getQuaStr(); tip += '
'; tip += '
'; tip += '时间戳:'; tip += this.vqt.getFullStampTimeStr(); tip += '
'; tip += '
'; return tip; }, getAVGTooltip: function () { if (this.avg == null) return null; var tip = '
' tip += '平均值:'; tip += (Math.floor(this.avg) != this.avg ? this.avg.toFixed(this.options.Num) : this.avg); if (this.unit && this.unit.length) { tip += " " + this.unit; } tip += '
'; return tip }, getAVGList: function() { var avg = {}; if (this.avg != null) { avg.value = (Math.floor(this.avg) != this.avg ? this.avg.toFixed(this.options.Num) : this.avg); if (this.unit && this.unit.length) { avg.unit = this.unit; } } return avg; }, getMinVQTTooltip: function () { if (!this.minVqt) return null; var tip = '
'; else tip += 'tooltpbadval">'; tip += '最小值:'; if (this.minVqt.Value != null) { tip += (this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value); if (this.unit && this.unit.length) { tip += " " + this.unit; } } tip += '
'; if (this.isGood(this.minVqt)) tip += '
'; else tip += '
'; tip += '质量码:'; tip += this.getQuaStr(this.minVqt); tip += '
'; tip += '
'; tip += '时间戳:'; tip += this.getFullStampTimeStr(this.minVqt); tip += '
'; tip += '
'; tip += '点击可定位最小值'; tip += '
'; tip += '
'; return tip; }, getMaxVQTTooltip: function () { if (!this.maxVqt) return null; var tip = '
'; else tip += 'tooltpbadval">'; tip += '最大值:'; if (this.maxVqt.Value != null) { tip += (this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value); if (this.unit && this.unit.length) { tip += " " + this.unit; } } tip += '
'; if (this.isGood(this.maxVqt)) tip += '
'; else tip += '
'; tip += '质量码:'; tip += this.getQuaStr(this.maxVqt); tip += '
'; tip += '
'; tip += '时间戳:'; tip += this.getFullStampTimeStr(this.maxVqt); tip += '
'; tip += '
'; tip += '点击可定位最大值'; tip += '
'; tip += '
'; return tip; }, posVQT: function(tip) { switch (tip) { case 'max': if (this.maxVqt != null) this.rtChart.posvIndicator(this.maxVqt.StampTime); break; case 'min': if (this.minVqt != null) this.rtChart.posvIndicator(this.minVqt.StampTime); break; } }, getValueTooltipAtTime: function (ft) { var vqt = null; var prev = null; var next = null; if (this.hisData) { var len = this.hisData.length; for (var i = 0; i < len; i++) { var findVQT = this.hisData[i]; if (findVQT.StampTime == ft) { vqt = findVQT; break; } else if (findVQT.StampTime > ft) { if (prev) { vqt = prev; next = findVQT; } else vqt = findVQT; break; } else prev = findVQT; } } var tip = '
vqt.StampTime && next.Value != null) { if (this.isString(vqt)) tip += (vqt.Value ? vqt.Value : ""); else if (this.isBoolen(vqt)) { if (vqt.Value) tip += "1"; else tip += "0"; } else { var inter = vqt.Value + (next.Value - vqt.Value) * (ft - vqt.StampTime) / (next.StampTime - vqt.StampTime); tip += inter.toFixed(this.options.Num); } } else { tip += ''; tip += this.getStampTimeStr(vqt); tip += ''; if (this.isString(vqt)) tip += (vqt.Value ? vqt.Value : ""); else if (this.isBoolen(vqt)) { if (vqt.Value) tip += "1"; else tip += "0"; } else tip += (this.isFloat(vqt) ? vqt.Value.toFixed(this.options.Num) : vqt.Value); } if (this.unit && this.unit.length) tip += " " + this.unit; } else { tip += ''; tip += this.getStampTimeStr(vqt); tip += ''; tip += '[!!空值]'; } } tip += '
'; return tip; }, getValueLine: function(iy) { var tip = '
'; tip += '不适合采用非阶跃的方式绘制趋势线,是否仍改变趋势线绘制方式?", okValue: '确定', ok: function () { pen.setStepLine(stepline, updateList, true); pen = null; return true; }, cancelValue: '取消', cancel: function () { pen.rtChart._updateList(pen.rowId, "阶跃", pen.options.stepLine == null ? false : pen.options.stepLine); } }); d.showModal(); return; } } this.options.stepLine = stepline; if (updateList !== false) this.rtChart._updateList(this.rowId, "阶跃", this.options.stepLine == null ? false : this.options.stepLine); this.rtChart.updateDataArea(); }, setDrawTag: function(drawTag, updateList) { if (this.options.drawTag === drawTag) return; this.options.drawTag = drawTag; if (updateList !== false) this.rtChart._updateList(this.rowId, "标记", this.options.drawTag); this.rtChart.updateDataArea(); }, setInterpolate: function(inter, updateList) { if (this.options.interpolate === inter) return; if (inter) { var type = null; if ((this.minVqt && this.isString(this.minVqt)) || (this.maxVqt && this.isString(this.maxVqt))) { type = "字符串"; } else if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) { type = "开关量"; } if (type != null) { var pen = this; var d = dialog({ title: '插值显示设置', content: '点:' + this.getLabel() + " 的数据类型为:" + type + ",
不适合采用插值显示方式?" }); d.show(); this.rtChart._updateList(pen.rowId, "插值", false); window.setTimeout(function () { d.close().remove(); d = null; }, 2000); return; } } this.options.interpolate = inter; if (updateList !== false) this.rtChart._updateList(this.rowId, "插值", this.options.interpolate); this.updateDataReader(); this.rtChart._updatevIndicatorTooltip(); }, updateListGrid: function () { if(!this.rowId) return; this.rtChart._updateList(this.rowId, "点名称", { uri: this.getURI(), color: this.getPenColor() }); this.rtChart._updateList(this.rowId, "线宽", this.options.penWidth); this.rtChart._updateList(this.rowId, "显示", this.options.drawLine); this.rtChart._updateList(this.rowId, "阶跃", this.options.stepLine == null ? false : this.options.stepLine); this.rtChart._updateList(this.rowId, "标记", this.options.drawTag); this.rtChart._updateList(this.rowId, "插值", this.options.interpolate); this.rtChart._updateList(this.rowId, "描述", this.getDes()); this.rtChart._updateList(this.rowId, "实时值", this.getVQTList()); this.rtChart._updateList(this.rowId, "最大值", this.getMaxVQTList()); this.rtChart._updateList(this.rowId, "最小值", this.getMinVQTList()); this.rtChart._updateList(this.rowId, "平均值", this.getAVGList()); this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange); this.updateRangeList(); this.updateDataReader(); }, onRtRefresh: function (status, data, opt) { switch (status) { case "getting": this.setLinkStatus("linking", "正在获取实时数据..."); break; case "error": this.setLinkStatus("error", "获取实时数据失败" + ((data && data.length) ? ("\n" + data) : "")); if (this.vqt && this.vqt.isGood()) { this.vqt.qua = 0x14; this.vqt.errMess = data; this.setRtVQT(this.vqt); } break; case "success": this.setLinkStatus("linked", "已成功获取实时数据"); this.setRtVQT(data); break; } }, refreshHisData: function (bClearData) { if (bClearData === true) delete this.hisData; else if (this.hisData) { var begTime = this.rtChart.getBegTime(); var endTime = this.rtChart.getEndTime(); if (this.getBegTime() <= begTime && this.getEndTime() >= endTime) return; else if (!((this.getBegTime() <= begTime && this.getEndTime() <= endTime) || (this.getBegTime() >= begTime && this.getEndTime() >= endTime))) delete this.hisData; } this.setHisStatus("wait", "正在等待查询启动"); if (!this.rtChart.requestHisData(this)) this.setHisStatus("error", "历史数据查询请求失败!"); }, getBegTime: function () { if (this.hisData && this.hisData.length) return this.hisData[0].StampTime; else return null; }, getEndTime: function () { if (this.hisData && this.hisData.length) return this.hisData[this.hisData.length - 1].StampTime; else return null; }, isHisRq: function () { if (!this.rtChart) return false; else if (this.options.itemDef!=null && this.options.itemDef.entityId!=null && this.options.itemDef.propId!=null) return true; else if (this.hisGetStaus == null) return true; else if (this.hisGetStaus == 'wait') return true; else if (this.hisGetStaus == 'error') { if (this.hisTime && (new Date() - this.hisTime > this.options.hisReTryTime)) return true; else return false; } else if (this.hisGetStaus != 'getting') { if (this.rtChart.getHisRefreshing()) return true; else if (this.hisGetStaus == 'nodata') return false; else if (!this.getEndTime()) return true; else if (this.getEndTime() < this.rtChart.getEndTime()) return true; else return false; } else { if (this.linkTime && new Date() - this.hisTime > this.options.hisReTryTime) return true; else return false; } }, getHisRequestTab: function () { var tab = new GoldenRtWeb.Tab(); tab.resultCode = 'S_RTREFRESHHISDATA'; if (this.options.itemDef == null) this.options.itemDef = {}; this.options.itemDef.dataMethod = 'HDBAGGREG_MAXMINMUM'; var gw = this.rtChart.getGridWidth(); var begTime = this.rtChart.getBegTime(); var endTime = this.rtChart.getEndTime(); if (this.rtChart.getHisRefreshing()) { if (this.getEndTime() != null && this.getEndTime() > begTime) { this.options.itemDef.beginTime = this.getEndTime(); this.options.itemDef.endTime = null; } else { this.options.itemDef.beginTime = begTime; this.options.itemDef.endTime = null; } this.options.itemDef.slotTime = gw; } else if (this.getBegTime() != null && this.getBegTime() <= begTime && this.getEndTime() != null && this.getEndTime() <= endTime) { this.options.itemDef.beginTime = this.getEndTime(); this.options.itemDef.endTime = endTime; this.options.itemDef.slotTime = gw * (this.options.itemDef.endTime - this.options.itemDef.beginTime) / this.rtChart.getTimeSpan() ; } else if (this.getBegTime() >= begTime && this.getEndTime() >= endTime) { this.options.itemDef.beginTime = begTime; this.options.itemDef.endTime = this.getBegTime(); this.options.itemDef.slotTime = gw * (this.options.itemDef.endTime - this.options.itemDef.beginTime) / this.rtChart.getTimeSpan() ; } else { this.options.itemDef.beginTime = begTime; this.options.itemDef.endTime = endTime; this.options.itemDef.slotTime = gw; } /*Modify*/ if (this.vqt) { if (this.options.itemDef.beginTime > this.vqt.StampTime) this.options.itemDef.beginTime = this.vqt.StampTime; if (this.options.itemDef.endTime > this.vqt.StampTime) this.optionsitemDef.endTime = 0; } //this.itemDef.slotTime = this.rtChart.getTimeSlot(); //if (this.itemDef.slotTime < PERHOUR && this.rtChart.getTimeSpan() > 120 * PERHOUR) // this.itemDef.slotTime = PERHOUR; var col = new GoldenRtWeb.Col(); col.key = "hisdata"; col.value = this.itemDef; var row = new GoldenRtWeb.Row(); row.addCol(col); tab.addRow(row); tab.hisRequestSeed = ++this.hisRequestSeed; return tab; }, onHisTab: function (tab) { // debugger; if (!this.rtChart) return; var err = null; if (tab.hisRequestSeed == this.hisRequestSeed) { var newData = tab.hisData; var lastVQT = newData[newData.length - 1]; if (lastVQT.StampTime < this.rtChart.getBegTime()) { this.setHisStatus("nodata", "查询不到有效的历史数据"); return; } this.newHisData = newData; this.setHisStatus("linked"); if (this.rtChart.getHisRefreshing()) this.rtChart._setNewLastTime(lastVQT.StampTime); this.rtChart._setNewLastTime(lastVQT.StampTime); this.rtChart._onNewHisData(); } else if (tab.isErr()) { err = "信息服务返回错误,错误码是:" + tab.resultCode + "
" + "错误信息是:" + tab.errMess + "
" + "错误源是:" + tab.errorSource; this.setHisStatus("error", err); } }, prepareHisData: function (begTime, endTime) { if (this.hisData && this.hisData.length) { var i = 0; var len = this.hisData.length; for (; i < len; i++) { if (this.hisData[i].StampTime >= begTime) break; } var prev = this.rtChart.options.reservePrevData || 1; if (i >= prev) this.hisDatRemove(this.hisData, 0, (i - prev)); } var dataChanged = false; if (this.newHisData && this.newHisData.length) { if (this.hisData && this.hisData.length > 0) { var firstTime = this.newHisData[0].StampTime; var lastTime = this.newHisData[this.newHisData.length - 1].StampTime; if (lastTime <= this.getBegTime()) { if (lastTime == this.getBegTime()) this.hisDatRemove(this.hisData, 0); dataChanged = true; this.hisData = this.newHisData.concat(this.hisData); } else if (firstTime < this.getBegTime() && lastTime <= this.getEndTime()) { var i = 0; for (; i < this.hisData.length; i++) { if (this.hisData[i].StampTime > lastTime) break; } if (i > 0) this.hisDatRemove(this.hisData, 0, i - 1); dataChanged = true; this.hisData = this.newHisData.concat(this.hisData); } else if (firstTime >= this.getBegTime() && lastTime > this.getEndTime()) { var i = 0; var len = this.hisData.length; for (; i < len; i++) { if (this.hisData[i].StampTime >= firstTime) break; } if (i < this.hisData.length) this.hisDatRemove(this.hisData, i, this.hisData.length - 1); dataChanged = true; this.hisData = this.hisData.concat(this.newHisData); } else if (firstTime >= this.getEndTime()) { if (firstTime == this.getEndTime()) this.hisDatRemove(this.hisData, -1); dataChanged = true; this.hisData = this.hisData.concat(this.newHisData); } } else { dataChanged = true; this.hisData = this.newHisData; } delete this.newHisData; } if (dataChanged || this.lastBegTime != begTime || this.lastEndTime != endTime) { this.lastBegTime = begTime; this.lastEndTime = endTime; var minVqt = null; var maxVqt = null; var goodCount = 0; var badCount = 0; var unCertain = 0; var sum = 0.0; var det = 0.0; var avg; var prevVQT; var min = this.rageMin; var max = this.rageMax; if (this.hisData) { var len = this.hisData.length; for (var i = 0; i < len; i++) { var vqt = this.hisData[i]; if (vqt.StampTime >= begTime && vqt.StampTime <= endTime) { if (this.isGood(vqt)) goodCount++; else if (this.isBad(vqt)) badCount++; else unCertain++; if (vqt.Value != null) { var val = this.GetNumber(vqt); if (minVqt == null || val < this.GetNumber(minVqt)) minVqt = vqt; if (maxVqt == null || val > this.GetNumber(maxVqt)) maxVqt = vqt; if (prevVQT && prevVQT.Value != null) { var dt = (vqt.StampTime - prevVQT.StampTime); sum += 0.5 * (val + this.GetNumber(prevVQT)) * dt; det += dt; } } prevVQT = vqt; } else if (vqt.StampTime < begTime) prevVQT = vqt; } } if (det != 0.0) avg = sum / det; else avg = null; var fix = false; var bIsBoolen = false; if (minVqt) { if (this.isString(minVqt) || this.isBoolen(minVqt)) { if (this.options.stepLine == null) this.setStepLine(true, true); } if (isNaN(min)) { if (this.isBoolen(maxVqt)) min = -1; else min = this.GetNumber(minVqt); } else if (!this.options.lockRange && (this.commAxis == null || this.commAxis.length == 0)) { if (min > this.GetNumber(minVqt)) { min = this.GetNumber(minVqt); fix = true; } } } if (maxVqt) { if (this.isString(maxVqt) || this.isBoolen(maxVqt)) { if (this.options.stepLine == null) this.setStepLine(true, true); } if (isNaN(max)) { if (this.isBoolen(maxVqt)) max = 5; else max = this.GetNumber(maxVqt); } else if (!this.options.lockRange && (this.commAxis == null || this.commAxis.length == 0)) { if (max < this.GetNumber(maxVqt)) { max = this.GetNumber(maxVqt); fix = true; } } } /*if (isNaN(min)) { if (!isNaN(max)) { if(maxVqt && this.isBoolen(maxVqt)) min = max - 4; else min = max - 0.1 * Math.abs(max); } else min = 0; } if (isNaN(max)) { if (!isNaN(min)) { if (minVqt && this.isBoolen(minVqt)) max = min + 4; else max = min + 0.1 * Math.abs(min); } else max = 1; } if (min == max) { if ((minVqt && this.isBoolen(minVqt)) || (maxVqt && this.isBoolen(maxVqt))) { min--; max++; } else max = min + 0.1 * Math.abs(min); }*/ /*Modify*/ /*if (this.rageMin == null || this.rageMax == null || fix) { if ((minVqt && this.isBoolen(minVqt)) || (maxVqt && this.isBoolen(maxVqt))) { if (fix) { min = -1; max = 5; } } else { min -= 0.2 * Math.abs(max - min); var saveMax = max; max += 20 * Math.abs(max - min); if (max > 2000.0) max = saveMax + 0.2 * Math.abs(saveMax - min); } } this.setRange(min, max); */ // 自由量程 min = this.GetNumber(minVqt); max = this.GetNumber(maxVqt); (function () { var diff = Math.abs(max - min); if (diff === 0 && avg !== 0) { diff = avg * 0.2; } else if (diff === 0 && avg === 0) { diff = 250; } min = min - diff * 0.2; max = max + diff * 0.2; })(); // 自由量程 if (this.rtChart && this.rtChart.options && this.rtChart.options.freeRange) { this.setRange(min, max); } else { // 固定量程 min = this.rageMin || 0; max = this.rageMax || 1000; this.setRange(this.rageMin, this.rageMax); } if (this.avg != avg) { this.avgChanged = true; this.rtChart.UpdateDataPan((this.avg == null || avg == null) ? true : false); this.avg = avg; this.rtChart._updateList(this.rowId, "平均值", this.getAVGList()); if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "avg" && !(this.requestLogin === true)) this.rtChart.UpdateTooltip(this.getAVGTooltip()); } if (this.minVqt != minVqt) { this.minChanged = true; this.rtChart.UpdateDataPan((this.minVqt == null || minVqt == null) ? true : false); this.minVqt = minVqt; if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "minVQT" && !(this.requestLogin === true)) this.rtChart.UpdateTooltip(this.getMinVQTTooltip()); this.rtChart._updateList(this.rowId, "最小值", this.getMinVQTList()); } if (this.maxVqt != maxVqt) { this.maxChanged = true; this.rtChart.UpdateDataPan((this.maxVqt == null || maxVqt == null) ? true : false); this.maxVqt = maxVqt; if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "maxVQT" && !(this.requestLogin === true)) this.rtChart.UpdateTooltip(this.getMaxVQTTooltip()); this.rtChart._updateList(this.rowId, "最大值", this.getMaxVQTList()); } if (this.maxVqt == null && this.minVqt == null) this.setHisStatus("nodata", "查询不到有效的历史数据"); this.updateDataReader(); } }, drawTrendLine: function (ctx, begTime, endTime, gw, gh, timeScale, shadowOffset) { if (!this.hisData || !this.hisData.length || !this.options.drawLine || this.rageMax == null || this.rageMin == null || this.rageMin == this.rageMax) return; var bStep = this.options.stepLine === true; if (bStep) ctx.lineJoin = 'miter'; else ctx.lineJoin = 'round'; if (shadowOffset == null) shadowOffset = 0; ctx.beginPath(); if (!shadowOffset) { ctx.lineWidth = (this.options.penWidth || 1); ctx.strokeStyle = this.options.penColor; } else ctx.lineWidth = (this.options.penWidth || 1) + 3; var yScale = -gh / (this.rageMax - this.rageMin); var yBase = gh; var bPrev = false; var x, y,px,py; var len = this.hisData.length; for (var i = 0; i < len; i++) { var vqt = this.hisData[i]; if (vqt != null && vqt.Value != null) { x = Math.floor((vqt.StampTime - begTime) * timeScale); py = y; y = Math.floor(yBase + (this.GetNumber(vqt) - this.rageMin) * yScale) + shadowOffset; if (bPrev) { if (!bStep) ctx.lineTo(x, y); else { ctx.lineTo(x + shadowOffset / 2, py); ctx.lineTo(x + shadowOffset / 2, y); } } else ctx.moveTo(x, y); if (this.options.drawTag) { ctx.arc(x, y, 4, 0, 2 * Math.PI, false); ctx.moveTo(x - 4, y ); ctx.lineTo(x + 4, y ); ctx.moveTo(x, y - 4); ctx.lineTo(x, y + 4); ctx.moveTo(x, y); } bPrev = true; } else { if (this.options.drawTag) { x = Math.floor((vqt.StampTime - begTime) * timeScale); y = Math.floor(yBase + 0,5*(this.rageMax - this.rageMin) * yScale) + shadowOffset; ctx.moveTo(x - 4, y - 4); ctx.lineTo(x + 4, y + 4); ctx.moveTo(x - 4, y + 4); ctx.lineTo(x + 4, y - 4); ctx.arc(x, y, 6, 0, 2 * Math.PI, false); ctx.moveTo(x, y); } bPrev = false; } if (vqt.StampTime > endTime) break; } ctx.stroke(); }, drawThumbsTrendLine: function (ctx, begTime, endTime, gh,gt, h, timeScale) { if (!this.hisData || !this.hisData.length || !this.options.drawLine || this.rageMax == null || this.rageMin == null || this.rageMin == this.rageMax) return; ctx.strokeStyle = this.options.penColor; var bStep = this.options.stepLine === true; if (bStep) ctx.lineJoin = 'miter'; else ctx.lineJoin = 'round'; ctx.beginPath(); var scale = h/gh; var yScale = -gh * scale / (this.rageMax - this.rageMin); var yBase = gt + h ; var bPrev = false; var x, y, py; var len = this.hisData.length; for (var i = 0; i < len; i++) { var vqt = this.hisData[i]; if (vqt != null && vqt.value != null) { x = Math.floor((vqt.StampTime - begTime) * timeScale); py = y; y = Math.floor(yBase + (this.GetNumber(vqt) - this.rageMin) * yScale); if (bPrev) { if (!bStep) ctx.lineTo(x, y); else { ctx.lineTo(x , py); ctx.lineTo(x , y); } } else ctx.moveTo(x, y); bPrev = true; } else bPrev = false; } ctx.stroke(); } }; TrendColor.prototype = { scale: function (rf, gf, bf, af) { var x = 4; while (-1 < --x) { if (!(arguments[x] === void 0)) this[this.rgba[x]] *= arguments[x]; } return this.normalize(); }, alpha: function (alpha) { if (!(alpha === void 0) && !(alpha === null)) { this.a = alpha; } return this.normalize(); }, clone: function () { return new TrendColor(this.r, this.b, this.g, this.a); }, limit: function (val, minVal, maxVal) { return Math.max(Math.min(val, maxVal), minVal); }, normalize: function () { var limit = this.limit; this.r = limit(parseInt(this.r, 10), 0, 255); this.g = limit(parseInt(this.g, 10), 0, 255); this.b = limit(parseInt(this.b, 10), 0, 255); this.a = limit(this.a, 0, 1); return this; }, distance: function (color) { if (!color) return; color = new TrendColor.parse(color); var dist = 0, x = 3; while (-1 < --x) { dist += Math.abs(this[this.rgba[x]] - color[this.rgba[x]]); } return dist; }, toString: function () { return (this.a >= 1.0) ? 'rgb(' + [this.r, this.g, this.b].join(',') + ')' : 'rgba(' + [this.r, this.g, this.b, this.a].join(',') + ')'; }, toRGBAString: function () { return 'rgba(' + [this.r, this.g, this.b, this.a].join(',') + ')'; }, contrast: function () { var test = 1 - (0.299 * this.r + 0.587 * this.g + 0.114 * this.b) / 255; return (test < 0.5 ? '#000000' : '#ffffff'); } }; })(jQuery);