dcim-topology2d 2.0.2 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/chart-diagram/index.d.ts +1 -1
  2. package/chart-diagram/index.js +1 -1
  3. package/chart-diagram/src/echarts/index.js +6 -6
  4. package/chart-diagram/src/register.js +2 -2
  5. package/chart-diagram/src/utils/changeOptions.d.ts +3 -0
  6. package/chart-diagram/src/utils/changeOptions.js +56 -0
  7. package/chart-diagram/src/utils/conversion.js +22 -37
  8. package/chart-diagram/src/utils/render.d.ts +1 -0
  9. package/chart-diagram/src/utils/render.js +17 -0
  10. package/core/src/common.js +81 -8
  11. package/core/src/core.js +58 -17
  12. package/core/src/divLayer.js +1 -1
  13. package/core/src/element/select.d.ts +2 -2
  14. package/core/src/element/select.js +92 -57
  15. package/core/src/element/tab.js +7 -10
  16. package/core/src/healps/changeData.js +20 -6
  17. package/core/src/middles/nodes/formselect.js +26 -12
  18. package/core/src/middles/nodes/iframe.js +5 -5
  19. package/core/src/models/pen.js +2 -50
  20. package/core/src/options.d.ts +1 -0
  21. package/core/src/options.js +2 -1
  22. package/core/src/preview.js +6 -1
  23. package/core/src/store/data.d.ts +70 -19
  24. package/core/src/store/data.js +88 -34
  25. package/core/src/utils/assignment.d.ts +1 -1
  26. package/core/src/utils/assignment.js +53 -23
  27. package/core/src/utils/construction.d.ts +2 -1
  28. package/core/src/utils/construction.js +2 -1
  29. package/core/src/utils/conversion.d.ts +1 -1
  30. package/core/src/utils/conversion.js +14 -20
  31. package/core/src/utils/onmousevent.d.ts +1 -1
  32. package/core/src/utils/onmousevent.js +4 -5
  33. package/core/src/utils/params.d.ts +2 -7
  34. package/core/src/utils/params.js +19 -87
  35. package/myShape-diagram/index.js +196 -0
  36. package/package.json +1 -1
  37. package/store/actions.js +1 -17
  38. package/store/clear.js +0 -62
  39. package/core/src/poll.js +0 -37
  40. package/myShape-diagram/myShape.js +0 -196
  41. /package/myShape-diagram/{myShape.ts → index.ts} +0 -0
@@ -1,46 +1,15 @@
1
- import { syncMqttData, clearMqttParams } from '../store';
2
- export function categoryDataParams(data) {
3
- clearMqttParams();
4
- getParams(data);
5
- }
6
- export function setParams(assetId) {
7
- const params = {
8
- tagIds: syncMqttData.params.tagIds.join(","),
9
- assetIds: syncMqttData.params.assetIds.join(","),
10
- areaIds: syncMqttData.params.areaIds.join(","),
11
- routingkey: syncMqttData.params.routingkey,
12
- echart: syncMqttData.params.tagEcharts.join(","),
13
- echartData: syncMqttData.params.echartData
14
- }
15
- if (syncMqttData.params.echartAssemblyData && syncMqttData.params.echartAssemblyData.length) {
16
- params.echartAssemblyData = syncMqttData.params.echartAssemblyData;
17
- }
18
- if(assetId) {
19
- params.varValueIds = syncMqttData.params.varVaule.join(",");
20
- }else {
21
- if(syncMqttData.params.assetIds.length && syncMqttData.params.varVaule.length) {
22
- const assetId = syncMqttData.params.assetIds[syncMqttData.params.assetIds.length -1];
23
- for(let va = 0; va < syncMqttData.params.varVaule.length; va++) {
24
- syncMqttData.params.varVaule[va] = `${assetId}_${syncMqttData.params.varVaule[va]}`;
25
- }
26
- params.varValueIds = syncMqttData.params.varVaule.join(",");
27
- }else {
28
- params.varVaule = syncMqttData.params.varVaule.join(",");
29
- }
30
- }
31
- return params;
32
- }
1
+ import {commonStore} from '../store';
33
2
  // 获取绑定数据的参数
34
- export function getParams(data) {
3
+ export function getParams(id, data) {
35
4
  data.map((item) => {
36
- filterParams(item);
5
+ filterParams(id, item);
37
6
  if (item.children && item.children.length) {
38
- getParams(item.children);
7
+ getParams(id, item.children);
39
8
  }
40
9
  });
41
10
  }
42
11
  // 过滤出参数
43
- export function filterParams(node) {
12
+ export function filterParams(id, node) {
44
13
  let tagIds = [];
45
14
  let kpiAddrs = [];
46
15
  let assetIds = [];
@@ -48,7 +17,13 @@ export function filterParams(node) {
48
17
  let tagEcharts = [];
49
18
  let echartData = [];
50
19
  let varVaule = [];
51
- let isMqttEventType = node.events.find((ev) => {return ev.type === 3});
20
+ let doorIds = [];
21
+ let isMqttEventType = false;
22
+ node.events.map((ev) => {
23
+ if(ev.value && ev.value === 'entranceGuard') doorIds.push(ev.params); // 门禁参数
24
+ if(ev.type === 3) isMqttEventType = true;
25
+ });
26
+ if(doorIds.length) commonStore[id].mqttParams.doorIds = [...commonStore[id].mqttParams.doorIds, ...doorIds];
52
27
  if(!isMqttEventType) return;
53
28
  if (node.data && Array.isArray(node.data) && node.data.length) {
54
29
  node.data.map((item) => {
@@ -72,54 +47,11 @@ export function filterParams(node) {
72
47
  if (node.data && Object.prototype.toString.call(node.data) === '[object Object]' && node.data.params && node.data.params.id) {
73
48
  echartData.push(node.data.params.id);
74
49
  }
75
- syncMqttData.params.tagIds = [...syncMqttData.params.tagIds, ...tagIds];
76
- syncMqttData.params.kpiAddrs = [...syncMqttData.params.kpiAddrs, ...kpiAddrs];
77
- syncMqttData.params.assetIds = [...syncMqttData.params.assetIds, ...assetIds];
78
- syncMqttData.params.areaIds = [...syncMqttData.params.areaIds, ...areaIds];
79
- syncMqttData.params.varVaule = [...syncMqttData.params.varVaule, ...varVaule];
80
- syncMqttData.params.tagEcharts = [...syncMqttData.params.tagEcharts, ...tagEcharts];
81
- syncMqttData.params.echartData = [...syncMqttData.params.echartData, ...echartData];
82
- }
83
- // 根据指标地址数据获取测点数据
84
- export function getTagIdsForKpiAddrs(data) {
85
- let tagIds = [];
86
- if (data && data.length > 0) {
87
- data.map((item) => {
88
- tagIds.push(item.tagId);
89
- })
90
- // syncMqttData.params.detailAssetData = data;
91
- }
92
- syncMqttData.params.tagIds = tagIds;
93
- syncMqttData.params.echartAssemblyData = data.echartAssemblyData;
94
- }
95
- // 获取绑定值类型参数
96
- export function getVarValueIdsForVarData(data) {
97
- const ids = [];
98
- if(data && data.length) {
99
- data.map((item) => {
100
- if(item.varVal) ids.push(item.assetVarIds);
101
- })
102
- }
103
- syncMqttData.params.varVaule = ids;
104
- }
105
- // 固定资产详情数据赋值
106
- export function renderForAssetPoperties(asset, data) {
107
- if(!(asset && Object.keys(asset).length)) return;
108
- data.map((node) => {
109
- if (node.data && Array.isArray(node.data) && node.data.length) {
110
- node.data.map((item) => {
111
- if (item.key === 'assetKey' && asset[item.value]) {
112
- if (['imgUrl', 'principleImg'].includes(item.value)) {
113
- node.text = '';
114
- node.image = `${syncMqttData.params.pathRewrite}${asset[item.value]}`;
115
- } else {
116
- node.text = asset[item.value];
117
- }
118
- }
119
- })
120
- }
121
- if (node.children && node.children.length) {
122
- renderForAssetPoperties(asset, node.children);
123
- }
124
- });
50
+ commonStore[id].mqttParams.tagIds = [...commonStore[id].mqttParams.tagIds, ...tagIds];
51
+ commonStore[id].mqttParams.kpiAddrs = [...commonStore[id].mqttParams.kpiAddrs, ...kpiAddrs];
52
+ commonStore[id].mqttParams.assetIds = [...commonStore[id].mqttParams.assetIds, ...assetIds];
53
+ commonStore[id].mqttParams.areaIds = [...commonStore[id].mqttParams.areaIds, ...areaIds];
54
+ commonStore[id].mqttParams.varVaule = [...commonStore[id].mqttParams.varVaule, ...varVaule];
55
+ commonStore[id].mqttParams.tagEcharts = [...commonStore[id].mqttParams.tagEcharts, ...tagEcharts];
56
+ commonStore[id].mqttParams.echartData = [...commonStore[id].mqttParams.echartData, ...echartData];
125
57
  }
@@ -0,0 +1,196 @@
1
+ // 源码版写法
2
+ import { registerNode } from '../core'
3
+
4
+ // 组件版写法和bundle一致
5
+ // window.Le5leTopology.registerNode
6
+
7
+ // 画骨架
8
+
9
+ function drawOuterLine(ctx, node) {
10
+ const R = Math.floor((node.rect.width - 6) / 2);
11
+ const r = Math.round((R * 1) / 2);
12
+
13
+ ctx.beginPath();
14
+ // 上半个圆形
15
+ ctx.arc(node.rect.x + R, node.rect.y + r, r, 0, Math.PI, true);
16
+ // 下半个圆形
17
+ const theta = Math.acos((r * 1.0) / R);
18
+ ctx.arc(
19
+ node.rect.x + R,
20
+ node.rect.y + node.rect.height - R,
21
+ R,
22
+ theta + Math.PI,
23
+ -theta,
24
+ true
25
+ ); // 逆时针
26
+ ctx.closePath();
27
+ ctx.stroke();
28
+ }
29
+
30
+ // 画底色
31
+ function drawBasic(ctx, node) {
32
+ const lingrad = ctx.createLinearGradient(
33
+ node.rect.x,
34
+ node.rect.y,
35
+ node.rect.width,
36
+ node.rect.height
37
+ );
38
+ lingrad.addColorStop(0, 'mediumvioletred');
39
+ lingrad.addColorStop(0.2, 'darkorange');
40
+ lingrad.addColorStop(0.4, 'gold');
41
+ lingrad.addColorStop(0.6, 'limegreen');
42
+ lingrad.addColorStop(0.8, 'navy');
43
+ lingrad.addColorStop(1, 'purple');
44
+ ctx.fillStyle = lingrad;
45
+ ctx.fill('evenodd');
46
+ }
47
+
48
+ function getYByValue(node, i) {
49
+ const R = Math.floor((node.rect.width - 6) / 2);
50
+ const r = Math.round((R * 1) / 2);
51
+
52
+ const min = 0;
53
+ const max = 40;
54
+
55
+ // 刻度线总高度
56
+ const scale_height = node.rect.height - 2 * R - 2 * r;
57
+ // 0刻度线所在位置
58
+ const zero_scale_y = node.rect.height - 2 * R;
59
+ const dy_dtem = scale_height / (max - min);
60
+ return zero_scale_y - dy_dtem * node.value;
61
+ }
62
+
63
+ // 画刻度线
64
+ function drawScale(ctx, node) {
65
+ const min = 0;
66
+ const max = 40;
67
+ const R = Math.floor((node.rect.width - 6) / 2);
68
+ const r = Math.round((R * 1) / 2);
69
+
70
+ for (let i = min; i <= max; i++) {
71
+ // 画刻度线
72
+ const y = getYByValue(node, i);
73
+ ctx.beginPath();
74
+ ctx.moveTo(R + r, y);
75
+ if (i % 10 == 0) {
76
+ ctx.lineWidth = 2;
77
+ ctx.lineTo(R + r - (r * 2) / 3, y);
78
+ // ctx.font = "15px bold";
79
+ ctx.fillText(i + '', R + r, y + 6);
80
+ ctx.stroke();
81
+ } else {
82
+ ctx.lineWidth = 1;
83
+ if (i % 5 == 0) {
84
+ ctx.lineTo(R + r - r / 2, y);
85
+ } else {
86
+ ctx.lineTo(R + r - r / 3, y);
87
+ }
88
+ ctx.stroke();
89
+ }
90
+ }
91
+ }
92
+
93
+ /////////////////////
94
+ // end 以下代码不完整,代码来自网上改写,仅作参考
95
+ /////////////////////
96
+
97
+ // 自定义图形库绘画函数
98
+ export function thermometer(ctx, node) {
99
+ ctx.beginPath();
100
+
101
+ drawOuterLine(ctx, node);
102
+ drawBasic(ctx, node);
103
+ ctx.clearRect(
104
+ node.rect.x,
105
+ node.rect.y,
106
+ node.rect.width,
107
+ getYByValue(node, node.value)
108
+ );
109
+ drawOuterLine(ctx, node);
110
+ drawScale(ctx, node);
111
+ }
112
+
113
+ // 自定义图形库绘画函数
114
+ export function pool(ctx, node) {
115
+ var wr = node.borderRadius;
116
+ var hr = node.borderRadius;
117
+ if (node.borderRadius < 1) {
118
+ wr = node.rect.width * node.borderRadius;
119
+ hr = node.rect.height * node.borderRadius;
120
+ }
121
+ var r = wr < hr ? wr : hr;
122
+ if (node.rect.width < 2 * r) {
123
+ r = node.rect.width / 2;
124
+ }
125
+ if (node.rect.height < 2 * r) {
126
+ r = node.rect.height / 2;
127
+ }
128
+ ctx.beginPath();
129
+ ctx.strokeStyle = "rgba(0,0,0,.0)"
130
+ var value = (1-node.value) * (node.rect.height - node.lineWidth/2)
131
+ ctx.moveTo(node.rect.x + node.lineWidth/2, node.rect.y + value);
132
+ ctx.lineTo(node.rect.ex - node.lineWidth/2, node.rect.y + value);
133
+ ctx.arcTo(node.rect.ex - node.lineWidth/2, node.rect.y + node.rect.height - node.lineWidth/2, node.rect.x + node.lineWidth/2, node.rect.y + node.rect.height - node.lineWidth/2, r);
134
+ ctx.arcTo(node.rect.x + node.lineWidth/2, node.rect.y + node.rect.height - node.lineWidth/2, node.rect.x + node.lineWidth/2, node.rect.y, r);
135
+ ctx.lineTo(node.rect.x + node.lineWidth/2, node.rect.y + value);
136
+ ctx.closePath();
137
+ (node.fillStyle || node.bkType) && ctx.fill();
138
+ ctx.stroke();
139
+
140
+ ctx.beginPath();
141
+ ctx.strokeStyle = node.strokeStyle
142
+ ctx.lineWidth = node.lineWidth
143
+ ctx.moveTo(node.rect.x + node.rect.width, node.rect.y);
144
+ ctx.arcTo(node.rect.x + node.rect.width, node.rect.y + node.rect.height, node.rect.x, node.rect.y + node.rect.height, r);
145
+ ctx.arcTo(node.rect.x, node.rect.y + node.rect.height, node.rect.x, node.rect.y, r);
146
+ ctx.arcTo(node.rect.x, node.rect.y, node.rect.x + node.rect.width, node.rect.y, r);
147
+ // ctx.closePath();
148
+ (node.fillStyle || node.bkType);
149
+ ctx.stroke();
150
+ }
151
+
152
+ // 自定义图形库绘画函数
153
+ export function electricFan(ctx, node) {
154
+ var wwr = node.rect.width / 2;
155
+ var hwr = node.rect.height / 2;
156
+ var hwr = node.rect.height / 2;
157
+ var x0 = node.rect.x + node.rect.width /2
158
+ var y0 = node.rect.y + node.rect.height / 2
159
+ var withinRadius = wwr < hwr ? wwr : hwr;
160
+ ctx.beginPath();
161
+ ctx.lineWidth = node.lineWidth
162
+ ctx.arc(x0,y0,withinRadius,0,2*Math.PI);
163
+ ctx.closePath();
164
+ ctx.stroke();
165
+ ctx.beginPath();
166
+ ctx.lineWidth = 1;
167
+ var fanCount = node.fanCount;
168
+ for(var i = 0; i < fanCount; i++){
169
+ var fanAngle = 2 * Math.PI / fanCount * i;
170
+ var x1 = x0 - withinRadius*Math.sin(fanAngle);
171
+ var y1 = y0 - withinRadius*Math.cos(fanAngle);
172
+ var xr = x0 - withinRadius*Math.sin(fanAngle)/2;
173
+ var yr = y0 - withinRadius*Math.cos(fanAngle)/2;
174
+ ctx.moveTo(x0, y0);
175
+ ctx.lineTo(x1, y1);
176
+ ctx.arc(xr, yr, withinRadius/2, Math.PI / 2 - fanAngle,3 * Math.PI / 2 - fanAngle);
177
+ }
178
+ ctx.closePath();
179
+ (node.fillStyle || node.bkType) && ctx.fill();
180
+ ctx.stroke();
181
+ ctx.beginPath();
182
+ ctx.lineWidth = 3;
183
+ ctx.arc(x0,y0,withinRadius/5,0,2*Math.PI);
184
+ ctx.closePath();
185
+ (node.fillStyle || node.bkType) && ctx.fill();
186
+ ctx.stroke();
187
+ }
188
+
189
+ // 注册自定义图形库
190
+ export function registerMyShape() {
191
+ registerNode('electricFan', electricFan);
192
+ registerNode('pool', pool);
193
+ registerNode('thermometer', thermometer);
194
+ }
195
+
196
+ // src\views\data.ts 里面加载到工具栏,第一个就是此自定义图形库
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcim-topology2d",
3
- "version": "2.0.2",
3
+ "version": "2.0.5",
4
4
  "description": "",
5
5
  "main": "-",
6
6
  "scripts": {
package/store/actions.js CHANGED
@@ -1,17 +1 @@
1
- // element 交互过渡数据
2
- export const elementInteractivePoor = {};
3
- // echarts
4
- export const echartsDataPool = {}; // echarts Dom节点数据
5
- export const echartsOptionsPool = {}; // echarts options节点数据
6
- export const echartsRealDataPool = {}; // echarts 实时数据
7
-
8
- // tabs
9
- export const switchTabDataPool = {};
10
-
11
- // form
12
- export const tableDataPool = {};
13
- export const selectDataPool = {};
14
- export const selectRealDataPool = {};
15
-
16
- // iframe
17
- export const iframeDataPool = {};
1
+ export const plugsPool = {};
package/store/clear.js CHANGED
@@ -1,66 +1,4 @@
1
- import {
2
- echartsDataPool,
3
- echartsOptionsPool,
4
- echartsRealDataPool,
5
- switchTabDataPool,
6
- tableDataPool,
7
- selectDataPool,
8
- elementInteractivePoor,
9
- selectRealDataPool,
10
- iframeDataPool
11
- } from './actions';
12
1
  import {setEventListener} from "../core";
13
-
14
- export const clearDataPool = function (){
15
- for (let [key, node] of Object.entries(echartsDataPool)) {
16
- if(node) {
17
- clearInterval(node.timeTicket);
18
- if(node.chart) {
19
- node.chart.off('mouseover');
20
- node.chart.off('mouseout');
21
- node.chart.dispose();
22
- }
23
- if(node.div && node.div.parentNode) node.div.parentNode.removeChild(node.div);
24
- }
25
- delete echartsDataPool[key];
26
- }
27
- for (let key of Object.keys(echartsOptionsPool)) {
28
- delete echartsOptionsPool[key];
29
- }
30
- for (let key of Object.keys(echartsRealDataPool)) {
31
- delete echartsRealDataPool[key];
32
- }
33
- for (let key of Object.keys(switchTabDataPool)) {
34
- delete switchTabDataPool[key];
35
- }
36
- for (let key of Object.keys(tableDataPool)) {
37
- delete tableDataPool[key];
38
- }
39
- if(Object.keys(selectDataPool).length) {
40
- let dropdownEle = null,
41
- dropdownListEle = null;
42
- for (let [key, node] of Object.entries(selectDataPool)) {
43
- if(!dropdownEle) {
44
- dropdownEle = node.dom.selectDropdown;
45
- dropdownListEle = node.dom.selectDropdownUl;
46
- }
47
- if(node.dom.selectEle && node.dom.selectEle.parentNode) node.dom.selectEle.parentNode.removeChild(node.dom.selectEle);
48
- delete selectDataPool[key];
49
- }
50
- if(dropdownEle) dropdownEle.style.display = 'none';
51
- if(dropdownListEle) dropdownListEle.innerHTML = '';
52
- }
53
- for (let key of Object.keys(elementInteractivePoor)) {
54
- delete elementInteractivePoor[key];
55
- }
56
- for (let key of Object.keys(selectRealDataPool)) {
57
- delete selectRealDataPool[key];
58
- }
59
- for (let [key, node] of Object.entries(iframeDataPool)) {
60
- node.iframe.parentNode.removeChild(node.iframe);
61
- delete iframeDataPool[key];
62
- }
63
- }
64
2
  export const removeAllElement = function (){
65
3
  const documentDefineEle = document.querySelectorAll('.documentDefine');
66
4
  if(documentDefineEle) {
package/core/src/poll.js DELETED
@@ -1,37 +0,0 @@
1
- // 轮询
2
- var POLL = /** @class */ (function () {
3
- function POLL(data, message, val) {
4
- this.data = data;
5
- this.client = message;
6
- this.val = val;
7
- this.init();
8
- };
9
- POLL.prototype.init = function () {
10
- let topics = ''
11
- this.getPen(this.data.pens, topics, JSON.stringify(this.client))
12
- };
13
- POLL.prototype.getPen = function (pens, topics, message) {
14
- const _this = this;
15
- pens.forEach((pen)=>{
16
- if(pen.children != undefined){
17
- _this.getPen(pen.children, topics, message)
18
- }else{
19
- var item = pen;
20
- for (var _b = 0, _c = item.events; _b < _c.length; _b++) {
21
- var event_1 = _c[_b];
22
- // if (event_1.type === EventType.Poll) {
23
- if ((event_1.type ===3 && this.val === 'Mqtt') || (event_1.type ===4 && this.val === 'Poll')
24
- || (event_1.type ===5 && this.val === 'Poll1') || (event_1.type ===6 && this.val === 'Poll2')) {
25
- event_1.name = topics;
26
- if(message){
27
- item.doSocketMqtt(event_1, message.toString());
28
- }
29
- }
30
- }
31
- }
32
- })
33
- };
34
- return POLL;
35
- }());
36
- export { POLL };
37
- //# sourceMappingURL=mqtt.js.map
@@ -1,196 +0,0 @@
1
- // 源码版写法
2
- import { registerNode } from '../core'
3
-
4
- // 组件版写法和bundle一致
5
- // window.Le5leTopology.registerNode
6
-
7
- // 画骨架
8
-
9
- function drawOuterLine(ctx, node) {
10
- const R = Math.floor((node.rect.width - 6) / 2);
11
- const r = Math.round((R * 1) / 2);
12
-
13
- ctx.beginPath();
14
- // 上半个圆形
15
- ctx.arc(node.rect.x + R, node.rect.y + r, r, 0, Math.PI, true);
16
- // 下半个圆形
17
- const theta = Math.acos((r * 1.0) / R);
18
- ctx.arc(
19
- node.rect.x + R,
20
- node.rect.y + node.rect.height - R,
21
- R,
22
- theta + Math.PI,
23
- -theta,
24
- true
25
- ); // 逆时针
26
- ctx.closePath();
27
- ctx.stroke();
28
- }
29
-
30
- // 画底色
31
- function drawBasic(ctx, node) {
32
- const lingrad = ctx.createLinearGradient(
33
- node.rect.x,
34
- node.rect.y,
35
- node.rect.width,
36
- node.rect.height
37
- );
38
- lingrad.addColorStop(0, 'mediumvioletred');
39
- lingrad.addColorStop(0.2, 'darkorange');
40
- lingrad.addColorStop(0.4, 'gold');
41
- lingrad.addColorStop(0.6, 'limegreen');
42
- lingrad.addColorStop(0.8, 'navy');
43
- lingrad.addColorStop(1, 'purple');
44
- ctx.fillStyle = lingrad;
45
- ctx.fill('evenodd');
46
- }
47
-
48
- function getYByValue(node, i) {
49
- const R = Math.floor((node.rect.width - 6) / 2);
50
- const r = Math.round((R * 1) / 2);
51
-
52
- const min = 0;
53
- const max = 40;
54
-
55
- // 刻度线总高度
56
- const scale_height = node.rect.height - 2 * R - 2 * r;
57
- // 0刻度线所在位置
58
- const zero_scale_y = node.rect.height - 2 * R;
59
- const dy_dtem = scale_height / (max - min);
60
- return zero_scale_y - dy_dtem * node.value;
61
- }
62
-
63
- // 画刻度线
64
- function drawScale(ctx, node) {
65
- const min = 0;
66
- const max = 40;
67
- const R = Math.floor((node.rect.width - 6) / 2);
68
- const r = Math.round((R * 1) / 2);
69
-
70
- for (let i = min; i <= max; i++) {
71
- // 画刻度线
72
- const y = getYByValue(node, i);
73
- ctx.beginPath();
74
- ctx.moveTo(R + r, y);
75
- if (i % 10 == 0) {
76
- ctx.lineWidth = 2;
77
- ctx.lineTo(R + r - (r * 2) / 3, y);
78
- // ctx.font = "15px bold";
79
- ctx.fillText(i + '', R + r, y + 6);
80
- ctx.stroke();
81
- } else {
82
- ctx.lineWidth = 1;
83
- if (i % 5 == 0) {
84
- ctx.lineTo(R + r - r / 2, y);
85
- } else {
86
- ctx.lineTo(R + r - r / 3, y);
87
- }
88
- ctx.stroke();
89
- }
90
- }
91
- }
92
-
93
- /////////////////////
94
- // end 以下代码不完整,代码来自网上改写,仅作参考
95
- /////////////////////
96
-
97
- // 自定义图形库绘画函数
98
- export function thermometer(ctx, node) {
99
- ctx.beginPath();
100
-
101
- drawOuterLine(ctx, node);
102
- drawBasic(ctx, node);
103
- ctx.clearRect(
104
- node.rect.x,
105
- node.rect.y,
106
- node.rect.width,
107
- getYByValue(node, node.value)
108
- );
109
- drawOuterLine(ctx, node);
110
- drawScale(ctx, node);
111
- }
112
-
113
- // 自定义图形库绘画函数
114
- export function pool(ctx, node) {
115
- var wr = node.borderRadius;
116
- var hr = node.borderRadius;
117
- if (node.borderRadius < 1) {
118
- wr = node.rect.width * node.borderRadius;
119
- hr = node.rect.height * node.borderRadius;
120
- }
121
- var r = wr < hr ? wr : hr;
122
- if (node.rect.width < 2 * r) {
123
- r = node.rect.width / 2;
124
- }
125
- if (node.rect.height < 2 * r) {
126
- r = node.rect.height / 2;
127
- }
128
- ctx.beginPath();
129
- ctx.strokeStyle = "rgba(0,0,0,.0)"
130
- var value = (1-node.value) * (node.rect.height - node.lineWidth/2)
131
- ctx.moveTo(node.rect.x + node.lineWidth/2, node.rect.y + value);
132
- ctx.lineTo(node.rect.ex - node.lineWidth/2, node.rect.y + value);
133
- ctx.arcTo(node.rect.ex - node.lineWidth/2, node.rect.y + node.rect.height - node.lineWidth/2, node.rect.x + node.lineWidth/2, node.rect.y + node.rect.height - node.lineWidth/2, r);
134
- ctx.arcTo(node.rect.x + node.lineWidth/2, node.rect.y + node.rect.height - node.lineWidth/2, node.rect.x + node.lineWidth/2, node.rect.y, r);
135
- ctx.lineTo(node.rect.x + node.lineWidth/2, node.rect.y + value);
136
- ctx.closePath();
137
- (node.fillStyle || node.bkType) && ctx.fill();
138
- ctx.stroke();
139
-
140
- ctx.beginPath();
141
- ctx.strokeStyle = node.strokeStyle
142
- ctx.lineWidth = node.lineWidth
143
- ctx.moveTo(node.rect.x + node.rect.width, node.rect.y);
144
- ctx.arcTo(node.rect.x + node.rect.width, node.rect.y + node.rect.height, node.rect.x, node.rect.y + node.rect.height, r);
145
- ctx.arcTo(node.rect.x, node.rect.y + node.rect.height, node.rect.x, node.rect.y, r);
146
- ctx.arcTo(node.rect.x, node.rect.y, node.rect.x + node.rect.width, node.rect.y, r);
147
- // ctx.closePath();
148
- (node.fillStyle || node.bkType);
149
- ctx.stroke();
150
- }
151
-
152
- // 自定义图形库绘画函数
153
- export function electricFan(ctx, node) {
154
- var wwr = node.rect.width / 2;
155
- var hwr = node.rect.height / 2;
156
- var hwr = node.rect.height / 2;
157
- var x0 = node.rect.x + node.rect.width /2
158
- var y0 = node.rect.y + node.rect.height / 2
159
- var withinRadius = wwr < hwr ? wwr : hwr;
160
- ctx.beginPath();
161
- ctx.lineWidth = node.lineWidth
162
- ctx.arc(x0,y0,withinRadius,0,2*Math.PI);
163
- ctx.closePath();
164
- ctx.stroke();
165
- ctx.beginPath();
166
- ctx.lineWidth = 1;
167
- var fanCount = node.fanCount;
168
- for(var i = 0; i < fanCount; i++){
169
- var fanAngle = 2 * Math.PI / fanCount * i;
170
- var x1 = x0 - withinRadius*Math.sin(fanAngle);
171
- var y1 = y0 - withinRadius*Math.cos(fanAngle);
172
- var xr = x0 - withinRadius*Math.sin(fanAngle)/2;
173
- var yr = y0 - withinRadius*Math.cos(fanAngle)/2;
174
- ctx.moveTo(x0, y0);
175
- ctx.lineTo(x1, y1);
176
- ctx.arc(xr, yr, withinRadius/2, Math.PI / 2 - fanAngle,3 * Math.PI / 2 - fanAngle);
177
- }
178
- ctx.closePath();
179
- (node.fillStyle || node.bkType) && ctx.fill();
180
- ctx.stroke();
181
- ctx.beginPath();
182
- ctx.lineWidth = 3;
183
- ctx.arc(x0,y0,withinRadius/5,0,2*Math.PI);
184
- ctx.closePath();
185
- (node.fillStyle || node.bkType) && ctx.fill();
186
- ctx.stroke();
187
- }
188
-
189
- // 注册自定义图形库
190
- export function registerMyShape() {
191
- registerNode('electricFan', electricFan);
192
- registerNode('pool', pool);
193
- registerNode('thermometer', thermometer);
194
- }
195
-
196
- // src\views\data.ts 里面加载到工具栏,第一个就是此自定义图形库
File without changes