Eduard Kharakhashyan commited on
Commit
50916a6
·
1 Parent(s): 2dfde63

short and full names, hints

Browse files
Files changed (1) hide show
  1. app.py +60 -11
app.py CHANGED
@@ -2,16 +2,19 @@ import streamlit as st
2
 
3
  ss = st.session_state
4
 
5
- GC_NAMES = ['Hydrogen sulphide',
6
- 'Carbone dioxide', 'Nitrogen', 'Methane', 'Ethane', 'Propane', 'N-butane', 'Iso-butane', 'N-pentane',
7
- 'Iso-pentane', 'N-hexane',
8
- 'N-heptane', 'C7+', 'Hydrogen', 'Air', 'Water', 'Oxygen']
 
 
 
 
 
 
 
 
9
 
10
- center_html = """
11
- <div style='display: flex; flex-direction: column; justify-content: center;; height: 38px;'>
12
- <span style='text-align: center; word-wrap: break-word;'>{}</span>
13
- </div>
14
- """
15
 
16
  sg_k = 'sg_value'
17
  pc_k = 'p_crit_value'
@@ -45,6 +48,51 @@ if sg_source == UD:
45
  else:
46
  st.text_input("sg", value=ss[sg_k], key="input_field", disabled=True, help="Calculated")
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  params = []
49
  ss[gc_state_k] = UD
50
  if sg_source != SG_GC:
@@ -59,8 +107,9 @@ with st.expander("Gas components") as gc_exp:
59
  if j >= len(cur_gc):
60
  break
61
  gc11, gc12 = col.columns([1, 1.5])
62
- gc11.markdown(center_html.format(cur_gc[j]), unsafe_allow_html=True)
63
- params.append(gc12.text_input(cur_gc[j], value=0, label_visibility='collapsed'))
 
64
  j += 1
65
 
66
 
 
2
 
3
  ss = st.session_state
4
 
5
+ gc_formula_k = "short"
6
+ gc_full_key = "full name"
7
+ GC_FULL_NAMES = ['Hydrogen sulphide',
8
+ 'Carbone dioxide', 'Nitrogen', 'Methane', 'Ethane', 'Propane', 'N-butane', 'Iso-butane', 'N-pentane',
9
+ 'Iso-pentane', 'N-hexane',
10
+ 'N-heptane', 'C7+', 'Hydrogen', 'Air', 'Water', 'Oxygen']
11
+ GC_SHORT_NAMES = ['H2S', 'CO2', 'N2', "C1", "C2", "C3", "nC4", "iC4", "nC5", "iC5", "C6",
12
+ "C7", "C7+", "H2", "Air", "H2O", "O2"]
13
+
14
+ GC_NAMES = []
15
+ for full_name, short_name in zip(GC_FULL_NAMES, GC_SHORT_NAMES):
16
+ GC_NAMES.append({gc_full_key: full_name, gc_formula_k: short_name})
17
 
 
 
 
 
 
18
 
19
  sg_k = 'sg_value'
20
  pc_k = 'p_crit_value'
 
48
  else:
49
  st.text_input("sg", value=ss[sg_k], key="input_field", disabled=True, help="Calculated")
50
 
51
+
52
+ def text_for_gc(col, gc):
53
+ # Generate unique class names for each image
54
+ hover_class = f'hoverable_{i}'
55
+ tooltip_class = f'tooltip_{i}'
56
+
57
+ # Define the unique CSS for each image
58
+ hover_css = f'''
59
+ .{hover_class} {{
60
+ display: flex;
61
+ flex-direction: column;
62
+ justify-content: center;
63
+ height: 38px;
64
+ }}
65
+ .{hover_class} .{tooltip_class} {{
66
+ visibility: hidden;
67
+ position: absolute;
68
+ bottom: 100%;
69
+ left: 50%;
70
+ transform: translateX(-50%);
71
+ transition: opacity 0.5s;
72
+ background-color: rgba(0, 0, 0, 0.8);
73
+ color: #fff;
74
+ padding: 4px;
75
+ border-radius: 4px;
76
+ text-align: center;
77
+ white-space: nowrap;
78
+ }}
79
+ .{hover_class}:hover .{tooltip_class} {{
80
+ visibility: visible;
81
+ }}
82
+ '''
83
+ tooltip_css = f"<style>{hover_css}</style>"
84
+
85
+ # Define the html for each image
86
+ text_div = f'''
87
+ <div class="{hover_class}">
88
+ <span style='text-align: center; word-wrap: break-word;'>{gc[gc_formula_k]}</span>
89
+ <div class="{tooltip_class}">{gc[gc_full_key]}</div>
90
+ </div>
91
+ '''
92
+ with col:
93
+ st.markdown(f'{text_div}{tooltip_css}', unsafe_allow_html=True)
94
+
95
+
96
  params = []
97
  ss[gc_state_k] = UD
98
  if sg_source != SG_GC:
 
107
  if j >= len(cur_gc):
108
  break
109
  gc11, gc12 = col.columns([1, 1.5])
110
+ text_for_gc(gc11, cur_gc[j])
111
+ params.append(gc12.text_input(cur_gc[j][gc_formula_k], value=0, label_visibility='collapsed',
112
+ help=cur_gc[j][gc_formula_k]))
113
  j += 1
114
 
115