Skip to content

Commit 4a81f9d

Browse files
committed
charts changes
1 parent 13987b1 commit 4a81f9d

File tree

93 files changed

+226
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+226
-371
lines changed

eslint.config-md.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@ export default [
3030
'react/jsx-uses-react': 'error',
3131
'react/jsx-uses-vars': 'error',
3232
'react/no-unknown-property': 'error',
33-
'react/jsx-no-undef': 'error'
33+
'react/jsx-no-undef': 'error',
34+
'no-restricted-imports': [
35+
'warn',
36+
{
37+
paths: [
38+
{
39+
name: 'react',
40+
importNames: ['default'],
41+
message: 'Please use named imports when importing from React.'
42+
}
43+
]
44+
}
45+
]
3446
}
3547
}
3648
];

packages/react-charts/src/victory/components/Chart/Chart.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { Chart } from './Chart';
43
import { ChartGroup } from '../ChartGroup/ChartGroup';

packages/react-charts/src/victory/components/Chart/Chart.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { Children, cloneElement, isValidElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33

44
/* eslint-disable camelcase */
@@ -69,7 +69,7 @@ export interface ChartProps extends VictoryChartProps {
6969
* The backgroundComponent prop takes a component instance which will be responsible for rendering a background if the
7070
* Chart's style component includes background styles. The new element created from the passed backgroundComponent
7171
* will be provided with the following properties calculated by Chart: height, polar, scale, style, x, y, width.
72-
* All of these props on Background should take prececence over what VictoryChart is trying to set.
72+
* All of these props on Background should take precedence over what VictoryChart is trying to set.
7373
*/
7474
backgroundComponent?: React.ReactElement<any>;
7575
/**
@@ -152,7 +152,7 @@ export interface ChartProps extends VictoryChartProps {
152152
* events. The eventKey may optionally be used to select a single element by index rather than
153153
* an entire set. The eventHandlers object should be given as an object whose keys are standard
154154
* event names (i.e. onClick) and whose values are event callbacks. The return value
155-
* of an event handler is used to modify elemnts. The return value should be given
155+
* of an event handler is used to modify elements. The return value should be given
156156
* as an object or an array of objects with optional target and eventKey keys,
157157
* and a mutation key whose value is a function. The target and eventKey keys
158158
* will default to those corresponding to the element the event handler was attached to.
@@ -513,15 +513,15 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
513513
containerComponent.props.labelComponent &&
514514
containerComponent.props.labelComponent.type.displayName === 'ChartLegendTooltip'
515515
) {
516-
labelComponent = React.cloneElement(containerComponent.props.labelComponent, {
516+
labelComponent = cloneElement(containerComponent.props.labelComponent, {
517517
theme,
518518
...(defaultPatternScale && { patternScale: defaultPatternScale }),
519519
...containerComponent.props.labelComponent.props
520520
});
521521
}
522522

523523
// Clone so users can override container props
524-
const container = React.cloneElement(containerComponent, {
524+
const container = cloneElement(containerComponent, {
525525
desc: ariaDesc,
526526
title: ariaTitle,
527527
theme,
@@ -536,22 +536,22 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
536536
legendXOffset = getLegendMaxTextWidth(legendData, theme);
537537
}
538538

539-
const legend = React.cloneElement(legendComponent, {
539+
const legend = cloneElement(legendComponent, {
540540
data: legendData,
541541
...(name && { name: `${name}-${(legendComponent as any).type.displayName}` }),
542542
orientation: legendOrientation,
543543
theme,
544544
themeColor,
545545
...(legendDirection === 'rtl' && {
546546
dataComponent: legendComponent.props.dataComponent ? (
547-
React.cloneElement(legendComponent.props.dataComponent, { transform: `translate(${legendXOffset})` })
547+
cloneElement(legendComponent.props.dataComponent, { transform: `translate(${legendXOffset})` })
548548
) : (
549549
<ChartPoint transform={`translate(${legendXOffset})`} />
550550
)
551551
}),
552552
...(legendDirection === 'rtl' && {
553553
labelComponent: legendComponent.props.labelComponent ? (
554-
React.cloneElement(legendComponent.props.labelComponent, { direction: 'rtl', dx: legendXOffset - 30 })
554+
cloneElement(legendComponent.props.labelComponent, { direction: 'rtl', dx: legendXOffset - 30 })
555555
) : (
556556
<ChartLabel direction="rtl" dx={legendXOffset - 30} />
557557
)
@@ -570,7 +570,7 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
570570
let legendTitleHeight = legend.props.title ? 10 : 0;
571571

572572
// Adjust for axis label
573-
React.Children.toArray(children).map((child: any) => {
573+
Children.toArray(children).map((child: any) => {
574574
if (child.type.role === 'axis' && child.props.label && child.props.fixAxisLabelHeight) {
575575
xAxisLabelHeight = getLabelTextSize({ text: child.props.label, theme }).height + 10;
576576
legendTitleHeight = 0;
@@ -608,10 +608,10 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
608608

609609
// Render children
610610
const renderChildren = () =>
611-
React.Children.toArray(children).map((child, index) => {
612-
if (React.isValidElement(child)) {
611+
Children.toArray(children).map((child, index) => {
612+
if (isValidElement(child)) {
613613
const { ...childProps } = child.props;
614-
return React.cloneElement(child, {
614+
return cloneElement(child, {
615615
colorScale,
616616
...(defaultPatternScale && { patternScale: defaultPatternScale }),
617617
...(name &&

packages/react-charts/src/victory/components/ChartArea/ChartArea.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { ChartArea } from '../ChartArea/ChartArea';
43

packages/react-charts/src/victory/components/ChartArea/ChartArea.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { cloneElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33
import {
44
AnimatePropTypeInterface,
@@ -129,7 +129,7 @@ export interface ChartAreaProps extends VictoryAreaProps {
129129
* Since ChartArea only renders a single element, the eventKey property is not used.
130130
* The eventHandlers object should be given as an object whose keys are standard
131131
* event names (i.e. onClick) and whose values are event callbacks. The return value
132-
* of an event handler is used to modify elemnts. The return value should be given
132+
* of an event handler is used to modify elements. The return value should be given
133133
* as an object or an array of objects with optional target and eventKey keys,
134134
* and a mutation key whose value is a function. The target and eventKey keys
135135
* will default to those corresponding to the element the event handler was attached to.
@@ -433,7 +433,7 @@ export const ChartArea: React.FunctionComponent<ChartAreaProps> = ({
433433
...rest
434434
}: ChartAreaProps) => {
435435
// Clone so users can override container props
436-
const container = React.cloneElement(containerComponent, {
436+
const container = cloneElement(containerComponent, {
437437
theme,
438438
...containerComponent.props
439439
});

packages/react-charts/src/victory/components/ChartArea/examples/ChartArea.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ propComponents: [
1111
]
1212
hideDarkMode: true
1313
---
14-
14+
import { createRef } from 'react';
1515
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThreshold, ChartThemeColor, ChartLegendTooltip, ChartVoronoiContainer, createContainer } from '@patternfly/react-charts/victory';
1616
import { getResizeObserver } from '@patternfly/react-core';
1717

@@ -23,7 +23,6 @@ PatternFly React charts are based on the [Victory](https://formidable.com/open-s
2323
## Examples
2424
### Basic with right aligned legend
2525
```js
26-
import React from 'react';
2726
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
2827
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
2928

@@ -88,7 +87,6 @@ import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '
8887
This demonstrates how to combine cursor and voronoi containers to display tooltips along with a cursor.
8988

9089
```js
91-
import React from 'react';
9290
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor, ChartLegendTooltip, createContainer } from '@patternfly/react-charts/victory';
9391
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
9492

@@ -172,15 +170,14 @@ class BottomAlignedLegend extends React.Component {
172170

173171
### Multi-color (unordered) bottom-left aligned legend and responsive container
174172
```js
175-
import React from 'react';
176173
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
177174
import { getResizeObserver } from '@patternfly/react-core';
178175
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
179176

180177
class MultiColorChart extends React.Component {
181178
constructor(props) {
182179
super(props);
183-
this.containerRef = React.createRef();
180+
this.containerRef = createRef();
184181
this.observer = () => {};
185182
this.state = {
186183
width: 0

packages/react-charts/src/victory/components/ChartAxis/ChartAxis.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { Chart } from '../Chart/Chart';
43
import { ChartGroup } from '../ChartGroup/ChartGroup';

packages/react-charts/src/victory/components/ChartAxis/ChartAxis.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { cloneElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33
import {
44
AnimatePropTypeInterface,
@@ -117,7 +117,7 @@ export interface ChartAxisProps extends VictoryAxisProps {
117117
* single element by index rather than an entire set. The eventHandlers object
118118
* should be given as an object whose keys are standard event names (i.e. onClick)
119119
* and whose values are event callbacks. The return value of an event handler
120-
* be used to modify other elemnts. The return value should be given as an object or
120+
* be used to modify other elements. The return value should be given as an object or
121121
* an array of objects with optional target and eventKey keys, and a mutation
122122
* key whose value is a function. The target and eventKey keys will default to those
123123
* corresponding to the element the event handler was attached to. The mutation
@@ -458,13 +458,13 @@ export const ChartAxis: React.FunctionComponent<ChartAxisProps> = ({
458458
const componentTheme = getComponentTheme(themeColor);
459459

460460
// Clone so users can override container props
461-
const container = React.cloneElement(containerComponent, {
461+
const container = cloneElement(containerComponent, {
462462
theme,
463463
...containerComponent.props
464464
});
465465

466466
const getAxisLabelComponent = () =>
467-
React.cloneElement(axisLabelComponent, {
467+
cloneElement(axisLabelComponent, {
468468
...(name && {
469469
id: () => `${name}-${(axisLabelComponent as any).type.displayName}`
470470
}),
@@ -473,7 +473,7 @@ export const ChartAxis: React.FunctionComponent<ChartAxisProps> = ({
473473
});
474474

475475
const getTickLabelComponent = () =>
476-
React.cloneElement(tickLabelComponent, {
476+
cloneElement(tickLabelComponent, {
477477
...(name && {
478478
id: (props: any) => `${name}-${(tickLabelComponent as any).type.displayName}-${props.index}`
479479
}),

packages/react-charts/src/victory/components/ChartBar/ChartBar.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { render } from '@testing-library/react';
32
import { Chart } from '../Chart/Chart';
43
import { ChartGroup } from '../ChartGroup/ChartGroup';

packages/react-charts/src/victory/components/ChartBar/ChartBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import { cloneElement } from 'react';
22
import hoistNonReactStatics from 'hoist-non-react-statics';
33
import {
44
AnimatePropTypeInterface,
@@ -169,7 +169,7 @@ export interface ChartBarProps extends VictoryBarProps {
169169
* The eventKey may optionally be used to select a single element by index rather than an entire
170170
* set. The eventHandlers object should be given as an object whose keys are standard
171171
* event names (i.e. onClick) and whose values are event callbacks. The return value
172-
* of an event handler is used to modify elemnts. The return value should be given
172+
* of an event handler is used to modify elements. The return value should be given
173173
* as an object or an array of objects with optional target and eventKey keys,
174174
* and a mutation key whose value is a function. The target and eventKey keys
175175
* will default to those corresponding to the element the event handler was attached to.
@@ -471,7 +471,7 @@ export const ChartBar: React.FunctionComponent<ChartBarProps> = ({
471471
...rest
472472
}: ChartBarProps) => {
473473
// Clone so users can override container props
474-
const container = React.cloneElement(containerComponent, {
474+
const container = cloneElement(containerComponent, {
475475
theme,
476476
...containerComponent.props
477477
});

0 commit comments

Comments
 (0)