Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return e.isTopOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.top2Bottom(), e, score)
class Bottom2Bottom(Condition):
u"""Align bottom of e bounding box to parent bottom margin."""
def test(self, e):
return e.isBottomOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.bottom2Bottom(), e, score)
class Origin2Bottom(Condition):
u"""Align origin of e bounding box to parent bottom margin."""
def test(self, e):
return e.isOriginOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.origin2Bottom(), e, score)
# Left Horizontal Sides
class Middle2BottomSide(Condition):
u"""Move middle (vertical center) of e bounding box on parent bottom side."""
def test(self, e):
return e.isMiddleOnBottomSide(self.tolerance)
def solve(self, e, score):
return e.isMiddleOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.middle2Bottom(), e, score)
class Top2Bottom(Condition):
u"""Align top of e bounding box on parent bottom margin."""
def test(self, e):
return e.isTopOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.top2Bottom(), e, score)
class Bottom2Bottom(Condition):
u"""Align bottom of e bounding box to parent bottom margin."""
def test(self, e):
return e.isBottomOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.bottom2Bottom(), e, score)
class Origin2Bottom(Condition):
u"""Align origin of e bounding box to parent bottom margin."""
def test(self, e):
return e.isOriginOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.origin2Bottom(), e, score)
return e.isMiddleOnMiddle(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.middle2Middle(), e, score)
class Middle2MiddleSides(Condition):
u"""Middle e bounding box vertical between parent vertical sides."""
def test(self, e):
return e.isMiddleOnMiddleSides(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.middle2MiddleSides(), e, score)
class Top2Middle(Condition):
u"""Align top of e bounding box vertical middle between parent margins."""
def test(self, e):
return e.isTopOnMiddle(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.top2Middle(), e, score)
class Top2MiddleSides(Condition):
u"""Align top of e bounding box on vertical middle between parent sides."""
def test(self, e):
return e.isTopOnMiddleSides(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.top2MiddleSides(), e, score)
return e.isOriginOnTop(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.origin2Top(), e, score)
class Middle2Top(Condition):
u"""Move middle (vertical center) of e bounding box on parent top margin."""
def test(self, e):
return e.isMiddleOnTop(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.middle2Top(), e, score)
class Middle2TopSide(Condition):
u"""Move middle (vertical center) of e bounding box on parent top side."""
def test(self, e):
return e.isMiddleOnTopSide(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.middle2TopSide(), e, score)
class Top2TopSide(Condition):
u"""Align left of e bounding box on parent top side."""
def test(self, e):
return e.isTopOnTopSide(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.top2TopSide(), e, score)
return e.isOriginOnTopSide(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.origin2TopSide(), e, score)
class Middle2Bottom(Condition):
u"""Move middle (vertical center) of e bounding box on parent bottom margin."""
def test(self, e):
return e.isMiddleOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.middle2Bottom(), e, score)
class Top2Bottom(Condition):
u"""Align top of e bounding box on parent bottom margin."""
def test(self, e):
return e.isTopOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.top2Bottom(), e, score)
class Bottom2Bottom(Condition):
u"""Align bottom of e bounding box to parent bottom margin."""
def test(self, e):
return e.isBottomOnBottom(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.bottom2Bottom(), e, score)
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.fitTopSide(), e, score)
class Fit2BottomSide(Condition):
def test(self, e):
return e.isBottomOnBottomSide(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.fitBottomSide(), e, score)
# C E N T E R H O R I Z O N T A L
# Center Horizontal Margins
class Center2Center(Condition):
u"""Center e bounding box horizontal between parent margins."""
def test(self, e):
return e.isCenterOnCenter(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.center2Center(), e, score)
class Left2Center(Condition):
u"""Align left of e bounding box horizontal between parent margins."""
def test(self, e):
return e.isLeftOnCenter(self.tolerance)
def solve(self, e, score):
if not self.test(e): # Only try to solve if condition test fails.
self.addScore(e.left2Center(), e, score)
if abs(parent.h - mt - e.top) <= self.tolerance:
return self.value
return self.error
def solve(self, e):
parent = e.parent
if parent is not None and self.evaluate(e) < 0:
mt = e.css('mt')
if parent.originTop:
e.top = mt
else:
e.top = parent.h - mt
return self.value
return self.error
class AlignOriginBottom(Condition):
def evaluate(self, e):
u"""Answer the value between 0 and 1 to the level where the element
is origin aligned with the top-margin of the parent."""
parent = e.parent
if parent is not None:
mt = parent.css('mt')
if parent.originTop:
if abs(mt - e.y) <= self.tolerance:
return self.value
else:
if abs(parent.h - mt - e.y) <= self.tolerance:
return self.value
return self.error
def solve(self, e):
parent = e.parent
def CG1():
t1 = table.Table("data/posts.xml")
t2 = select(t1, Condition("PostTypeId","==", 1), ["Id","OwnerUserId"])
t3 = select(t1, Condition("PostTypeId","==", 2), ["ParentId","OwnerUserId"])
t4 = join(t2,t3,[("Id","ParentId")])
t5 = group(t4, ["OwnerUserId1", "OwnerUserId2"], "Count", "cnt")
g = graph.Graph("directed")
g.addNodes(t1,"OwnerUserId")
g.addEdges(t5,"OwnerUserId1","OwnerUserId2",["Count"])
return g
def CG1():
t1 = table.Table("data/posts.xml")
t2 = select(t1, Condition("PostTypeId","==", 1), ["Id","OwnerUserId"])
t3 = select(t1, Condition("PostTypeId","==", 2), ["ParentId","OwnerUserId"])
t4 = join(t2,t3,[("Id","ParentId")])
t5 = group(t4, ["OwnerUserId1", "OwnerUserId2"], "Count", "cnt")
g = graph.Graph("directed")
g.addNodes(t1,"OwnerUserId")
g.addEdges(t5,"OwnerUserId1","OwnerUserId2",["Count"])
return g