box chart and activity chart improvements (holoview)
This commit is contained in:
@@ -169,16 +169,31 @@ def interactive_boxchart(datadf,fieldname,extratitle=''):
|
||||
if datadf.empty:
|
||||
return '','It looks like there are no data matching your filter'
|
||||
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,hover'
|
||||
tooltips = [
|
||||
('Value', '@'+fieldname),
|
||||
]
|
||||
|
||||
hover = HoverTool(tooltips=tooltips)
|
||||
|
||||
plot = BoxPlot(datadf, values=fieldname, label='date',
|
||||
legend=False,
|
||||
title=axlabels[fieldname]+' '+extratitle,
|
||||
outliers=False,
|
||||
tools=TOOLS,
|
||||
toolbar_location="above",
|
||||
toolbar_sticky=False,
|
||||
x_mapper_type='datetime',plot_width=920)
|
||||
TOOLS = [hover]
|
||||
|
||||
|
||||
hv.extension('bokeh')
|
||||
|
||||
boxwhiskers = hv.BoxWhisker(datadf,'date',fieldname)
|
||||
boxwhiskers.opts(tools=TOOLS)
|
||||
|
||||
|
||||
plot = hv.render(boxwhiskers)
|
||||
|
||||
#plot = BoxPlot(datadf, values=fieldname, label='date',
|
||||
# legend=False,
|
||||
# title=axlabels[fieldname]+' '+extratitle,
|
||||
# outliers=False,
|
||||
# tools=TOOLS,
|
||||
# toolbar_location="above",
|
||||
# toolbar_sticky=False,
|
||||
# x_mapper_type='datetime',plot_width=920)
|
||||
|
||||
yrange1 = Range1d(start=yaxminima[fieldname],end=yaxmaxima[fieldname])
|
||||
plot.y_range = yrange1
|
||||
@@ -188,33 +203,6 @@ def interactive_boxchart(datadf,fieldname,extratitle=''):
|
||||
plot.yaxis.axis_label = axlabels[fieldname]
|
||||
|
||||
|
||||
# add watermark
|
||||
watermarkurl = "/static/img/logo7.png"
|
||||
watermarksource = ColumnDataSource(dict(
|
||||
url = [watermarkurl],))
|
||||
|
||||
watermarkrange = Range1d(start=0,end=1)
|
||||
watermarkalpha = 0.6
|
||||
watermarkx = 0.99
|
||||
watermarky = 0.01
|
||||
watermarkw = 184
|
||||
watermarkh = 35
|
||||
watermarkanchor = 'bottom_right'
|
||||
plot.extra_y_ranges = {"watermark": watermarkrange}
|
||||
plot.extra_x_ranges = {"watermark": watermarkrange}
|
||||
|
||||
plot.image_url([watermarkurl],watermarkx,watermarky,
|
||||
watermarkw,watermarkh,
|
||||
global_alpha=watermarkalpha,
|
||||
w_units='screen',
|
||||
h_units='screen',
|
||||
anchor=watermarkanchor,
|
||||
dilate=True,
|
||||
x_range_name = "watermark",
|
||||
y_range_name = "watermark",
|
||||
)
|
||||
|
||||
|
||||
plot.xaxis.formatter = DatetimeTickFormatter(
|
||||
days=["%d %B %Y"],
|
||||
months=["%d %B %Y"],
|
||||
@@ -230,15 +218,9 @@ def interactive_boxchart(datadf,fieldname,extratitle=''):
|
||||
|
||||
plot.xaxis.major_label_orientation = pi/4
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
hover.tooltips = OrderedDict([
|
||||
('Value','@y'),
|
||||
('Date','@x'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
plot.plot_width=920
|
||||
plot.plot_height=600
|
||||
|
||||
script, div = components(plot)
|
||||
|
||||
return script,div
|
||||
@@ -255,6 +237,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
||||
seen = ['seen']
|
||||
idseen = []
|
||||
|
||||
|
||||
for w in workouts:
|
||||
aantal=1
|
||||
initials = w.user.user.first_name[0:aantal]+w.user.user.last_name[0:aantal]
|
||||
@@ -302,7 +285,10 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
||||
dates_sorting.append(d.strftime('%Y/%m/%d'))
|
||||
durations.append(0)
|
||||
types.append('rower')
|
||||
rowers.append('Sander')
|
||||
try:
|
||||
rowers.append(rowersinitials[workouts[0].user.id])
|
||||
except IndexError:
|
||||
rowers.append(str(workouts[0].user))
|
||||
d += datetime.timedelta(days=1)
|
||||
|
||||
|
||||
@@ -318,12 +304,16 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
||||
|
||||
hv.extension('bokeh')
|
||||
|
||||
table = hv.Table(df,[('date','Date'),('type','Workout Type')],[('duration','Minutes')])
|
||||
if stack == 'type':
|
||||
table = hv.Table(df,[('date','Date'),('type','Workout Type')],[('duration','Minutes')])
|
||||
else:
|
||||
table = hv.Table(df,[('date','Date'),('rower','Rower')],[('duration','Minutes')])
|
||||
|
||||
bars=table.to.bars(['date','type'],['duration'])
|
||||
bars=table.to.bars(['date',stack],['duration'])
|
||||
bars.opts(
|
||||
opts.Bars(color=hv.Cycle('Category20'), show_legend=True, stacked=True,
|
||||
tools=['hover'], width=600, xrotation=90))
|
||||
tools=['hover'], width=600, xrotation=90,))
|
||||
# legend_position='bottom',show_frame=True))
|
||||
|
||||
|
||||
p = hv.render(bars)
|
||||
@@ -332,8 +322,8 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
||||
d1 = startdate.strftime("%Y-%m-%d"),
|
||||
d2 = enddate.strftime("%Y-%m-%d"),
|
||||
)
|
||||
p.plot_width=350
|
||||
p.plot_height=250
|
||||
p.plot_width=550
|
||||
p.plot_height=350
|
||||
p.toolbar_location = None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user