Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -783,33 +783,31 @@ def enhanced_likert_scale(question_data):
|
|
| 783 |
st.markdown(f"<div style='text-align:right; font-weight:bold; margin-bottom:15px; direction: rtl;'>{question}</div>",
|
| 784 |
unsafe_allow_html=True)
|
| 785 |
|
| 786 |
-
#
|
| 787 |
-
|
| 788 |
-
<div style='display: flex; justify-content: space-between; max-width: 475px; margin: 0 auto 25px; direction: rtl; position: relative; height: 30px;'>
|
| 789 |
-
<div style='position: absolute; right: 0; text-align: center;'>
|
| 790 |
-
<span style='font-size: 14px; font-weight: bold; color: #6a0dad;'>{labels[0]}</span>
|
| 791 |
-
<div style='height: 15px; width: 2px; background: #6a0dad; margin: 2px auto;'></div>
|
| 792 |
-
</div>
|
| 793 |
-
"""
|
| 794 |
-
|
| 795 |
if scale % 2 == 1: # اگر مقیاس فرد باشد
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
<
|
| 799 |
-
|
| 800 |
-
|
| 801 |
"""
|
| 802 |
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 807 |
</div>
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
# نمایش برچسبها
|
| 812 |
-
st.markdown(labels_html, unsafe_allow_html=True)
|
| 813 |
|
| 814 |
# رادیو باتن اصلی (مخفی)
|
| 815 |
selected_value = st.radio(
|
|
@@ -849,26 +847,14 @@ def enhanced_likert_scale(question_data):
|
|
| 849 |
</script>
|
| 850 |
"""
|
| 851 |
|
| 852 |
-
# ایجاد دکمههای سفارشی با
|
| 853 |
-
options_html = [
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
option_html = f"""
|
| 861 |
-
<div class="likert-option-container" style="position: relative;">
|
| 862 |
-
<div class="likert-option {'selected' if is_selected else ''}"
|
| 863 |
-
onclick="handleLikertClick({i})">
|
| 864 |
-
<span class="likert-number">{i+1}</span>
|
| 865 |
-
</div>
|
| 866 |
-
{'<div class="likert-guide-line"></div>' if is_first or is_last or is_middle else ''}
|
| 867 |
-
</div>
|
| 868 |
-
"""
|
| 869 |
-
options_html.append(option_html)
|
| 870 |
-
|
| 871 |
-
options_html = "".join(options_html)
|
| 872 |
|
| 873 |
# ترکیب تمام بخشها با استایل بهبود یافته
|
| 874 |
components.html(
|
|
@@ -883,11 +869,7 @@ def enhanced_likert_scale(question_data):
|
|
| 883 |
margin: 0 auto;
|
| 884 |
direction: rtl;
|
| 885 |
position: relative;
|
| 886 |
-
|
| 887 |
-
.likert-option-container {{
|
| 888 |
-
display: flex;
|
| 889 |
-
flex-direction: column;
|
| 890 |
-
align-items: center;
|
| 891 |
}}
|
| 892 |
.likert-option {{
|
| 893 |
width: 36px;
|
|
@@ -902,7 +884,7 @@ def enhanced_likert_scale(question_data):
|
|
| 902 |
margin: 0 3px;
|
| 903 |
transition: all 0.2s;
|
| 904 |
position: relative;
|
| 905 |
-
z-index:
|
| 906 |
}}
|
| 907 |
.likert-option:hover {{
|
| 908 |
transform: scale(1.1);
|
|
@@ -921,20 +903,96 @@ def enhanced_likert_scale(question_data):
|
|
| 921 |
.likert-option.selected .likert-number {{
|
| 922 |
color: white;
|
| 923 |
}}
|
| 924 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 925 |
position: absolute;
|
| 926 |
-
bottom: -
|
| 927 |
-
|
|
|
|
| 928 |
width: 2px;
|
| 929 |
-
|
| 930 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 931 |
}}
|
| 932 |
</style>
|
| 933 |
<div class="likert-container">
|
| 934 |
{options_html}
|
| 935 |
</div>
|
| 936 |
""",
|
| 937 |
-
height=
|
| 938 |
)
|
| 939 |
|
| 940 |
# نمایش وضعیت انتخاب با استایل بهبود یافته
|
|
@@ -945,7 +1003,7 @@ def enhanced_likert_scale(question_data):
|
|
| 945 |
text-align: right;
|
| 946 |
color: #6a0dad;
|
| 947 |
direction: rtl;
|
| 948 |
-
margin-top:
|
| 949 |
padding: 10px;
|
| 950 |
background-color: #f8f0ff;
|
| 951 |
border-radius: 8px;
|
|
|
|
| 783 |
st.markdown(f"<div style='text-align:right; font-weight:bold; margin-bottom:15px; direction: rtl;'>{question}</div>",
|
| 784 |
unsafe_allow_html=True)
|
| 785 |
|
| 786 |
+
# نمایش برچسبها با خطوط ارتباطی
|
| 787 |
+
middle_label = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
if scale % 2 == 1: # اگر مقیاس فرد باشد
|
| 789 |
+
middle_value = (scale // 2) + 1
|
| 790 |
+
middle_label = f"""
|
| 791 |
+
<div class='label-container middle-label' style='left: 50%; transform: translateX(-50%);'>
|
| 792 |
+
<span>متوسط</span>
|
| 793 |
+
</div>
|
| 794 |
"""
|
| 795 |
|
| 796 |
+
# ایجاد ساختار HTML برای برچسبها
|
| 797 |
+
st.markdown(
|
| 798 |
+
f"""
|
| 799 |
+
<div class='labels-container'>
|
| 800 |
+
<div class='label-container left-label'>
|
| 801 |
+
<span>{labels[0]}</span>
|
| 802 |
+
</div>
|
| 803 |
+
{middle_label}
|
| 804 |
+
<div class='label-container right-label'>
|
| 805 |
+
<span>{labels[1]}</span>
|
| 806 |
+
</div>
|
| 807 |
</div>
|
| 808 |
+
""",
|
| 809 |
+
unsafe_allow_html=True
|
| 810 |
+
)
|
|
|
|
|
|
|
| 811 |
|
| 812 |
# رادیو باتن اصلی (مخفی)
|
| 813 |
selected_value = st.radio(
|
|
|
|
| 847 |
</script>
|
| 848 |
"""
|
| 849 |
|
| 850 |
+
# ایجاد دکمههای سفارشی با استایل بهبود یافته
|
| 851 |
+
options_html = "".join([
|
| 852 |
+
f'<div class="likert-option {"selected" if st.session_state.get(key) == i+1 else ""} {"middle-option" if (scale % 2 == 1 and i+1 == (scale//2 + 1)) else ""}" '
|
| 853 |
+
f'onclick="handleLikertClick({i})">'
|
| 854 |
+
f'<span class="likert-number">{i+1}</span>'
|
| 855 |
+
'</div>'
|
| 856 |
+
for i in range(scale)
|
| 857 |
+
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 858 |
|
| 859 |
# ترکیب تمام بخشها با استایل بهبود یافته
|
| 860 |
components.html(
|
|
|
|
| 869 |
margin: 0 auto;
|
| 870 |
direction: rtl;
|
| 871 |
position: relative;
|
| 872 |
+
padding-top: 40px; /* فضای کافی برای خطوط و لیبلها */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 873 |
}}
|
| 874 |
.likert-option {{
|
| 875 |
width: 36px;
|
|
|
|
| 884 |
margin: 0 3px;
|
| 885 |
transition: all 0.2s;
|
| 886 |
position: relative;
|
| 887 |
+
z-index: 1;
|
| 888 |
}}
|
| 889 |
.likert-option:hover {{
|
| 890 |
transform: scale(1.1);
|
|
|
|
| 903 |
.likert-option.selected .likert-number {{
|
| 904 |
color: white;
|
| 905 |
}}
|
| 906 |
+
.labels-container {{
|
| 907 |
+
display: flex;
|
| 908 |
+
justify-content: space-between;
|
| 909 |
+
width: 100%;
|
| 910 |
+
max-width: 475px;
|
| 911 |
+
margin: 0 auto 10px;
|
| 912 |
+
position: relative;
|
| 913 |
+
direction: rtl;
|
| 914 |
+
}}
|
| 915 |
+
.label-container {{
|
| 916 |
+
position: relative;
|
| 917 |
+
font-size: 14px;
|
| 918 |
+
font-weight: bold;
|
| 919 |
+
color: #6a0dad;
|
| 920 |
+
text-align: center;
|
| 921 |
+
}}
|
| 922 |
+
.label-container span {{
|
| 923 |
+
display: inline-block;
|
| 924 |
+
}}
|
| 925 |
+
/* خطوط ارتباطی */
|
| 926 |
+
.left-label::before {{
|
| 927 |
+
content: '';
|
| 928 |
position: absolute;
|
| 929 |
+
bottom: -30px;
|
| 930 |
+
right: 50%;
|
| 931 |
+
transform: translateX(50%);
|
| 932 |
width: 2px;
|
| 933 |
+
height: 25px;
|
| 934 |
+
background-color: #6a0dad;
|
| 935 |
+
}}
|
| 936 |
+
.right-label::before {{
|
| 937 |
+
content: '';
|
| 938 |
+
position: absolute;
|
| 939 |
+
bottom: -30px;
|
| 940 |
+
left: 50%;
|
| 941 |
+
transform: translateX(-50%);
|
| 942 |
+
width: 2px;
|
| 943 |
+
height: 25px;
|
| 944 |
+
background-color: #6a0dad;
|
| 945 |
+
}}
|
| 946 |
+
.middle-label::before {{
|
| 947 |
+
content: '';
|
| 948 |
+
position: absolute;
|
| 949 |
+
bottom: -30px;
|
| 950 |
+
left: 50%;
|
| 951 |
+
transform: translateX(-50%);
|
| 952 |
+
width: 2px;
|
| 953 |
+
height: 25px;
|
| 954 |
+
background-color: #6a0dad;
|
| 955 |
+
}}
|
| 956 |
+
/* تنظیم موقعیت خطوط برای گزینههای مقیاس */
|
| 957 |
+
.likert-option:nth-child(1)::before {{
|
| 958 |
+
content: '';
|
| 959 |
+
position: absolute;
|
| 960 |
+
top: -25px;
|
| 961 |
+
left: 50%;
|
| 962 |
+
transform: translateX(-50%);
|
| 963 |
+
width: 2px;
|
| 964 |
+
height: 25px;
|
| 965 |
+
background-color: #6a0dad;
|
| 966 |
+
z-index: 0;
|
| 967 |
+
}}
|
| 968 |
+
.likert-option:nth-child({scale})::before {{
|
| 969 |
+
content: '';
|
| 970 |
+
position: absolute;
|
| 971 |
+
top: -25px;
|
| 972 |
+
left: 50%;
|
| 973 |
+
transform: translateX(-50%);
|
| 974 |
+
width: 2px;
|
| 975 |
+
height: 25px;
|
| 976 |
+
background-color: #6a0dad;
|
| 977 |
+
z-index: 0;
|
| 978 |
+
}}
|
| 979 |
+
.likert-option.middle-option::before {{
|
| 980 |
+
content: '';
|
| 981 |
+
position: absolute;
|
| 982 |
+
top: -25px;
|
| 983 |
+
left: 50%;
|
| 984 |
+
transform: translateX(-50%);
|
| 985 |
+
width: 2px;
|
| 986 |
+
height: 25px;
|
| 987 |
+
background-color: #6a0dad;
|
| 988 |
+
z-index: 0;
|
| 989 |
}}
|
| 990 |
</style>
|
| 991 |
<div class="likert-container">
|
| 992 |
{options_html}
|
| 993 |
</div>
|
| 994 |
""",
|
| 995 |
+
height=110 # افزایش ارتفاع برای جا دادن خطوط و لیبلها
|
| 996 |
)
|
| 997 |
|
| 998 |
# نمایش وضعیت انتخاب با استایل بهبود یافته
|
|
|
|
| 1003 |
text-align: right;
|
| 1004 |
color: #6a0dad;
|
| 1005 |
direction: rtl;
|
| 1006 |
+
margin-top: 20px;
|
| 1007 |
padding: 10px;
|
| 1008 |
background-color: #f8f0ff;
|
| 1009 |
border-radius: 8px;
|