From db534d98d3cc95b3949fee9b9f929c697b650c09 Mon Sep 17 00:00:00 2001
From: 81041 <81041@DESKTOP-025NVD9>
Date: 星期五, 27 十二月 2019 16:11:10 +0800
Subject: [PATCH] Merge branch 'dev_lxw' of http://whyclxw@118.89.139.230:10101/r/~whyclxw/Device_Manage.git into dev_lxw

---
 Device_Manage/WebRoot/js/common_functions.js |  179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 179 insertions(+), 0 deletions(-)

diff --git a/Device_Manage/WebRoot/js/common_functions.js b/Device_Manage/WebRoot/js/common_functions.js
index 48acde1..96b66b1 100644
--- a/Device_Manage/WebRoot/js/common_functions.js
+++ b/Device_Manage/WebRoot/js/common_functions.js
@@ -481,4 +481,183 @@
         }
     }
     return equal;
+};
+
+// F2灏佽
+function FGraph(el, type) {
+    this.id = el.getAttribute("id");
+    this.minMax = {
+        min: 0,
+        max: 0
+    };
+    this.colors = {
+        min: 'red',
+        max: 'green',
+        normal: 'blue'
+    };
+    this.chart = "";
+    this.txtShapes = {
+        show: true,
+        list: []
+    };
+    if (this.id) {
+        this._init(this.id, type);
+    } else {
+        this._init(null, type);
+    }
+};
+
+// 鍒濆鍖�
+FGraph.prototype._init = function (id, type) {
+    var self = this;
+    // 鍒涘缓 Chart 瀵硅薄
+    this.chart = new F2.Chart({
+        id: id,
+        pixelRatio: window.devicePixelRatio, // 鎸囧畾鍒嗚鲸鐜�
+        syncY: true,
+        animate: false
+    });
+
+    // 璁剧疆x杞寸嚎
+    this.chart.axis("x", {
+        line: {
+            lineWidth: 1,
+            stroke: '#bbb',
+            top: true // 灞曠ず鍦ㄦ渶涓婂眰
+        }
+    });
+    // 璁剧疆y杞寸嚎
+    this.chart.axis("y", {
+        line: {
+            lineWidth: 1,
+            stroke: '#bbb',
+            top: true // 灞曠ず鍦ㄦ渶涓婂眰
+        },
+        grid: {
+            lineWidth: 1,
+            stroke: '#bbb'
+        }
+    });
+
+    // 璁剧疆鎻愮ず妗�
+    this.chart.tooltip({
+        alwaysShow: false
+    });
+
+    // 杞藉叆鏁版嵁婧�
+    this.chart.source([]);
+
+    // 璁剧疆鏈�澶у�煎拰鏈�灏忓��
+    this.setMinMax([]);
+
+    // 璁剧疆鍥捐〃绫诲瀷
+    this._setType(type);
+
+    // 涓嶆樉绀簂egend
+    this.chart.legend(false);
+
+    // 娓叉煋鍥捐〃
+    this.chart.render();
+};
+// 璁剧疆鍥捐〃绫诲瀷
+FGraph.prototype._setType = function (type) {
+    var self = this;
+    // 鏍规嵁绫诲瀷璁剧疆鍥捐〃
+    switch (type) {
+        case 'line':
+            this.chart.line().position('x*y');
+            // 涓嶆樉绀烘枃鏈�
+            this.txtShapes.show = false;
+            break;
+        default:
+            // 璁剧疆棰滆壊
+            this.chart.interval().position('x*y').color('x*y', function (x, y) {
+                var minMax = self.minMax;
+                var colors = self.colors;
+                var color = colors.normal;
+                if (y == minMax.min) {
+                    color = colors.min;
+                } else if (y == minMax.max) {
+                    color = colors.max;;
+                }
+                return color;
+            });
+            break;
+    }
+};
+// 鏇存柊鏁版嵁
+FGraph.prototype.changeData = function (data) {
+    // 璁剧疆鏈�澶у�煎拰鏈�灏忓��
+    this.setMinMax(data);
+    // 鏇存敼鏁版嵁
+    this.chart.changeData(data);
+};
+
+// 璁剧疆鏂囨湰
+FGraph.prototype._addTxtShape = function (data) {
+    //  鍒ゆ柇鏄惁鏄剧ず鏂囨湰
+    if (!this.txtShapes.show) {
+        return;
+    }
+    var self = this;
+    var chart = this.chart;
+    // 绉婚櫎鏂囨湰
+    this._txtShapesDestory();
+    // 缁樺埗鏌辩姸鍥炬枃鏈�
+    var offset = -5;
+    var canvas = chart.get('canvas');
+    var group = canvas.addGroup();
+    data.forEach(function (obj) {
+        var point = chart.getPosition(obj);
+        var text = group.addShape('text', {
+            attrs: {
+                x: point.x,
+                y: point.y + offset,
+                text: obj.y,
+                textAlign: 'center',
+                textBaseline: 'bottom',
+                fill: '#808080'
+            }
+        });
+        self.txtShapes.list.push(text);
+    });
+};
+// 淇敼澶у皬
+FGraph.prototype.changeSize = function (width, height) {
+    width = width ? width : null;
+    height = height ? height : null;
+    this.chart.changeSize(width, height);
+};
+
+// 鏍规嵁data鐨勫�艰幏鍙栨渶澶у�煎拰鏈�灏忓��
+FGraph.prototype.setMinMax = function (data) {
+    var rs = {
+        min: 0,
+        max: 0
+    };
+    // 璁剧疆data绗竴涓�煎埌rs涓�
+    if (data.length != 0) {
+        rs.min = data[0].y;
+        rs.max = data[0].y;
+    }
+    // 閬嶅巻data鐨勫��
+    for (var i = 1; i < data.length; i++) {
+        var _data = data[i];
+        // 璁剧疆鏈�澶у�煎拰鏈�灏忓��
+        rs.min = rs.min > _data.y ? _data.y : rs.min;
+        rs.max = rs.max < _data.y ? _data.y : rs.max;
+    }
+    this.minMax = rs;
+};
+// 閿�姣乼xtShapes
+FGraph.prototype._txtShapesDestory = function () {
+    var txtShapes = this.txtShapes.list;
+    // 閬嶅巻txtShapes
+    for (var i = 0; i < txtShapes.length; i++) {
+        var txtShape = txtShapes[i];
+        // 閿�姣�
+        txtShape.destroy();
+    }
+    // 閲嶇疆鏁扮粍
+    this.txtShapes.list = [];
 };
\ No newline at end of file

--
Gitblit v1.9.1