class_docstr: Chart internal behaviour related functions
class_docstr_tok: ["Chart","internal","behaviour","related","functions"]
docstr: Prepare the values to start with sane values
docstr_tok: ["Prepare","the","values","to","start","with","sane","values"]
code: def prepare_values(self, raw, offset=0):
      """Prepare the values to start with sane values"""
      from pygal import Histogram
      from pygal.graph.map import BaseMap
  
      if self.zero == 0 and isinstance(self, BaseMap):
          self.zero = 1
  
      if self.x_label_rotation:
          self.x_label_rotation %= 360
  
      if self.y_label_rotation:
          self.y_label_rotation %= 360
  
      for key in ("x_labels", "y_labels"):
          if getattr(self, key):
              setattr(self, key, list(getattr(self, key)))
      if not raw:
          return
  
      adapters = list(self._adapters) or [lambda x: x]
      if self.logarithmic:
          for fun in not_zero, positive:
              if fun in adapters:
                  adapters.remove(fun)
          adapters = adapters + [positive, not_zero]
      adapters = adapters + [decimal_to_float]
  
      self._adapt = (
          reduce(compose, adapters) if not self.strict else ident
      )
      self._x_adapt = (
          reduce(compose, self._x_adapters)
          if not self.strict and getattr(self, "_x_adapters", None)
          else ident
      )
  
      series = []
  
      raw = [
          (
              list(raw_values)
              if not isinstance(raw_values, dict)
              else raw_values,
              serie_config_kwargs,
          )
          for raw_values, serie_config_kwargs in raw
      ]
  
      width = max(
          [len(values) for values, _ in raw]
          + [len(self.x_labels or [])]
      )
  
      for raw_values, serie_config_kwargs in raw:
          metadata = {}
          values = []
          if isinstance(raw_values, dict):
              if isinstance(self, BaseMap):
                  raw_values = list(raw_values.items())
              else:
                  value_list = [None] * width
                  for k, v in raw_values.items():
                      if k in (self.x_labels or []):
                          value_list[self.x_labels.index(k)] = v
                  raw_values = value_list
  
          for index, raw_value in enumerate(
              raw_values
              + (
                  (width - len(raw_values)) * [None]  # aligning values
                  if len(raw_values) < width
                  else []
              )
          ):
              if isinstance(raw_value, dict):
                  raw_value = dict(raw_value)
                  value = raw_value.pop("value", None)
                  metadata[index] = raw_value
              else:
                  value = raw_value
  
              # Fix this by doing this in charts class methods
              if isinstance(self, Histogram):
                  if value is None:
                      value = (None, None, None)
                  elif not is_list_like(value):
                      value = (value, self.zero, self.zero)
                  elif len(value) == 2:
                      value = (1, value[0], value[1])
                  value = list(map(self._adapt, value))
              elif self._dual:
                  if value is None:
                      value = (None, None)
                  elif not is_list_like(value):
                      value = (value, self.zero)
                  if self._x_adapt:
                      value = (
                          self._x_adapt(value[0]),
                          self._adapt(value[1]),
                      )
                  if isinstance(self, BaseMap):
                      value = (self._adapt(value[0]), value[1])
                  else:
                      value = list(map(self._adapt, value))
              else:
                  value = self._adapt(value)
  
              values.append(value)
          serie_config = SerieConfig()
          serie_config(
              **dict(
                  (k, v)
                  for k, v in self.state.__dict__.items()
                  if k in dir(serie_config)
              )
          )
          serie_config(**serie_config_kwargs)
          series.append(
              Serie(
                  offset + len(series), values, serie_config, metadata
              )
          )
      return series
  
imports: import os
  from functools import reduce
  from uuid import uuid4
  from pygal._compat import is_list_like
  from pygal.adapters import decimal_to_float, not_zero, positive
  from pygal.config import Config, SerieConfig
  from pygal.serie import Serie
  from pygal.state import State
  from pygal.svg import Svg
  from pygal.util import compose, ident
  from pygal.view import Box, Margin
label_desc: Use image node_id 4 for calling the BaseGraph obj's underlying member method code with example usage: obj.prepare_values(raw, offset) and returns: series