Skip to content

Commit

Permalink
Made the Box element's API consistent with Ellipse
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Jun 2, 2017
1 parent 15af712 commit b312be2
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions holoviews/element/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,45 @@ class Box(BaseShape):

y = param.Number(default=0, doc="The y-position of the box center.")

width = param.Number(default=1, doc="The width of the box.")

height = param.Number(default=1, doc="The height of the box.")

aspect= param.Number(default=1, doc=""""
The aspect ratio of the box if supplied, otherwise an aspect
of 1.0 is used.""")
orientation = param.Number(default=0, doc="""
Orientation in the Cartesian coordinate system, the
counterclockwise angle in radians between the first axis and the
horizontal.""")

aspect= param.Number(default=1.0, doc="""
Optional multiplier applied to the box length to compute the
width in cases where only the length value is set.""")

group = param.String(default='Box', constant=True, doc="The assigned group name.")

__pos_params = ['x','y', 'height']

def __init__(self, x, y, height, **params):
super(Box, self).__init__([], x=x,y =y, height=height, **params)
width = height * self.aspect
(l,b,r,t) = (x-width/2.0, y-height/2, x+width/2.0, y+height/2)
self.data = [np.array([(l, b), (l, t), (r, t), (r, b),(l, b)])]
def __init__(self, x, y, spec, **params):

if isinstance(spec, tuple):
if 'aspect' in params:
raise ValueError('Aspect parameter not supported when supplying '
'(width, height) specification.')
(height, width) = spec
else:
width, height = params.get('width', spec), spec

params['width']=params.get('width',width)
super(Box, self).__init__([], x=x, y=y, height=height, **params)

half_width = (self.width * self.aspect)/ 2.0
half_height = self.height / 2.0
(l,b,r,t) = (x-half_width, y-half_height, x+half_width, y+half_height)

box = np.array([(l, b), (l, t), (r, t), (r, b),(l, b)])
rot = np.array([[np.cos(self.orientation), -np.sin(self.orientation)],
[np.sin(self.orientation), np.cos(self.orientation)]])

self.data = [np.tensordot(rot, box.T, axes=[1,0]).T]


class Ellipse(BaseShape):
Expand Down Expand Up @@ -243,8 +267,8 @@ def __init__(self, x, y, spec, **params):
super(Ellipse, self).__init__([], x=x, y=y, height=height, **params)

angles = np.linspace(0, 2*np.pi, self.samples)
half_height = self.height / 2.0
half_width = (self.width * self.aspect)/ 2.0
half_height = self.height / 2.0
#create points
ellipse = np.array(
list(zip(half_width*np.sin(angles),
Expand Down

0 comments on commit b312be2

Please sign in to comment.