css, more layout tweaks, add suspended back into display

This commit is contained in:
Damien Elmes 2011-03-30 18:11:05 +09:00
parent 282d0bb9ba
commit 30d62875d0

View file

@ -16,6 +16,7 @@ colCram = "#ff0"
colIvl = "#077" colIvl = "#077"
colTime = "#770" colTime = "#770"
colUnseen = "#000" colUnseen = "#000"
colSusp = "#ff0"
class Graphs(object): class Graphs(object):
@ -31,7 +32,8 @@ class Graphs(object):
# 0=days, 1=weeks, 2=months # 0=days, 1=weeks, 2=months
# period-dependent graphs # period-dependent graphs
self.type = type self.type = type
txt = self.dueGraph() txt = self.css
txt += self.dueGraph()
txt += self.repsGraph() txt += self.repsGraph()
txt += self.ivlGraph() txt += self.ivlGraph()
# other graphs # other graphs
@ -39,6 +41,15 @@ class Graphs(object):
txt += self.cardGraph() txt += self.cardGraph()
return "<script>%s\n</script><center>%s</center>" % (anki.js.all, txt) return "<script>%s\n</script><center>%s</center>" % (anki.js.all, txt)
css = """
<style>
h1 { margin-bottom: 0; }
body { font-size: 14px; }
table * { font-size: 14px; }
.pielabel { text-align:center; padding:2px; color:black; }
</style>
"""
# Due and cumulative due # Due and cumulative due
###################################################################### ######################################################################
@ -314,7 +325,8 @@ order by thetype, ease""")
for c, (t, col) in enumerate(( for c, (t, col) in enumerate((
(_("Mature"), colMature), (_("Mature"), colMature),
(_("Young+Learn"), colYoung), (_("Young+Learn"), colYoung),
(_("Unseen"), colUnseen))): (_("Unseen"), colUnseen),
(_("Suspended"), colSusp))):
d.append(dict(data=div[c], label=t, color=col)) d.append(dict(data=div[c], label=t, color=col))
# text data # text data
i = [] i = []
@ -354,7 +366,8 @@ from cards where queue = 2 %s""" % self._limit())
select select
sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr
sum(case when queue=1 or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn sum(case when queue=1 or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn
sum(case when queue=0 then 1 else 0 end) -- new sum(case when queue=0 then 1 else 0 end), -- new
sum(case when queue=-1 then 1 else 0 end) -- susp
%s %s
from cards""" % self._limit()) from cards""" % self._limit())
@ -364,7 +377,10 @@ from cards""" % self._limit())
def _graph(self, id, data, conf={}, def _graph(self, id, data, conf={},
type="bars", ylabel=_("Cards"), timeTicks=True): type="bars", ylabel=_("Cards"), timeTicks=True):
# display settings # display settings
conf['legend'] = {'container': "#%sLegend" % id, 'noColumns':10} if type == "pie":
conf['legend'] = {'container': "#%sLegend" % id, 'noColumns':2}
else:
conf['legend'] = {'container': "#%sLegend" % id, 'noColumns':10}
conf['series'] = dict(stack=True) conf['series'] = dict(stack=True)
if not 'yaxis' in conf: if not 'yaxis' in conf:
conf['yaxis'] = {} conf['yaxis'] = {}
@ -385,20 +401,19 @@ from cards""" % self._limit())
elif type == "fill": elif type == "fill":
conf['series']['lines'] = dict(show=True, fill=True) conf['series']['lines'] = dict(show=True, fill=True)
elif type == "pie": elif type == "pie":
width /= 2 width /= 2.3
height *= 1.5 height *= 1.5
ylabel = "" ylabel = ""
conf['series']['pie'] = dict( conf['series']['pie'] = dict(
show=True, show=True,
radius=1, radius=0.8,
stroke=dict(color="#000", width=3), stroke=dict(color="#000", width=3),
label=dict( label=dict(
show=True, show=True,
radius=1, #3/4.0, radius=1,
background=dict( threshold=0.01))
opacity=1,
color='#000'))) #conf['legend'] = dict(show=False)
conf['legend'] = dict(show=False)
return ( return (
""" """
<table cellpadding=0 cellspacing=10> <table cellpadding=0 cellspacing=10>
@ -419,7 +434,7 @@ $(function () {
} }
if (conf.series.pie) { if (conf.series.pie) {
conf.series.pie.label.formatter = function(label, series){ conf.series.pie.label.formatter = function(label, series){
return '<div style="font-size:10pt; text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%%</div>'; return '<div class=pielabel>'+'<small>'+label+'</small><br>'+Math.round(series.percent)+'%%</div>';
}; };
} }
$.plot($("#%(id)s"), %(data)s, conf); $.plot($("#%(id)s"), %(data)s, conf);
@ -436,4 +451,4 @@ $(function () {
return "" return ""
def _title(self, title, subtitle=""): def _title(self, title, subtitle=""):
return '<h1 style="margin-bottom: 0; margin-top: 1em;">%s</h1>%s' % (title, subtitle) return '<h1>%s</h1>%s' % (title, subtitle)