1
1
import { errorMsg } from "./tools.js" ;
2
2
import { PdgToggle } from "./menu/show-pdg.js" ;
3
3
import { drawAll } from "./draw.js" ;
4
- import {
5
- bits ,
6
- genStatus ,
7
- renderRangeParameters ,
8
- parametersRange ,
9
- getWidthFilterContent ,
10
- renderGenSim ,
11
- } from "./menu/filter/filter.js" ;
12
- import {
13
- mouseDown ,
14
- mouseUp ,
15
- mouseOut ,
16
- mouseMove ,
17
- getVisible ,
18
- onScroll ,
19
- } from "./events.js" ;
20
- import { loadObjects } from "./types/load.js" ;
21
- import { objectTypes } from "./types/objects.js" ;
22
- import { copyObject } from "./lib/copy.js" ;
4
+ import { getWidthFilterContent } from "./menu/filter/filter.js" ;
5
+ import { mouseDown , mouseUp , mouseOut , mouseMove , onScroll } from "./events.js" ;
6
+ import { showEventSwitcher , loadSelectedEvent } from "./menu/event-number.js" ;
7
+ import { renderEvent } from "./menu/event-number.js" ;
23
8
24
9
const canvas = document . getElementById ( "canvas" ) ;
25
10
const ctx = canvas . getContext ( "2d" ) ;
26
11
27
- const manipulationTools = document . getElementsByClassName ( "manipulation-tool" ) ;
28
- const filter = document . getElementById ( "filter" ) ;
29
- const filters = document . getElementById ( "filters" ) ;
30
-
31
12
canvas . width = window . innerWidth ;
32
13
canvas . height = window . innerHeight ;
33
14
34
- let jsonData = { } ;
15
+ const jsonData = { } ;
35
16
36
17
const dragTools = {
37
18
draggedObject : null ,
@@ -46,17 +27,9 @@ const currentObjects = {};
46
27
47
28
const visibleObjects = { } ;
48
29
49
- function start ( currentObjects , visibleObjects ) {
50
- for ( const [ key , value ] of Object . entries ( currentObjects ) ) {
51
- const classType = objectTypes [ key ] ;
52
- const collection = value . collection ;
53
- classType . setup ( collection , canvas ) ;
54
- }
55
-
56
- drawAll ( ctx , currentObjects ) ;
57
-
58
- getVisible ( currentObjects , visibleObjects ) ;
59
- }
30
+ const selectedObjectTypes = {
31
+ types : [ "edm4hep::MCParticle" ] ,
32
+ } ;
60
33
61
34
canvas . onmousedown = ( event ) => {
62
35
mouseDown ( event , visibleObjects , dragTools ) ;
@@ -74,14 +47,6 @@ window.onscroll = () => {
74
47
onScroll ( currentObjects , visibleObjects ) ;
75
48
} ;
76
49
77
- /*
78
- function showInputModal() {
79
- const modal = document.getElementById("input-modal");
80
-
81
- modal.style.display = "block";
82
- }
83
- */
84
-
85
50
function hideInputModal ( ) {
86
51
const modal = document . getElementById ( "input-modal" ) ;
87
52
@@ -101,11 +66,37 @@ document.getElementById("input-file").addEventListener("change", (event) => {
101
66
const reader = new FileReader ( ) ;
102
67
reader . addEventListener ( "load" , ( event ) => {
103
68
const fileText = event . target . result ;
104
- jsonData = JSON . parse ( fileText ) ;
69
+ jsonData . data = JSON . parse ( fileText ) ;
105
70
106
71
const eventNumberInput = document . getElementById ( "event-number" ) ;
107
- eventNumberInput . max = Object . keys ( jsonData ) . length - 1 ;
72
+ const options = Object . keys ( jsonData . data ) . map ( ( event ) =>
73
+ parseInt ( event . replace ( "Event " , "" ) )
74
+ ) ;
75
+ eventNumberInput . max = Object . keys ( options ) . length - 1 ;
76
+ if ( options . length === 0 ) {
77
+ errorMsg ( "No events found in the file!" ) ;
78
+ return ;
79
+ }
80
+ eventNumberInput . value = options [ 0 ] ;
108
81
document . getElementById ( "event-selector" ) . style . display = "block" ;
82
+ const eventOptions = document . getElementById ( "event-number" ) ;
83
+ const eventSelectorMenu = document . getElementById ( "event-selector-menu" ) ;
84
+ eventOptions . replaceChildren ( ) ;
85
+ eventSelectorMenu . replaceChildren ( ) ;
86
+ options . forEach ( ( option ) => {
87
+ const optionElement = document . createElement ( "option" ) ;
88
+ optionElement . appendChild ( document . createTextNode ( option ) ) ;
89
+ eventOptions . appendChild ( optionElement ) ;
90
+
91
+ const optionElementMenu = document . createElement ( "div" ) ;
92
+ optionElementMenu . className = "event-option" ;
93
+ optionElementMenu . appendChild ( document . createTextNode ( option ) ) ;
94
+ eventSelectorMenu . appendChild ( optionElementMenu ) ;
95
+ optionElementMenu . addEventListener ( "click" , ( ) => {
96
+ renderEvent ( option ) ;
97
+ eventSelectorMenu . style . display = "none" ;
98
+ } ) ;
99
+ } ) ;
109
100
} ) ;
110
101
reader . readAsText ( file ) ;
111
102
break ;
@@ -118,42 +109,12 @@ document
118
109
event . preventDefault ( ) ;
119
110
const eventNum = document . getElementById ( "event-number" ) . value ;
120
111
121
- const selectedObjectTypes = [ "edm4hep::MCParticle" ] ;
122
- const objects = loadObjects ( jsonData , eventNum , selectedObjectTypes ) ;
123
-
124
- copyObject ( objects , loadedObjects ) ;
125
- copyObject ( objects , currentObjects ) ;
126
-
127
- const length = Object . values ( loadedObjects )
128
- . map ( ( obj ) => obj . collection . length )
129
- . reduce ( ( a , b ) => a + b , 0 ) ;
130
-
131
- if ( length === 0 ) {
132
- errorMsg ( "Provided file does not contain any MC particle tree!" ) ;
133
- return ;
134
- }
135
- for ( const eventNum in jsonData ) {
136
- delete jsonData [ eventNum ] ;
137
- }
138
- start ( currentObjects , visibleObjects ) ;
139
112
hideInputModal ( ) ;
140
- window . scroll ( ( canvas . width - window . innerWidth ) / 2 , 0 ) ;
113
+ showEventSwitcher ( eventNum ) ;
114
+ loadSelectedEvent ( ) ;
141
115
142
- for ( const tool of manipulationTools ) {
143
- tool . style . display = "flex" ;
144
- }
145
-
146
- const mcObjects = loadedObjects [ "edm4hep::MCParticle" ] . collection ;
147
- mcObjects . forEach ( ( mcObject ) => {
148
- genStatus . add ( mcObject . generatorStatus ) ;
149
- } ) ;
150
- genStatus . setCheckBoxes ( ) ;
151
- renderRangeParameters ( filters , parametersRange ) ;
152
116
const width = getWidthFilterContent ( ) ;
153
117
filter . style . width = width ;
154
-
155
- renderGenSim ( bits , genStatus , filters ) ;
156
-
157
118
const pdgToggle = new PdgToggle ( "show-pdg" ) ;
158
119
pdgToggle . init ( ( ) => {
159
120
pdgToggle . toggle ( currentObjects , ( ) => {
@@ -162,4 +123,12 @@ document
162
123
} ) ;
163
124
} ) ;
164
125
165
- export { canvas , ctx , loadedObjects , currentObjects , visibleObjects } ;
126
+ export {
127
+ canvas ,
128
+ ctx ,
129
+ loadedObjects ,
130
+ currentObjects ,
131
+ visibleObjects ,
132
+ jsonData ,
133
+ selectedObjectTypes ,
134
+ } ;
0 commit comments