code: def population_chart_legend_extractor(impact_report, component_metadata):
      
      context = {}
  
      context['inasafe_resources_base_dir'] = resources_path()
  
      """Population Charts."""
  
      population_donut_path = impact_report.component_absolute_output_path(
          'population-chart-png')
  
      css_label_classes = []
      try:
          population_chart_context = impact_report.metadata.component_by_key(
              'population-chart').context['context']
          """
          :type: safe.report.extractors.infographic_elements.svg_charts.
              DonutChartContext
          """
          for pie_slice in population_chart_context.slices:
              label = pie_slice['label']
              if not label:
                  continue
              css_class = label.replace(' ', '').lower()
              css_label_classes.append(css_class)
      except KeyError:
          population_chart_context = None
  
      context['population_chart'] = {
          'img_path': resource_url(population_donut_path),
          'context': population_chart_context,
          'css_label_classes': css_label_classes
      }
  
      return context
docs: Extracting legend of population chart.
  
      :param impact_report: the impact report that acts as a proxy to fetch
          all the data that extractor needed
      :type impact_report: safe.report.impact_report.ImpactReport
  
      :param component_metadata: the component metadata. Used to obtain
          information about the component we want to render
      :type component_metadata: safe.report.report_metadata.
          ReportComponentsMetadata
  
      :return: context for rendering phase
      :rtype: dict
  
      .. versionadded:: 4.2