tx3bas commited on
Commit
18f19b5
·
verified ·
1 Parent(s): c065ffc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -2
app.py CHANGED
@@ -11,6 +11,11 @@ def hex_to_rgba(hex_color, alpha=1.0):
11
  hex_color = hex_color.lstrip('#')
12
  return f'rgba({int(hex_color[0:2], 16)},{int(hex_color[2:4], 16)},{int(hex_color[4:6], 16)},{alpha})'
13
 
 
 
 
 
 
14
  # Lista de fuentes más utilizadas
15
  font_options = [
16
  "Times New Roman", "Arial", "Helvetica", "Calibri", "Verdana",
@@ -50,15 +55,39 @@ show_grid = st.sidebar.checkbox("Mostrar Líneas de Rejilla", value=True)
50
  x_axis_label = st.sidebar.text_input("Etiqueta para el Eje X", "Tiempo")
51
  y_axis_label = st.sidebar.text_input("Etiqueta para el Eje Y", "Variables")
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # Crear el DataFrame con franjas de tiempo
54
  data_list = []
55
- for y_name, (start_date, end_date) in y_values.items():
56
  if start_date and end_date and y_name:
57
  data_list.append({
58
  'Variable': y_name,
59
  'Start': datetime.strptime(start_date, '%Y-%m-%d'),
60
  'End': datetime.strptime(end_date, '%Y-%m-%d'),
61
- 'Category': '' if stacked else y_name # Eliminar "Apilado" cuando se apilen las franjas
 
 
 
 
62
  })
63
 
64
  data = pd.DataFrame(data_list)
@@ -73,6 +102,11 @@ if stacked:
73
  # Crear gráfico de franjas de tiempo
74
  fig = px.timeline(data, x_start="Start", x_end="End", y="Category", color="Variable", title=chart_title)
75
 
 
 
 
 
 
76
  # Actualizar el diseño del gráfico
77
  fig.update_yaxes(categoryorder="total ascending")
78
 
 
11
  hex_color = hex_color.lstrip('#')
12
  return f'rgba({int(hex_color[0:2], 16)},{int(hex_color[2:4], 16)},{int(hex_color[4:6], 16)},{alpha})'
13
 
14
+ # Colores predefinidos
15
+ predefined_colors = [
16
+ "#FF5C5C", "#5CCFFF", "#FFA500", "#90EE90", "#9370DB", "#FFD700"
17
+ ]
18
+
19
  # Lista de fuentes más utilizadas
20
  font_options = [
21
  "Times New Roman", "Arial", "Helvetica", "Calibri", "Verdana",
 
55
  x_axis_label = st.sidebar.text_input("Etiqueta para el Eje X", "Tiempo")
56
  y_axis_label = st.sidebar.text_input("Etiqueta para el Eje Y", "Variables")
57
 
58
+ # Opción para múltiples colores
59
+ use_multiple_colors = st.sidebar.checkbox("Usar múltiples colores", value=True, key="use_multiple_colors")
60
+
61
+ # Seleccionar color(es) para el gráfico
62
+ selected_color = st.sidebar.color_picker("Color", "#24CBA0", key="single_color")
63
+
64
+ # Definir colores
65
+ if use_multiple_colors:
66
+ colors = [hex_to_rgba(st.sidebar.color_picker(f"Color {i+1}", predefined_colors[i % len(predefined_colors)], key=f"color_{i}"))
67
+ for i in range(num_y_vars)]
68
+ else:
69
+ color = hex_to_rgba(selected_color)
70
+ colors = [color] * num_y_vars # Definir colors para casos donde no se usa múltiple colores
71
+
72
+ # Opciones adicionales
73
+ with st.sidebar.expander("Opciones Adicionales"):
74
+ opacity = st.slider("Opacidad (%)", min_value=0, max_value=100, value=100, step=1) / 100
75
+ border_width = st.slider("Grosor del Borde", min_value=0.0, max_value=3.0, value=1.0, step=0.1)
76
+ border_opacity = st.slider("Opacidad del Borde (%)", min_value=0, max_value=100, value=100, step=1) / 100
77
+
78
  # Crear el DataFrame con franjas de tiempo
79
  data_list = []
80
+ for idx, (y_name, (start_date, end_date)) in enumerate(y_values.items()):
81
  if start_date and end_date and y_name:
82
  data_list.append({
83
  'Variable': y_name,
84
  'Start': datetime.strptime(start_date, '%Y-%m-%d'),
85
  'End': datetime.strptime(end_date, '%Y-%m-%d'),
86
+ 'Category': '' if stacked else y_name, # Eliminar "Apilado" cuando se apilen las franjas
87
+ 'Color': colors[idx], # Asignar color a cada variable
88
+ 'Opacity': opacity,
89
+ 'Border Width': border_width,
90
+ 'Border Opacity': border_opacity
91
  })
92
 
93
  data = pd.DataFrame(data_list)
 
102
  # Crear gráfico de franjas de tiempo
103
  fig = px.timeline(data, x_start="Start", x_end="End", y="Category", color="Variable", title=chart_title)
104
 
105
+ # Actualizar los colores y estilos de las franjas
106
+ for idx, row in data.iterrows():
107
+ fig.data[idx].update(marker_color=row['Color'], opacity=row['Opacity'])
108
+ fig.data[idx].update(marker_line=dict(width=row['Border Width'], color=f'rgba(0,0,0,{row["Border Opacity"]})'))
109
+
110
  # Actualizar el diseño del gráfico
111
  fig.update_yaxes(categoryorder="total ascending")
112