Skip to content

Commit

Permalink
added support for boxplot
Browse files Browse the repository at this point in the history
  • Loading branch information
yash2189 committed Aug 27, 2024
1 parent ba32830 commit 0b44944
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ itteration of [widgetastic.patternfly4](https://github.com/RedHatQE/widgetastic.

### Charts:
- [bullet-chart](https://www.patternfly.org/charts/bullet-chart)
- [boxplot-chart](https://www.patternfly.org/charts/box-plot-chart)
- [donut-chart](https://www.patternfly.org/charts/donut-chart)
- [legends](https://www.patternfly.org/charts/legends)
- [line-chart](https://www.patternfly.org/charts/line-chart)
Expand Down
2 changes: 2 additions & 0 deletions src/widgetastic_patternfly5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .charts.boxplot_chart import BoxPlotChart
from .charts.bullet_chart import BulletChart
from .charts.donut_chart import DonutChart
from .charts.legend import DataPoint
Expand Down Expand Up @@ -72,6 +73,7 @@
__all__ = [
"Alert",
"BreadCrumb",
"BoxPlotChart",
"BulletChart",
"Button",
"CalendarMonth",
Expand Down
42 changes: 42 additions & 0 deletions src/widgetastic_patternfly5/charts/boxplot_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from widgetastic.widget import ParametrizedLocator
from widgetastic.widget import View

from .legend import Legend
from widgetastic_patternfly5.charts.line_chart import LineChart


class BoxPlotChart(LineChart):
"""Represents the Patternfly Line Chart.
https://patternfly-react-main.surge.sh/charts/box-plot-chart#embedded-legend
Args:
id: If you want to look the input up by id, use this parameter, pass the id.
locator: If you have specific locator else it will take pf-chart.
"""

ROOT = ParametrizedLocator("{@locator}")

X_AXIS_LABELS = "(.//*[name()='g' and *[name()='line'] and *[name()='g']])[1]//*[name()='text']"
Y_AXIS_LABELS = "(.//*[name()='g' and *[name()='line'] and *[name()='g']])[2]//*[name()='text']"

TOOLTIP = (
".//*[name()='g' and .//*[name()='g' and "
".//*[name()='text' and contains(@id, 'legend-labels')]]]"
)

TOOLTIP_X_AXIS_LABLE = ".//*[name()='text']"
TOOLTIP_LABLES = ".//*[name()='g']/*[name()='text' and not(contains(@id, 'legend-label'))]"
TOOLTIP_VALUES = ".//*[name()='g']/*[name()='text' and contains(@id, 'legend-label')]"

_legends = View.nested(Legend)

def __init__(self, parent=None, id=None, locator=None, logger=None):
View.__init__(self, parent=parent, logger=logger)

assert id or locator, "Provide id or locator."

if id:
self.locator = f".//div[@id='{id}']"
else:
self.locator = locator
44 changes: 44 additions & 0 deletions testing/charts/test_boxplot_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest
from widgetastic.widget import View

from widgetastic_patternfly5 import BoxPlotChart

TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/charts/box-plot-chart"

TEST_DATA = {
"2015": {"Cats": "q1: 1.75, q3: 3.5", "Limit": "12"},
"2016": {"Cats": "q1: 2.75, q3: 8.5", "Limit": "12"},
"2017": {"Cats": "q1: 4.25, q3: 6.5", "Limit": "12"},
"2018": {"Cats": "q1: 1.75, q3: 4.5", "Limit": "12"},
}


@pytest.fixture
def view(browser):
class TestView(View):
ROOT = ".//div[@id='ws-react-c-box-plot-chart-embedded-legend']"
chart = BoxPlotChart(locator=".//div[@class='pf-v5-c-chart']")

return TestView(browser)


def test_boxplot_chart(view):
legend_names = view.chart.legend_names

# check chart is displayed
assert view.chart.is_displayed

# validate chart data
assert view.chart.read() == TEST_DATA

expected_legend_names = list(TEST_DATA.values())[0].keys()

# validate legend names
assert set(legend_names) == set(expected_legend_names)

# validate x-axis keys
assert view.chart.labels_x_axis == list(TEST_DATA.keys())

# Validate Legends
cats_legend = view.chart.get_legend("Cats")
assert cats_legend.label == "Cats"

0 comments on commit 0b44944

Please sign in to comment.