/** * @throws \Exception */ public function draw(AbstractGraphic $graphic) { if ($this->state instanceof AbstractState) { $graphic->addLegend($this->label, $this->styleAttributes); $this->state->draw($graphic); } else { throw new \Exception('State is not Set!'); } return $graphic->draw(); }
/** * Draw this State * * @param AbstractGraphic $graphic * @param bool $propagation * @return mixed * @throws \Exception */ public function draw(AbstractGraphic $graphic, $propagation = true) { if (0 == strlen(trim($this->getLabel()))) { throw new \Exception("Label cannot be empty!"); } $this->configureAvailableTransitions(); $drawnState = $graphic->addState($this->getId(), $this->getLabel(), $this->styleAttributes); if ($propagation) { /** @var Transition $transition */ foreach ($this->availableTransitions as $transition) { $nextState = $transition->getState(); if ($this->getId() == $nextState->getId()) { $propagation = false; } $drawnNextState = $nextState->draw($graphic, $propagation); $label = ''; $styleAttributes = $transition->styleAttributes; if ($transition->getCondition() instanceof AbstractCondition) { $label = $transition->getCondition()->getLabel(); $styleAttributes = $transition->getCondition()->getStyleAttributes(); } $graphic->addTransition($drawnState, $drawnNextState, $label, $styleAttributes); } } return $drawnState; }