Skip to content

Conversation

@Qxisylolo
Copy link
Contributor

@Qxisylolo Qxisylolo commented Oct 9, 2025

Description

this pr adds bar gauge

Screenshot

2025-10-14.15.59.38.mov
2025-10-14.17.19.17.mov

Testing the changes

Changelog

  • feat: add bar gauge

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

opensearch-changeset-bot bot added a commit to Qxisylolo/OpenSearch-Dashboards that referenced this pull request Oct 9, 2025
@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 80.61224% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.52%. Comparing base (f50abc7) to head (fea707f).

Files with missing lines Patch % Lines
...mponents/visualizations/bar_gauge/to_expression.ts 75.28% 7 Missing and 15 partials ⚠️
...onents/visualizations/bar_gauge/bar_gauge_utils.ts 89.65% 0 Missing and 6 partials ⚠️
...visualizations/bar_gauge/bar_gauge_vis_options.tsx 73.68% 5 Missing ⚠️
...ions/bar_gauge/bar_gauge_exclusive_vis_options.tsx 90.47% 0 Missing and 2 partials ⚠️
...ublic/components/visualizations/rule_repository.ts 0.00% 1 Missing ⚠️
...nts/visualizations/style_panel/unit/unit_panel.tsx 0.00% 1 Missing ⚠️
.../components/visualizations/theme/default_colors.ts 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10697      +/-   ##
==========================================
+ Coverage   60.49%   60.52%   +0.03%     
==========================================
  Files        4506     4511       +5     
  Lines      121106   121296     +190     
  Branches    20174    20234      +60     
==========================================
+ Hits        73262    73420     +158     
- Misses      42722    42732      +10     
- Partials     5122     5144      +22     
Flag Coverage Δ
Linux_1 26.56% <ø> (ø)
Linux_2 38.82% <ø> (ø)
Linux_3 39.08% <ø> (+<0.01%) ⬆️
Linux_4 33.62% <80.61%> (+0.10%) ⬆️
Windows_1 26.57% <ø> (ø)
Windows_2 38.79% <ø> (ø)
Windows_3 39.08% <ø> (+<0.01%) ⬆️
Windows_4 33.62% <80.61%> (+0.10%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

availableMappings: [
{
[AxisRole.Y]: { type: VisFieldType.Numerical, index: 0 },
[AxisRole.X]: { type: VisFieldType.Categorical, index: 0 },
Copy link
Member

Choose a reason for hiding this comment

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

Can we support numerical field as x axis?

Copy link
Contributor Author

@Qxisylolo Qxisylolo Oct 16, 2025

Choose a reason for hiding this comment

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

yes, updated:
Here is a case where x axis is numerical

2025-10-16.12.53.35.mov

Comment on lines 97 to 100
export const getUnfilledArea = () => {
if (darkMode) return '#27252C';
return '#f1f1f1ff';
};
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to default_colors.ts? we can have a shade color code based on dark/light, also we can use this shade at where DEFAULT_GREY is used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function isn't suitable for DEFAULT_GREY as it returns as almost black in dark mode. I will introduce a new function getGrey to return the appropriate grey depending on light or dark mode.

};
const nullStyle = { axis: null };

const shouldSwapAxes = (isXNumerical && isHorizontal) || (!isXNumerical && isHorizontal);
Copy link
Collaborator

Choose a reason for hiding this comment

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

could this simplified as const shouldSwapAxes = isHorizontal;?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes!thanks for pointing out.

defaultMessage: 'Horizontal',
}),
},
];
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we can make it clear to read like this

const getOrientationOptions = (isXaxisNumerical: boolean) => {
    const isVerticalLabel = isXaxisNumerical ? 'Horizontal' : 'Vertical';
    const isHorizontalLabel = isXaxisNumerical ? 'Vertical' : 'Horizontal';
    return [
      { id: 'vertical', label: isVerticalLabel },
      { id: 'horizontal', label: isHorizontalLabel }
    ];
  };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated! thanks~


export const NormalizeData = (data: number, start: number, end: number) => {
// normalize data value between start and end into 0–1 range
return (data - start) / (end - start);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: we may need add a check for case end == start

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, updated, thanks!

const result: any[] = [];

for (let i = 0; i < thresholds.length; i++) {
const start = thresholds[0].value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

is thresholds a sorted array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.we will sort threshold in threshold panel

hex = '#' + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
}

let r = parseInt(hex.slice(1, 3), 16);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: would better have a check for hex to make sure it's vaild

return result;
};

export const NormalizeData = (data: number, start: number, end: number) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: normalizeData

Hailong-am
Hailong-am previously approved these changes Oct 24, 2025
ruanyl
ruanyl previously approved these changes Oct 24, 2025
? {
id: 'horizontal',
label: i18n.translate(
'explore.vis.barGauge.orientation.threshold.horizontal.isXaxisNumerical',
Copy link
Member

Choose a reason for hiding this comment

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

isXaxisNumerical this key seems incorrect

isXaxisNumerical
? {
id: 'vertical',
label: i18n.translate('explore.vis.barGauge.orientation.vertical.isXaxisNumerical', {
Copy link
Member

Choose a reason for hiding this comment

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

isXaxisNumerical this key seems incorrect, should be orientation.vertical?

{ offset: 0, color: thresholds[0].color },
{
offset: 1,
color: darkenColor(thresholds[0]?.color, 2),
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need to darken the color, just use thresholds[0].color in this case

@Qxisylolo Qxisylolo dismissed stale reviews from ruanyl and Hailong-am via 6fe849c October 24, 2025 09:37
Qxisylolo and others added 18 commits October 24, 2025 17:48
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Signed-off-by: Qxisylolo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants