Private
Public Access
1
0

working links, solving #479

This commit is contained in:
Sander Roosendaal
2019-05-20 22:22:32 +02:00
parent b679bd6988
commit 4ebb702795

View File

@@ -37,7 +37,8 @@ from bokeh.models import (
Span, Label
)
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.core.properties import value
@@ -238,6 +239,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
types = []
rowers = []
durations = []
links = []
rowersinitials = {}
seen = ['seen']
@@ -265,6 +267,12 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
dates.append(dd)
dates_sorting.append(dd2)
durations.append(du)
links.append(
"{siteurl}/rowers/workout/{code}/".format(
siteurl = settings.SITE_URL,
code = encoder.encode_hex(w.id)
)
)
types.append(w.workouttype)
try:
@@ -290,6 +298,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
dates_sorting.append(d.strftime('%Y/%m/%d'))
durations.append(0)
links.append('')
types.append('rower')
try:
rowers.append(rowers[0])
@@ -302,42 +311,64 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
d += datetime.timedelta(days=1)
df = pd.DataFrame({
thedict = {
'date':dates,
'date_sorting':dates_sorting,
'duration':durations,
'type':types,
'rower':rowers,
})
'link':links,
}
df = pd.DataFrame(thedict)
source = ColumnDataSource(df)
df.sort_values('date_sorting',inplace=True)
hv.extension('bokeh')
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:
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.opts(
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))
p = hv.render(bars)
p = hv.render(bars)
p.title.text = 'Activity {d1} to {d2}'.format(
d1 = startdate.strftime("%Y-%m-%d"),
d2 = enddate.strftime("%Y-%m-%d"),
)
p.plot_width=550
p.plot_height=350
p.toolbar_location = None
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)
return script,div