Skip to content

Commit

Permalink
autoColor for extended brushes and non-orth plots
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremysanders committed Mar 18, 2017
1 parent f1ec63e commit 228afef
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 21 deletions.
10 changes: 9 additions & 1 deletion veusz/document/painthelper.py
Expand Up @@ -146,7 +146,8 @@ def __init__(self, document, pagesize,
self.widgetstack = []

# current index for each plotter (if wanting automatic colors)
self.autoplotterindex = {}
self.autoplottercount = 0
self.autoplottermap = {}

@property
def maxdim(self):
Expand Down Expand Up @@ -309,3 +310,10 @@ def widgetBoundsIterator(self, widgettype=None):
yield state.widget, state.bounds
# remove the widget itself from the stack and insert children
stack = state.children + stack[1:]

def autoColorIndex(self, key):
"""Return automatic color index for key given."""
if key not in self.autoplottermap:
self.autoplottermap[key] = self.autoplottercount
self.autoplottercount += 1
return self.autoplottermap[key]
4 changes: 2 additions & 2 deletions veusz/setting/collections.py
Expand Up @@ -69,7 +69,7 @@ def makeQPen(self, painter):
color.setAlphaF((100-self.transparency) / 100.)
width = self.get('width').convert(painter)
style, dashpattern = setting.LineStyle._linecnvt[self.style]
pen = qt4.QPen( color, width, style )
pen = qt4.QPen(color, width, style)

if dashpattern:
pen.setDashPattern(dashpattern)
Expand Down Expand Up @@ -345,7 +345,7 @@ def __init__(self, name, **args):
usertext = _('Underline') ) )
self.add( setting.Bool(
'hide', False,
descr = _('Hide the text')
descr = _('Hide the text'),
usertext = _('Hide')) )

def copy(self):
Expand Down
8 changes: 6 additions & 2 deletions veusz/setting/setting.py
Expand Up @@ -1378,8 +1378,12 @@ def copy(self):
"""Make a copy of the setting."""
return self._copyHelper((), (), {})

def color(self, painter):
"""Return QColor for color."""
def color(self, painter, dataindex=0):
"""Return QColor from color.
painter is a Veusz Painter
dataindex is index for automatically getting colors for subdatasets.
"""

if self.val.lower() == 'auto':
# lookup widget
Expand Down
8 changes: 4 additions & 4 deletions veusz/utils/extbrushfilling.py
Expand Up @@ -195,7 +195,7 @@ def brushExtFillPath(painter, extbrush, path, ignorehide=False,
style = extbrush.style
if style in _fillcnvt:
# standard fill: use Qt styles for painting
color = painter.docColor(extbrush.color)
color = extbrush.get('color').color(painter)
if extbrush.transparency >= 0:
color.setAlphaF((100-extbrush.transparency) / 100.)
brush = qt4.QBrush(color, _fillcnvt[style])
Expand All @@ -213,13 +213,13 @@ def brushExtFillPath(painter, extbrush, path, ignorehide=False,

if not extbrush.backhide:
# background brush
color = painter.docColor(extbrush.backcolor)
if extbrush.backtransparency >= 0:
color = extbrush.get('backcolor').color(painter)
if extbrush.backtransparency > 0:
color.setAlphaF((100-extbrush.backtransparency) / 100.)
brush = qt4.QBrush(color)
painter.fillPath(path, brush)

color = painter.docColor(extbrush.color)
color = extbrush.get('color').color(painter)
if extbrush.transparency >= 0:
color.setAlphaF((100-extbrush.transparency) / 100.)
width = extbrush.get('linewidth').convert(painter)
Expand Down
8 changes: 3 additions & 5 deletions veusz/widgets/graph.py
Expand Up @@ -250,12 +250,10 @@ def draw(self, parentposn, painthelper, outerbounds = None):
# don't duplicate drawing axes
axesdrawn = set()

# map color indices to children
autoplotterindex = 0
# reset counter and compute automatic colors
painthelper.autoplottercount = 0
for c in self.children:
if c.isplotter and c not in painthelper.autoplotterindex:
painthelper.autoplotterindex[c] = autoplotterindex
autoplotterindex += 1
c.autoColor(painter)

# do normal drawing of children
# iterate over children in reverse order
Expand Down
5 changes: 5 additions & 0 deletions veusz/widgets/nonorthfunction.py
Expand Up @@ -159,6 +159,11 @@ def pickPoint(self, x0, y0, bounds, distance='radial'):
def pickIndex(self, oldindex, direction, bounds):
return self._pickable().pickIndex(oldindex, direction, bounds)

def autoColor(self, painter, dataindex=0):
"""Automatic color for plotting."""
return painter.docColorAuto(
painter.helper.autoColorIndex((self, dataindex)))

def draw(self, parentposn, phelper, outerbounds=None):
'''Plot the function on a plotter.'''

Expand Down
5 changes: 5 additions & 0 deletions veusz/widgets/nonorthgraph.py
Expand Up @@ -147,6 +147,11 @@ def draw(self, parentposn, phelper, outerbounds=None):

painter = phelper.painter(self, bounds)
with painter:
# reset counter and compute automatic colors
phelper.autoplottercount = 0
for c in self.children:
c.autoColor(painter)

# plot graph
datarange = self.getDataRange()
self.drawGraph(painter, bounds, datarange, outerbounds=outerbounds)
Expand Down
5 changes: 5 additions & 0 deletions veusz/widgets/nonorthpoint.py
Expand Up @@ -188,6 +188,11 @@ def getColorbarParameters(self):
return (c.min, c.max, c.scaling, s.MarkerFill.colorMap, 0,
s.MarkerFill.colorMapInvert)

def autoColor(self, painter, dataindex=0):
"""Automatic color for plotting."""
return painter.docColorAuto(
painter.helper.autoColorIndex((self, dataindex)))

def draw(self, parentposn, phelper, outerbounds=None):
'''Plot the data on a plotter.'''

Expand Down
9 changes: 3 additions & 6 deletions veusz/widgets/plotters.py
Expand Up @@ -63,13 +63,10 @@ def addSettings(klass, s):
descr = _('Name of Y-axis to use'),
usertext=_('Y axis')) )

def autoColor(self, painter):
def autoColor(self, painter, dataindex=0):
"""Automatic color for plotting."""
helper = painter.helper
if self in helper.autoplotterindex:
return painter.docColorAuto(helper.autoplotterindex[self])
else:
return 'foreground'
return painter.docColorAuto(
painter.helper.autoColorIndex((self, dataindex)))

def getAxesNames(self):
"""Returns names of axes used."""
Expand Down
2 changes: 1 addition & 1 deletion veusz/widgets/widget.py
Expand Up @@ -418,7 +418,7 @@ def updateControlItem(self, controlitem, pos):

pass

def autoColor(self, painter):
def autoColor(self, painter, dataindex=0):
"""Return automatic color for plotting."""
return 'foreground'

Expand Down

0 comments on commit 228afef

Please sign in to comment.