Skip to content
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

feat(flowchart): add classDef style group definition #3923

Merged

Conversation

tomperr
Copy link
Contributor

@tomperr tomperr commented Dec 17, 2022

📑 Summary

Enable to add styles to many classDef in a single statement
Add unit test on addClass function of flowDb

Resolves #3036

📏 Design Decisions

Split the ids using ,.
e.g. classDef a,b stroke:gold

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added unit/e2e tests (if appropriate)
  • 🔖 targeted develop branch

enable to add styles to many classDef in a single statement
@weedySeaDragon
Copy link
Contributor

I have some questions about this PR:

  1. What is the purpose? I'm not clear on this
  2. Your code doesn't change anything for the user

1. Purpose?

Can you clarify what the goal of this PR is? I've read through issue #3036.
I see your comment that a user can indeed apply a style definition (classDef) to one or many nodes or links. (Here's the documentation section on that.)
But I'm not clear on why you want to define a style class (classDef = style class definition) with multiple ids (names).

For example, here is the statement that a users would (theoretically) write in a flowchart diagram text in order to call the addClass() method with many class ids (names):

classDef firstStyleID,secondStyleID, font-size: larger, color:red

firstShape[First shape] --> secondShape(second shape)

%% Here is where the style (with 2 different ids) could be applied:
class firstShape firstStyleID
class secondShape secondStyleID

This would mean you are defining the same class style (font is larger and color is red) with 2 different names: firstStyleID and secondStyleID

A user would (and should) just use firstStyleID everywhere in their diagram definition, like this:

class firstShape,secondShape firstStyleID

I may very well be missing something.

2. No change for a user

Your code does change how flowDb addClass() can work (it can accept multiple class ids for a single class style definition). (And kudos for writing tests!!) But it doesn't change what can be parsed from the user.
You'd need to also change the parser in flowchart/parser/flow.jison (and write tests, of course.)

@tomperr
Copy link
Contributor Author

tomperr commented Dec 19, 2022

Hey, thanks for your review.
I may have missed something, but if I'm not wrong, it is currently not possible to add style to many classes in one statement (which is something common in CSS for example). I will take a look again in the next days. Sorry for this unclear PR, I will add new comments once checked a second time to make it clear

@weedySeaDragon
Copy link
Contributor

Thanks for clarifying for me. Makes more sense now.
(You'll still need to modify the parser flow.jison. But I think you understand that. :-) )

@tomperr
Copy link
Contributor Author

tomperr commented Dec 22, 2022

Sorry for the wait. I will start from the beginning so that everything is clear (I hope :))

Purpose

Initially, this issue was about declaring style (with linkStyle) for many links at the same time, instead of having one statement for each link which could be redundant:

linkStyle 0,1,2 stroke:gold, stroke-width:4px

instead of

linkStyle 0 stroke:gold, stroke-width:4px
linkStyle 1 stroke:gold, stroke-width:4px
linkStyle 2 stroke:gold, stroke-width:4px

In the discussion, people thought that it could be great to have the same for classes: being allowed to add a class to many nodes at the same time:

class A,B,C active_node;

instead of

class A active_node;
class B active_node;
class C active_node;

I discovered that those two features were already implemented. But to be consistent, why not having the same for classDef? classDef add style to a class, and to avoid redundancy in some cases, declaring styles to many classes at the same time could be interesting:

classDef basic_nodes,error_nodes,success_nodes stroke-width:8px,font-size:12pt,color:white

classDef basic_nodes fill:#A0A0A0,stroke:#A0A0A0
classDef error_nodes fill:#BA1919,stroke:#BA1919
classDef success_nodes fill:#2F9A11,stroke:#2F9A11

instead of

classDef basic_nodes fill:#C0C0C0,stroke:#C0C0C0,stroke-width:8px,font-size:12pt,color:white
classDef error_nodes fill:#BA1919,stroke:#BA1919,stroke-width:8px,font-size:12pt,color:white
classDef success_nodes fill:#2F9A11,stroke:#2F9A11,stroke-width:8px,font-size:12pt,color:white

No change for a user

Let's take the example of the following statement:

classDef basic_nodes,error_nodes,success_nodes stroke-width:8px,font-size:12pt,color:white

Currently (on the develop branch), once this statement is parsed, the addClass function will be called with "basic_nodes,error_nodes,success_nodes" as id parameter, and "stroke-width:8px,font-size:12pt,color:white" as style parameter. So basic_nodes,error_nodes,success_nodes is treated as one class, and not the concatenation of many. For this reason, we have to split it (using comma separator) and apply styles to each of them.

Modifying the parser is not (in my opinion) mandatory, as classes and styles are well detected. Instead of having the string "basic_nodes,error_nodes,success_nodes" in id parameter of the addClass function, we may have an array like ["basic_nodes", "error_nodes", "success_nodes"] which would be easier to use. However, code that allows group class definition (explained in the previous section) doesn't implement it this way:

classStatement:CLASS SPACE alphaNum SPACE alphaNum
    {$$ = $1;yy.setClass($3, $5);}
    ;
export const setClass = function (ids, className) {
  ids.split(',').forEach(function (_id) {
    // ...
  });
};

This could be a good refactoring, but the behavior won't change, and to be honest I'm still not comfortable with Bison grammar rules.

@tomperr
Copy link
Contributor Author

tomperr commented Dec 22, 2022

I will add more documentation on all the features I talked about, and I will try to add more tests :)

@brunolnetto
Copy link

Hi @tomperr. It has been a while since your last comment here. Are you ok? If yes, it would be kind of you if you made any advance on this direction e.g. on these classDef incremental properties on mermaid-code-string composition. I am particularly interested on graphs with colorful arrows and classDef groups. :-)

@tomperr
Copy link
Contributor Author

tomperr commented Jan 9, 2023

Sorry, I just don't have the time these days

@brunolnetto
Copy link

No worries. Take your time.

@jgreywolf
Copy link
Contributor

@tomperr I have tagged @knsv and @sidharthv96 to review your PR as is

@jgreywolf jgreywolf requested review from sidharthv96 and knsv and removed request for sidharthv96 January 26, 2023 19:17
@jgreywolf jgreywolf removed the Type: PR label Jun 7, 2023
@jgreywolf
Copy link
Contributor

@knsv @sidharthv96 Can you please review?

* develop: (783 commits)
  chore(deps): update all minor dependencies
  chore: Run codecov based on E2E test status
  change REAMDME.md coverage from coveralls into codecov
  Add codecov.yaml
  Upload E2E
  set normal mode for vitest coverage
  Fix path name
  Add codecov to unit tests
  Add codecov to E2E
  chore: Add coverage scripts
  chore: add excludes
  chore: update deps
  Merge coverages
  Add coverage paths
  Rebuild
  chore: update pnpm
  Add coverage for E2E tests
  rename plugin variable into info in infoDetector.ts
  remove cypress/platform/index.html
  update pnpm-lock.yaml
  ...
@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2023

Codecov Report

Merging #3923 (0c2b5d0) into develop (2ee3775) will increase coverage by 6.21%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3923      +/-   ##
===========================================
+ Coverage    77.29%   83.50%   +6.21%     
===========================================
  Files          136      136              
  Lines        10446    10446              
  Branches       492      492              
===========================================
+ Hits          8074     8723     +649     
+ Misses        2194     1574     -620     
+ Partials       178      149      -29     
Flag Coverage Δ
e2e 83.39% <100.00%> (+6.24%) ⬆️
unit 28.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/mermaid/src/diagrams/flowchart/flowDb.js 82.59% <100.00%> (+4.14%) ⬆️

... and 22 files with indirect coverage changes

@sidharthv96 sidharthv96 merged commit 2cc9a52 into mermaid-js:develop Jun 18, 2023
13 checks passed
@mermaid-bot
Copy link

mermaid-bot bot commented Jun 18, 2023

@tomperr, Thank you for the contribution!
You are now eligible for a year of Premium account on MermaidChart.
Sign up with your GitHub account to activate.

@brunolnetto
Copy link

I see an approval, I like! :-) do the style apply to the arrow as well?

@tomperr tomperr deleted the feature/3036_group_style_definition branch June 19, 2023 14:58
github-merge-queue bot pushed a commit to fuxingloh/contented that referenced this pull request Jul 2, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [mermaid](https://togithub.com/mermaid-js/mermaid) | [`10.2.3` ->
`10.2.4`](https://renovatebot.com/diffs/npm/mermaid/10.2.3/10.2.4) |
[![age](https://badges.renovateapi.com/packages/npm/mermaid/10.2.4/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/npm/mermaid/10.2.4/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/npm/mermaid/10.2.4/compatibility-slim/10.2.3)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/npm/mermaid/10.2.4/confidence-slim/10.2.3)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>mermaid-js/mermaid (mermaid)</summary>

###
[`v10.2.4`](https://togithub.com/mermaid-js/mermaid/releases/tag/v10.2.4):
10.2.4

[Compare
Source](https://togithub.com/mermaid-js/mermaid/compare/v10.2.3...v10.2.4)

#### Features

- Add Plausible analytics to mermaid.js.org by
[@&#8203;sidharthv96](https://togithub.com/sidharthv96) in
[mermaid-js/mermaid#4473
- Support for development in Docker by
[@&#8203;nirname](https://togithub.com/nirname) in
[mermaid-js/mermaid#4478
- standardize info diagram definitions by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[mermaid-js/mermaid#4486
- Change C4 stereotype braces from ASCII <\</>> to Unicode «/» by
[@&#8203;jonathan-r-young](https://togithub.com/jonathan-r-young) in
[mermaid-js/mermaid#4460
- Add coverage for E2E tests by
[@&#8203;sidharthv96](https://togithub.com/sidharthv96) in
[mermaid-js/mermaid#4498
- set normal mode for vitest coverage by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[mermaid-js/mermaid#4505
- Use v8 coverage in vitest by
[@&#8203;sidharthv96](https://togithub.com/sidharthv96) in
[mermaid-js/mermaid#4560
- feat(flowchart): add classDef style group definition by
[@&#8203;tomperr](https://togithub.com/tomperr) in
[mermaid-js/mermaid#3923
- add cypress coverage clean by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[mermaid-js/mermaid#4556
- fix(class): keep members in namespace classes by
[@&#8203;tomperr](https://togithub.com/tomperr) in
[mermaid-js/mermaid#4532

#### Bugfixes

- Add hint on "flowchart" and "graph" by
[@&#8203;koppor](https://togithub.com/koppor) in
[mermaid-js/mermaid#4096
- fix(flowchart): apply style on doublecircle by
[@&#8203;tomperr](https://togithub.com/tomperr) in
[mermaid-js/mermaid#4540
- fix not rendered style when style is optional by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[mermaid-js/mermaid#4528
- fix(flowchart): allow multiple vertices with style by
[@&#8203;tomperr](https://togithub.com/tomperr) in
[mermaid-js/mermaid#4553

#### Documentation

- change REAMDME.md coverage from coveralls into codecov by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[mermaid-js/mermaid#4507
- Update latest news section by
[@&#8203;huynhicode](https://togithub.com/huynhicode) in
[mermaid-js/mermaid#4468
- Fix link to Tutorials from n00b-overview page by
[@&#8203;Spiderpig86](https://togithub.com/Spiderpig86) in
[mermaid-js/mermaid#4472
- Fix Directives Documentation by
[@&#8203;adamazing](https://togithub.com/adamazing) in
[mermaid-js/mermaid#4475
- Correct "Bronze" spelling in timeline docs by
[@&#8203;adamazing](https://togithub.com/adamazing) in
[mermaid-js/mermaid#4467
- Document recommended file extension and MIME type docs by
[@&#8203;bollwyvl](https://togithub.com/bollwyvl) in
[mermaid-js/mermaid#4485
- Fix typo in quadrant chart documentation by
[@&#8203;tobie](https://togithub.com/tobie) in
[mermaid-js/mermaid#4512
- fix cspell issues in \*.md files by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[mermaid-js/mermaid#4531
- docs: Howto on foreground color on timelines by
[@&#8203;mcbeelen](https://togithub.com/mcbeelen) in
[mermaid-js/mermaid#4524
- Add citation.cff file by
[@&#8203;schackartk](https://togithub.com/schackartk) in
[mermaid-js/mermaid#4521
- Update Tutorials.md by
[@&#8203;ellenealds](https://togithub.com/ellenealds) in
[mermaid-js/mermaid#4539
- Add Standard Notes extension in integrations page by
[@&#8203;nienow](https://togithub.com/nienow) in
[mermaid-js/mermaid#4557
- Fix up Gantt Chart demo by
[@&#8203;AlexMooney](https://togithub.com/AlexMooney) in
[mermaid-js/mermaid#4561

#### Chore

- Update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4482
- chore: revise Contributing documentation by
[@&#8203;weedySeaDragon](https://togithub.com/weedySeaDragon) in
[mermaid-js/mermaid#3814
- chore(deps): update all minor dependencies (minor) by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4435
- fix(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4510
- fix(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4535
- chore(deps): update dependency eslint-plugin-jsdoc to v46 by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4544
- chore(deps): update dependency jsdom to v22 by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4546
- chore(deps): update dependency eslint-plugin-unicorn to v47 by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4545
- chore(deps): update dependency workbox-window to v7 by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4547
- chore(deps): update node.js to v20 by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4548
- fix(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[mermaid-js/mermaid#4543
- add `Suggested Solutions` field in `bug_report.yml` by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[mermaid-js/mermaid#4541

#### New Contributors

- [@&#8203;Spiderpig86](https://togithub.com/Spiderpig86) made their
first contribution in
[mermaid-js/mermaid#4472
- [@&#8203;adamazing](https://togithub.com/adamazing) made their first
contribution in
[mermaid-js/mermaid#4475
- [@&#8203;koppor](https://togithub.com/koppor) made their first
contribution in
[mermaid-js/mermaid#4096
- [@&#8203;nirname](https://togithub.com/nirname) made their first
contribution in
[mermaid-js/mermaid#4478
- [@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) made their first
contribution in
[mermaid-js/mermaid#4486
- [@&#8203;jonathan-r-young](https://togithub.com/jonathan-r-young) made
their first contribution in
[mermaid-js/mermaid#4460
- [@&#8203;tobie](https://togithub.com/tobie) made their first
contribution in
[mermaid-js/mermaid#4512
- [@&#8203;schackartk](https://togithub.com/schackartk) made their first
contribution in
[mermaid-js/mermaid#4521
- [@&#8203;mcbeelen](https://togithub.com/mcbeelen) made their first
contribution in
[mermaid-js/mermaid#4524
- [@&#8203;ellenealds](https://togithub.com/ellenealds) made their first
contribution in
[mermaid-js/mermaid#4539
- [@&#8203;nienow](https://togithub.com/nienow) made their first
contribution in
[mermaid-js/mermaid#4557
- [@&#8203;AlexMooney](https://togithub.com/AlexMooney) made their first
contribution in
[mermaid-js/mermaid#4561

**Full Changelog**:
mermaid-js/mermaid@v10.2.3...v10.2.4

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/levaintech/contented).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNDQuMiIsInVwZGF0ZWRJblZlciI6IjM1LjE0NC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

linkStyle classDef and link group style definition
6 participants