@hatiolab/things-scene 8.0.0-alpha.1 → 8.0.0-alpha.3

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.
package/db.sqlite CHANGED
Binary file
@@ -5,7 +5,7 @@ chrome.runtime.sendMessage({ type: 'GET_TAB_INFO' }, response => {
5
5
  if (response && response.tabId) {
6
6
  const tabId = response.tabId
7
7
 
8
- function updateChart(data) {
8
+ function updateChart(data = {}) {
9
9
  chrome.runtime.sendMessage({ type: 'UPDATE_CHART', tabId, data })
10
10
  }
11
11
 
@@ -13,14 +13,20 @@ chrome.runtime.sendMessage({ type: 'GET_TAB_INFO' }, response => {
13
13
  if (event.source !== window || !event.data.type) return
14
14
 
15
15
  if (event.data.type === 'RESIDENT_COUNT') {
16
- const { timestamp, componentResidentsCount, sceneResidentsCount, referenceMapResidentsCount } = event.data
16
+ const { timestamp, componentResidentsCount, sceneResidentsCount, sceneResidents, referenceMapResidentsCount } =
17
+ event.data
17
18
 
18
19
  try {
19
20
  chrome.storage.local.get({ residentData: {} }, result => {
20
21
  const residentData = result.residentData || {}
21
- residentData[tabId] = residentData[tabId] || []
22
+ const tabData = (residentData[tabId] = /* temporary condition */ Array.isArray(residentData[tabId])
23
+ ? {}
24
+ : residentData[tabId] || {})
22
25
 
23
- residentData[tabId].push({
26
+ tabData.sceneResidents = sceneResidents
27
+ const history = (tabData.history = tabData.history || [])
28
+
29
+ history.push({
24
30
  timestamp,
25
31
  componentResidentsCount,
26
32
  sceneResidentsCount,
@@ -28,13 +34,13 @@ chrome.runtime.sendMessage({ type: 'GET_TAB_INFO' }, response => {
28
34
  })
29
35
 
30
36
  // 데이터가 100개 이상일 경우 오래된 데이터 삭제
31
- if (residentData[tabId].length > 100) {
32
- residentData[tabId].shift()
37
+ if (history.length > 100) {
38
+ history.shift()
33
39
  }
34
40
 
35
41
  chrome.storage.local.set({ residentData }, () => {
36
42
  try {
37
- updateChart(residentData[tabId])
43
+ updateChart(tabData)
38
44
  } catch (e) {
39
45
  console.error('Error updating chart:', e)
40
46
  }
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Component Residents Monitor</title>
7
- <script src="libs/Chart.min.js"></script>
7
+ <script src="libs/chart.min.js"></script>
8
8
  <script src="devtools.js"></script>
9
9
  <style>
10
10
  body {
@@ -17,6 +17,7 @@
17
17
  min-height: 800px;
18
18
  box-sizing: border-box;
19
19
  }
20
+
20
21
  canvas {
21
22
  flex: 1;
22
23
  border: 1px solid #000;
@@ -24,15 +25,45 @@
24
25
  width: 100%;
25
26
  box-sizing: border-box;
26
27
  }
28
+
29
+ table {
30
+ width: 100%;
31
+ border-collapse: collapse;
32
+ margin-top: 20px;
33
+ }
34
+
35
+ th,
36
+ td {
37
+ padding: 8px;
38
+ text-align: left;
39
+ border-bottom: 1px solid #ddd;
40
+ }
41
+
42
+ th {
43
+ background-color: #f2f2f2;
44
+ }
27
45
  </style>
28
46
  </head>
29
47
  <body>
30
48
  <h1>Component Residents Monitor</h1>
31
- <div id="resident-components"></div>
32
- <div id="resident-scenes"></div>
33
- <div id="resident-reference-maps"></div>
34
49
  <canvas id="residentChart1"></canvas>
35
50
  <canvas id="residentChart2"></canvas>
36
51
  <canvas id="residentChart3"></canvas>
52
+
53
+ <!-- sceneResidents 데이터를 보여줄 테이블 -->
54
+ <h2>Scene Residents Data</h2>
55
+ <table id="residentsTable">
56
+ <thead>
57
+ <tr>
58
+ <th>Type</th>
59
+ <th>Up</th>
60
+ <th>Down</th>
61
+ <th>Difference (Up - Down)</th>
62
+ </tr>
63
+ </thead>
64
+ <tbody>
65
+ <!-- 데이터가 동적으로 추가됩니다 -->
66
+ </tbody>
67
+ </table>
37
68
  </body>
38
69
  </html>
@@ -1,126 +1,115 @@
1
- let panelCreated = false
2
-
3
- chrome.devtools.panels.create('Board Monitor', 'icons/icon48.png', 'devtools.html', function (panel) {
4
- if (panelCreated) {
5
- console.log('Panel already created, skipping creation.')
6
- return
7
- }
8
-
1
+ chrome.devtools.panels.create('Scene', 'icons/icon48.png', 'devtools.html', function (panel) {
9
2
  var residentChart1, residentChart2, residentChart3
10
3
  var listenerRegistered = false
4
+ var chartsInitialized = false
11
5
 
12
6
  // 차트 업데이트 함수
13
- const updateCharts = data => {
14
- console.log('Updating charts:', residentChart1, residentChart2, residentChart3)
15
- if (residentChart1 && residentChart2 && residentChart3) {
16
- residentChart1.data.labels = data.map(entry => entry.timestamp)
17
- residentChart1.data.datasets[0].data = data.map(entry => entry.componentResidentsCount)
18
- residentChart1.update()
19
-
20
- residentChart2.data.labels = data.map(entry => entry.timestamp)
21
- residentChart2.data.datasets[0].data = data.map(entry => entry.sceneResidentsCount)
22
- residentChart2.update()
23
-
24
- residentChart3.data.labels = data.map(entry => entry.timestamp)
25
- residentChart3.data.datasets[0].data = data.map(entry => entry.referenceMapResidentsCount)
26
- residentChart3.update()
27
- } else {
28
- const text1 = window.document.getElementById('resident-components')
29
- const text2 = window.document.getElementById('resident-scenes')
30
- const text3 = window.document.getElementById('resident-reference-maps')
31
-
32
- text1.textContent = data.map(entry => entry.componentResidentsCount)
33
- text2.textContent = data.map(entry => entry.sceneResidentsCount)
34
- text3.textContent = data.map(entry => entry.referenceMapResidentsCount)
35
-
36
- console.error('Charts are not initialized yet.')
7
+ const updateCharts = ({ sceneResidents, history }) => {
8
+ residentChart1.data.labels = history.map(entry => entry.timestamp)
9
+ residentChart1.data.datasets[0].data = history.map(entry => entry.componentResidentsCount)
10
+ residentChart1.update()
11
+
12
+ residentChart2.data.labels = history.map(entry => entry.timestamp)
13
+ residentChart2.data.datasets[0].data = history.map(entry => entry.sceneResidentsCount)
14
+ residentChart2.update()
15
+
16
+ residentChart3.data.labels = history.map(entry => entry.timestamp)
17
+ residentChart3.data.datasets[0].data = history.map(entry => entry.referenceMapResidentsCount)
18
+ residentChart3.update()
19
+
20
+ updateResidentsTable(sceneResidents)
21
+ }
22
+
23
+ // sceneResidents 테이블 업데이트 함수
24
+ const updateResidentsTable = sceneResidents => {
25
+ console.log('updateResidentesTable', sceneResidents)
26
+ if (typeof sceneResidents !== 'object') {
27
+ return
28
+ }
29
+
30
+ const table = document.getElementById('residentsTable')
31
+ table.innerHTML = '' // 기존 테이블 내용을 지움
32
+
33
+ // 테이블 헤더 생성
34
+ const headerRow = document.createElement('tr')
35
+ headerRow.innerHTML = '<th>Type</th><th>Up</th><th>Down</th><th>Difference (Up - Down)</th>'
36
+ table.appendChild(headerRow)
37
+
38
+ // sceneResidents 데이터로 테이블 행 생성
39
+ for (const [type, residents] of Object.entries(sceneResidents)) {
40
+ residents.forEach(({ up, down }) => {
41
+ const row = document.createElement('tr')
42
+ const difference = up - down
43
+ row.innerHTML = `<td>${type}</td><td>${up}</td><td>${down}</td><td>${difference}</td>`
44
+ table.appendChild(row)
45
+ })
37
46
  }
38
47
  }
39
48
 
40
49
  // 차트 초기화 함수
41
50
  const resetCharts = window => {
42
- if (residentChart1 || residentChart2 || residentChart3) {
43
- console.log('Charts already initialized, skipping reset.')
44
- return // 이미 초기화된 경우 차트를 다시 초기화하지 않음
51
+ const createChart = (ctx, label) => {
52
+ return new Chart(ctx, {
53
+ type: 'bar', // Bar chart
54
+ data: {
55
+ labels: [], // X축 라벨을 비워둠으로써 시리즈명을 숨김
56
+ datasets: [
57
+ {
58
+ label: label, // 데이터셋의 레이블 (범례로 표시되지 않음)
59
+ data: [], // 실제 데이터
60
+ backgroundColor: 'rgba(75, 192, 192, 0.5)', // 막대의 색상
61
+ borderColor: 'rgba(75, 192, 192, 1)', // 막대의 테두리 색상
62
+ borderWidth: 1 // 막대의 테두리 두께
63
+ }
64
+ ]
65
+ },
66
+ options: {
67
+ animation: false, // 애니메이션 비활성화
68
+ scales: {
69
+ x: {
70
+ display: false, // X축 숨기기 (전체)
71
+ grid: {
72
+ display: false // X축의 격자선 숨기기
73
+ },
74
+ ticks: {
75
+ display: false // X축 틱 마크 숨기기
76
+ }
77
+ },
78
+ y: {
79
+ beginAtZero: true, // Y축이 0에서 시작되도록 설정
80
+ title: {
81
+ display: true,
82
+ text: label // Y축의 레이블
83
+ },
84
+ ticks: {
85
+ stepSize: 1
86
+ }
87
+ }
88
+ },
89
+ plugins: {
90
+ legend: {
91
+ display: false // 범례 숨기기
92
+ }
93
+ }
94
+ }
95
+ })
45
96
  }
46
97
 
47
98
  const ctx1 = window.document.getElementById('residentChart1').getContext('2d')
48
99
  const ctx2 = window.document.getElementById('residentChart2').getContext('2d')
49
100
  const ctx3 = window.document.getElementById('residentChart3').getContext('2d')
50
- console.log('Initializing charts:', ctx1, ctx2, ctx3)
51
-
52
- residentChart1 = new Chart(ctx1, {
53
- type: 'line',
54
- data: {
55
- labels: [],
56
- datasets: [
57
- {
58
- label: 'Component Residents Count',
59
- data: [],
60
- borderColor: 'rgba(75, 192, 192, 1)',
61
- borderWidth: 1,
62
- fill: false
63
- }
64
- ]
65
- },
66
- options: {
67
- scales: {
68
- x: { display: false, ticks: { display: false } },
69
- y: { title: { display: true, text: 'Component Residents Count' } }
70
- }
71
- }
72
- })
73
101
 
74
- residentChart2 = new Chart(ctx2, {
75
- type: 'line',
76
- data: {
77
- labels: [],
78
- datasets: [
79
- {
80
- label: 'Scene Residents Count',
81
- data: [],
82
- borderColor: 'rgba(75, 192, 192, 1)',
83
- borderWidth: 1,
84
- fill: false
85
- }
86
- ]
87
- },
88
- options: {
89
- scales: {
90
- x: { display: false, ticks: { display: false } },
91
- y: { title: { display: true, text: 'Scene Residents Count' } }
92
- }
93
- }
94
- })
102
+ residentChart1 = createChart(ctx1, 'Component Residents Count')
103
+ residentChart2 = createChart(ctx2, 'Scene Residents Count')
104
+ residentChart3 = createChart(ctx3, 'ReferenceMap Residents Count')
95
105
 
96
- residentChart3 = new Chart(ctx3, {
97
- type: 'line',
98
- data: {
99
- labels: [],
100
- datasets: [
101
- {
102
- label: 'ReferenceMap Residents Count',
103
- data: [],
104
- borderColor: 'rgba(75, 192, 192, 1)',
105
- borderWidth: 1,
106
- fill: false
107
- }
108
- ]
109
- },
110
- options: {
111
- scales: {
112
- x: { display: false, ticks: { display: false } },
113
- y: { title: { display: true, text: 'ReferenceMap Residents Count' } }
114
- }
115
- }
116
- })
117
-
118
- console.log('Charts initialized:', residentChart1, residentChart2, residentChart3)
106
+ chartsInitialized = true
119
107
  }
120
108
 
121
109
  // 패널이 처음 열리거나 다시 열릴 때마다 호출
122
110
  panel.onShown.addListener(function (window) {
123
111
  console.log('DevTools panel shown')
112
+ panelWindow = window
124
113
  resetCharts(window) // 패널이 열릴 때 차트를 초기화
125
114
 
126
115
  // 초기 로딩 시 저장된 데이터를 가져옴
@@ -140,9 +129,8 @@ chrome.devtools.panels.create('Board Monitor', 'icons/icon48.png', 'devtools.htm
140
129
  const tabId = chrome.devtools.inspectedWindow.tabId
141
130
 
142
131
  if (tabId && message.type === 'UPDATE_CHART' && message.tabId === tabId) {
143
- console.log('Received UPDATE_CHART message:', tabId, message)
144
132
  chrome.storage.local.get({ residentData: {} }, result => {
145
- if (result.residentData[tabId]) {
133
+ if (chartsInitialized && result.residentData[tabId]) {
146
134
  updateCharts(result.residentData[tabId])
147
135
  }
148
136
  })
@@ -150,6 +138,4 @@ chrome.devtools.panels.create('Board Monitor', 'icons/icon48.png', 'devtools.htm
150
138
  })
151
139
  listenerRegistered = true // 리스너가 중복 등록되지 않도록 설정
152
140
  }
153
-
154
- panelCreated = true // 패널이 생성되었음을 표시
155
141
  })
@@ -1,28 +1,25 @@
1
1
  function logComponentResidents() {
2
- const componentResidentsCount = window.scene.Component?.residentsCount || 0;
3
- const sceneResidentsCount = window.scene.Scene?.residentsCount || 0;
4
- const referenceMapResidentsCount =
5
- window.scene.ReferenceMap?.residentsCount || 0;
6
- const timestamp = new Date().toISOString();
7
-
8
- console.log(
9
- `Component Residents Count: ${componentResidentsCount}, Scene Residents Count: ${sceneResidentsCount}, ReferenceMap Residents Count: ${referenceMapResidentsCount} at ${timestamp}`
10
- );
2
+ const componentResidentsCount = window.scene.Component?.residentsCount || 0
3
+ const sceneResidentsCount = window.scene.Scene?.residentsCount || 0
4
+ const sceneResidents = window.scene.Scene?.residents || {}
5
+ const referenceMapResidentsCount = window.scene.ReferenceMap?.residentsCount || 0
6
+ const timestamp = new Date().toISOString()
11
7
 
12
8
  window.postMessage(
13
9
  {
14
- type: "RESIDENT_COUNT",
10
+ type: 'RESIDENT_COUNT',
15
11
  timestamp,
16
12
  componentResidentsCount,
17
13
  sceneResidentsCount,
18
- referenceMapResidentsCount,
14
+ sceneResidents,
15
+ referenceMapResidentsCount
19
16
  },
20
- "*"
21
- );
17
+ '*'
18
+ )
22
19
  }
23
20
 
24
21
  setTimeout(() => {
25
22
  if (window.scene) {
26
- setInterval(logComponentResidents, 5000);
23
+ setInterval(logComponentResidents, 5000)
27
24
  }
28
- }, 5000);
25
+ }, 5000)