Hello everyone,
First of all, I beg your indulgence
I’ve been struggling with this problem for a few weeks, I haven’t found a way to get what I want.
I’m trying to drag and drop rectangles along the oy axis using TapTool (but another would be nice). I’ve tried to adapt this case
https://discourse.bokeh.org/t/solution-drag-and-drop-for-labels-and-etc/4239/1,
without success.
I’m just starting to learn js with the examples provided here and there.
My example code is as follows:
from bokeh.plotting import figure, show, ColumnDataSource
import pandas as pd
import datetime
pd.options.mode.chained_assignment = None # default='warn'
import numpy as np
from bokeh.io import curdoc
from bokeh.models import DatetimeTickFormatter, HoverTool, TapTool
from bokeh.layouts import Column, Row
#
#
TaskDF = pd.DataFrame({
'SKILL':[1,7,11,12,13,19,2,4,5,9,14,15,17,18,23,3,6,8,10,16,20,21,22],
'TYPE':["A","B","C","D","C","C","A","B","B","B","C","D","C","C","A","A",
"B","B","C","C","E","E","A"],
'GROUPE':[1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3],
'STARTTIME':['03/04/2024 19:35','03/04/2024 17:40','03/04/2024 16:05','03/04/2024 15:10',
'03/04/2024 20:15','03/04/2024 14:05','03/04/2024 20:30','03/04/2024 15:10',
'03/04/2024 17:24','03/04/2024 13:35','03/04/2024 16:25','03/04/2024 16:25',
'03/04/2024 19:40','03/04/2024 18:40','03/04/2024 13:00','03/04/2024 20:30',
'03/04/2024 16:25','03/04/2024 19:10','03/04/2024 13:05','03/04/2024 18:10',
'03/04/2024 13:55','03/04/2024 14:45','03/04/2024 14:25'],
'ENDTIME':['03/04/2024 20:05','03/04/2024 19:10','03/04/2024 16:45','03/04/2024 16:15',
'03/04/2024 20:55','03/04/2024 14:45','03/04/2024 21:00','03/04/2024 16:10',
'03/04/2024 18:25','03/04/2024 14:57','03/04/2024 17:10','03/04/2024 16:55',
'03/04/2024 20:15','03/04/2024 19:25','03/04/2024 13:30','03/04/2024 21:00',
'03/04/2024 17:45','03/04/2024 20:25','03/04/2024 13:45','03/04/2024 18:45',
'03/04/2024 14:20','03/04/2024 16:15','03/04/2024 14:45']
}
)
Hshift = 40
TaskDF['STARTTIME'] = pd.to_datetime(TaskDF['STARTTIME'], format="%d/%m/%Y %H:%M")
TaskDF['ENDTIME'] = pd.to_datetime(TaskDF['ENDTIME'], format="%d/%m/%Y %H:%M")
TaskDF['XCENTER'] = TaskDF[['STARTTIME','ENDTIME']].apply(lambda x: x['STARTTIME'] +
(x['ENDTIME'] - x['STARTTIME'])/2, axis=1)
TaskDF['WIDTH'] = TaskDF[['STARTTIME','ENDTIME']].apply(lambda x: x['ENDTIME'] -
x['STARTTIME'], axis=1)
#
TaskDF['TYPE'] = TaskDF['TYPE'].apply(lambda x: 'lightgray' if str(x)=='D'
else ('aquamarine' if str(x)=='C' else ('gold' if str(x)=='E'
else ('plum' if str(x)=='A' else ('coral')))))
#
TaskDF['HEIGHT'] = Hshift-6
#
dayformater={
'@Time' : 'datetime',}
#
MaxY = 2*Hshift*len(TaskDF['GROUPE'].unique())
TaskDF['YCENTER'] = np.linspace(1,MaxY,num=len(TaskDF['GROUPE']), endpoint=True)
#
TaskSRC = ColumnDataSource(data=TaskDF)
#
plot = figure(height=int(MaxY), width=750, x_axis_type = "datetime", tools=['tap,reset,box_select'])
ptasks = plot.rect(x='XCENTER', y='YCENTER', width='WIDTH', height='HEIGHT',
color="TYPE", source=TaskSRC, alpha=0.5, border_radius=5, selection_color="firebrick",)
plot.xaxis.major_label_orientation = np.pi/4
plot.xaxis.ticker.desired_num_ticks = 20
plot.xaxis.formatter = DatetimeTickFormatter(hours='%Hh %M')
curdoc().add_root(plot)
Thanks for your help.
Translated with DeepL.com (free version)