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

bug/4849_center_axis_labels #4860

Merged
merged 7 commits into from
Sep 22, 2023

Conversation

dreathed
Copy link
Contributor

📑 Summary

This PR centers the axis labels of a quadrant diagram.

Resolves #4849

📏 Design Decisions

There was a condition that would center the labels only if there were no data points.
I removed the condition and replaced the checks for that condition with the code that would execute when the condition would evaluate to true.

Since this issue was marked as a bug I did not add any new test and did not update documentation.

📋 Tasks

Make sure you

@netlify
Copy link

netlify bot commented Sep 20, 2023

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 2f6c197
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/650d282f58b2b40008875c5a
😎 Deploy Preview https://deploy-preview-4860--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@dreathed dreathed changed the title center labels: removed condition bug/4849_center_axis_labels Sep 20, 2023
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Merging #4860 (2f6c197) into develop (4201e47) will decrease coverage by 0.88%.
Report is 10 commits behind head on develop.
The diff coverage is 60.00%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4860      +/-   ##
===========================================
- Coverage    80.55%   79.67%   -0.88%     
===========================================
  Files          148      148              
  Lines        13024    13025       +1     
  Branches       612      612              
===========================================
- Hits         10491    10378     -113     
- Misses        2400     2510     +110     
- Partials       133      137       +4     
Flag Coverage Δ
e2e 84.71% <60.00%> (-1.09%) ⬇️
unit 43.67% <ø> (ø)

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

Files Changed Coverage Δ
...aid/src/diagrams/quadrant-chart/quadrantBuilder.ts 80.53% <60.00%> (-3.40%) ⬇️

... and 12 files with indirect coverage changes

@dreathed dreathed marked this pull request as ready for review September 21, 2023 00:00
@sidharthv96
Copy link
Member

@subhash-halder was there any reason why the option to align left/center was added?
This seems like a deliberate action than a bug.

@subhash-halder
Copy link
Contributor

subhash-halder commented Sep 21, 2023

@sidharthv96 yes it was intentional, we decided to have the label in the center when there are no data points, and they will align to the left when there are data points.

@sidharthv96
Copy link
Member

But I can't recollect "why" that decision was made. Was it based on any reference images or standards?

@subhash-halder
Copy link
Contributor

subhash-halder commented Sep 21, 2023

I think it's because we are drawing the labels to the left only and here you suggested if there are no data points it is better to draw the label in center #4383 (comment)

I think if we forced the label to be in a certain place we add a config to do that.

@sidharthv96
Copy link
Member

Ok, so the alignment should depend on how many labels are there.

Label Count per axis Position
1 left/bottom
2 center

If there are 2 labels on the axis, it might not make sense to have points in the graph, with the labels in the current example, but there might exist a usecase where points might make sense.

So, @dreathed, you'll have to revert the changes, and only change the criteria for drawing in center or left.

-    const drawAxisLabelInMiddle = this.data.points.length === 0;
+   const drawAxisLabelInMiddle = <check if label count == 2>;

Current behaviour is correct
image

Fixed behaviour is incorrect (Labels should start from left/bottom)
image


Current behaviour is incorrect (Should be in center, as per issue)
image

Fixed behaviour is correct
image

@dreathed
Copy link
Contributor Author

dreathed commented Sep 21, 2023

@sidharthv96 Done.
The condition is now per axis (since may be possible for one axis to have two and the other to have only one label). The condition is: If there is a xAxisRightLabel then the text will be centered. This is because if there is a right label there must be a left label. The same is done for the yAxis.
Just so you know that this condition is not explicitly the number of labels.
If you prefer to bind the condition explicitly to the number of labels I will do 😃 !

@subhash-halder
Copy link
Contributor

@dreathed I think the condition would be to draw the label in the middle only if any of the top or right label is there.

const drawAxisLabelInMiddle = this.data.yAxisTopText || this.data.xAxisRightText

@sidharthv96 can you confirm

@dreathed
Copy link
Contributor Author

@subhash-halder Well this is about how the output should be if one axis has two and the other has one label. My current solution gives this output:
Sol

Your suggestion would give this one:
269527106-10f99b2b-29c3-4e9e-9689-aa632985f578

In the usual case where both axis have either one or two labels, the output will be the same.

@sidharthv96
Copy link
Member

I think this solution is good. @dreathed can you add some tests in cypress/integration/rendering/quadrantChart.spec.js to verify the behaviour?

Although the situation where only one axis having 2 labels seem unlikely for a quadrant chart, that's upto the authors of the charts. Our labels should be positioned based on the number of labels on that particular axis.

The other option would be to throw an error if the label count is mismatched, but I don't think we should be mandating that.

@dreathed
Copy link
Contributor Author

dreathed commented Sep 21, 2023

@sidharthv96 I added a couple of new snapshot tests. Of course the old snapshots are effected and need to be replaced. Here are some of the new ones:
Quadrant-Chart-should-render-a-complete-quadrant-chart snap
Quadrant-Chart-should-render-both-axes-labels-on-the-left,-if-both-axes-have-only-one-label snap
Quadrant-Chart-should-render-x-axis-labels-in-the-center,-if-x-axis-has-two-labels snap
Quadrant-Chart-should-render-both-axes-labels-on-the-left-and-bottom,-if-both-axes-have-only-one-label snap

@sidharthv96 sidharthv96 added this pull request to the merge queue Sep 22, 2023
Merged via the queue into mermaid-js:develop with commit 0534d75 Sep 22, 2023
15 of 16 checks passed
@mermaid-bot
Copy link

mermaid-bot bot commented Sep 22, 2023

@dreathed, 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.

fuxingloh referenced this pull request in fuxingloh/contented Nov 3, 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.5.1` ->
`10.6.0`](https://renovatebot.com/diffs/npm/mermaid/10.5.1/10.6.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/mermaid/10.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/mermaid/10.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/mermaid/10.5.1/10.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/mermaid/10.5.1/10.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

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

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

#### What's Changed

- Add new chart xychart by
[@&#8203;subhash-halder](https://togithub.com/subhash-halder) in
[https://github.com/mermaid-js/mermaid/pull/4413](https://togithub.com/mermaid-js/mermaid/pull/4413)

#### Fix

- bug/4849\_center_axis_labels by
[@&#8203;dreathed](https://togithub.com/dreathed) in
[https://github.com/mermaid-js/mermaid/pull/4860](https://togithub.com/mermaid-js/mermaid/pull/4860)
- Better handling of large flowcharts and long edges
[@&#8203;knsv](https://togithub.com/knsv)

#### Docs

- Add new Atlassian integrations by
[@&#8203;janjonas](https://togithub.com/janjonas) in
[https://github.com/mermaid-js/mermaid/pull/4862](https://togithub.com/mermaid-js/mermaid/pull/4862)
- docs: fix typo by
[@&#8203;dennis0324](https://togithub.com/dennis0324) in
[https://github.com/mermaid-js/mermaid/pull/4887](https://togithub.com/mermaid-js/mermaid/pull/4887)
- Update notes on orientation in GitGraph documentation by
[@&#8203;guypursey](https://togithub.com/guypursey) in
[https://github.com/mermaid-js/mermaid/pull/4897](https://togithub.com/mermaid-js/mermaid/pull/4897)
- Enhancment: twitter logo in doc by
[@&#8203;chaursiyasanjeet](https://togithub.com/chaursiyasanjeet) in
[https://github.com/mermaid-js/mermaid/pull/4925](https://togithub.com/mermaid-js/mermaid/pull/4925)
- Update link for the Mermaid integration in JetBrains IDEs by
[@&#8203;FirstTimeInForever](https://togithub.com/FirstTimeInForever) in
[https://github.com/mermaid-js/mermaid/pull/4883](https://togithub.com/mermaid-js/mermaid/pull/4883)

#### Chores

- Wait for `marker_unique_id.html` E2E test to render before taking a
screenshot by [@&#8203;aloi](https://togithub.com/aloi)

sklink[https://github.com/mermaid-js/mermaid/pull/4847](https://togithub.com/mermaid-js/mermaid/pull/4847)4847
- Wait for `theme-directives.html` E2E test to render before taking a
screenshot by [@&#8203;aloisklink](https://togithub.com/aloisklink) in
[https://github.com/mermaid-js/mermaid/pull/4846](https://togithub.com/mermaid-js/mermaid/pull/4846)
- chore(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4851](https://togithub.com/mermaid-js/mermaid/pull/4851)
- chore(dev-deps): update `@typescript-eslint/*` plugins to v6 (major)
by [@&#8203;aloisklink](https://togithub.com/aloisklink) in
[https://github.com/mermaid-js/mermaid/pull/4857](https://togithub.com/mermaid-js/mermaid/pull/4857)
- chore: shorten `flow-huge.spec.js` test case using `.repeat` by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[https://github.com/mermaid-js/mermaid/pull/4859](https://togithub.com/mermaid-js/mermaid/pull/4859)
- Publish Live Editor previews for the `develop` & `next` branches by
[@&#8203;sidharthv96](https://togithub.com/sidharthv96) in
[https://github.com/mermaid-js/mermaid/pull/4841](https://togithub.com/mermaid-js/mermaid/pull/4841)
- chore(deps): update all minor dependencies (minor) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4870](https://togithub.com/mermaid-js/mermaid/pull/4870)
- chore(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4869](https://togithub.com/mermaid-js/mermaid/pull/4869)
- Commented out broken test by
[@&#8203;nirname](https://togithub.com/nirname) in
[https://github.com/mermaid-js/mermaid/pull/4913](https://togithub.com/mermaid-js/mermaid/pull/4913)
- chore(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4891](https://togithub.com/mermaid-js/mermaid/pull/4891)
- fix(class): avoid duplicate definition of fill by
[@&#8203;Mister-Hope](https://togithub.com/Mister-Hope) in
[https://github.com/mermaid-js/mermaid/pull/4929](https://togithub.com/mermaid-js/mermaid/pull/4929)
- chore(deps): update all minor dependencies (minor) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4892](https://togithub.com/mermaid-js/mermaid/pull/4892)
- making consitent config imports from diagramAPI by
[@&#8203;dreathed](https://togithub.com/dreathed) in
[https://github.com/mermaid-js/mermaid/pull/4889](https://togithub.com/mermaid-js/mermaid/pull/4889)
- fix(typos): Fix minor typos in the source code by
[@&#8203;mribeirodantas](https://togithub.com/mribeirodantas) in
[https://github.com/mermaid-js/mermaid/pull/4928](https://togithub.com/mermaid-js/mermaid/pull/4928)
- chore(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4945](https://togithub.com/mermaid-js/mermaid/pull/4945)
- Bump [@&#8203;babel/traverse](https://togithub.com/babel/traverse)
from 7.22.10 to 7.23.2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/mermaid-js/mermaid/pull/4951](https://togithub.com/mermaid-js/mermaid/pull/4951)
- Replace rehype-mermaidjs with rehype-mermaid by
[@&#8203;remcohaszing](https://togithub.com/remcohaszing) in
[https://github.com/mermaid-js/mermaid/pull/4970](https://togithub.com/mermaid-js/mermaid/pull/4970)

#### New Contributors

- [@&#8203;dreathed](https://togithub.com/dreathed) made their first
contribution in
[https://github.com/mermaid-js/mermaid/pull/4860](https://togithub.com/mermaid-js/mermaid/pull/4860)
- [@&#8203;janjonas](https://togithub.com/janjonas) made their first
contribution in
[https://github.com/mermaid-js/mermaid/pull/4862](https://togithub.com/mermaid-js/mermaid/pull/4862)
- [@&#8203;dennis0324](https://togithub.com/dennis0324) made their first
contribution in
[https://github.com/mermaid-js/mermaid/pull/4887](https://togithub.com/mermaid-js/mermaid/pull/4887)
- [@&#8203;FirstTimeInForever](https://togithub.com/FirstTimeInForever)
made their first contribution in
[https://github.com/mermaid-js/mermaid/pull/4883](https://togithub.com/mermaid-js/mermaid/pull/4883)
- [@&#8203;guypursey](https://togithub.com/guypursey) made their first
contribution in
[https://github.com/mermaid-js/mermaid/pull/4897](https://togithub.com/mermaid-js/mermaid/pull/4897)
- [@&#8203;chaursiyasanjeet](https://togithub.com/chaursiyasanjeet) made
their first contribution in
[https://github.com/mermaid-js/mermaid/pull/4925](https://togithub.com/mermaid-js/mermaid/pull/4925)
- [@&#8203;mribeirodantas](https://togithub.com/mribeirodantas) made
their first contribution in
[https://github.com/mermaid-js/mermaid/pull/4928](https://togithub.com/mermaid-js/mermaid/pull/4928)

**Full Changelog**:
mermaid-js/mermaid@v10.5.1...v10.6.0

</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:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMS41IiwidXBkYXRlZEluVmVyIjoiMzcuMzEuNSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

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.

[quadrantChart] x-axis and y-axis label won't be in center if there are points
3 participants