@fmsim/machine 0.0.67 → 0.0.69

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,141 +0,0 @@
1
- import { SubscriptionClient } from 'subscriptions-transport-ws'
2
- import { Component, ComponentNature, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
3
- import { getRestServiceFullPath } from '@fmsim/api/restful.js'
4
-
5
- const COMPONENT_IMAGE = new URL('../icons/symbol-data-subscription.png', import.meta.url).href
6
-
7
- const NATURE: ComponentNature = {
8
- mutable: false,
9
- resizable: true,
10
- rotatable: true,
11
- properties: [
12
- {
13
- type: 'string',
14
- label: 'tag',
15
- name: 'tag'
16
- }
17
- ],
18
- 'value-property': 'tag',
19
- help: 'scene/component/data-subscription'
20
- }
21
-
22
- export default class DataSubscription extends DataSource(RectPath(Shape)) {
23
- static _image
24
- subscription
25
- client
26
- disposed
27
-
28
- static get image() {
29
- if (!DataSubscription._image) {
30
- DataSubscription._image = new Image()
31
- DataSubscription._image.src = COMPONENT_IMAGE
32
- }
33
-
34
- return DataSubscription._image
35
- }
36
-
37
- dispose() {
38
- if (this.subscription) {
39
- this.subscription.unsubscribe()
40
- }
41
- if (this.client) {
42
- this.client.unsubscribeAll()
43
- this.client.close(true)
44
- }
45
-
46
- super.dispose()
47
- }
48
-
49
- render(context) {
50
- var { left, top, width, height } = this.bounds
51
-
52
- context.beginPath()
53
- this.drawImage(context, DataSubscription.image, left, top, width, height)
54
- }
55
-
56
- ready() {
57
- this._initDataSubscription()
58
- }
59
-
60
- get nature() {
61
- return NATURE
62
- }
63
-
64
- get tag() {
65
- return this.state.tag
66
- }
67
-
68
- set tag(tag) {
69
- this.setState('tag', tag)
70
- }
71
-
72
- _initDataSubscription() {
73
- if (!this.app.isViewMode) return
74
-
75
- this.requestData()
76
- }
77
-
78
- async requestData() {
79
- var { tag } = this.state
80
- var self = this
81
- var query = `"${tag}"`
82
- // var query = `
83
- // subscription {
84
- // data(tag: "${tag}") {
85
- // tag
86
- // data
87
- // }
88
- // }`
89
- let wsKey = guid()
90
- // url = 'ws://' + mcsAutoConfig.serverInfo.address + mcsAutoConfig.serverInfo.prefix + '/ws/fmbServer/' + wsKey
91
- var endpoint = getRestServiceFullPath().replace(/^http/, 'ws') + '/ws/fmbServer/' + wsKey
92
- // sessionStorage.getItem('')
93
- this.client = new SubscriptionClient(
94
- endpoint,
95
- {
96
- reconnect: true,
97
- connectionParams: {
98
- headers: {}
99
- }
100
- },
101
- null
102
- )
103
-
104
- this.client.onError(e => {
105
- var client = this.client
106
- // 보드가 실행중이면 재시도, 아니면 재연결 취소
107
- if (this.disposed) {
108
- client.reconnect = false
109
-
110
- this.client.unsubscribeAll()
111
- this.client.close(true)
112
- }
113
- })
114
- this.client.onConnected(() => {
115
- this.subscription = this.client.request({ query }).subscribe({
116
- next({ data }) {
117
- if (data) {
118
- self.data = data.data.data
119
- }
120
- }
121
- })
122
- console.log('this.subscription : ', this.subscription)
123
- })
124
- // this.subscription = this.client.request({ query }).subscribe({
125
- // next({ data }) {
126
- // if (data) {
127
- // self.data = data.data.data
128
- // }
129
- // }
130
- // })
131
-
132
- function guid() {
133
- function s4() {
134
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
135
- }
136
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4()
137
- }
138
- }
139
- }
140
-
141
- Component.register('data-subscription', DataSubscription)
@@ -1,45 +0,0 @@
1
- import { getThemes } from '@fmsim/api/restful.js'
2
-
3
- export const themesColorMap = async () => {
4
- var result = (await getThemes())?.data
5
- if (!result || !result.status) {
6
- document.dispatchEvent(
7
- new CustomEvent('notify', {
8
- detail: {
9
- level: 'info',
10
- message: `Fetch Connection List Error!`
11
- }
12
- })
13
- )
14
- }
15
-
16
- const items = ((result && result.themeList.items) || [])
17
- .filter((item: any) => item.type == 'color-map')
18
- .map((item: any) => item.name)
19
-
20
- const sorted = items.sort()
21
-
22
- return [''].concat(sorted)
23
- }
24
-
25
- export const themesColorRange = async () => {
26
- var result = (await getThemes())?.data
27
- if (!result || !result.status) {
28
- document.dispatchEvent(
29
- new CustomEvent('notify', {
30
- detail: {
31
- level: 'info',
32
- message: `Fetch Connection List Error!`
33
- }
34
- })
35
- )
36
- }
37
-
38
- const items = ((result && result.themeList.items) || [])
39
- .filter((item: any) => item.type == 'color-ranges')
40
- .map((item: any) => item.name)
41
-
42
- const sorted = items.sort()
43
-
44
- return [''].concat(sorted)
45
- }
@@ -1,52 +0,0 @@
1
- import gql from 'graphql-tag'
2
-
3
- import { client } from '@operato/graphql'
4
-
5
- export const themesColorMap = async () => {
6
- var response = await client.query({
7
- query: gql`
8
- query {
9
- themes {
10
- items {
11
- name
12
- type
13
- }
14
- }
15
- }
16
- `
17
- })
18
-
19
- if (response.errors) {
20
- return ['']
21
- }
22
-
23
- const items = response.data.themes.items.filter((item: any) => item.type == 'color-map').map((item: any) => item.name)
24
- const sorted = items.sort()
25
-
26
- return [''].concat(sorted)
27
- }
28
-
29
- export const themesColorRange = async () => {
30
- var response = await client.query({
31
- query: gql`
32
- query {
33
- themes {
34
- items {
35
- name
36
- type
37
- }
38
- }
39
- }
40
- `
41
- })
42
- if (response.errors) {
43
- return ['']
44
- }
45
-
46
- const items = response.data.themes.items
47
- .filter((item: any) => item.type == 'color-ranges')
48
- .map((item: any) => item.name)
49
- const sorted = items.sort()
50
-
51
- return [''].concat(sorted)
52
- }
@@ -1,113 +0,0 @@
1
- import { Component, ComponentNature, Ellipse, Properties } from '@hatiolab/things-scene'
2
- import { getVaueOnRanges } from './utils/get-value-on-ranges'
3
- import { MCSStatusMixin } from './features/mcs-status-mixin'
4
- import { LEGEND_CAPACITY, Legend } from './features/mcs-status-default'
5
-
6
- const NATURE: ComponentNature = {
7
- mutable: false,
8
- resizable: true,
9
- rotatable: true,
10
- properties: [
11
- {
12
- type: 'number',
13
- name: 'currentUsage',
14
- label: 'current-usage'
15
- },
16
- {
17
- type: 'number',
18
- name: 'highWatermark',
19
- label: 'high-watermark'
20
- },
21
- {
22
- type: 'number',
23
- name: 'maxCapacity',
24
- label: 'max-capacity'
25
- },
26
- {
27
- type: 'hidden',
28
- name: 'usage',
29
- label: 'usage'
30
- }
31
- ],
32
- 'value-property': 'usage'
33
- }
34
-
35
- export default class MCSGaugeCapacityCircle extends MCSStatusMixin(Ellipse) {
36
- static get nature() {
37
- return NATURE
38
- }
39
-
40
- getTheme() {
41
- const { legendName } = this.state
42
-
43
- if (legendName) {
44
- return (this.root as any)?.style?.[legendName]
45
- }
46
- }
47
-
48
- get legend(): Legend {
49
- return this.getTheme() || this.getLegendFallback()
50
- }
51
-
52
- getLegendFallback() {
53
- return LEGEND_CAPACITY
54
- }
55
-
56
- get statusColor() {
57
- return getVaueOnRanges(this.usage, this.legend)
58
- }
59
-
60
- render(context: CanvasRenderingContext2D) {
61
- var { cx, cy, rx, ry } = this.state
62
- const radius = Math.min(rx, ry)
63
-
64
- context.beginPath()
65
-
66
- context.arc(cx, cy, radius, 0, Math.PI * 2)
67
- context.fillStyle = 'gray'
68
- context.fill()
69
- this.drawStroke(context)
70
-
71
- const startAngle = Math.PI * -0.5
72
- const endAngle = startAngle + Math.PI * 2 * (this.value / 100)
73
-
74
- context.beginPath()
75
-
76
- context.moveTo(cx, cy)
77
- context.arc(cx, cy, radius, startAngle, endAngle)
78
- context.lineTo(cx, cy)
79
- context.fillStyle = this.statusColor!
80
-
81
- context.fill()
82
- }
83
-
84
- get usage() {
85
- const { currentUsage = 0, maxCapacity = 100 } = this.state
86
- return Math.round((currentUsage / maxCapacity) * 100)
87
- }
88
-
89
- set usage(usage: number) {
90
- // intentionally have done nothing
91
- }
92
-
93
- onchangeData(after: Properties, before: Properties): void {
94
- const {
95
- CURRENTCAPACITY = 0,
96
- MAXCAPACITY = 100,
97
- HIGHWATERMARK = 100
98
- } = typeof this.data == 'object' ? this.data : {}
99
-
100
- const currentUsage = Number(CURRENTCAPACITY) || 0
101
- const maxCapacity = Number(MAXCAPACITY) || 100
102
- const highWatermark = Number(HIGHWATERMARK) || 100
103
-
104
- this.setState({
105
- currentUsage,
106
- maxCapacity,
107
- highWatermark,
108
- usage: Math.round((currentUsage / maxCapacity) * 100)
109
- })
110
- }
111
- }
112
-
113
- Component.register('MCSGaugeCapacityCircle', MCSGaugeCapacityCircle)