# 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
            'title': data.get('title', None),
            'span': data.get('span', None),
            'nullPointMode': data.get('nullPointMode', 'null'),
            'valueName': data.get('valueName', 'current')
        })
        panel_json['targets'] = self.registry.create_component(Targets, data).gen_json() if 'targets' in data else []
        if 'sparkline' in data:
            panel_json['sparkline'] = {
                'show': True,
                'full': data['sparkline'].get('full', False),
                'lineColor': data['sparkline'].get('lineColor', 'rgb(31, 120, 193)'),
                'fillColor': data['sparkline'].get('fillColor', 'rgba(31, 118, 189, 0.18)')
            }
        if 'gauge' in data:
            panel_json['gauge'] = {
                'show': True,
                'minValue': data['gauge'].get('minValue', 0),
                'maxValue': data['gauge'].get('maxValue', 100),
                'thresholdMarkers': data['gauge'].get('thresholdMarkers', True),
                'thresholdLabels': data['gauge'].get('thresholdLabels', False)
            }
        if 'colors' not in data:
            panel_json['colors'] = [
                'rgba(50, 172, 45, 0.97)',
                'rgba(237, 129, 40, 0.89)',
                'rgba(245, 54, 54, 0.9)'
            ]
        if 'valueMaps' in data:
            panel_json['valueMaps'] = [{'value': value, 'op': '=', 'text': text} for value, text in
                                       data['valueMaps'].items()]

# 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

            'title': data.get('title', None),
            'span': data.get('span', None),
            'nullPointMode': data.get('nullPointMode', 'null'),
            'valueName': data.get('valueName', 'current')
        })
        panel_json['targets'] = self.registry.create_component(Targets, data).gen_json() if 'targets' in data else []
        if 'sparkline' in data:
            panel_json['sparkline'] = {
                'show': True,
                'full': data['sparkline'].get('full', False),
                'lineColor': data['sparkline'].get('lineColor', 'rgb(31, 120, 193)'),
                'fillColor': data['sparkline'].get('fillColor', 'rgba(31, 118, 189, 0.18)')
            }
        if 'gauge' in data:
            panel_json['gauge'] = {
                'show': True,
                'minValue': data['gauge'].get('minValue', 0),
                'maxValue': data['gauge'].get('maxValue', 100),
                'thresholdMarkers': data['gauge'].get('thresholdMarkers', True),
                'thresholdLabels': data['gauge'].get('thresholdLabels', False)
            }
        if 'colors' not in data:
            panel_json['colors'] = [
                'rgba(50, 172, 45, 0.97)',
                'rgba(237, 129, 40, 0.89)',
                'rgba(245, 54, 54, 0.9)'
            ]
        if 'valueMaps' in data:
            panel_json['valueMaps'] = [{'value': value, 'op': '=', 'text': text} for value, text in
                                       data['valueMaps'].items()]

        if get_component_type(Links) in data: