class_docstr: Graph super class containing generic common functions
class_docstr_tok: ["Graph","super","class","containing","generic","common","functions"]
docstr: Make the legend box
code: def _legend(self):
      """Make the legend box"""
      if not self.show_legend:
          return
      truncation = self.truncate_legend
      if self.legend_at_bottom:
          x = self.margin_box.left + self.spacing
          y = (
              self.margin_box.top
              + self.view.height
              + self._x_title_height
              + self._x_labels_height
              + self.spacing
          )
          cols = (
              self.legend_at_bottom_columns
              or ceil(sqrt(self._order))
              or 1
          )
  
          if not truncation:
              available_space = self.view.width / cols - (
                  self.legend_box_size + 5
              )
              truncation = reverse_text_len(
                  available_space, self.style.legend_font_size
              )
      else:
          x = self.spacing
          y = self.margin_box.top + self.spacing
          cols = 1
          if not truncation:
              truncation = 15
  
      legends = self.svg.node(
          self.nodes["graph"],
          class_="legends",
          transform="translate(%d, %d)" % (x, y),
      )
  
      h = max(self.legend_box_size, self.style.legend_font_size)
      x_step = self.view.width / cols
      if self.legend_at_bottom:
          secondary_legends = legends  # svg node is the same
      else:
          # draw secondary axis on right
          x = self.margin_box.left + self.view.width + self.spacing
          if self._y_2nd_labels:
              h, w = get_texts_box(
                  cut(self._y_2nd_labels), self.style.label_font_size
              )
              x += self.spacing + max(
                  w * abs(cos(rad(self.y_label_rotation))), h
              )
  
          y = self.margin_box.top + self.spacing
  
          secondary_legends = self.svg.node(
              self.nodes["graph"],
              class_="legends",
              transform="translate(%d, %d)" % (x, y),
          )
  
      serie_number = -1
      i = 0
  
      for titles, is_secondary in (
          (self._legends, False),
          (self._secondary_legends, True),
      ):
          if not self.legend_at_bottom and is_secondary:
              i = 0
  
          for title in titles:
              serie_number += 1
              if title is None:
                  continue
              col = i % cols
              row = i // cols
  
              legend = self.svg.node(
                  secondary_legends if is_secondary else legends,
                  class_="legend reactive activate-serie",
                  id="activate-serie-%d" % serie_number,
              )
              self.svg.node(
                  legend,
                  "rect",
                  x=col * x_step,
                  y=1.5 * row * h
                  + (
                      self.style.legend_font_size - self.legend_box_size
                      if self.style.legend_font_size
                      > self.legend_box_size
                      else 0
                  )
                  / 2,
                  width=self.legend_box_size,
                  height=self.legend_box_size,
                  class_="color-%d reactive" % serie_number,
              )
  
              if isinstance(title, dict):
                  node = decorate(self.svg, legend, title)
                  title = title["title"]
              else:
                  node = legend
  
              truncated = truncate(title, truncation)
              self.svg.node(
                  node,
                  "text",
                  x=col * x_step + self.legend_box_size + 5,
                  y=1.5 * row * h
                  + 0.5 * h
                  + 0.3 * self.style.legend_font_size,
              ).text = truncated
  
              if truncated != title:
                  self.svg.node(legend, "title").text = title
  
              i += 1
  
imports: from math import ceil, cos, sin, sqrt
  from pygal import stats
  from pygal._compat import is_list_like
  from pygal.graph.public import PublicApi
  from pygal.interpolate import INTERPOLATIONS
  from pygal.util import cached_property, compute_scale, cut, decorate, filter_kwargs, get_text_box, get_texts_box, majorize, rad, reverse_text_len, split_title, truncate
  from pygal.view import LogView, ReverseView, View, XYLogView
label_desc: Use image node_id 7 for calling the Graph obj's underlying member method code with example usage: obj._legend() without return types