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

Replace react-vis with Recharts #1722

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

anikdhabal
Copy link
Contributor

Which problem is this PR solving?

Resolves #1597

Screenshot 2023-08-22 053025

Checklist

Signed-off-by: Anik Dhabal Babu <adhabal2002@gmail.com>
@anikdhabal anikdhabal changed the title Replace react-vis with recharts Replace react-vis with Recharts Aug 22, 2023
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

@anshgoyalevil mind reviewing this?

@anshgoyalevil
Copy link
Contributor

On it 🚀

package.json Outdated Show resolved Hide resolved
Comment on lines 119 to 139
crosshairValues: [
{
key: 1,
...serviceMetrics.service_call_rate.metricPoints[0],
},
],
});
expect(wrapper.find('AreaSeries').render()).toMatchSnapshot();
expect(wrapper.find('LineSeries').render()).toMatchSnapshot();
});

it('AreaSeries onNearestX, XYPlot onMouseLeave', () => {
wrapper.setProps({
...props,
loading: false,
metricsData: serviceMetrics.service_call_rate,
});
wrapper.find('AreaSeries').at(0).prop('onNearestX')({ x: 1, y: 2 }, { index: 7 });
expect(wrapper.state().crosshairValues).toEqual([{ label: 0.95 }]);
wrapper.find('XYPlot').prop('onMouseLeave')();
expect(wrapper.state().crosshairValues).toEqual([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think removing these tests defeats the purpose of test-driven development. Can we add some similar assumptions for tooltip hover test to verify the functionality?

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, on it.

yAxisTickFormat?: (v: number) => number;
yAxisTickFormat?: (v: number) => string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we return a number here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, as I previously described that timeFormatter function only accept string.

Comment on lines +84 to +89
type="monotone"
dataKey="y"
connectNulls
fillOpacity={0.1}
stroke={color || this.colors[idx]}
fill={color || this.colors[idx]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't we passing on the data prop here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no props to pass the data here. Also, we don't need to pass the data props here; the data props is passed to the parent component.

data={line.metricPoints ? line.metricPoints : []}
color={[color || this.colors[idx]]}
/>
<Line connectNulls key={i++} type="monotone" dataKey="y" stroke={color || this.colors[idx]} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't we passing on the data prop here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need.

Signed-off-by: Anik Dhabal Babu <adhabal2002@gmail.com>
it('Loading indicator is displayed', () => {
expect(wrapper).toMatchSnapshot();
it('displays loading indicator when loading', () => {
expect(wrapper.find('LoadingIndicator').exists()).toBe(true);
Copy link
Member

Choose a reason for hiding this comment

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

exists()).toBe(true) - is there a simpler form like isNotNull?

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 don't think. But there are similar from like toBeTruthy() or toBeTrue()

Copy link
Member

Choose a reason for hiding this comment

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

expect(wrapper.find(ServiceGraph).first().prop('error')).not.toBeNull();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh OKK

@yurishkuro
Copy link
Member

Q: in the screenshot all dots are the same size, but the original chart used number of spans to control the size of the trace. Is such functionality supported in recharts?

@anikdhabal
Copy link
Contributor Author

Q: in the screenshot all dots are the same size, but the original chart used number of spans to control the size of the trace. Is such functionality supported in recharts?

Apart from the X and Y axes, Recharts also provides a Z-axis. With the assistance of the range property of Z axis, we can achieve this desired functionality. (similar to sizeRange in react-vis)

@yurishkuro
Copy link
Member

Apart from the X and Y axes, Recharts also provides a Z-axis. With the assistance of the range property of Z axis, we can achieve this desired functionality. (similar to sizeRange in react-vis)

Are you planning to add that? Otherwise you're removing exiting functionality

anikdhabal and others added 3 commits August 29, 2023 00:20
Signed-off-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
Signed-off-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
Signed-off-by: Anik Dhabal Babu <adhabal2002@gmail.com>
@anikdhabal
Copy link
Contributor Author

Apart from the X and Y axes, Recharts also provides a Z-axis. With the assistance of the range property of Z axis, we can achieve this desired functionality. (similar to sizeRange in react-vis)

Are you planning to add that? Otherwise you're removing exiting functionality

I've added Z-axis for the size range and set the data key to 'size' as it carries the span length.
Screenshot 2023-08-29 000542

@yurishkuro
Copy link
Member

when I run yarn test locally I am getting various errors related to your changes, like this:

 FAIL  src/components/SearchTracePage/SearchResults/ScatterPlot.test.js
  ● Console

    console.error
      Warning: Failed prop type: Invalid prop `data[0].traceID` of type `number` supplied to `ScatterPlot`, expected `string`.
          at data (/Users/ysh/dev/jaegertracing/jaeger-ui/packages/jaeger-ui/src/components/SearchTracePage/SearchResults/ScatterPlot.jsx:33:11)

      55 | it('<ScatterPlot /> should render base case correctly', () => {
      56 |   const wrapper = shallow(
    > 57 |     <ScatterPlot
         |     ^
      58 |       data={[
      59 |         { x: Date.now() - 3000, y: 1, traceID: 1 },
      60 |         { x: Date.now() - 2000, y: 2, traceID: 2 },

(for some reason they are not included in the CI output).

@anikdhabal
Copy link
Contributor Author

when I run yarn test locally I am getting various errors related to your changes, like this:

 FAIL  src/components/SearchTracePage/SearchResults/ScatterPlot.test.js
  ● Console

    console.error
      Warning: Failed prop type: Invalid prop `data[0].traceID` of type `number` supplied to `ScatterPlot`, expected `string`.
          at data (/Users/ysh/dev/jaegertracing/jaeger-ui/packages/jaeger-ui/src/components/SearchTracePage/SearchResults/ScatterPlot.jsx:33:11)

      55 | it('<ScatterPlot /> should render base case correctly', () => {
      56 |   const wrapper = shallow(
    > 57 |     <ScatterPlot
         |     ^
      58 |       data={[
      59 |         { x: Date.now() - 3000, y: 1, traceID: 1 },
      60 |         { x: Date.now() - 2000, y: 2, traceID: 2 },

(for some reason they are not included in the CI output).

Okay, let me go through it and try to fix it.

@anshgoyalevil
Copy link
Contributor

anshgoyalevil commented Aug 29, 2023

for some reason they are not included in the CI output

I also noticed the same. There are a lot of warnings because of the Deprecated Enzyme API, and due to that, the useful errors cannot be seen in CI output.

A quick fix here can be to use the --silent flag in test-ci script.
This would help suppressing the warnings and console logs, after which the errors can hopefully be seen in CI output.

Though ignoring the warnings by suppressing them is also wrong. In future, we may fix all of the warnings (hopefully), and fail the CI on warning too.

@anikdhabal
Copy link
Contributor Author

for some reason they are not included in the CI output

I also noticed the same. There are a lot of warnings because of the Deprecated Enzyme API, and due to that, the useful errors cannot be seen in CI output.

A quick fix here can be to use the --silent flag in test-ci script. This would help suppressing the warnings and console logs, after which the errors can hopefully be seen in CI output.

Though ignoring the warnings by suppressing them is also wrong. In future, we may fix all of the warnings (hopefully), and fail the CI on warning too.

Thanks for your review. I will definitely try it.

Signed-off-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
@yurishkuro
Copy link
Member

the two CI builds now very clearly show the breaks, both from linter and compiler

@anikdhabal
Copy link
Contributor Author

the two CI builds now very clearly show the breaks, both from linter and compiler

It gives this error every time: 'TypeError: window.ResizeObserver is not a constructor.

@anshgoyalevil
Copy link
Contributor

@anikdhabal

global.ResizeObserver = jest.fn().mockImplementation(() => ({
    observe: jest.fn(),
    unobserve: jest.fn(),
    disconnect: jest.fn(),
}))

Add the above code to packages/jaeger-ui/test/jest-per-test-setup.js or jest.global-setup.js.

It should then work.

Ref: https://stackoverflow.com/questions/64558062/how-to-mock-resizeobserver-to-work-in-unit-tests-using-react-testing-library

@priyanshu-kun
Copy link
Contributor

@anikdhabal are you still working on this issue?

@anikdhabal
Copy link
Contributor Author

@anikdhabal are you still working on this issue?

Yeah, I was inactive due to my exam, but I have fixed that issue now.

@MarkPollmann
Copy link

Can we help to get this shipped?

@yurishkuro
Copy link
Member

help is welcome, this needs a rebase

@MarkPollmann
Copy link

Okay, I'm on it

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.

Replace react-vis library for drawing charts
5 participants