Skip to content

Commit

Permalink
fix #224
Browse files Browse the repository at this point in the history
  • Loading branch information
doutriaux1 committed Jul 12, 2017
1 parent d0fb012 commit 7254e53
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Share/initial.attributes

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions vcs/taylor.py
Expand Up @@ -1975,9 +1975,13 @@ def plot(self, data, template='deftaylor', skill=None, bg=0, canvas=None):
# Ok now draws the little comment/source, etc
self.displays += self.template.plot(canvas, data, self, bg=bg)
if not sum(map(len,self.Marker.id)) == 0 : # Not all empty string:
self.template.drawLinesAndMarkersLegend(canvas, self.Marker.line_color, self.Marker.line_type, self.Marker.line_size,
if self.quadrans == 1:
stacking = "vertical"
else:
stacking = "horizontal"
self.template.drawLinesAndMarkersLegend(canvas, self.Marker.line_color, self.Marker.line_type, [0,]*len(self.Marker.line_size),
self.Marker.color, self.Marker.symbol, self.Marker.size, self.Marker.id, scratched=None, stringscolors=self.Marker.id_color,
bg=False, render=True)
stacking=stacking, bg=False, render=True)
if resetoutter:
self.outtervalue = None
if savedstdmax is not None:
Expand Down
7 changes: 5 additions & 2 deletions vcs/template.py
Expand Up @@ -1484,7 +1484,7 @@ def scalefont(self, scale):
def drawLinesAndMarkersLegend(self, canvas,
linecolors, linetypes, linewidths,
markercolors, markertypes, markersizes,
strings, scratched=None, stringscolors=None, bg=False, render=True):
strings, scratched=None, stringscolors=None, stacking="horizontal", bg=False, render=True):
"""Draws a legend with line/marker/text inside a template legend box.
Auto adjusts text size to make it fit inside the box.
Auto arranges the elements to fill the box nicely.
Expand Down Expand Up @@ -1562,6 +1562,9 @@ def drawLinesAndMarkersLegend(self, canvas,
or a string color name.
:type stringscolors: `list`_
:param stacking: Prefered direction to stack element ('horizontal' or 'vertical')
:type stringscolors: `string`_
:param bg: Boolean value indicating whether or not to draw in the
background. Defaults to False.
:type bg: bool
Expand All @@ -1574,7 +1577,7 @@ def drawLinesAndMarkersLegend(self, canvas,
self.legend,
linecolors, linetypes, linewidths,
markercolors, markertypes, markersizes,
strings, scratched, stringscolors, bg, render)
strings, scratched, stringscolors, stacking, bg, render)

def drawAttributes(self, x, slab, gm, bg=False, **kargs):
"""Draws attributes of slab onto a canvas
Expand Down
32 changes: 24 additions & 8 deletions vcs/utils.py
Expand Up @@ -2489,7 +2489,7 @@ def download_sample_data_files(path=None):
def drawLinesAndMarkersLegend(canvas, templateLegend,
linecolors, linetypes, linewidths,
markercolors, markertypes, markersizes,
strings, scratched=None, stringscolors=None, bg=False, render=True):
strings, scratched=None, stringscolors=None, stacking="horizontal", bg=False, render=True):
"""Draws a legend with line/marker/text inside a template legend box
Auto adjust text size to make it fit inside the box
Auto arrange the elements to fill the box nicely
Expand Down Expand Up @@ -2553,6 +2553,9 @@ def drawLinesAndMarkersLegend(canvas, templateLegend,
or a string color name.
:type stringscolors: `list`_
:param stacking: Prefered direction to stack element ('horizontal' or 'vertical')
:type stringscolors: `string`_
:param bg: Boolean value indicating to draw in background (True),
Or foreground (False).
:type bg: `bool`_
Expand Down Expand Up @@ -2582,7 +2585,10 @@ def drawLinesAndMarkersLegend(canvas, templateLegend,
ext = canvas.gettextextent(text)[0]
maxwidth = max(maxwidth, ext[1] - ext[0])
maxheight = max(maxheight, ext[3] - ext[2])
leg_lines = maxwidth / 3.
if len(strings[i])>4:
leg_lines = maxwidth / 3.
else:
leg_lines = maxwidth
leg_spc = leg_lines / 3.
maxwidth = maxwidth + leg_lines + leg_spc
maxx = int(dx / maxwidth)
Expand All @@ -2596,8 +2602,12 @@ def drawLinesAndMarkersLegend(canvas, templateLegend,
text.height = 1
break

nH = min(maxx, len(strings)) # How many elts on horizontal direction
nV = numpy.ceil(nlines / float(nH)) # How many elts vertically
if stacking[:3].lower() == "hor":
nH = min(maxx, len(strings)) # How many elts on horizontal direction
nV = numpy.ceil(nlines / float(nH)) # How many elts vertically
else:
nV = min(maxy, len(strings)) # How many elts on horizontal direction
nH = numpy.ceil(nlines / float(nV)) # How many elts vertically
spcX = (dx - maxwidth * nH) / (nH + 1)
spcY = (dy - maxheight * nV) / (nV + 1)
txs = []
Expand All @@ -2620,15 +2630,21 @@ def drawLinesAndMarkersLegend(canvas, templateLegend,
ln = canvas.createline()
ln.color = [linecolors[i], ]
ln.type = linetypes[i]
ln.width = linewidths[i]
ln.priority = templateLegend.priority
if linewidths[i]>0:
ln.width = linewidths[i]
ln.priority = templateLegend.priority
else:
ln.priority = 0
# TODO check if previous marker was identical
# so that we create less objet/renderers
mrk = canvas.createmarker()
mrk.color = [markercolors[i]]
mrk.type = markertypes[i]
mrk.size = markersizes[i]
mrk.priority = templateLegend.priority
if markersizes[i]>0:
mrk.size = markersizes[i]
mrk.priority = templateLegend.priority
else:
mrk.priority = 0
xs = x1 + spcX + col * (maxwidth + spcX)
ln.x = [xs, xs + leg_lines]
mrk.x = [xs + leg_lines / 2.]
Expand Down

0 comments on commit 7254e53

Please sign in to comment.