-
Couldn't load subscription status.
- Fork 1.1k
[Explore Vis]Feat/add bar gauge #10697
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
Merged
ruanyl
merged 18 commits into
opensearch-project:main
from
Qxisylolo:feat/add_bar_gauge
Oct 27, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3817c91
finish
Qxisylolo e3ece3d
add tests
Qxisylolo d345485
Changeset file for PR #10697 created/updated
opensearch-changeset-bot[bot] 75d0904
a little update
Qxisylolo b96d2ae
temp
Qxisylolo aa04072
update
Qxisylolo e2b914b
increase font size
Qxisylolo 3987170
fix baseline
Qxisylolo 1a21f42
update
Qxisylolo 7258536
support y numerical
Qxisylolo b25d124
new gradient
Qxisylolo 43f18e3
fixtests
Qxisylolo 5953d8a
remain fix
Qxisylolo b97aa18
fix stack bar
Qxisylolo 3d63f35
set background shade
Qxisylolo 5c4ea13
fix scale
Qxisylolo 41e7dbb
comments
Qxisylolo fea707f
optimization
Qxisylolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| feat: | ||
| - Add bar gauge ([#10697](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10697)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...plore/public/components/visualizations/bar_gauge/bar_gauge_exclusive_vis_options.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { render, fireEvent } from '@testing-library/react'; | ||
| import { BarGaugeExclusiveVisOptions } from './bar_gauge_exclusive_vis_options'; | ||
| import { ExclusiveBarGaugeConfig } from './bar_gauge_vis_config'; | ||
|
|
||
| jest.mock('@osd/i18n', () => ({ | ||
| i18n: { | ||
| translate: jest.fn().mockImplementation((id, { defaultMessage }) => defaultMessage), | ||
| }, | ||
| })); | ||
|
|
||
| describe('BarGaugeExclusiveVisOptions', () => { | ||
| const defaultStyles: ExclusiveBarGaugeConfig = { | ||
| orientation: 'vertical', | ||
| displayMode: 'gradient', | ||
| valueDisplay: 'valueColor', | ||
| showUnfilledArea: true, | ||
| }; | ||
|
|
||
| const mockOnChange = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should call onChange when orientation is changed', () => { | ||
| const { getByText } = render( | ||
| <BarGaugeExclusiveVisOptions | ||
| styles={defaultStyles} | ||
| onChange={mockOnChange} | ||
| isXaxisNumerical={false} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(getByText('Horizontal')); | ||
|
|
||
| expect(mockOnChange).toHaveBeenCalledWith({ | ||
| ...defaultStyles, | ||
| orientation: 'horizontal', | ||
| }); | ||
| }); | ||
|
|
||
| it('should call onChange when display mode is changed', () => { | ||
| const { getByText } = render( | ||
| <BarGaugeExclusiveVisOptions | ||
| styles={defaultStyles} | ||
| onChange={mockOnChange} | ||
| isXaxisNumerical={false} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(getByText('Stack')); | ||
|
|
||
| expect(mockOnChange).toHaveBeenCalledWith({ | ||
| ...defaultStyles, | ||
| displayMode: 'stack', | ||
| }); | ||
| }); | ||
|
|
||
| it('should call onChange when value display is changed', () => { | ||
| const { getByText } = render( | ||
| <BarGaugeExclusiveVisOptions | ||
| styles={defaultStyles} | ||
| onChange={mockOnChange} | ||
| isXaxisNumerical={false} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(getByText('Text Color')); | ||
|
|
||
| expect(mockOnChange).toHaveBeenCalledWith({ | ||
| ...defaultStyles, | ||
| valueDisplay: 'textColor', | ||
| }); | ||
| }); | ||
|
|
||
| it('should call onChange when unfilled area switch is toggled', () => { | ||
| const { getByRole } = render( | ||
| <BarGaugeExclusiveVisOptions | ||
| styles={defaultStyles} | ||
| onChange={mockOnChange} | ||
| isXaxisNumerical={false} | ||
| /> | ||
| ); | ||
|
|
||
| const switchElement = getByRole('switch'); | ||
| fireEvent.click(switchElement); | ||
|
|
||
| expect(mockOnChange).toHaveBeenCalledWith({ | ||
| ...defaultStyles, | ||
| showUnfilledArea: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle undefined styles with defaults', () => { | ||
| const { getByText } = render( | ||
| <BarGaugeExclusiveVisOptions | ||
| styles={undefined as any} | ||
| onChange={mockOnChange} | ||
| isXaxisNumerical={false} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(getByText('Horizontal')); | ||
|
|
||
| expect(mockOnChange).toHaveBeenCalledWith({ | ||
| orientation: 'horizontal', | ||
| }); | ||
| }); | ||
| }); |
173 changes: 173 additions & 0 deletions
173
...ns/explore/public/components/visualizations/bar_gauge/bar_gauge_exclusive_vis_options.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { i18n } from '@osd/i18n'; | ||
| import { EuiSwitch, EuiButtonGroup, EuiFormRow } from '@elastic/eui'; | ||
| import React from 'react'; | ||
| import { BarGaugeChartStyle } from './bar_gauge_vis_config'; | ||
| import { StyleAccordion } from '../style_panel/style_accordion'; | ||
|
|
||
| interface BarGaugeVisOptionsProps { | ||
| styles: BarGaugeChartStyle['exclusive']; | ||
| onChange: (styles: BarGaugeChartStyle['exclusive']) => void; | ||
| isXaxisNumerical: boolean; | ||
| } | ||
|
|
||
| const displayModeOption = [ | ||
| { | ||
| id: 'gradient', | ||
| label: i18n.translate('explore.vis.barGauge.displayMode.gradient', { | ||
| defaultMessage: 'Gradient', | ||
| }), | ||
| }, | ||
| { | ||
| id: 'stack', | ||
| label: i18n.translate('explore.vis.barGauge.displayMode.stack', { | ||
| defaultMessage: 'Stack', | ||
| }), | ||
| }, | ||
| { | ||
| id: 'basic', | ||
| label: i18n.translate('explore.vis.barGauge.displayMode.basic', { | ||
| defaultMessage: 'Basic', | ||
| }), | ||
| }, | ||
| ]; | ||
|
|
||
| const valueDisplayOption = [ | ||
| { | ||
| id: 'valueColor', | ||
| label: i18n.translate('explore.vis.barGauge.valueDisplay.valueColor', { | ||
| defaultMessage: 'Value Color', | ||
| }), | ||
| }, | ||
| { | ||
| id: 'textColor', | ||
| label: i18n.translate('explore.vis.barGauge.valueDisplay.textColor', { | ||
| defaultMessage: 'Text Color', | ||
| }), | ||
| }, | ||
| { | ||
| id: 'hidden', | ||
| label: i18n.translate('explore.vis.barGauge.valueDisplay.hidden', { | ||
| defaultMessage: 'Hidden', | ||
| }), | ||
| }, | ||
| ]; | ||
|
|
||
| export const BarGaugeExclusiveVisOptions = ({ | ||
| styles, | ||
| onChange, | ||
| isXaxisNumerical, | ||
| }: BarGaugeVisOptionsProps) => { | ||
| const getOrientationOptions = () => { | ||
| const horizontalLabel = i18n.translate('explore.vis.barGauge.orientation.horizontal', { | ||
| defaultMessage: 'Horizontal', | ||
| }); | ||
| const verticalLabel = i18n.translate('explore.vis.barGauge.orientation.vertical', { | ||
| defaultMessage: 'Vertical', | ||
| }); | ||
|
|
||
| // When X-axis is numerical, the labels are swapped | ||
| const verticalOptionLabel = isXaxisNumerical ? horizontalLabel : verticalLabel; | ||
| const horizontalOptionLabel = isXaxisNumerical ? verticalLabel : horizontalLabel; | ||
|
|
||
| return [ | ||
| { id: 'vertical', label: verticalOptionLabel }, | ||
| { id: 'horizontal', label: horizontalOptionLabel }, | ||
| ]; | ||
| }; | ||
|
|
||
| const orientationOption = getOrientationOptions(); | ||
|
|
||
| const updateExclusiveOption = (key: keyof BarGaugeChartStyle['exclusive'], value: any) => { | ||
| onChange({ | ||
| ...styles, | ||
| [key]: value, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <StyleAccordion | ||
| id="barGaugeSection" | ||
| accordionLabel={i18n.translate('explore.stylePanel.tabs.barGauge', { | ||
| defaultMessage: 'Bar Gauge', | ||
| })} | ||
| initialIsOpen={true} | ||
| data-test-subj="barGaugeExclusivePanel" | ||
| > | ||
| <EuiFormRow | ||
| label={i18n.translate('explore.stylePanel.barGauge.exclusive.orientation', { | ||
| defaultMessage: 'Orientation', | ||
| })} | ||
| > | ||
| <EuiButtonGroup | ||
| legend={i18n.translate('explore.stylePanel.barGauge.exclusive.orientation', { | ||
| defaultMessage: 'Orientation', | ||
| })} | ||
| isFullWidth | ||
| options={orientationOption} | ||
| onChange={(optionId) => { | ||
| updateExclusiveOption('orientation', optionId); | ||
| }} | ||
| type="single" | ||
| idSelected={styles?.orientation ?? 'vertical'} | ||
| buttonSize="compressed" | ||
| /> | ||
| </EuiFormRow> | ||
|
|
||
| <EuiFormRow | ||
| label={i18n.translate('explore.stylePanel.barGauge.exclusive.displayMode', { | ||
| defaultMessage: 'Display mode', | ||
| })} | ||
| > | ||
| <EuiButtonGroup | ||
| legend={i18n.translate('explore.stylePanel.barGauge.exclusive.displayMode', { | ||
| defaultMessage: 'Display mode', | ||
| })} | ||
| isFullWidth | ||
| options={displayModeOption} | ||
| onChange={(optionId) => { | ||
| updateExclusiveOption('displayMode', optionId); | ||
| }} | ||
| type="single" | ||
| idSelected={styles?.displayMode ?? 'gradient'} | ||
| buttonSize="compressed" | ||
| /> | ||
| </EuiFormRow> | ||
|
|
||
| <EuiFormRow | ||
| label={i18n.translate('explore.stylePanel.barGauge.exclusive.valueDisplay', { | ||
| defaultMessage: 'Value display', | ||
| })} | ||
| > | ||
| <EuiButtonGroup | ||
| legend={i18n.translate('explore.stylePanel.barGauge.exclusive.valueDisplay', { | ||
| defaultMessage: 'Value display', | ||
| })} | ||
| isFullWidth | ||
| options={valueDisplayOption} | ||
| onChange={(optionId) => { | ||
| updateExclusiveOption('valueDisplay', optionId); | ||
| }} | ||
| type="single" | ||
| idSelected={styles?.valueDisplay ?? 'valueColor'} | ||
| buttonSize="compressed" | ||
| /> | ||
| </EuiFormRow> | ||
|
|
||
| <EuiFormRow> | ||
| <EuiSwitch | ||
| compressed | ||
| label={i18n.translate('explore.vis.heatmap.showUnfilledArea', { | ||
| defaultMessage: 'Show unfilled area', | ||
| })} | ||
| checked={styles?.showUnfilledArea ?? false} | ||
| onChange={(e) => updateExclusiveOption('showUnfilledArea', e.target.checked)} | ||
| /> | ||
| </EuiFormRow> | ||
| </StyleAccordion> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: why this is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just cleaning, legend should be controlled by encoding.color, I cleaned some when I was doing global thresholds, I missed to clean this one.