working links, solving #479
This commit is contained in:
@@ -37,7 +37,8 @@ from bokeh.models import (
|
|||||||
Span, Label
|
Span, Label
|
||||||
)
|
)
|
||||||
from bokeh.models.glyphs import ImageURL
|
from bokeh.models.glyphs import ImageURL
|
||||||
|
from bokeh.models import OpenURL, TapTool
|
||||||
|
from rowers.opaque import encoder
|
||||||
#from bokeh.models.widgets import Slider, Select, TextInput
|
#from bokeh.models.widgets import Slider, Select, TextInput
|
||||||
from bokeh.core.properties import value
|
from bokeh.core.properties import value
|
||||||
|
|
||||||
@@ -238,6 +239,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
|||||||
types = []
|
types = []
|
||||||
rowers = []
|
rowers = []
|
||||||
durations = []
|
durations = []
|
||||||
|
links = []
|
||||||
|
|
||||||
rowersinitials = {}
|
rowersinitials = {}
|
||||||
seen = ['seen']
|
seen = ['seen']
|
||||||
@@ -265,6 +267,12 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
|||||||
dates.append(dd)
|
dates.append(dd)
|
||||||
dates_sorting.append(dd2)
|
dates_sorting.append(dd2)
|
||||||
durations.append(du)
|
durations.append(du)
|
||||||
|
links.append(
|
||||||
|
"{siteurl}/rowers/workout/{code}/".format(
|
||||||
|
siteurl = settings.SITE_URL,
|
||||||
|
code = encoder.encode_hex(w.id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
types.append(w.workouttype)
|
types.append(w.workouttype)
|
||||||
try:
|
try:
|
||||||
@@ -290,6 +298,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
|||||||
|
|
||||||
dates_sorting.append(d.strftime('%Y/%m/%d'))
|
dates_sorting.append(d.strftime('%Y/%m/%d'))
|
||||||
durations.append(0)
|
durations.append(0)
|
||||||
|
links.append('')
|
||||||
types.append('rower')
|
types.append('rower')
|
||||||
try:
|
try:
|
||||||
rowers.append(rowers[0])
|
rowers.append(rowers[0])
|
||||||
@@ -302,42 +311,64 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
|||||||
d += datetime.timedelta(days=1)
|
d += datetime.timedelta(days=1)
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame({
|
thedict = {
|
||||||
'date':dates,
|
'date':dates,
|
||||||
'date_sorting':dates_sorting,
|
'date_sorting':dates_sorting,
|
||||||
'duration':durations,
|
'duration':durations,
|
||||||
'type':types,
|
'type':types,
|
||||||
'rower':rowers,
|
'rower':rowers,
|
||||||
})
|
'link':links,
|
||||||
|
}
|
||||||
|
|
||||||
|
df = pd.DataFrame(thedict)
|
||||||
|
|
||||||
|
source = ColumnDataSource(df)
|
||||||
|
|
||||||
df.sort_values('date_sorting',inplace=True)
|
df.sort_values('date_sorting',inplace=True)
|
||||||
|
|
||||||
hv.extension('bokeh')
|
hv.extension('bokeh')
|
||||||
|
|
||||||
if stack == 'type':
|
if stack == 'type':
|
||||||
table = hv.Table(df,[('date','Date'),('type','Workout Type')],[('duration','Minutes')])
|
table = hv.Table(df,[('date','Date'),('type','Workout Type')],[('duration','Minutes'),('link','link')])
|
||||||
else:
|
else:
|
||||||
table = hv.Table(df,[('date','Date'),('rower','Rower')],[('duration','Minutes')])
|
table = hv.Table(df,[('date','Date'),('rower','Rower')],[('duration','Minutes'),('link','link')])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bars=table.to.bars(['date',stack],['duration'])
|
bars=table.to.bars(['date',stack],['duration'])
|
||||||
bars.opts(
|
bars.opts(
|
||||||
opts.Bars(color=hv.Cycle('Category10'), show_legend=True, stacked=True,
|
opts.Bars(color=hv.Cycle('Category10'), show_legend=True, stacked=True,
|
||||||
tools=['hover'], width=550, xrotation=45,padding=(0,(0,.1)),
|
tools=['tap','hover'], width=550, xrotation=45,padding=(0,(0,.1)),
|
||||||
legend_position='bottom',show_frame=True))
|
legend_position='bottom',show_frame=True))
|
||||||
|
|
||||||
|
|
||||||
p = hv.render(bars)
|
|
||||||
|
|
||||||
|
p = hv.render(bars)
|
||||||
|
|
||||||
p.title.text = 'Activity {d1} to {d2}'.format(
|
p.title.text = 'Activity {d1} to {d2}'.format(
|
||||||
d1 = startdate.strftime("%Y-%m-%d"),
|
d1 = startdate.strftime("%Y-%m-%d"),
|
||||||
d2 = enddate.strftime("%Y-%m-%d"),
|
d2 = enddate.strftime("%Y-%m-%d"),
|
||||||
)
|
)
|
||||||
|
|
||||||
p.plot_width=550
|
p.plot_width=550
|
||||||
p.plot_height=350
|
p.plot_height=350
|
||||||
p.toolbar_location = None
|
p.toolbar_location = None
|
||||||
p.sizing_mode = 'scale_width'
|
p.sizing_mode = 'scale_width'
|
||||||
|
url = "http://rowsandall.com/rowers/workout/@duration/"
|
||||||
|
taptool = p.select(type=TapTool)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
callback = CustomJS(args={'links':df.link}, code="""
|
||||||
|
var index = cb_data.source.selected['1d'].indices[0];
|
||||||
|
console.log(links);
|
||||||
|
console.log(index);
|
||||||
|
console.log(links[index]);
|
||||||
|
window.location.href = links[index]
|
||||||
|
""")
|
||||||
|
|
||||||
|
taptool.callback = callback
|
||||||
|
|
||||||
|
|
||||||
script,div = components(p)
|
script,div = components(p)
|
||||||
return script,div
|
return script,div
|
||||||
|
|||||||
Reference in New Issue
Block a user