svg/charts/graph.py
def add_popup(self, x, y, label):
		"""
		Add pop-up information to a point on the graph.
		"""
		txt_width = len(label) * self.font_size * 0.6 + 10
		tx = x + [5, -5][int(x + txt_width > self.width)]
		anchor = ['start', 'end'][x + txt_width > self.width]
		style = 'fill: #000; text-anchor: %s;' % anchor
		id = 'label-%s' % self._w3c_name(label)
		attrs = {
			'x': str(tx),
			'y': str(y - self.font_size),
			'visibility': 'hidden',
			'style': style,
			'text': label,
			'id': id,
		}
		etree.SubElement(self.foreground, 'text', attrs)

		# add the circle element to the foreground
		vis_tmpl = (
			"document.getElementById('{id}').setAttribute('visibility', {val})"
		)
		attrs = {
			'cx': str(x),
			'cy': str(y),
			'r': str(10),
			'style': 'opacity: 0;',
			'onmouseover': vis_tmpl.format(val='visible', id=id),
			'onmouseout': vis_tmpl.format(val='hidden', id=id),
		}
		etree.SubElement(self.foreground, 'circle', attrs)
def add_popup(self, x, y, label):
		"""
		Add pop-up information to a point on the graph.
		"""
		txt_width = len(label) * self.font_size * 0.6 + 10
		tx = x + [5, -5][int(x + txt_width > self.width)]
		anchor = ['start', 'end'][x + txt_width > self.width]
		style = 'fill: #000; text-anchor: %s;' % anchor
		id = 'label-%s' % self._w3c_name(label)
		attrs = {
			'x': str(tx),
			'y': str(y - self.font_size),
			'visibility': 'hidden',
			'style': style,
			'text': label,
			'id': id,
		}
		etree.SubElement(self.foreground, 'text', attrs)

		# add the circle element to the foreground
		vis_tmpl = (
			"document.getElementById('{id}').setAttribute('visibility', {val})"
		)
		attrs = {
			'cx': str(x),
			'cy': str(y),
			'r': str(10),
			'style': 'opacity: 0;',
			'onmouseover': vis_tmpl.format(val='visible', id=id),
			'onmouseout': vis_tmpl.format(val='hidden', id=id),
		}
		etree.SubElement(self.foreground, 'circle', attrs)
Add pop-up information to a point on the graph.