Skip to content

Commit 248d741

Browse files
committed
fix(Charts): update chart refs, fixes of scatter chart
1 parent e847086 commit 248d741

File tree

12 files changed

+36
-66
lines changed

12 files changed

+36
-66
lines changed

packages/charts/src/components/BarChart/BarChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export interface BarChartProps extends IChartBaseProps {
9393
/**
9494
* <code>import { BarChart } from '@ui5/webcomponents-react-charts/lib/BarChart';</code>
9595
*/
96-
const BarChart: FC<BarChartProps> = forwardRef((props: BarChartProps, ref: Ref<any>) => {
96+
const BarChart: FC<BarChartProps> = forwardRef((props: BarChartProps, ref: Ref<HTMLDivElement>) => {
9797
const {
9898
loading,
9999
dataset,

packages/charts/src/components/ColumnChart/ColumnChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const measureDefaults = {
9191
/**
9292
* <code>import { ColumnChart } from '@ui5/webcomponents-react-charts/lib/ColumnChart';</code>
9393
*/
94-
const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, ref: Ref<any>) => {
94+
const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, ref: Ref<HTMLDivElement>) => {
9595
const {
9696
loading,
9797
dataset,

packages/charts/src/components/ComposedChart/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type AvailableChartTypes = 'line' | 'bar' | 'area' | string;
107107
/**
108108
* <code>import { ComposedChart } from '@ui5/webcomponents-react-charts/lib/ComposedChart';</code>
109109
*/
110-
const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartProps, ref: Ref<any>) => {
110+
const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartProps, ref: Ref<HTMLDivElement>) => {
111111
const {
112112
loading,
113113
dataset,

packages/charts/src/components/LineChart/LineChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const measureDefaults = {
8383
/**
8484
* <code>import { LineChart } from '@ui5/webcomponents-react-charts/lib/LineChart';</code>
8585
*/
86-
const LineChart: FC<LineChartProps> = forwardRef((props: LineChartProps, ref: Ref<any>) => {
86+
const LineChart: FC<LineChartProps> = forwardRef((props: LineChartProps, ref: Ref<HTMLDivElement>) => {
8787
const {
8888
dataset,
8989
loading,
@@ -158,7 +158,7 @@ const LineChart: FC<LineChartProps> = forwardRef((props: LineChartProps, ref: Re
158158
const [yAxisWidth, legendPosition] = useLongestYAxisLabel(dataset, measures);
159159
const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
160160
const xAxisHeights = useObserveXAxisHeights(chartRef, props.dimensions.length);
161-
console.log(dataset);
161+
162162
return (
163163
<ChartContainer
164164
dataset={dataset}

packages/charts/src/components/MicroBarChart/MicroBarChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const microBarChartMargin = { left: -30, right: 30, top: 40, bottom: 30 };
7878
/**
7979
* <code>import { MicroBarChart } from '@ui5/webcomponents-react-charts/lib/MicroBarChart';</code>
8080
*/
81-
const MicroBarChart: FC<MicroBarChartProps> = forwardRef((props: MicroBarChartProps, ref: Ref<any>) => {
81+
const MicroBarChart: FC<MicroBarChartProps> = forwardRef((props: MicroBarChartProps, ref: Ref<HTMLDivElement>) => {
8282
const { loading, dataset, onDataPointClick, style, className, tooltip, slot } = props;
8383

8484
const chartRef = useConsolidatedRef<any>(ref);

packages/charts/src/components/PieChart/PieChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface PieChartProps extends IChartBaseProps<IPolarChartConfig> {
5858
/**
5959
* <code>import { PieChart } from '@ui5/webcomponents-react-charts/lib/PieChart';</code>
6060
*/
61-
const PieChart: FC<PieChartProps> = forwardRef((props: PieChartProps, ref: Ref<any>) => {
61+
const PieChart: FC<PieChartProps> = forwardRef((props: PieChartProps, ref: Ref<HTMLDivElement>) => {
6262
const {
6363
loading,
6464
dataset,

packages/charts/src/components/RadarChart/RadarChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const measureDefaults = {
6868
/**
6969
* <code>import { RadarChart } from '@ui5/webcomponents-react-charts/lib/RadarChart';</code>
7070
*/
71-
const RadarChart: FC<RadarChartProps> = forwardRef((props: RadarChartProps, ref: Ref<any>) => {
71+
const RadarChart: FC<RadarChartProps> = forwardRef((props: RadarChartProps, ref: Ref<HTMLDivElement>) => {
7272
const {
7373
loading,
7474
dataset,

packages/charts/src/components/RadialChart/RadialChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const radialBarLabelStyle = { fontSize: ThemingParameters.sapFontHeader3Size, fi
2121
/**
2222
* <code>import { RadialChart } from '@ui5/webcomponents-react-charts/lib/RadialChart';</code>
2323
*/
24-
const RadialChart: FC<RadialChartProps> = forwardRef((props: RadialChartProps, ref: Ref<any>) => {
24+
const RadialChart: FC<RadialChartProps> = forwardRef((props: RadialChartProps, ref: Ref<HTMLDivElement>) => {
2525
const { maxValue = 100, value, displayValue, onDataPointClick, color, style, className, tooltip, slot } = props;
2626

2727
const range = useMemo(() => {

packages/charts/src/components/ScatterChart/ScatterChart.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { action } from '@storybook/addon-actions';
22
import { boolean } from '@storybook/addon-knobs';
33
import React from 'react';
4-
import { ScatterChart } from '../../lib/ScatterChart';
5-
import { bigDataSet, complexDataSet, scatterColorDataSet, scatterComplexDataSet } from '../../resources/DemoProps';
4+
import { ScatterChart } from '@ui5/webcomponents-react-charts/lib/ScatterChart';
5+
import { scatterColorDataSet, scatterComplexDataSet } from '../../resources/DemoProps';
66

77
export default {
88
title: 'Charts / ScatterChart',

packages/charts/src/components/ScatterChart/ScatterChart.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { boolean } from '@storybook/addon-knobs';
33
import { mount } from 'enzyme';
44
import * as React from 'react';
55
import { scatterComplexDataSet } from '../../resources/DemoProps';
6-
import { ScatterChart } from './ScatterChart';
6+
import { ScatterChart } from '@ui5/webcomponents-react-charts/lib/ScatterChart';
77

8-
describe('LineChart', () => {
8+
describe('Scatter Chart', () => {
99
test('Renders with data', () => {
1010
expect(
1111
mount(

packages/charts/src/components/ScatterChart/ScatterChart.tsx

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616
Tooltip,
1717
XAxis,
1818
YAxis,
19-
ZAxis,
20-
Label
19+
ZAxis
2120
} from 'recharts';
2221
import { useChartMargin } from '../../hooks/useChartMargin';
2322
import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel';
@@ -30,19 +29,9 @@ import { tickLineConfig, tooltipContentStyle, tooltipFillOpacity, xAxisPadding }
3029
import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights';
3130

3231
interface MeasureConfig extends IChartMeasure {
33-
/**
34-
* Line Width
35-
* @default 1
36-
*/
37-
width?: number;
38-
/**
39-
* Line Opacity
40-
* @default 1
41-
*/
4232
opacity?: number;
4333
/**
4434
* Defines axis of measures
45-
* @default 1
4635
*/
4736
axis: 'x' | 'y' | 'z';
4837
}
@@ -62,16 +51,6 @@ export interface ScatterChartProps extends IChartBaseProps {
6251
* - `accessor`: string containing the path to the dataset key this line should display. Supports object structures by using <code>'parent.child'</code>.
6352
* Can also be a getter.
6453
*
65-
* <h4>Optional properties</h4>
66-
*
67-
* - `label`: Label to display in legends or tooltips. Falls back to the <code>accessor</code> if not present.
68-
* - `color`: any valid CSS Color or CSS Variable. Defaults to the `sapChart_Ordinal` colors
69-
* - `formatter`: function will be called for each data label and allows you to format it according to your needs
70-
* - `hideDataLabel`: flag whether the data labels should be hidden in the chart for this line.
71-
* - `DataLabel`: a custom component to be used for the data label
72-
* - `width`: line width, defaults to `1`
73-
* - `opacity`: line opacity, defaults to `1`
74-
*
7554
*/
7655
measures?: MeasureConfig[];
7756
}
@@ -81,9 +60,9 @@ const measureDefaults = {
8160
};
8261

8362
/**
84-
* <code>import { LineChart } from '@ui5/webcomponents-react-charts/lib/LineChart';</code>
63+
* <code>import { ScatterChart } from '@ui5/webcomponents-react-charts/lib/ScatterChart';</code>
8564
*/
86-
const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps, ref: Ref<any>) => {
65+
const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps, ref: Ref<HTMLDivElement>) => {
8766
const {
8867
dataset,
8968
loading,
@@ -136,17 +115,13 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
136115
},
137116
[onDataPointClick]
138117
);
139-
140118
const isBigDataSet = dataset?.length > 30 ?? false;
141119

142-
const xMeasure = measures.filter(({ axis }) => axis === 'x');
143-
const yMeasure = measures.filter(({ axis }) => axis === 'y');
144-
const zMeasure = measures.filter(({ axis }) => axis === 'z');
120+
const xMeasure = measures.find(({ axis }) => axis === 'x');
121+
const yMeasure = measures.find(({ axis }) => axis === 'y');
122+
const zMeasure = measures.find(({ axis }) => axis === 'z');
145123

146-
const [yAxisWidth, legendPosition] = useLongestYAxisLabel(
147-
dataset?.[0].data,
148-
measures.filter(({ axis }) => axis === 'y')
149-
);
124+
const [yAxisWidth, legendPosition] = useLongestYAxisLabel(dataset?.[0].data, [yMeasure]);
150125
const xAxisHeights = useObserveXAxisHeights(chartRef, 1);
151126
const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
152127

@@ -175,36 +150,31 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
175150
{chartConfig.xAxisVisible && (
176151
<XAxis
177152
type={'number'}
178-
key={xMeasure?.[0]?.accessor}
179-
dataKey={xMeasure?.[0]?.accessor}
153+
key={xMeasure?.accessor}
154+
dataKey={xMeasure?.accessor}
180155
xAxisId={0}
181-
interval={xMeasure?.[0]?.interval ?? (isBigDataSet ? 'preserveStart' : 0)}
182-
tick={<XAxisTicks config={xMeasure?.[0]} />}
156+
interval={xMeasure?.interval ?? (isBigDataSet ? 'preserveStart' : 0)}
157+
tick={<XAxisTicks config={xMeasure} />}
183158
padding={xAxisPadding}
184159
height={xAxisHeights[0]}
185-
label={xMeasure?.[0]?.label ? { value: xMeasure?.[0]?.label, dy: 15, position: 'insideRight' } : 0}
160+
label={xMeasure?.label ? { value: xMeasure?.label, dy: 15, position: 'insideRight' } : 0}
186161
/>
187162
)}
188163
<YAxis
189-
label={yMeasure?.[0]?.label ? { value: yMeasure?.[0]?.label, angle: -90, position: 'insideLeft' } : false}
164+
label={yMeasure?.label ? { value: yMeasure?.label, angle: -90, position: 'insideLeft' } : false}
190165
type={'number'}
191-
name={yMeasure?.[0]?.accessor}
166+
name={yMeasure?.accessor}
192167
axisLine={chartConfig.yAxisVisible}
193168
tickLine={tickLineConfig}
194-
key={yMeasure?.[0]?.accessor}
195-
dataKey={yMeasure?.[0]?.accessor}
196-
tickFormatter={yMeasure?.[0]?.formatter}
169+
key={yMeasure?.accessor}
170+
dataKey={yMeasure?.accessor}
171+
tickFormatter={yMeasure?.formatter}
197172
interval={0}
198-
tick={<YAxisTicks config={yMeasure[0]} />}
199-
width={yMeasure?.[0]?.label ? yAxisWidth + 10 : yAxisWidth}
200-
margin={yMeasure?.[0]?.label ? { left: 200 } : 0}
201-
/>
202-
<ZAxis
203-
name={zMeasure?.[0]?.accessor}
204-
dataKey={zMeasure?.[0]?.accessor}
205-
range={[0, 5000]}
206-
key={zMeasure?.[0]?.accessor}
173+
tick={<YAxisTicks config={yMeasure} />}
174+
width={yMeasure?.label ? yAxisWidth + 10 : yAxisWidth}
175+
margin={yMeasure?.label ? { left: 200 } : 0}
207176
/>
177+
<ZAxis name={zMeasure?.accessor} dataKey={zMeasure?.accessor} range={[0, 5000]} key={zMeasure?.accessor} />
208178
{dataset?.map((dataSet, index) => {
209179
return (
210180
<Scatter

packages/charts/src/components/ScatterChart/__snapshots__/ScatterChart.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`LineChart Renders with data 1`] = `
3+
exports[`Scatter Chart Renders with data 1`] = `
44
<div
55
style="font-family: var(--sapFontFamily); width: 100%; height: 400px; position: relative;"
66
>
@@ -14,7 +14,7 @@ exports[`LineChart Renders with data 1`] = `
1414
</div>
1515
`;
1616

17-
exports[`LineChart loading placeholder 1`] = `
17+
exports[`Scatter Chart loading placeholder 1`] = `
1818
<div
1919
style="font-family: var(--sapFontFamily); width: 30%; height: 400px; position: relative;"
2020
>

0 commit comments

Comments
 (0)