# Path: grafana_dashboards/common.py
# def get_component_type(clazz):
#     """
# 
#     :type clazz: type
#     """
#     return _all_cap_re.sub(r'\1-\2', _first_cap_re.sub(r'\1-\2', clazz.__name__)).lower()
# 
# Path: grafana_dashboards/components/axes.py
# class Yaxes(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Yaxes, self).__init__(data, registry, YaxesItemBase)
# 
#     def gen_json_from_data(self, data, context):
#         if len(data) == 1:
#             data.append(data[0])
#         return super(Yaxes, self).gen_json_from_data(data, context)
# 
#     def gen_item_json(self, items, result_list):
#         if isinstance(items, dict) and len(items) > 1:
#             result_list.append(items)
#         else:
#             super(Yaxes, self).gen_item_json(items, result_list)
# 
# Path: grafana_dashboards/components/base.py
# class JsonListGenerator(JsonGenerator):
#     def __init__(self, data, registry, item_base_class):
#         super(JsonListGenerator, self).__init__(data, registry)
#         self.component_item_types = [get_component_type(clazz) for clazz in _get_subclasses(item_base_class)]
# 
#     def gen_json_from_data(self, data, context):
#         super(JsonListGenerator, self).gen_json_from_data(data, context)
#         result_list = []
#         for items in data:
#             self.gen_item_json(items, result_list)
#         return result_list
# 
#     def gen_item_json(self, items, result_list):
#         if isinstance(items, basestring):
#             # this is component without context
#             result_list += self.registry.get_component(type(self), items).gen_json()
#         else:
#             self._gen_item_json_with_context(items, result_list)
# 
#     def _gen_item_json_with_context(self, items, result_list):
#         # TODO add check for dictionary
#         for (item_type, item_data) in items.items():
#             if item_type not in self.component_item_types:
#                 # this is named component with context
#                 for context in Context.create_context(item_data, get_placeholders(item_type)):
#                     result_list += self.registry.get_component(type(self), item_type).gen_json(context)
#             else:
#                 # this is inplace defined component
#                 item = self.registry.create_component(item_type, {item_type: item_data}).gen_json()
#                 if isinstance(item, list):
#                     result_list += item
#                 else:
#                     result_list.append(item)
# 
# class JsonGenerator(ComponentBase):
# 
#     _copy_fields = set()
# 
#     def gen_json(self, context=Context()):
#         return self.gen_json_from_data(context.expand_placeholders(self.data), context)
# 
#     def gen_json_from_data(self, data, context):
#         component_type = get_component_type(type(self))
#         if self.name:
#             logger.debug("Processing component '%s' with name '%s' from template '%s'",
#                          component_type, context.expand_placeholders(self.name), self.name)
#         else:
#             logger.debug("Processing anonymous component '%s'", component_type)
#         json = {}
#         for field in self._copy_fields:
#             if field in data:
#                 json[field] = data[field]
#         return json
# 
# Path: grafana_dashboards/components/links.py
# class Links(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Links, self).__init__(data, registry, LinksItemBase)
# 
# Path: grafana_dashboards/components/targets.py
# class Targets(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Targets, self).__init__(data, registry, TargetsItemBase)
# 
#     def gen_item_json(self, items, result_list):
#         try:
#             super(Targets, self).gen_item_json(items, result_list)
#         except UnregisteredComponentError:
#             result_list.append(
#                 self.registry.create_component(GraphiteTarget, {get_component_type(GraphiteTarget): items}).gen_json()
#             )


from grafana_dashboards.common import get_component_type
from grafana_dashboards.components.axes import Yaxes
from grafana_dashboards.components.base import JsonListGenerator, JsonGenerator
from grafana_dashboards.components.links import Links
from grafana_dashboards.components.targets import Targets
                'threshold2Color': grid_data.get('threshold2Color', 'rgba(234, 112, 112, 0.22)')
            }
        if 'legend' in self.data:
            panel_json['legend'] = {
                'show': self.data['legend'].get('show', True),
                'values': self.data['legend'].get('values', False),
                'min': self.data['legend'].get('min', False),
                'max': self.data['legend'].get('max', False),
                'current': self.data['legend'].get('current', False),
                'total': self.data['legend'].get('total', False),
                'avg': self.data['legend'].get('avg', False),
                'alignAsTable': self.data['legend'].get('alignAsTable', False),
                'rightSide': self.data['legend'].get('rightSide', False),
                'hideEmpty': self.data['legend'].get('hideEmpty', False),
                'hideZero': self.data['legend'].get('hideZero', False),
                'sideWidth': self.data['legend'].get('sideWidth', None)
            }
        if 'tooltip' in self.data:
            panel_json['tooltip'] = {
                'value_type': self.data['tooltip'].get('value_type', 'individual'),
                'shared': self.data['tooltip'].get('shared', False),
            }
        if 'seriesOverrides' in self.data:
            overrides = []
            for override in self.data['seriesOverrides']:
                for alias, settings in override.items():
                    to_add = {'alias': alias}
                    to_add.update(settings)
                    overrides.append(to_add)
            panel_json['seriesOverrides'] = overrides

# Path: grafana_dashboards/common.py
# def get_component_type(clazz):
#     """
# 
#     :type clazz: type
#     """
#     return _all_cap_re.sub(r'\1-\2', _first_cap_re.sub(r'\1-\2', clazz.__name__)).lower()
# 
# Path: grafana_dashboards/components/axes.py
# class Yaxes(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Yaxes, self).__init__(data, registry, YaxesItemBase)
# 
#     def gen_json_from_data(self, data, context):
#         if len(data) == 1:
#             data.append(data[0])
#         return super(Yaxes, self).gen_json_from_data(data, context)
# 
#     def gen_item_json(self, items, result_list):
#         if isinstance(items, dict) and len(items) > 1:
#             result_list.append(items)
#         else:
#             super(Yaxes, self).gen_item_json(items, result_list)
# 
# Path: grafana_dashboards/components/base.py
# class JsonListGenerator(JsonGenerator):
#     def __init__(self, data, registry, item_base_class):
#         super(JsonListGenerator, self).__init__(data, registry)
#         self.component_item_types = [get_component_type(clazz) for clazz in _get_subclasses(item_base_class)]
# 
#     def gen_json_from_data(self, data, context):
#         super(JsonListGenerator, self).gen_json_from_data(data, context)
#         result_list = []
#         for items in data:
#             self.gen_item_json(items, result_list)
#         return result_list
# 
#     def gen_item_json(self, items, result_list):
#         if isinstance(items, basestring):
#             # this is component without context
#             result_list += self.registry.get_component(type(self), items).gen_json()
#         else:
#             self._gen_item_json_with_context(items, result_list)
# 
#     def _gen_item_json_with_context(self, items, result_list):
#         # TODO add check for dictionary
#         for (item_type, item_data) in items.items():
#             if item_type not in self.component_item_types:
#                 # this is named component with context
#                 for context in Context.create_context(item_data, get_placeholders(item_type)):
#                     result_list += self.registry.get_component(type(self), item_type).gen_json(context)
#             else:
#                 # this is inplace defined component
#                 item = self.registry.create_component(item_type, {item_type: item_data}).gen_json()
#                 if isinstance(item, list):
#                     result_list += item
#                 else:
#                     result_list.append(item)
# 
# class JsonGenerator(ComponentBase):
# 
#     _copy_fields = set()
# 
#     def gen_json(self, context=Context()):
#         return self.gen_json_from_data(context.expand_placeholders(self.data), context)
# 
#     def gen_json_from_data(self, data, context):
#         component_type = get_component_type(type(self))
#         if self.name:
#             logger.debug("Processing component '%s' with name '%s' from template '%s'",
#                          component_type, context.expand_placeholders(self.name), self.name)
#         else:
#             logger.debug("Processing anonymous component '%s'", component_type)
#         json = {}
#         for field in self._copy_fields:
#             if field in data:
#                 json[field] = data[field]
#         return json
# 
# Path: grafana_dashboards/components/links.py
# class Links(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Links, self).__init__(data, registry, LinksItemBase)
# 
# Path: grafana_dashboards/components/targets.py
# class Targets(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Targets, self).__init__(data, registry, TargetsItemBase)
# 
#     def gen_item_json(self, items, result_list):
#         try:
#             super(Targets, self).gen_item_json(items, result_list)
#         except UnregisteredComponentError:
#             result_list.append(
#                 self.registry.create_component(GraphiteTarget, {get_component_type(GraphiteTarget): items}).gen_json()
#             )


# Path: grafana_dashboards/components/panels.py
from grafana_dashboards.common import get_component_type
from grafana_dashboards.components.axes import Yaxes
from grafana_dashboards.components.base import JsonListGenerator, JsonGenerator
from grafana_dashboards.components.links import Links
from grafana_dashboards.components.targets import Targets

                'threshold2Color': grid_data.get('threshold2Color', 'rgba(234, 112, 112, 0.22)')
            }
        if 'legend' in self.data:
            panel_json['legend'] = {
                'show': self.data['legend'].get('show', True),
                'values': self.data['legend'].get('values', False),
                'min': self.data['legend'].get('min', False),
                'max': self.data['legend'].get('max', False),
                'current': self.data['legend'].get('current', False),
                'total': self.data['legend'].get('total', False),
                'avg': self.data['legend'].get('avg', False),
                'alignAsTable': self.data['legend'].get('alignAsTable', False),
                'rightSide': self.data['legend'].get('rightSide', False),
                'hideEmpty': self.data['legend'].get('hideEmpty', False),
                'hideZero': self.data['legend'].get('hideZero', False),
                'sideWidth': self.data['legend'].get('sideWidth', None)
            }
        if 'tooltip' in self.data:
            panel_json['tooltip'] = {
                'value_type': self.data['tooltip'].get('value_type', 'individual'),
                'shared': self.data['tooltip'].get('shared', False),
            }
        if 'seriesOverrides' in self.data:
            overrides = []
            for override in self.data['seriesOverrides']:
                for alias, settings in override.items():
                    to_add = {'alias': alias}
                    to_add.update(settings)
                    overrides.append(to_add)
            panel_json['seriesOverrides'] = overrides

        self._create_component(panel_json, Links, self.data)