Skip to content

Commit

Permalink
cleaner handling of AxisCoords in InsetBox
Browse files Browse the repository at this point in the history
  • Loading branch information
poke1024 committed Sep 15, 2016
1 parent 182e251 commit a4efb0d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mathics/builtin/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def add(self, x, y):
p = (self.p[0] + x, self.p[1] + y)
return Coords(self.graphics, pos=p)

def is_absolute(self):
return False


class AxisCoords(Coords):
def __init__(self, graphics, expr=None, pos=None, d=None):
Expand All @@ -99,6 +102,9 @@ def pos(self):
def add(self, x, y):
raise NotImplementedError

def is_absolute(self):
return True


def cut(value):
"Cut values in graphics primitives (not displayed otherwise in SVG)"
Expand Down Expand Up @@ -2252,14 +2258,12 @@ def instances():


class InsetBox(_GraphicsElement):
def init(self, graphics, style, item=None, content=None, pos=None,
opos=(0, 0), absolute_coordinates=False):
def init(self, graphics, style, item=None, content=None, pos=None, opos=(0, 0)):
super(InsetBox, self).init(graphics, item, style)

self.color = self.style.get_option('System`FontColor')
if self.color is None:
self.color, _ = style.get_style(_Color, face_element=False)
self.absolute_coordinates = absolute_coordinates

if item is not None:
if len(item.leaves) not in (1, 2, 3):
Expand Down Expand Up @@ -2295,19 +2299,21 @@ def extent(self):

def to_svg(self):
x, y = self.pos.pos()
absolute = self.pos.is_absolute()

content = self.content.boxes_to_xml(
evaluation=self.graphics.evaluation)
style = create_css(font_color=self.color)

if not self.absolute_coordinates:
if not absolute:
x, y = list(self.graphics.local_to_screen.transform([(x, y)]))[0]

svg = (
'<foreignObject x="%f" y="%f" ox="%f" oy="%f" style="%s">'
'<math>%s</math></foreignObject>') % (
x, y, self.opos[0], self.opos[1], style, content)

if not self.absolute_coordinates:
if not absolute:
svg = self.graphics.inverse_local_to_screen.to_svg(svg)

return svg
Expand Down Expand Up @@ -3054,7 +3060,7 @@ def add_element(element):
elements, tick_label_style,
content=content,
pos=AxisCoords(elements, pos=p_origin(x),
d=p_self0(-tick_label_d)), opos=p_self0(1), absolute_coordinates=True))
d=p_self0(-tick_label_d)), opos=p_self0(1)))
for x in ticks_small:
pos = p_origin(x)
ticks_lines.append([AxisCoords(elements, pos=pos),
Expand Down

0 comments on commit a4efb0d

Please sign in to comment.