Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 5c2ae7a

Browse files
author
clittle
committed
Patched gradient display bug
1 parent f28d665 commit 5c2ae7a

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

layers/exporters/svg_objects.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ def __init__(self, height, width, fill):
155155

156156
class SVG_HeaderBlock:
157157
@staticmethod
158-
def build(height, width, label, variant='text', t1text=None, t1size=None, t2text=None, t2size=None, colors=[],
159-
values=(0,100)):
158+
def build(height, width, label, variant='text', t1text=None, t1size=None, t2text=None, t2size=None, colors=[]):
160159
"""
161160
Build a single SVG Header Block object
162161
@@ -168,8 +167,7 @@ def build(height, width, label, variant='text', t1text=None, t1size=None, t2text
168167
:param t1size: upper text size
169168
:param t2text: lower text
170169
:param t2size: lower text size
171-
:param colors: colors for the graphic variant
172-
:param values: values for the graphic variant's gradient
170+
:param colors: array of tuple (color, score value) for the graphic variant
173171
:return:
174172
"""
175173
g = G(ty=5)
@@ -215,19 +213,16 @@ def build(height, width, label, variant='text', t1text=None, t1size=None, t2text
215213
cells = G(ctype="legendCells")
216214
sub2.append(cells)
217215
offset = 0
218-
span = [values[0]]
219-
for blah in colors[:-1]:
220-
span.append(int(values[1]/(len(colors)-1) * (colors.index(blah) + 1)))
221216
for entry in colors:
222217
cell = G(ctype="cell", tx=offset)
223-
conv = entry
218+
conv = entry[0]
224219
if conv.startswith('#'):
225220
conv = conv[1:]
226221
block = Swatch(15, block_width, tuple(int(conv[i:i+2], 16) for i in (0, 2, 4)))
227222
offset += block_width
228223
cell.append(block)
229224
cells.append(cell)
230-
tblob = str(span[colors.index(entry)])
225+
tblob = str(entry[1])
231226
off = (block_width-(5 * (1+ len(tblob))))/2
232227
label = Text(tblob, 12, ctype='label', ty=25, tx=off)
233228
cell.append(label)

layers/exporters/svg_templates.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ def _build_headers(self, name, desc=None, filters=None, gradient=None):
9090
psych += 1
9191
if gradient is not None:
9292
b3 = G(tx=operation_x / header_count * psych)
93-
colors = [gradient.compute_color(gradient.minValue)]
94-
for i in range(1, len(gradient.colors) * 2):
95-
colors.append(gradient.compute_color(int(gradient.maxValue/(len(gradient.colors)*2)) * i))
93+
colors = []
94+
div = round((gradient.maxValue - gradient.minValue)/(len(gradient.colors) * 2 - 1))
95+
for i in range(0, len(gradient.colors) * 2 - 1):
96+
colors.append((gradient.compute_color(int(gradient.minValue + div * i)), gradient.minValue + div * i))
97+
colors.append((gradient.compute_color(gradient.maxValue), gradient.maxValue))
9698
g3 = SVG_HeaderBlock().build(height=self.header_height, width=header_width, label='legend',
97-
variant='graphic', colors=colors,
98-
values=(gradient.minValue, gradient.maxValue))
99+
variant='graphic', colors=colors)
99100
header.append(b3)
100101
b3.append(g3)
101102
d.append(root)

0 commit comments

Comments
 (0)