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(toolbar): add tooltips #1766

Conversation

markchou0225
Copy link
Contributor

@markchou0225 markchou0225 commented Feb 25, 2024

Closes #1549

Updates

  • Add tooltip (with top placement) for toolbars
  • Expose more translation strings

Some testing

  1. Mouse hovering on toolbar and it should display the tooltips
  2. Using tab can trigger toolbar focus and display the tooltips
  3. Hover the label title -> press tab to get toolbar focus -> move mouse over the label title should still see consistent tooltip content.
  4. Can apply following options to check translated strings
    https://deploy-preview-1766--carbon-charts-angular.netlify.app/?path=/story/utility-truncations--truncated-labels-simple-bar
  5. Repeat 1-4 in full screen mode
{
    "title": "Truncated labels (simple bar)",
      "locale": {
      "translations": {
        "toolbar": {
          "makeFullScreen": "進入全螢幕",
          "exitFullScreen": "離開全螢幕",
          "showAsTable": "顯示為表格",
          "moreOptions": "更多選項",
          "exportAsCSV": "轉存為CSV",
          "exportAsJPG": "轉存為JPG",
          "exportAsPNG": "轉存為PNG"
          }
      },
    "axes": {
      "left": {
        "mapsTo": "group",
        "scaleType": "labels",
        "truncation": {
          "type": "mid_line",
          "threshold": 10,
          "numCharacter": 14
        }
      },
      "bottom": {
        "mapsTo": "value"
      }
    },
    "legend": {
      "truncation": {
        "type": "mid_line",
        "threshold": 15,
        "numCharacter": 12
      }
    },
    "height": "400px",
    "theme": "g100"
  }
}

Demo screenshot or recording

  1. Hovering toolbar and shows translation strings (g10 theme)
Screenshot 2024-02-25 at 10 12 54 PM
  1. Using tab to focus toolbar and shows translation strings (g100 theme)
Screenshot 2024-02-25 at 10 13 41 PM

@markchou0225 markchou0225 requested review from theiliad and a team as code owners February 25, 2024 07:03
Copy link

netlify bot commented Feb 25, 2024

Deploy Preview for carbon-charts-core ready!

Name Link
🔨 Latest commit d1ae2ab
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-core/deploys/65e741fdc8cb6e0008a70836
😎 Deploy Preview https://deploy-preview-1766--carbon-charts-core.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.

Copy link

netlify bot commented Feb 25, 2024

Deploy Preview for carbon-charts-angular ready!

Name Link
🔨 Latest commit d1ae2ab
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-angular/deploys/65e741fd4bc31f0008837fad
😎 Deploy Preview https://deploy-preview-1766--carbon-charts-angular.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.

Copy link

netlify bot commented Feb 25, 2024

Deploy Preview for carbon-charts-react ready!

Name Link
🔨 Latest commit d1ae2ab
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-react/deploys/65e741fde955d600093f59fd
😎 Deploy Preview https://deploy-preview-1766--carbon-charts-react.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.

@markchou0225 markchou0225 changed the title feat(toolbar): add tooltips WIP: feat(toolbar): add tooltips Feb 25, 2024
@markchou0225 markchou0225 force-pushed the story/1549-tooltips-of-toolbar branch 2 times, most recently from 6bfc973 to e50106f Compare February 25, 2024 14:14
@markchou0225 markchou0225 changed the title WIP: feat(toolbar): add tooltips feat(toolbar): add tooltips Feb 25, 2024
@@ -101,12 +101,26 @@ export class Toolbar extends Component {
.each(function (d: any, index: number) {
select(this)
.select('svg')
.style('pointer-events', 'none')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable pointer-events of svg as we only want event emitted by button.

if (this.tooltip.classed('hidden') === false) {
if (this.lastTriggeredEventType !== Events.Toolbar.SHOW_TOOLTIP &&
this.tooltip.classed('hidden') === false
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to keep this lastTriggeredEventType to prevent a display issue when combining keyboard and mouse.

Can use following steps to verify on:
https://deploy-preview-1766--carbon-charts-angular.netlify.app/?path=/story/utility-truncations--truncated-labels-simple-bar

  1. Put to mouse over truncated label title --> See the tooltip
  2. Keep pressing Tab until one of the toolbar (e.g.: Show as table) got focus and show the tooltip.
  3. Slightly move the mouse over truncated label title
    --->
    The tooltip will be shown as "Show as table", but not the label title if lastTriggeredEventType is not used here.

@@ -110,6 +125,10 @@ export class Tooltip extends Component {

// remove the listener on chart-mouseout
this.services.events.removeEventListener(Events.Chart.MOUSEOUT, this.handleHideTooltip)

// remote the listener of the toolbar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly correct the spelling for remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @RiyaJethwa.
Append commit 351a4b0 to fix it and also do a rebase.

@markchou0225 markchou0225 force-pushed the story/1549-tooltips-of-toolbar branch 2 times, most recently from fff8fa9 to 351a4b0 Compare February 27, 2024 14:08
@theiliad
Copy link
Member

@markchou0225 thank you 🙌🏻

I think we should fix this issue
image

there's enough room on both sides, the tooltip shouldn't really wrap into 2 lines

@markchou0225 markchou0225 changed the title feat(toolbar): add tooltips WIP: feat(toolbar): add tooltips Feb 28, 2024
@markchou0225
Copy link
Contributor Author

Thank you @theiliad,
mark as WIP and will append a commit for this

@markchou0225 markchou0225 force-pushed the story/1549-tooltips-of-toolbar branch 2 times, most recently from 174d4e4 to cf4c417 Compare February 28, 2024 11:57
@markchou0225
Copy link
Contributor Author

markchou0225 commented Feb 28, 2024

Hi @theiliad,

The tooltip is made to be with a centered-top placement. The wrapped div behavior is caused by its width not exceed to the chart holder.

Before commit (wrapped div)
Screenshot 2024-02-28 at 6 50 29 PM

New commit (non-wrapped):
Screenshot 2024-02-28 at 8 00 04 PM

Tried one of the solutions in commit cf4c417 to make the toolbar tooltips always non-wrapped. The assumption is that all charts may have enough padding in user pages. Another way I can think of is to shift the toolbar to the left about 1~2rem. Can do further adjustments or even expose options in the future. 🤠

@markchou0225 markchou0225 changed the title WIP: feat(toolbar): add tooltips feat(toolbar): add tooltips Feb 28, 2024
Copy link
Member

@theiliad theiliad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markchou0225 I think we're almost there. I'm just noticing another bug where if there's no room in the top of the chart, the tooltip still shows up to the top

image

it should really use our position util to figure out where to place itself

@markchou0225
Copy link
Contributor Author

markchou0225 commented Feb 29, 2024

Hi @theiliad,

Okay, I removed the added static placement in my first commit(19ac243) and use the existed positioning logic. It would go left/right now.

tooltip_auto

@theiliad
Copy link
Member

Hi @theiliad,

Okay, I removed the added static placement in my first commit(19ac243) and use the existed positioning logic. It would go left/right now.

tooltip_auto tooltip_auto

@markchou0225 sorry for the back and fourth, but there must be a nicer way to position them.

Could we maybe check if there are placements that are open, and place them centered to that placement?

E.g. if top open, place in center-top, if not, bottom-center, if right is not open, left-center etc...

@markchou0225 markchou0225 force-pushed the story/1549-tooltips-of-toolbar branch from 7ed85b1 to ffd19d7 Compare March 1, 2024 06:28
Comment on lines +118 to +119
noWrap: true,
placements: ['top', 'bottom']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @theiliad,

Thanks for the reviewing, now we would support multiple candidates for .findBestPlacement() to determine the best placement.

@markchou0225 markchou0225 force-pushed the story/1549-tooltips-of-toolbar branch 2 times, most recently from 4a6741b to e17ac8c Compare March 1, 2024 07:05
Copy link
Member

@theiliad theiliad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @markchou0225 again for the back and fourth, but could you pls just make sure that the tooltip does show up in the right place?

If I move chart to the top of the page, the tooltip still tries to show up in the top, and I can't see it

image

@markchou0225
Copy link
Contributor Author

Hi @theiliad,

Sorry I miss that, append commit 6a83bfb and hope that should do the trick. But as the toolbar is very close to the chart-holder, we probably never see top placement now. Please refer to the demo GIF below: the top placement will only appear if I add some padding-top to the chart-holder.
tooltip_demo

@markchou0225 markchou0225 force-pushed the story/1549-tooltips-of-toolbar branch from 6a83bfb to d1ae2ab Compare March 5, 2024 16:02
@markchou0225
Copy link
Contributor Author

Hi @theiliad,
Sorry for my misunderstanding. I just realize what you mean. Please find the demo gif below with the updated commit d1ae2ab. Thank you~

chart_fina

Copy link
Member

@theiliad theiliad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@theiliad
Copy link
Member

theiliad commented Mar 5, 2024

thank you @markchou0225 🙌🏻

@theiliad theiliad merged commit d8189d8 into carbon-design-system:master Mar 5, 2024
4 checks passed
@markchou0225 markchou0225 deleted the story/1549-tooltips-of-toolbar branch March 8, 2024 10:49
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.

[Accessibility]: Chart toolbar buttons don't have tooltips
3 participants