@operato/scene-legend 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- package/@types/global/index.d.ts +1 -0
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/assets/legend.png +0 -0
- package/dist/editors/editor-legend-status.d.ts +4 -0
- package/dist/editors/editor-legend-status.js +313 -0
- package/dist/editors/editor-legend-status.js.map +1 -0
- package/dist/editors/index.d.ts +5 -0
- package/dist/editors/index.js +11 -0
- package/dist/editors/index.js.map +1 -0
- package/dist/editors/property-editor-legend-status.d.ts +7 -0
- package/dist/editors/property-editor-legend-status.js +13 -0
- package/dist/editors/property-editor-legend-status.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/legend-item.d.ts +15 -0
- package/dist/legend-item.js +42 -0
- package/dist/legend-item.js.map +1 -0
- package/dist/legend.d.ts +40 -0
- package/dist/legend.js +177 -0
- package/dist/legend.js.map +1 -0
- package/dist/templates/index.d.ts +18 -0
- package/dist/templates/index.js +3 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/legend.d.ts +18 -0
- package/dist/templates/legend.js +19 -0
- package/dist/templates/legend.js.map +1 -0
- package/helps/scene/component/legend.ko.md +18 -0
- package/helps/scene/component/legend.md +18 -0
- package/helps/scene/component/legend.zh.md +20 -0
- package/helps/scene/images/legend-01.png +0 -0
- package/helps/scene/images/legend-02.png +0 -0
- package/package.json +63 -0
- package/src/editors/editor-legend-status.ts +339 -0
- package/src/editors/index.ts +11 -0
- package/src/editors/property-editor-legend-status.ts +17 -0
- package/src/index.ts +6 -0
- package/src/legend-item.ts +52 -0
- package/src/legend.ts +232 -0
- package/src/templates/index.ts +3 -0
- package/src/templates/legend.ts +19 -0
- package/test/basic-test.html +67 -0
- package/test/index.html +24 -0
- package/test/unit/test-legend.js +33 -0
- package/test/unit/util.js +22 -0
- package/things-scene.config.js +7 -0
- package/tsconfig.json +23 -0
- package/tsconfig.tsbuildinfo +1 -0
package/dist/legend.js
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
import { Component, Container, Model, TableLayout } from '@hatiolab/things-scene';
|
5
|
+
const NATURE = {
|
6
|
+
mutable: false,
|
7
|
+
resizable: true,
|
8
|
+
rotatable: true,
|
9
|
+
properties: [
|
10
|
+
{
|
11
|
+
type: 'number',
|
12
|
+
label: 'rows',
|
13
|
+
name: 'rows'
|
14
|
+
},
|
15
|
+
{
|
16
|
+
type: 'number',
|
17
|
+
label: 'columns',
|
18
|
+
name: 'columns'
|
19
|
+
},
|
20
|
+
{
|
21
|
+
type: 'select',
|
22
|
+
label: 'direction',
|
23
|
+
name: 'direction',
|
24
|
+
property: {
|
25
|
+
options: [
|
26
|
+
{
|
27
|
+
display: 'Horizontal',
|
28
|
+
value: 'horizontal'
|
29
|
+
},
|
30
|
+
{
|
31
|
+
display: 'Vertical',
|
32
|
+
value: 'vertical'
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
},
|
37
|
+
{
|
38
|
+
type: 'number',
|
39
|
+
label: 'round',
|
40
|
+
name: 'round'
|
41
|
+
},
|
42
|
+
{
|
43
|
+
type: 'legend-status',
|
44
|
+
label: '',
|
45
|
+
name: 'status'
|
46
|
+
}
|
47
|
+
],
|
48
|
+
help: 'scene/component/legend'
|
49
|
+
};
|
50
|
+
var controlHandler = {
|
51
|
+
ondragmove: function (point, index, component) {
|
52
|
+
var { left, top, width, height } = component.model;
|
53
|
+
/*
|
54
|
+
* point의 좌표는 부모 레이어 기준의 x, y 값이다.
|
55
|
+
* 따라서, 도형의 회전을 감안한 좌표로의 변환이 필요하다.
|
56
|
+
* Transcoord시에는 point좌표가 부모까지 transcoord되어있는 상태이므로,
|
57
|
+
* 컴포넌트자신에 대한 transcoord만 필요하다.(마지막 파라미터를 false로).
|
58
|
+
*/
|
59
|
+
var transcoorded = component.transcoordP2S(point.x, point.y);
|
60
|
+
var round = ((transcoorded.x - left) / (width / 2)) * 100;
|
61
|
+
round = roundSet(round, width, height);
|
62
|
+
component.set({ round });
|
63
|
+
}
|
64
|
+
};
|
65
|
+
function roundSet(round, width, height) {
|
66
|
+
var max = width > height ? (height / width) * 100 : 100;
|
67
|
+
if (round >= max)
|
68
|
+
round = max;
|
69
|
+
else if (round <= 0)
|
70
|
+
round = 0;
|
71
|
+
return round;
|
72
|
+
}
|
73
|
+
export default class Legend extends Container {
|
74
|
+
ready() {
|
75
|
+
this.rebuildLegendItems();
|
76
|
+
}
|
77
|
+
get showMoveHandle() {
|
78
|
+
return false;
|
79
|
+
}
|
80
|
+
render(context) {
|
81
|
+
var { round = 0 } = this.model;
|
82
|
+
var { left, top, width, height } = this.bounds;
|
83
|
+
// 박스 그리기
|
84
|
+
context.beginPath();
|
85
|
+
round = roundSet(round, width, height);
|
86
|
+
if (round > 0) {
|
87
|
+
var radius = (round / 100) * (width / 2);
|
88
|
+
context.moveTo(left + radius, top);
|
89
|
+
context.lineTo(left + width - radius, top);
|
90
|
+
context.quadraticCurveTo(left + width, top, left + width, top + radius);
|
91
|
+
context.lineTo(left + width, top + height - radius);
|
92
|
+
context.quadraticCurveTo(left + width, top + height, left + width - radius, top + height);
|
93
|
+
context.lineTo(left + radius, top + height);
|
94
|
+
context.quadraticCurveTo(left, top + height, left, top + height - radius);
|
95
|
+
context.lineTo(left, top + radius);
|
96
|
+
context.quadraticCurveTo(left, top, left + radius, top);
|
97
|
+
this.model.padding = {
|
98
|
+
top: round / 2,
|
99
|
+
left: round / 2,
|
100
|
+
right: round / 2,
|
101
|
+
bottom: round / 2
|
102
|
+
};
|
103
|
+
}
|
104
|
+
else {
|
105
|
+
context.rect(left, top, width, height);
|
106
|
+
}
|
107
|
+
this.drawFill(context);
|
108
|
+
this.drawStroke(context);
|
109
|
+
}
|
110
|
+
get controls() {
|
111
|
+
var { left, top, width, round, height } = this.model;
|
112
|
+
round = round == undefined ? 0 : roundSet(round, width, height);
|
113
|
+
return [
|
114
|
+
{
|
115
|
+
x: left + (width / 2) * (round / 100),
|
116
|
+
y: top,
|
117
|
+
handler: controlHandler
|
118
|
+
}
|
119
|
+
];
|
120
|
+
}
|
121
|
+
get layout() {
|
122
|
+
return TableLayout;
|
123
|
+
}
|
124
|
+
get nature() {
|
125
|
+
return NATURE;
|
126
|
+
}
|
127
|
+
rebuildLegendItems() {
|
128
|
+
if (this.components.length) {
|
129
|
+
this.components.slice().forEach(m => m.dispose());
|
130
|
+
}
|
131
|
+
var { left, top, width, height, fillStyle, strokeStyle, fontColor, fontFamily, fontSize, lineHeight, textAlign = 'left', round = 0, italic, bold, lineWidth = 0, rows, columns, status = {} } = this.model;
|
132
|
+
let statusRanges = status.ranges || [];
|
133
|
+
var count = statusRanges.length;
|
134
|
+
this.add(statusRanges.map(range => Model.compile({
|
135
|
+
type: 'legend-item',
|
136
|
+
text: range.description || `${range.min || ''} ~ ${range.max || ''}`,
|
137
|
+
width: 1,
|
138
|
+
height: 1,
|
139
|
+
color: range.color,
|
140
|
+
fontColor,
|
141
|
+
fontFamily,
|
142
|
+
fontSize,
|
143
|
+
lineHeight,
|
144
|
+
italic,
|
145
|
+
bold,
|
146
|
+
textAlign
|
147
|
+
})));
|
148
|
+
var rows, columns;
|
149
|
+
if (!columns && !rows) {
|
150
|
+
rows = count;
|
151
|
+
columns = 1;
|
152
|
+
}
|
153
|
+
else if (columns && !rows) {
|
154
|
+
rows = Math.ceil(count / Number(columns));
|
155
|
+
}
|
156
|
+
else if (rows && !columns) {
|
157
|
+
columns = Math.ceil(count / Number(rows));
|
158
|
+
}
|
159
|
+
this.set({
|
160
|
+
layoutConfig: {
|
161
|
+
rows,
|
162
|
+
columns
|
163
|
+
}
|
164
|
+
});
|
165
|
+
}
|
166
|
+
get hasTextProperty() {
|
167
|
+
return true;
|
168
|
+
}
|
169
|
+
get textHidden() {
|
170
|
+
return true;
|
171
|
+
}
|
172
|
+
onchange(after, before) {
|
173
|
+
this.rebuildLegendItems();
|
174
|
+
}
|
175
|
+
}
|
176
|
+
Component.register('legend', Legend);
|
177
|
+
//# sourceMappingURL=legend.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"legend.js","sourceRoot":"","sources":["../src/legend.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAwB,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEvG,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,UAAU,EAAE;QACV;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,SAAS;SAChB;QACD;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,WAAW;YAClB,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE;gBACR,OAAO,EAAE;oBACP;wBACE,OAAO,EAAE,YAAY;wBACrB,KAAK,EAAE,YAAY;qBACpB;oBACD;wBACE,OAAO,EAAE,UAAU;wBACnB,KAAK,EAAE,UAAU;qBAClB;iBACF;aACF;SACF;QACD;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,QAAQ;SACf;KACF;IACD,IAAI,EAAE,wBAAwB;CAC/B,CAAA;AAED,IAAI,cAAc,GAAG;IACnB,UAAU,EAAE,UAAU,KAAe,EAAE,KAAa,EAAE,SAAoB;QACxE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,CAAA;QAClD;;;;;WAKG;QACH,IAAI,YAAY,GAAG,SAAS,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AE,CAAA;IAC3B,CAAC;CACF;AAED,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\nimport { Component, Container, Model, POSITION, Properties, TableLayout } from '@hatiolab/things-scene'\n\nconst NATURE = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'number',\n label: 'rows',\n name: 'rows'\n },\n {\n type: 'number',\n label: 'columns',\n name: 'columns'\n },\n {\n type: 'select',\n label: 'direction',\n name: 'direction',\n property: {\n options: [\n {\n display: 'Horizontal',\n value: 'horizontal'\n },\n {\n display: 'Vertical',\n value: 'vertical'\n }\n ]\n }\n },\n {\n type: 'number',\n label: 'round',\n name: 'round'\n },\n {\n type: 'legend-status',\n label: '',\n name: 'status'\n }\n ],\n help: 'scene/component/legend'\n}\n\nvar controlHandler = {\n ondragmove: function (point: POSITION, index: number, component: Component) {\n var { left, top, width, height } = component.model\n /*\n * point의 좌표는 부모 레이어 기준의 x, y 값이다.\n * 따라서, 도형의 회전을 감안한 좌표로의 변환이 필요하다.\n * Transcoord시에는 point좌표가 부모까지 transcoord되어있는 상태이므로,\n * 컴포넌트자신에 대한 transcoord만 필요하다.(마지막 파라미터를 false로).\n */\n var transcoorded = component.transcoordP2S(point.x, point.y)\n var round = ((transcoorded.x - left) / (width / 2)) * 100\n\n round = roundSet(round, width, height)\n\n component.set({ round })\n }\n}\n\nfunction roundSet(round: number, width: number, height: number) {\n var max = width > height ? (height / width) * 100 : 100\n\n if (round >= max) round = max\n else if (round <= 0) round = 0\n\n return round\n}\n\nexport default class Legend extends Container {\n ready() {\n this.rebuildLegendItems()\n }\n\n get showMoveHandle() {\n return false\n }\n\n render(context: CanvasRenderingContext2D) {\n var { round = 0 } = this.model\n\n var { left, top, width, height } = this.bounds\n\n // 박스 그리기\n context.beginPath()\n\n round = roundSet(round, width, height)\n\n if (round > 0) {\n var radius = (round / 100) * (width / 2)\n\n context.moveTo(left + radius, top)\n context.lineTo(left + width - radius, top)\n context.quadraticCurveTo(left + width, top, left + width, top + radius)\n context.lineTo(left + width, top + height - radius)\n context.quadraticCurveTo(left + width, top + height, left + width - radius, top + height)\n context.lineTo(left + radius, top + height)\n context.quadraticCurveTo(left, top + height, left, top + height - radius)\n context.lineTo(left, top + radius)\n context.quadraticCurveTo(left, top, left + radius, top)\n\n this.model.padding = {\n top: round / 2,\n left: round / 2,\n right: round / 2,\n bottom: round / 2\n }\n } else {\n context.rect(left, top, width, height)\n }\n\n this.drawFill(context)\n this.drawStroke(context)\n }\n\n get controls() {\n var { left, top, width, round, height } = this.model\n round = round == undefined ? 0 : roundSet(round, width, height)\n\n return [\n {\n x: left + (width / 2) * (round / 100),\n y: top,\n handler: controlHandler\n }\n ]\n }\n\n get layout() {\n return TableLayout\n }\n\n get nature() {\n return NATURE\n }\n\n rebuildLegendItems() {\n if (this.components.length) {\n this.components.slice().forEach(m => m.dispose())\n }\n\n var {\n left,\n top,\n width,\n height,\n fillStyle,\n strokeStyle,\n fontColor,\n fontFamily,\n fontSize,\n lineHeight,\n textAlign = 'left',\n round = 0,\n italic,\n bold,\n lineWidth = 0,\n rows,\n columns,\n status = {}\n } = this.model\n\n let statusRanges: {\n min: string\n max: string\n description: string\n color: string\n }[] = status.ranges || []\n\n var count = statusRanges.length\n\n this.add(\n statusRanges.map(range =>\n Model.compile({\n type: 'legend-item',\n text: range.description || `${range.min || ''} ~ ${range.max || ''}`,\n width: 1,\n height: 1,\n color: range.color,\n fontColor,\n fontFamily,\n fontSize,\n lineHeight,\n italic,\n bold,\n textAlign\n })\n )\n )\n\n var rows, columns\n\n if (!columns && !rows) {\n rows = count\n columns = 1\n } else if (columns && !rows) {\n rows = Math.ceil(count / Number(columns))\n } else if (rows && !columns) {\n columns = Math.ceil(count / Number(rows))\n }\n\n this.set({\n layoutConfig: {\n rows,\n columns\n }\n })\n }\n\n get hasTextProperty() {\n return true\n }\n\n get textHidden() {\n return true\n }\n\n onchange(after: Properties, before: Properties) {\n this.rebuildLegendItems()\n }\n}\n\nComponent.register('legend', Legend)\n"]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
declare const _default: {
|
2
|
+
type: string;
|
3
|
+
description: string;
|
4
|
+
group: string;
|
5
|
+
icon: any;
|
6
|
+
model: {
|
7
|
+
type: string;
|
8
|
+
left: number;
|
9
|
+
top: number;
|
10
|
+
width: number;
|
11
|
+
height: number;
|
12
|
+
fillStyle: string;
|
13
|
+
direction: string;
|
14
|
+
strokeStyle: string;
|
15
|
+
lineWidth: number;
|
16
|
+
};
|
17
|
+
}[];
|
18
|
+
export default _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAA;AAE7B,eAAe,CAAC,MAAM,CAAC,CAAA","sourcesContent":["import legend from './legend'\n\nexport default [legend]\n"]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
declare const _default: {
|
2
|
+
type: string;
|
3
|
+
description: string;
|
4
|
+
group: string;
|
5
|
+
icon: any;
|
6
|
+
model: {
|
7
|
+
type: string;
|
8
|
+
left: number;
|
9
|
+
top: number;
|
10
|
+
width: number;
|
11
|
+
height: number;
|
12
|
+
fillStyle: string;
|
13
|
+
direction: string;
|
14
|
+
strokeStyle: string;
|
15
|
+
lineWidth: number;
|
16
|
+
};
|
17
|
+
};
|
18
|
+
export default _default;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import icon from '../../assets/legend.png';
|
2
|
+
export default {
|
3
|
+
type: 'legend',
|
4
|
+
description: 'legend for visualizer',
|
5
|
+
group: 'warehouse' /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */,
|
6
|
+
icon,
|
7
|
+
model: {
|
8
|
+
type: 'legend',
|
9
|
+
left: 100,
|
10
|
+
top: 100,
|
11
|
+
width: 200,
|
12
|
+
height: 150,
|
13
|
+
fillStyle: '#efefef',
|
14
|
+
direction: 'vertical',
|
15
|
+
strokeStyle: 'rgba(0, 0, 0, 0.3)',
|
16
|
+
lineWidth: 1
|
17
|
+
}
|
18
|
+
};
|
19
|
+
//# sourceMappingURL=legend.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"legend.js","sourceRoot":"","sources":["../../src/templates/legend.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,yBAAyB,CAAA;AAE1C,eAAe;IACb,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,uBAAuB;IACpC,KAAK,EAAE,WAAW,CAAC,gGAAgG;IACnH,IAAI;IACJ,KAAK,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,GAAG;QACR,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;QACX,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,UAAU;QACrB,WAAW,EAAE,oBAAoB;QACjC,SAAS,EAAE,CAAC;KACb;CACF,CAAA","sourcesContent":["import icon from '../../assets/legend.png'\n\nexport default {\n type: 'legend',\n description: 'legend for visualizer',\n group: 'warehouse' /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */,\n icon,\n model: {\n type: 'legend',\n left: 100,\n top: 100,\n width: 200,\n height: 150,\n fillStyle: '#efefef',\n direction: 'vertical',\n strokeStyle: 'rgba(0, 0, 0, 0.3)',\n lineWidth: 1\n }\n}\n"]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# legend[ko]
|
2
|
+
![컴포넌트-Legend][legend-01]
|
3
|
+
|
4
|
+
상태값에 대하여 설정하고, 설정된 상태에 근거하여 범주를 생성해주는 컴포넌트.
|
5
|
+
|
6
|
+
## properties
|
7
|
+
|
8
|
+
1. 행 : 범주를 몇 행으로 맞추어 표현할지 결정
|
9
|
+
2. 열 : 범주를 몇 열으로 맞추어 표현할지 결정
|
10
|
+
3. Direction : 범주가 표현될 방향
|
11
|
+
4. 둥글게 : 모서리의 둥근 정도를 결정
|
12
|
+
5. field : 데이터의 어떠한 필드값이 상태값을 결정하는 필드인지 지정
|
13
|
+
6. 기본 색상 : 상태 범위에 해당되지 않을 경우 기본으로 나타낼 색상
|
14
|
+
7. 상태설정 : 값의 상태 범위 및 색상을 지정 ![상태설정][legend-02]
|
15
|
+
|
16
|
+
|
17
|
+
[legend-01]: ../images/legend-01.png
|
18
|
+
[legend-02]: ../images/legend-02.png
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# legend[en]
|
2
|
+
![component-Legend][legend-01]
|
3
|
+
|
4
|
+
A component that sets the status value and creates a category based on the set status.
|
5
|
+
|
6
|
+
## properties
|
7
|
+
|
8
|
+
1. Row : Determine how many rows the category should be represented.
|
9
|
+
2. Column : Determine how many columns the category should be represented.
|
10
|
+
3. Direction : The direction in which the category will be represented.
|
11
|
+
4. Round : Determine the roundness of the edges.
|
12
|
+
5. field : Specify which field values in the data are fields that determine the status value.
|
13
|
+
6. Default color : The color to be displayed by default if it is not in the status range.
|
14
|
+
7. Status setting : Specify the status range and color of the values. ![Status setting][legend-02]
|
15
|
+
|
16
|
+
|
17
|
+
[legend-01]: ../images/legend-01.png
|
18
|
+
[legend-02]: ../images/legend-02.png
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# legend[zh]
|
2
|
+
![组件-Legend][legend-01]
|
3
|
+
|
4
|
+
设置状态值并根据所设置的状态创建类别的组件。
|
5
|
+
|
6
|
+
|
7
|
+
## properties
|
8
|
+
|
9
|
+
1. 行:决定用几个行来显示该类别。
|
10
|
+
2. 列:决定用几个列来显示该类别。
|
11
|
+
3. 方向:将会显示类别的方向。
|
12
|
+
4. 圆化:确定边缘的圆度。
|
13
|
+
5. 字段:指定数据的哪些字段值是决定状态值的字段。
|
14
|
+
6. 默认颜色:如果不在状态范围内,就会默认显示的颜色。
|
15
|
+
7. 状态设置:指定值的状态范围和颜色。 ![状态设置][legend-02]
|
16
|
+
|
17
|
+
|
18
|
+
[legend-01]: ../images/legend-01.png
|
19
|
+
|
20
|
+
[legend-02]: ../images/legend-02.png
|
Binary file
|
Binary file
|
package/package.json
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
{
|
2
|
+
"name": "@operato/scene-legend",
|
3
|
+
"description": "Legend component for things-scene.",
|
4
|
+
"license": "MIT",
|
5
|
+
"author": "heartyoh",
|
6
|
+
"version": "0.0.11",
|
7
|
+
"main": "dist/index.js",
|
8
|
+
"module": "dist/index.js",
|
9
|
+
"things-scene": true,
|
10
|
+
"publishConfig": {
|
11
|
+
"access": "public",
|
12
|
+
"@oprato:registry": "https://registry.npmjs.org"
|
13
|
+
},
|
14
|
+
"repository": {
|
15
|
+
"type": "git",
|
16
|
+
"url": "git+https://github.com/things-scene/operato-scene.git",
|
17
|
+
"directory": "packages/legend"
|
18
|
+
},
|
19
|
+
"scripts": {
|
20
|
+
"serve": "tsc && things-factory-dev",
|
21
|
+
"start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
|
22
|
+
"build": "tsc",
|
23
|
+
"prepublish": "tsc",
|
24
|
+
"lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
|
25
|
+
"format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
|
26
|
+
"migration": "things-factory-migration"
|
27
|
+
},
|
28
|
+
"dependencies": {
|
29
|
+
"@hatiolab/things-scene": "^2.7.23",
|
30
|
+
"lit": "^2.0.2"
|
31
|
+
},
|
32
|
+
"devDependencies": {
|
33
|
+
"@hatiolab/prettier-config": "^1.0.0",
|
34
|
+
"@hatiolab/things-scene": "^2.7.23",
|
35
|
+
"@operato/board": "^0.2.35",
|
36
|
+
"@things-factory/builder": "^4.0.10",
|
37
|
+
"@things-factory/operato-board": "^4.0.10",
|
38
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
39
|
+
"@typescript-eslint/parser": "^4.33.0",
|
40
|
+
"@web/dev-server": "^0.1.28",
|
41
|
+
"concurrently": "^5.3.0",
|
42
|
+
"eslint": "^7.32.0",
|
43
|
+
"eslint-config-prettier": "^8.3.0",
|
44
|
+
"husky": "^4.3.8",
|
45
|
+
"lint-staged": "^10.5.4",
|
46
|
+
"prettier": "^2.4.1",
|
47
|
+
"tslib": "^2.3.1",
|
48
|
+
"typescript": "^4.5.2"
|
49
|
+
},
|
50
|
+
"prettier": "@hatiolab/prettier-config",
|
51
|
+
"husky": {
|
52
|
+
"hooks": {
|
53
|
+
"pre-commit": "lint-staged"
|
54
|
+
}
|
55
|
+
},
|
56
|
+
"lint-staged": {
|
57
|
+
"*.ts": [
|
58
|
+
"eslint --fix",
|
59
|
+
"prettier --write"
|
60
|
+
]
|
61
|
+
},
|
62
|
+
"gitHead": "1421380ee3530169c280b01a21c81af8d1b9f9c4"
|
63
|
+
}
|