📄 gauge.ie.js
字号:
/* * Bindows 1.01 * http://www.bindows.net/ * Copyright (c) 2003-2004 MB Technologies * * Bindows(tm) belongs to MB Technologies (Georgia, USA). All rights reserved. * You are not allowed to copy or modify this code. Commercial use requires * license. */function BiGauge(){ BiComponent.call(this); this._rangeModel = new BiRangeModel(); this.setHtmlProperty("coordsize", "1000 1000"); this._rangeModel.addEventListener("change", this._onchange, this); this.setCursor("default"); this._sections = []; this._minorTicks = new BiGaugeMinorTicks(this); this._majorTicks = new BiGaugeMajorTicks(this); this._plate = new BiGaugePlate(this); this._warningSection = new BiGaugeSection(this, 90, 100); this._needle = new BiGaugeNeedle(this); this._labels = new BiGaugeLabels(this); this._title = new BiGaugeTitle(this); this._warningSection.setOpacity(0.75); this.add(this._plate); this.add(this._warningSection); this.add(this._minorTicks); this.add(this._majorTicks); this.add(this._labels); this.add(this._title); this.add(this._needle);}var _p = BiGauge.prototype = new BiComponent;_p._className = "BiGauge";_p._minimumAngle = -135;_p._maximumAngle = 135;_p._majorTickInterval = 10;_p._minorTickInterval = 1;_p._labelInterval = 20;_p._warningValue = 90;_p._tagName = "v:group";_p._showLabels = true;_p._showMajorTicks = true;_p._showMinorTicks = true;_p._showWarningSection = true;_p._showTitle = false;_p.add = function(oChild, oBefore){ BiComponent.prototype.add.call(this, oChild, oBefore); if (oChild instanceof BiGaugeSection) { if (oBefore instanceof BiGaugeSection) this._sections.insertBefore(oChild, oBefore); else this._sections.push(oChild); }};_p.remove = function(oChild){ BiComponent.prototype.add.call(this, oChild, oBefore); if (oChild instanceof BiGaugeSection) this._sections.remove(oChild); return oChild;};BiGauge.prototype.getSections = function(){ return this._sections;} ;BiGauge.prototype.getPlate = function(){ return this._plate;} ;BiGauge.prototype.getMinorTicks = function(){ return this._minorTicks;} ;BiGauge.prototype.getMajorTicks = function(){ return this._majorTicks;} ;BiGauge.prototype.getNeedle = function(){ return this._needle;} ;BiGauge.prototype.getTitle = function(){ return this._title;} ;BiGauge.prototype.getLabels = function(){ return this._labels;} ;_p.setPlate = function(oPlate){ this.add(oPlate, this._plate); this._plate = oPlate;};_p.setMinorTicks = function(oTicks){ this.add(oTicks, this._minorTicks); this._minorTicks = oTicks;};_p.setMajorTicks = function(oTicks){ this.add(oTicks, this._majorTicks); this._majorTicks = oTicks;};_p.setNeedle = function(oNeedle){ this.add(oNeedle, this._needle); this._needle = oNeedle;};_p.setWarningSection = function(oSection){ this.add(oSection, this._warningSextion); this._warningSection = oSection;};_p.setTitle = function(oTitle){ this.add(oTitle, this._title); this._title = oTitle;};_p.setLabels = function(oLabels){ this.add(oLabels, this._labels); this._labels = oLabels;};_p.setValue = function(nValue){ this._rangeModel.setValue(nValue);} ;_p.getValue = function(){ return this._rangeModel.getValue();} ;_p.setMaximum = function(nMaximum){ this._rangeModel.setMaximum(nMaximum); if (this._warningSection) this._warningSection.setEndValue(nMaximum); this._updateAll();};_p.getMaximum = function(){ return this._rangeModel.getMaximum();} ;_p.setMinimum = function(nMinimum){ this._rangeModel.setMinimum(nMinimum); this._updateAll();};_p.getMinimum = function(){ return this._rangeModel.getMinimum();} ;_p.setWarningValue = function(n){ if (this._warningValue != n) { this._warningValue = n; if (this._warningValue) this._warningSection.setStartValue(n); }};BiGauge.prototype.getWarningValue = function(){ return this._warningValue;} ;_p.setShowLabels = function(b){ if (this._showLabels != b) { this._showLabels = b; this._labels.setVisible(b); }};BiGauge.prototype.getShowLabels = function(){ return this._showLabels;} ;_p.setShowTitle = function(b){ this._showTitle = b; this._title.setVisible(b);};BiGauge.prototype.getShowTitle = function(){ return this._showTitle;} ;_p.setShowMajorTicks = function(b){ this._showMajorTicks = b; this._majorTicks.setVisible(b);};BiGauge.prototype.getShowMajorTicks = function(){ return this._showMajorTicks;} ;_p.setShowMinorTicks = function(b){ if (this._showMinorTicks != b) { this._showMinorTicks = b; this._minorTicks.setVisible(b); }};BiGauge.prototype.getShowMinorTicks = function(){ return this._showMinorTicks;} ;_p.setShowWarningSection = function(b){ if (this._showWarningSection != b) { this._showWarningSection = b; if (this._warningSection) this._warningSection.setVisible(b); }};BiGauge.prototype.getShowWarningSection = function(){ return this._showWarningSection;} ;_p.setLabelInterval = function(n){ if (this._labelInterval != n) { this._labelInterval = n; this._labels._update(); }};BiGauge.prototype.getLabelInterval = function(){ return this._labelInterval;} ;_p.setMajorTickInterval = function(n){ if (this._majorTickInterval != n) { this._majorTickInterval = n; this._majorTicks._update(); }};BiGauge.prototype.getMajorTickInterval = function(){ return this._majorTickInterval;} ;_p.setMinorTickInterval = function(n){ if (this._minorTickInterval != n) { this._minorTickInterval = n; this._minorTicks._update(); }};BiGauge.prototype.getMinorTickInterval = function(){ return this._minorTickInterval;} ;_p.setMinimumAngle = function(n){ if (this._minimumAngle != n) { this._minimumAngle = n; this._updateAll(); }};BiGauge.prototype.getMinimumAngle = function(){ return this._minimumAngle;} ;_p.setMaximumAngle = function(n){ if (this._maximumAngle != n) { this._maximumAngle = n; this._updateAll(); }};BiGauge.prototype.getMaximumAngle = function(){ return this._maximumAngle;} ;_p._updateAll = function(){ this._labels._update(); this._majorTicks._update(); this._minorTicks._update(); this._positionNeedle() this._positionSections();};_p._positionNeedle = function(){ this._needle.setValue(this.getValue());} ;_p._positionSections = function(){ var s; for (var i = 0; i < this._sections.length; i++) { s = this._sections[i]; s.setStartValue(s.getStartValue()); s.setEndValue(s.getEndValue()); }};_p._valueToAngle = function(n){ return (n - this.getMinimum()) / (this.getMaximum() - this.getMinimum()) * (this._maximumAngle - this._minimumAngle) + this._minimumAngle;} ;_p._getTickPath = function(nValue, r1, r2){ var v = this._valueToAngle(nValue); var vr = v / 180 * Math.PI var x1 = r1 * Math.sin(vr); var y1 = r1 * Math.cos(vr); var x2 = r2 * Math.sin(vr); var y2 = r2 * Math.cos(vr); x1 = Math.round(500 + x1); y1 = Math.round(500 - y1); x2 = Math.round(500 + x2); y2 = Math.round(500 - y2); return "m" + x1 + "," + y1 + "l" + x2 + "," + y2;};_p.dispose = function(){ if (this._disposed) return; BiComponent.prototype.dispose.call(this); this._sections = null; this._plate = null; this._needle = null; this._majorTicks = null; this._minorTicks = null; this._labels = null;};_p._onchange = function(e){ this._positionNeedle();} ;function BiGaugeSection(oGauge, nStart, nEnd){ BiComponent.call(this); this._gauge = oGauge; this.setZIndex(0); var r = 425; this.setSize(r * 2, r * 2); this.setLocation(500 - r, 500 - r); this.setColor("red"); this.setStartValue( typeof nStart == "number" ? nStart : 90); this.setEndValue( typeof nEnd == "number" ? nEnd : 100); this.setHtmlProperty("filled", false); this._stroke = new BiComponent; this._stroke._tagName = "v:stroke"; this.add(this._stroke);}var _p = BiGaugeSection.prototype = new BiComponent;_p._className = "BiGaugeSection";_p._tagName = "v:arc";_p._startValue = 90;_p._endValue = 100;_p._color = null;_p.setColor = function(sColor){ this._color = sColor; this.setHtmlProperty("strokecolor", sColor);};BiGaugeSection.prototype.getColor = function(){ return this._color;} ;_p.setStartValue = function(n){ this._startValue = n; var g = this.getGauge(); n = Math.min(g.getMaximum(), Math.max(g.getMinimum(), n)); this.setHtmlProperty("startangle", g._valueToAngle(n));};_p.setEndValue = function(n){ this._endValue = n; var g = this.getGauge(); n = Math.min(g.getMaximum(), Math.max(g.getMinimum(), n)); this.setHtmlProperty("endangle", g._valueToAngle(n));};BiGaugeSection.prototype.getStartValue = function(){ return this._startValue;} ;BiGaugeSection.prototype.getEndValue = function(){ return this._endValue;} ;BiGaugeSection.prototype.getGauge = function(){ return this._gauge;} ;_p.layoutComponent = function(){ BiComponent.prototype.layoutComponent.call(this); this._resizeNonScalable();};_p.layoutComponentX = function(){ BiComponent.prototype.layoutComponentX.call(this); this._resizeNonScalable();};_p.layoutComponentY = function(){ BiComponent.prototype.layoutComponentY.call(this); this._resizeNonScalable();};_p._resizeNonScalable = function(){ if (!this.getCreated()) return; var cw = this.getGauge().getClientWidth(); var ch = this.getGauge().getClientHeight(); var s = Math.min(cw, ch); try { this._element.stroke.weight = s / 45; } catch (ex) { this.setHtmlProperty("strokeweight", s / 45); }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -