/** * Finish the current legend. * * @param LegendInterface $legend Return the final legend. * * @return PaletteBuilder * * @throws DcGeneralRuntimeException When no legend is stored in the builder. */ public function finishLegend(&$legend = null) { if (!$this->legend) { throw new DcGeneralRuntimeException('Legend is missing, please create a legend first'); } if ($this->property) { $this->finishProperty(); } $event = new FinishLegendEvent($this->legend, $this); $this->dispatchEvent($event); $legend = $event->getLegend(); if ($this->palette) { $this->palette->addLegend($legend); } $this->legend = null; return $this; }
/** * Fill a palette from a multidimensional array of legends. * * @param PaletteInterface $palette The palette. * * @param array $legends The legends. * * @return void * * @throws DcGeneralInvalidArgumentException When an invalid legend has been passed. */ public static function fillPalette(PaletteInterface $palette, array $legends) { foreach ($legends as $legend) { if ($legend instanceof LegendInterface) { $palette->addLegend($legend); } elseif (is_array($legend)) { static::fillPalette($palette, $legend); } else { $type = is_object($legend) ? get_class($legend) : gettype($legend); throw new DcGeneralInvalidArgumentException('Legend [' . $type . '] does not implement LegendInterface'); } } }
/** * Retrieve the legend with the given name. * * @param string $name Name of the legend. * * @param PaletteInterface $palette The palette. * * @param LegendInterface $prevLegend The previous legend. * * @return LegendInterface */ protected function getLegend($name, $palette, $prevLegend = null) { if (!$palette->hasLegend($name)) { $palette->addLegend(new Legend($name), $prevLegend); } return $palette->getLegend($name); }
/** * Retrieve the legend with the given name. * * @param string $name Name of the legend. * * @param PaletteInterface $palette The palette. * * @param LegendInterface $prevLegend The previous legend. * * @return LegendInterface */ public function getLegend($name, $palette, $prevLegend = null) { if ($name[0] == '+') { $name = substr($name, 1); } if (!$palette->hasLegend($name)) { $palette->addLegend(new Legend($name), $prevLegend); } return $palette->getLegend($name); }