public function finishPalette(&$palette = null)
    {
        if (!$this->palette) {
            throw new DcGeneralRuntimeException('Palette is missing, please create a palette first');
        }

        if ($this->legend) {
            $this->finishLegend();
        }
        if ($this->condition) {
            $this->finishCondition();
        }

        $event = new FinishPaletteEvent($this->palette, $this);
        $this->dispatchEvent($event);
        $palette = $event->getPalette();

        if ($this->paletteCollection) {
            $this->paletteCollection->addPalette($palette);
        }

        $this->palette = null;

        return $this;
    }