Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Workflow] Add colors to workflow dumps #28874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexislefebvre opened this issue Oct 15, 2018 · 9 comments · Fixed by #29538
Closed

[Workflow] Add colors to workflow dumps #28874

alexislefebvre opened this issue Oct 15, 2018 · 9 comments · Fixed by #29538

Comments

@alexislefebvre
Copy link
Contributor

alexislefebvre commented Oct 15, 2018

Description
The PR [Workflow] Add a MetadataStore to fetch some metadata #26092 has been merged so we can add some metadata to our workflows.

The text of the PR shows an example with color: grey, so it looks like the support of color was planned.

When I dump the workflow with both formats, there are no color on the images, like the examples in the documentation.

How can we add colors to the dumped workflow? Is the feature implemented yet?

See also symfony/symfony-docs#9476 if it needs it be documented.

Example

I use symfony/workflow:4.1.3 (the problem is the same with 4.1.6).

I have a workflow like this:

framework:
    workflows:
        my_entity:
            type: 'state_machine'
            marking_store:
                type: 'single_state'
                arguments:
                    - 'state'
            supports:
                - App\Entity\MyEntity
            initial_place: created
            places:
                created:
                    metadata:
                        description: Entity created, waiting for next step
                        color: green
            #

And the output doesn't use the colors or the description.

@alexislefebvre
Copy link
Contributor Author

alexislefebvre commented Oct 15, 2018

When I run bin/console workflow:dump my_entity without passing output to a graph tool through a pipe, the text output is the same with and without metadata. There are neither description nor color in output, that's why the images have default values.

So it looks like the metadata is not dumped.


I confirm that metadata is not dumped and color is hard-coded: https://github.com/symfony/symfony/blob/76465fc1f740f9432ee7edcb3c16d86e0ccbd93b/src/Symfony/Component/Workflow/Dumper/GraphvizDumper.php

So this issue is a feature request.

@alexislefebvre alexislefebvre changed the title [Workflow] How to add colors to workflow dumps? [Workflow] Add colors to workflow dumps Oct 15, 2018
@alexislefebvre
Copy link
Contributor Author

Setting color in a PlantUML file is not trivial: http://wiki.plantuml.net/site/state-diagram#skinparam

I see several solutions to add colors or formatting:

  • add logic in the dumpers in order to format data for the GraphViz and PlantUML formats, it may be very complicated since there are options for borders, font colors, etc.
  • pass data from YAML to the dumps without transformation, in other words: we would need to write configuration for each node in metadata and the content would be added to the dumps, so it requires work when writing the configuration and it's easier to implement in Symfony Workflow component (:crossed_fingers:)

@alexislefebvre
Copy link
Contributor Author

alexislefebvre commented Oct 20, 2018

I identified 3 possible solutions for the configuration:

Define every option:

blog_publishing:
    transitions:
        to_review:
            metadata:
                label: Submit for review
                arrow_color: "Blue"
                label_color: "MediumBlue"

Pros:

  • Simple to write for users

Cons:

  • May require lot of work on the dumper to treat every option (there are literally hundreds of options see Font color, name and size)

Define output format directly

blog_publishing:
    transitions:
        to_review:
            metadata:
                label: Submit for review
                arrow_style: "[#Blue]"
                label_prefix: "<font color=MediumBlue>"

Pros:

  • Users can define every option they want and it will be added in output file as is

Cons:

  • Will work for only dot or PUML output and break the other format

Define output format specifically for dot or puml

blog_publishing:
    transitions:
        to_review:
            metadata:
                label: Submit for review
                puml_format:
                    arrow_style: "[#Blue]"
                    label_prefix: "<font color=MediumBlue>"

Pros:

  • Users can define every option they want and it will be added in output file as is
  • Users can define options for dot, PUML or both formats

Cons:

  • Users must write configuration two times but I think that users will choose dot or PUML formats instead of styling both outputs

@alexislefebvre
Copy link
Contributor Author

Ping @lyrixx please give your feedback on this new feature. 😉

@lyrixx
Copy link
Member

lyrixx commented Nov 8, 2018

Hello. Thanks for working on this feature.

As you said, it's complicated.

Initially, metadata were not introduced to control the dump redering. But it could be a nice idea to leverage this extension point.

As you have many (2 for now) dumper, it's IMHO a bad idea to support your first option "Define every option" and it's the same for the second option "Define output format directly".

About the third option, I'm not super fan of it too.

So I would like to introduce a new option:

  1. We support only a very few range of option (label, arrow_color, label_color)
  2. We implement theses options for all dumpers
  3. If people want more control on the dumper : They extend a dumper a do what ever they want

What do you think ? Do you want do give it a try ?

@alexislefebvre
Copy link
Contributor Author

Thanks for the detailed answer.

Sorry for the late answer, I think that I'll implement this feature in a bundle so I'll be able to add colors to my project's workflow. Because even if a PR is merged in symfony in a near future, it will be available only on the 4.3 branch and it won't be usable in my project.

@alexislefebvre
Copy link
Contributor Author

I implemented styling in a proof of concept Bundle: https://github.com/alexislefebvre/SymfonyWorkflowStyleBundle

@lyrixx
Copy link
Member

lyrixx commented Nov 26, 2018

Ok, thanks for your work. If you want to contribute your feature for Symfony, I will be glad to merge it.
For now, I think we can close this issue. But feel free to re-open it if you think it's needed.

@lyrixx lyrixx closed this as completed Nov 26, 2018
@alexislefebvre
Copy link
Contributor Author

Thanks @lyrixx, I'll try to stabilize the feature and I'll open a request for Symfony when it will be working.

alexislefebvre added a commit to alexislefebvre/symfony that referenced this issue Dec 9, 2018
alexislefebvre added a commit to alexislefebvre/symfony that referenced this issue Feb 5, 2019
alexislefebvre added a commit to alexislefebvre/symfony that referenced this issue Feb 5, 2019
alexislefebvre added a commit to alexislefebvre/symfony that referenced this issue Feb 5, 2019
alexislefebvre added a commit to alexislefebvre/symfony that referenced this issue Feb 5, 2019
alexislefebvre added a commit to alexislefebvre/symfony that referenced this issue Feb 5, 2019
alexislefebvre added a commit to alexislefebvre/symfony that referenced this issue Mar 13, 2019
fabpot added a commit that referenced this issue Mar 19, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes #29538).

Discussion
----------

[Workflow] Add colors to workflow dumps

Fixes #28874

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28874, replaces #28933
| License       | MIT
| Doc PR        | TODO, requires symfony/symfony-docs#9476

Fetch data with the `MetadataStore` from #26092 in order to add colors to the dumps.

Example of configuration:

```yaml
            transitions:
                submit:
                    from: start
                    to: travis
                    metadata:
                        title: transition submit title
                        dump_style:
                            label: 'My custom label'
                            arrow_color: '#0088FF'
                            label_color: 'Red'
```

This code was developed as a bundle, examples can be found on its repository: https://github.com/alexislefebvre/SymfonyWorkflowStyleBundle

Commits
-------

60ad109 [Workflow] Add colors to workflow dumps
@nicolas-grekas nicolas-grekas removed this from the next milestone Oct 27, 2019
@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants