1111FONT_SIZE = 18
1212DOT_SIZE_2D = 20
1313DOT_SIZE_3D = 10
14-
14+ LABELS_SUMMARY_LENGTH = 15
1515
1616def extract_annotation_vectors (db : DbClient ):
1717 vectors = []
@@ -73,19 +73,30 @@ def minifold_vectors_3d(vectors: np.array):
7373 return vectors_3d
7474
7575
76- def plot_vectors_2d (vectors_2d : np .array , title ):
77- fig = px .scatter (x = vectors_2d [:, 0 ], y = vectors_2d [:, 1 ])
78- fig .update_layout (title = title , xaxis_title = "X" , yaxis_title = "Y" )
76+ def plot_vectors_2d (vectors_2d : np .array , title : str , labels : list = None ):
77+ fig = px .scatter (
78+ x = vectors_2d [:, 0 ],
79+ y = vectors_2d [:, 1 ],
80+ text = labels ,
81+ )
82+ fig .update_traces (textposition = 'top center' )
83+ fig .update_layout (
84+ title = title ,
85+ xaxis_title = "X" ,
86+ yaxis_title = "Y" ,
87+ )
7988 st .plotly_chart (fig , use_container_width = True )
8089
8190
82- def plot_vectors_3d (vectors_3d : np .array , title ):
91+ def plot_vectors_3d (vectors_3d : np .array , title : str , labels : list = None ):
8392 fig = px .scatter_3d (
8493 x = vectors_3d [:, 0 ],
8594 y = vectors_3d [:, 1 ],
8695 z = vectors_3d [:, 2 ],
8796 color = vectors_3d [:, 2 ],
97+ text = labels ,
8898 )
99+ fig .update_traces (textposition = 'top center' )
89100 fig .update_layout (title = title , xaxis_title = "X" , yaxis_title = "Y" )
90101 st .plotly_chart (fig , use_container_width = True )
91102
@@ -180,29 +191,31 @@ def plot_2_sets_in_one_3d(
180191def visualize_vectors ():
181192 st .header ("Visualizing vectors" )
182193 with get_db_client () as db :
183- Req_tab , Anno_tab , Req_Anno_tab = st .tabs (
194+ req_tab , anno_tab , req_anno_tab = st .tabs (
184195 ["Requirements" , "Annotations" , "Requirements vs Annotations" ]
185196 )
186- with Req_tab :
197+ with req_tab :
187198 st .subheader ("Requirements vectors" )
188199 progress_bar = st .progress (0 )
189200
190201 requirement_vectors = extract_requirement_vectors (db )
191202 progress_bar .progress (20 , "Extracted" )
192203 reqs_vectors_2d = minifold_vectors_2d (requirement_vectors )
193204 progress_bar .progress (40 , "Minifolded for 2D" )
194- plot_vectors_2d (reqs_vectors_2d , "Requirements" )
205+ req_labels = db .get_column_values ("external_id" , from_table = "Requirements" )
206+ plot_vectors_2d (reqs_vectors_2d , "Requirements" , labels = req_labels )
195207 progress_bar .progress (60 , "Plotted in 2D" )
196208 reqs_vectors_3d = minifold_vectors_3d (requirement_vectors )
197209 progress_bar .progress (80 , "Minifolded for 3D" )
198210 plot_vectors_3d (reqs_vectors_3d , "Requirements" )
199211 progress_bar .progress (100 , "Plotted in 3D" )
200212
201- with Anno_tab :
213+ with anno_tab :
202214 st .subheader ("Annotations vectors" )
203215 progress_bar = st .progress (0 )
204216
205217 annotation_vectors = extract_annotation_vectors (db )
218+ anno_labels = db .get_column_values ("id" , from_table = "Annotations" )
206219 progress_bar .progress (20 , "Extracted" )
207220 anno_vectors_2d = minifold_vectors_2d (annotation_vectors )
208221 progress_bar .progress (40 , "Minifolded for 2D" )
@@ -213,17 +226,23 @@ def visualize_vectors():
213226 plot_vectors_3d (anno_vectors_3d , "Annotations" )
214227 progress_bar .progress (100 , "Plotted in 3D" )
215228
216- with Req_Anno_tab :
229+ with req_anno_tab :
217230 # Show how these 2 groups of vectors are different
218231 st .subheader ("Requirements vs Annotations" )
219232 progress_bar = st .progress (40 , "Extracted" )
220233 plot_2_sets_in_one_2d (
221- reqs_vectors_2d , anno_vectors_2d , "Requerements" , "Annotations"
234+ reqs_vectors_2d ,
235+ anno_vectors_2d ,
236+ first_title = "Requirements" ,
237+ second_title = "Annotations" ,
222238 )
223239 progress_bar .progress (60 , "Plotted in 2D" )
224240
225241 plot_2_sets_in_one_3d (
226- reqs_vectors_3d , anno_vectors_3d , "Requerements" , "Annotations"
242+ reqs_vectors_3d ,
243+ anno_vectors_3d ,
244+ first_title = "Requirements" ,
245+ second_title = "Annotations" ,
227246 )
228247 progress_bar .progress (80 , "Plotted in 3D" )
229248
@@ -232,7 +251,10 @@ def visualize_vectors():
232251 )
233252
234253 plot_2_sets_in_one_2d (
235- reqs_vectors_2d , anno_vectors_2d , "Requerements" , "Annotations"
254+ reqs_vectors_2d ,
255+ anno_vectors_2d ,
256+ first_title = "Requirements" ,
257+ second_title = "Annotations" ,
236258 )
237259 progress_bar .progress (100 , "Minifolded and Plotted in 2D" )
238260
0 commit comments