Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Charts
grid_group = ET.Element('g')
chart_count = len(self._charts)
grid_width = math.ceil(math.sqrt(chart_count))
grid_height = math.ceil(chart_count / grid_width)
chart_width = width / grid_width
chart_height = height / grid_height
for i, chart in enumerate(self._charts):
x = (i % grid_width) * chart_width
y = math.floor(i / grid_width) * chart_height
group = ET.Element('g')
group.set('transform', svg.translate(x, y))
chart = chart.to_svg_group(chart_width, chart_height)
group.append(chart)
grid_group.append(group)
root_group.append(grid_group)
svg_text = svg.stringify(root)
close = True
if path:
f = None
try:
if hasattr(path, 'write'):
rows = 1
indent = 0
for i, (series, shape) in enumerate(layers):
text = six.text_type(series._name or 'Series %i' % i)
text_width = (len(text) + 4) * theme.legend_font_char_width
if indent + text_width + bubble_width > width:
indent = 0
rows += 1
y = (rows - 1) * (theme.legend_font_char_height + theme.legend_gap)
# Group
item_group = ET.Element('g')
item_group.set('transform', svg.translate(indent, y))
fill_color = getattr(shape, '_fill_color', None)
stroke_color = getattr(shape, '_stroke_color', None)
if callable(fill_color):
# TODO
fill_color = 'black'
# Bubble
bubble = ET.Element('rect',
x=six.text_type(0),
y=six.text_type(-theme.legend_font_char_height + theme.legend_bubble_offset),
width=six.text_type(theme.legend_bubble_size),
height=six.text_type(theme.legend_bubble_size)
)
margin = Box(*margin)
# Root / background
root_group = ET.Element('g')
root_group.append(ET.Element('rect',
x=six.text_type(0),
y=six.text_type(0),
width=six.text_type(width),
height=six.text_type(height),
fill=theme.background_color
))
# Margins
margin_group = ET.Element('g')
margin_group.set('transform', svg.translate(margin.left, margin.top))
margin_width = width - (margin.left + margin.right)
margin_height = height - (margin.top + margin.bottom)
root_group.append(margin_group)
# Header
header_group = ET.Element('g')
header_margin = 0
if self._title:
label = ET.Element('text',
x=six.text_type(0),
y=six.text_type(0),
fill=theme.title_color
x_scale, x_axis = self._validate_dimension(X)
y_scale, y_axis = self._validate_dimension(Y)
bottom_margin = x_axis.estimate_label_margin(x_scale, 'bottom')
left_margin = y_axis.estimate_label_margin(y_scale, 'left')
canvas_width = body_width - left_margin
canvas_height = body_height - bottom_margin
axes_group = ET.Element('g')
axes_group.set('transform', svg.translate(left_margin, 0))
axes_group.append(x_axis.to_svg(canvas_width, canvas_height, x_scale, 'bottom'))
axes_group.append(y_axis.to_svg(canvas_width, canvas_height, y_scale, 'left'))
header_group.set('transform', svg.translate(left_margin, 0))
body_group.append(axes_group)
# Series
series_group = ET.Element('g')
palette = self._palette()
for series, shape in self._layers:
series_group.append(shape.to_svg(canvas_width, canvas_height, x_scale, y_scale, series, palette))
axes_group.append(series_group)
return root_group
for i, chart in enumerate(self._charts):
x = (i % grid_width) * chart_width
y = math.floor(i / grid_width) * chart_height
group = ET.Element('g')
group.set('transform', svg.translate(x, y))
chart = chart.to_svg_group(chart_width, chart_height)
group.append(chart)
grid_group.append(group)
root_group.append(grid_group)
svg_text = svg.stringify(root)
close = True
if path:
f = None
try:
if hasattr(path, 'write'):
f = path
close = False
else:
dirpath = os.path.dirname(path)
if dirpath and not os.path.exists(dirpath):
os.makedirs(dirpath)
f = open(path, 'w')
def to_svg(self, width, height, scale, orient):
"""
Render this axis to SVG elements.
"""
group = ET.Element('g')
group.set('class', 'axis ' + orient)
# Axis title
if self._name is not None:
if orient == 'left':
title_x = -(self._estimate_left_tick_width(scale) + theme.axis_title_gap)
title_y = height / 2
dy=''
transform = svg.rotate(270, title_x, title_y)
elif orient == 'bottom':
title_x = width / 2
title_y = height + theme.tick_font_char_height + (theme.tick_size * 2) + theme.axis_title_gap
dy='1em'
transform = ''
title = ET.Element('text',
x=six.text_type(title_x),
y=six.text_type(title_y),
dy=dy,
fill=theme.axis_title_color,
transform=transform
)
title.set('text-anchor', 'middle')
title.set('font-family', theme.axis_title_font_family)
title.text = self._name