|
From: Michael J G. <mic...@us...> - 2016-02-23 19:43:44
|
graph.style.density() needs to use an alpha channel when the set of
points is not a complete rectangle but has missing points. It uses ARGB
format for that, which is fine for PDF output. But the save method of
image which is used for SVG output can deal with RGBA only (__init__
allows ARGB), so that writeSVGfile() fails. This affects also the inline
display in ipython notebooks which uses _repr_svg_().
While a complete fix would teach the save method how to deal with ARGB,
RGBA can be saved more quickly anyways. That is why this patch teaches
graph.style.density to use RGBA instead of ARGB.
A simple test case:
from pyx import *
g = graph.graphxy(width=10)
g.plot(graph.data.points([ [0, 0, 0], [0, 1, 1], [1, 0, 2] ], x=1, y=2, color=3), [graph.style.density(gradient=color.rgbgradient.Hue)])
g.writePDFfile() # embeds directly; works
g._repr_png_() # uses pipeGS; works
g.writeSVGfile() # fails
g._repr_svg_() # uses writeSVGfile; fails
Signed-off-by: Michael J Gruber <mic...@us...>
---
pyx/graph/style.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pyx/graph/style.py b/pyx/graph/style.py
index 1d1e283..165b076 100644
--- a/pyx/graph/style.py
+++ b/pyx/graph/style.py
@@ -1967,7 +1967,7 @@ class density(_keygraphstyle):
"/DeviceRGB": "RGB",
"/DeviceCMYK": "CMYK"}[self.gradient.getcolor(0).colorspacestring()]
if needalpha:
- mode = "A" + mode
+ mode = mode +"A"
empty = b"\0"*len(mode)
data = io.BytesIO()
for value2 in values2:
@@ -1982,9 +1982,9 @@ class density(_keygraphstyle):
continue
c = privatedata.colors[value1][value2]
c = self.color(privatedata, c)
+ data.write(c.to8bitbytes())
if needalpha:
data.write(bytes((255,)))
- data.write(c.to8bitbytes())
i = bitmap.image(len(values1), len(values2), mode, data.getvalue())
v1enlargement = (values1[-1]-values1[0])*0.5/(len(values1)-1)
--
2.7.1.505.g1c9a602
|