@fmsim/machine 2.0.0-beta.104 → 2.0.0-beta.107

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.
@@ -1,301 +1,36 @@
1
- import { Component, ComponentNature, POSITION, Properties, sceneComponent } from '@hatiolab/things-scene'
2
- import { themesColorRange } from '@fmsim/api'
3
- import { LEGEND_CAPACITY } from './features/mcs-status-default'
4
- import { safeRound } from './utils/safe-round'
5
- import { getValueOnRanges } from './utils/get-value-on-ranges'
1
+ import { ComponentNature, sceneComponent } from '@hatiolab/things-scene'
2
+ import { LEGEND_CAPACITY, Legend } from './features/mcs-status-default'
6
3
  import { MCSZoneMixin, MCSZoneMixinProperties } from './features/mcs-zone-mixin'
7
4
  import { ParentObjectMixinProperties } from './features/parent-object-mixin'
5
+ import { CapacityGaugeMixin, CapacityGaugeMixinProperties } from './features/capacity-gauge-mixin'
8
6
  import MCSUnit from './mcs-unit'
9
7
 
8
+ /**
9
+ * 존(zone) 게이지.
10
+ *
11
+ * mode 에 따라 capacity / carrier / abnormal 3가지 게이지를 표현한다 — 그리는 규칙은
12
+ * StockerCapacityBar 와 동일하며 CapacityGaugeMixin 에서 공유한다(단일 소스).
13
+ * 스토커 게이지와 달리 존 게이지는 자체 id 로 데이터를 받는 Unit(identifiable) 이며,
14
+ * legend 폴백만 zone 전역 테마(zoneCapacityLegendTheme)로 다르다.
15
+ *
16
+ * mode 소스: root.stockerGaugeMode — 스토커 게이지와 같은 런타임 스위치로 함께 전환된다.
17
+ */
18
+
10
19
  const NATURE: ComponentNature = {
11
20
  mutable: false,
12
21
  resizable: true,
13
22
  rotatable: true,
14
- properties: [
15
- ...MCSZoneMixinProperties,
16
- ...ParentObjectMixinProperties,
17
- {
18
- type: 'select',
19
- label: 'legend-name',
20
- name: 'legendName',
21
- property: {
22
- options: themesColorRange
23
- }
24
- },
25
- {
26
- type: 'number',
27
- name: 'currentUsage',
28
- label: 'current-usage'
29
- },
30
- {
31
- type: 'number',
32
- name: 'highWatermark',
33
- label: 'high-watermark'
34
- },
35
- {
36
- type: 'number',
37
- name: 'lowWatermark',
38
- label: 'low-watermark'
39
- },
40
- {
41
- type: 'number',
42
- name: 'maxCapacity',
43
- label: 'max-capacity'
44
- },
45
- {
46
- type: 'boolean',
47
- name: 'fullup',
48
- label: 'fullup'
49
- },
50
- {
51
- type: 'number',
52
- label: 'round',
53
- name: 'round',
54
- property: {
55
- min: 0
56
- }
57
- },
58
- {
59
- type: 'hidden',
60
- name: 'usage',
61
- label: 'usage'
62
- }
63
- ],
23
+ properties: [...MCSZoneMixinProperties, ...ParentObjectMixinProperties, ...CapacityGaugeMixinProperties],
64
24
  'value-property': 'usage'
65
25
  }
66
26
 
67
- var controlHandler = {
68
- ondragmove: function (point: POSITION, index: number, component: Component) {
69
- var { left, top, width, height } = component.model
70
-
71
- var transcoorded = component.transcoordP2S(point.x, point.y)
72
- var round = ((transcoorded.x - left) / (width / 2)) * 100
73
-
74
- round = safeRound(round, width, height)
75
-
76
- component.set({
77
- round
78
- })
79
- }
80
- }
81
-
82
27
  @sceneComponent('ZoneCapacityBar')
83
- export default class ZoneCapacityBar extends MCSZoneMixin(MCSUnit) {
28
+ export default class ZoneCapacityBar extends CapacityGaugeMixin(MCSZoneMixin(MCSUnit)) {
84
29
  static get nature() {
85
30
  return NATURE
86
31
  }
87
32
 
88
- get controls() {
89
- var { left, top, width, round, height } = this.state
90
- round = round == undefined ? 0 : safeRound(round, width, height)
91
-
92
- return [
93
- {
94
- x: left + (width / 2) * (round / 100),
95
- y: top,
96
- handler: controlHandler
97
- }
98
- ]
99
- }
100
-
101
- getLegendFallback() {
33
+ getLegendFallback(): Legend {
102
34
  return (this.root as any).zoneCapacityLegendTheme || LEGEND_CAPACITY
103
35
  }
104
-
105
- get statusColor() {
106
- const { fullup } = this.state
107
- return fullup ? 'red' : getValueOnRanges(this.usage, this.legend)
108
- }
109
-
110
- get text() {
111
- return this.usage + '%'
112
- }
113
-
114
- render(context: CanvasRenderingContext2D) {
115
- const { left, top, width, height } = this.bounds
116
-
117
- if (width >= height) {
118
- this.renderLandscape(context)
119
- } else {
120
- this.renderPortrait(context)
121
- }
122
- }
123
-
124
- renderLandscape(context: CanvasRenderingContext2D) {
125
- const { left, top, width, height } = this.bounds
126
- const { highWatermark, lowWatermark, lineWidth, strokeStyle, round, fillStyle = 'white' } = this.state
127
-
128
- context.save()
129
- context.translate(left, top)
130
-
131
- // gauge background
132
- context.beginPath()
133
-
134
- context.fillStyle = fillStyle
135
- context.roundRect(0, 0, width, height, round)
136
-
137
- context.fill()
138
- context.stroke()
139
-
140
- context.clip()
141
-
142
- // gauge foreground
143
- context.beginPath()
144
-
145
- context.fillStyle = this.statusColor!
146
-
147
- context.rect(0, 0, (width / 100) * this.usage, height)
148
- context.fill()
149
-
150
- // high-watermark level
151
-
152
- if (highWatermark && highWatermark > 0 && highWatermark < 100) {
153
- context.beginPath()
154
-
155
- context.strokeStyle = 'black'
156
- context.lineWidth = 1
157
- context.setLineDash([3])
158
-
159
- const x = (width / 100) * highWatermark
160
- context.moveTo(x, 0)
161
- context.lineTo(x, height)
162
-
163
- context.stroke()
164
- }
165
-
166
- // low-watermark level
167
-
168
- if (lowWatermark && lowWatermark > 0 && lowWatermark < 100) {
169
- context.beginPath()
170
-
171
- context.strokeStyle = 'black'
172
- context.lineWidth = 1
173
- context.setLineDash([3])
174
-
175
- const x = (width / 100) * lowWatermark
176
- context.moveTo(x, 0)
177
- context.lineTo(x, height)
178
-
179
- context.stroke()
180
- }
181
-
182
- // gauge outline
183
- context.beginPath()
184
-
185
- context.setLineDash([])
186
- context.strokeStyle = strokeStyle
187
- context.lineWidth = lineWidth
188
- context.roundRect(0, 0, width, height, round)
189
- context.stroke()
190
-
191
- context.beginPath()
192
-
193
- context.translate(-left, -top)
194
- context.restore()
195
- }
196
-
197
- renderPortrait(context: CanvasRenderingContext2D) {
198
- const { left, top, width, height } = this.bounds
199
- const { highWatermark, lowWatermark, lineWidth, strokeStyle, round, fillStyle = 'white' } = this.state
200
-
201
- context.save()
202
- context.translate(left, top)
203
-
204
- // gauge background
205
- context.beginPath()
206
-
207
- context.fillStyle = fillStyle
208
- context.roundRect(0, 0, width, height, round)
209
-
210
- context.fill()
211
-
212
- context.clip()
213
-
214
- // gauge foreground
215
- context.beginPath()
216
-
217
- context.fillStyle = this.statusColor!
218
-
219
- context.rect(0, height - (height / 100) * this.usage, width, (height / 100) * this.usage)
220
- context.fill()
221
-
222
- // high-watermark level
223
-
224
- if (highWatermark && highWatermark > 0 && highWatermark < 100) {
225
- context.beginPath()
226
-
227
- context.strokeStyle = 'black'
228
- context.lineWidth = 1
229
- context.setLineDash([3])
230
-
231
- const y = height - (height / 100) * highWatermark
232
- context.moveTo(0, y)
233
- context.lineTo(width, y)
234
-
235
- context.stroke()
236
- }
237
-
238
- // low-watermark level
239
-
240
- if (lowWatermark && lowWatermark > 0 && lowWatermark < 100) {
241
- context.beginPath()
242
-
243
- context.strokeStyle = 'black'
244
- context.lineWidth = 1
245
- context.setLineDash([3])
246
-
247
- const y = height - (height / 100) * lowWatermark
248
- context.moveTo(0, y)
249
- context.lineTo(width, y)
250
-
251
- context.stroke()
252
- }
253
-
254
- // gauge outline
255
- context.beginPath()
256
-
257
- context.setLineDash([])
258
- context.strokeStyle = strokeStyle
259
- context.lineWidth = lineWidth
260
- context.roundRect(0, 0, width, height, round)
261
- context.stroke()
262
-
263
- context.beginPath()
264
-
265
- context.translate(-left, -top)
266
- context.restore()
267
- }
268
-
269
- get usage() {
270
- const { currentUsage = 0, maxCapacity = 100 } = this.state
271
- return Math.round((currentUsage / maxCapacity) * 100)
272
- }
273
-
274
- set usage(usage: number) {
275
- // intentionally have done nothing
276
- }
277
-
278
- onchangeData(after: Record<string, any>, before: Record<string, any>): void {
279
- const {
280
- CURRENTCAPACITY = 0,
281
- MAXCAPACITY = 100,
282
- HIGHWATERMARK = 100,
283
- LOWWATERMARK = 0,
284
- FULLUP = 'F'
285
- } = this.data && typeof this.data == 'object' ? this.data : {}
286
-
287
- const currentUsage = Number(CURRENTCAPACITY) || 0
288
- const maxCapacity = Number(MAXCAPACITY) || 100
289
- const highWatermark = Number(HIGHWATERMARK) || 100
290
- const lowWatermark = Number(LOWWATERMARK) || 0
291
-
292
- this.setState({
293
- currentUsage,
294
- maxCapacity,
295
- highWatermark,
296
- lowWatermark,
297
- fullup: FULLUP == 'T',
298
- usage: Math.round((currentUsage / maxCapacity) * 100)
299
- })
300
- }
301
36
  }