标签:style blog http color os io 使用 ar for
电信网管系统中,设备状态信息的实时展示非常重要,通常会挂载一堆图标来展示状态或告警信息,图标的信息量有限,有时需要更详细的面板,甚至以图表的形式展现,本文将结合最近客户提到的需求,使用 Qunee1.6 beta版本,实现拓扑图中设备信息的实时显示。var cpu = new Q.LabelUI("CPU"); cpu.position = {x: 27, y: 47}; cpu.anchorPosition = Q.Position.RIGHT_MIDDLE; var cpuBar = new BarUI(); cpuBar.position = {x: 30, y: 47}; cpuBar.anchorPosition = Q.Position.LEFT_MIDDLE; node.addUI(cpu); node.addUI(cpuBar, { property : "cpu", propertyType : Q.Consts.PROPERTY_TYPE_CLIENT, bindingProperty : "data" }); node.set("cpu", 0.56);实际使用中我们对函数做了封装,看起来会不太一样,下面是节点展开时的 ui 分布设置,主体为一个140 X 120的圆角矩形,上面分布多个文本,图标和柱状图
var w = 140, h = 120, r = 10; var shape = Q.Shapes.getRect(-w/2, -h/2, w, h, r, r); this.image = shape; var gradient = new Q.Gradient(Q.Consts.GRADIENT_TYPE_LINEAR, ["#F4F4F4", "#FFFFFF", "#DFDFDF", "#E9E9E9"]); gradient.angle = Math.PI / 2; this.setStyle(Q.Styles.SHAPE_FILL_GRADIENT, gradient); this.setStyle(Q.Styles.SHAPE_STROKE, 0); this.setStyle(Q.Styles.SHAPE_OUTLINE, 1); this.setStyle(Q.Styles.SHAPE_OUTLINE_STYLE, "#C9C9C9"); this.setStyle(Q.Styles.LAYOUT_BY_PATH, false); function addUIAt(node, ui, x, y, bindingProperty, value){ ui.syncSelection = false; ui.zIndex = 1; ui.position = {x: x, y: y}; ui.anchorPosition = Q.Position.LEFT_TOP; ui.fontSize = 10; var binding; if(bindingProperty){ binding = { property : bindingProperty, propertyType : Q.Consts.PROPERTY_TYPE_CLIENT, bindingProperty : "data" } } node.addUI(ui, binding); return ui; } var icon = new Q.ImageUI(image); icon.size = this.iconSize; addUIAt(this, icon, 15, 12, "icon").anchorPosition = Q.Position.CENTER_MIDDLE; addUIAt(this, new Q.LabelUI(name), 30, 5); addUIAt(this, new Q.LabelUI(id), 30, 22).color = "#D00"; addUIAt(this, new Q.LabelUI("CPU"), 27, 47).anchorPosition = Q.Position.RIGHT_MIDDLE; addUIAt(this, new Q.LabelUI("MEM"), 27, 65).anchorPosition = Q.Position.RIGHT_MIDDLE; addUIAt(this, new BarUI(), 30, 47, "cpu").anchorPosition = Q.Position.LEFT_MIDDLE; addUIAt(this, new BarUI(), 30, 65, "memory").anchorPosition = Q.Position.LEFT_MIDDLE; addUIAt(this, new Q.LabelUI("Incoming:"), 71, 90).anchorPosition = Q.Position.RIGHT_MIDDLE; addUIAt(this, new Q.LabelUI("Outgoing:"), 71, 106).anchorPosition = Q.Position.RIGHT_MIDDLE; var ui = addUIAt(this, new Q.LabelUI(), 75, 90, "incoming"); ui.anchorPosition = Q.Position.LEFT_MIDDLE; ui.color = "#C20"; ui = addUIAt(this, new Q.LabelUI(), 75, 106, "outgoing"); ui.anchorPosition = Q.Position.LEFT_MIDDLE; ui.color = "#C20";
Object.defineProperties(CustomServerNode.prototype, { showDetail: { get: function(){ return this._showDetail; }, set: function(show){ if(this._showDetail == show){ return; } this._showDetail = show; this.image = show ? this.shape : this.get("image"); this.name = show ? "双击合并" : (this.get("name") + "\n" + this.get("id")); var uis = this.bindingUIs; if(uis){ uis.forEach(function(ui){ ui.ui.visible = show; }) this.invalidate(); } } } })
graph.ondblclick = function(evt){ var element = evt.getData(); if(element){ element.showDetail = !element.showDetail; } }
标签:style blog http color os io 使用 ar for
原文地址:http://my.oschina.net/nosand/blog/310298