Skip to content

Commit 7117d51

Browse files
feat: UNT-T20403: Work on Audit changes
1 parent a66664b commit 7117d51

27 files changed

+104
-123
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ export default App;
201201

202202
---
203203

204-
### ToolTip Props
204+
### Tooltip Props
205205

206206
| Prop | Default | Type | Description | BarChart | LineChart |
207207
| :----------------------- | :------ | :------ | :-------------------------------------- | -------- | --------- |
208-
| displayToolTip | false | boolean | Flag to handle tooltip visibility | ✔️ | ✔️ |
208+
| displayTooltip | false | boolean | Flag to handle tooltip visibility | ✔️ | ✔️ |
209209
| toolTipLabelFontSize | 12 | number | Font size | ✔️ | ✔️ |
210210
| toolTipColor | #FF0000 | string | Tooltip color | ✔️ | ✔️ |
211211
| toolTipDataColor | #FFFFFF | string | Tooltip data color | ✔️ | ✔️ |
-49.7 KB
Binary file not shown.
-164 KB
Binary file not shown.

example/src/utils/CommonUtils.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

example/src/utils/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"scripts": {
2525
"prepare": "husky install && yarn build",
2626
"clean": "rm -rf node_modules",
27-
"build": "rm -rf lib && tsc -p . && cp -R ./src/assets ./lib/ ",
27+
"build": "rm -rf lib && tsc -p . ",
2828
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
2929
"lint:fix": "eslint 'src/**/*.{js,jsx,ts,tsx}' -c .eslintrc --fix ",
3030
"build:local": "yarn build && yarn pack",

src/assets/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/bar-chart/BarChart.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import { Canvas, Path } from '@shopify/react-native-skia';
22
import React from 'react';
33
import { ScrollView, Text as RNText, View } from 'react-native';
44
import { Colors } from '../../theme';
5+
import { Tooltip } from '../tooltip';
56
import { styles } from './BarChartStyles';
67
import type { BarChartProps } from './BarChartTypes';
78
import { RenderHorizontalGridLines, XAxisLabels, YAxisLabels } from './components';
89
import useBarChart from './useBarChart';
9-
import { ToolTip } from '../tooltip';
1010

11+
/**
12+
* The custom text input component
13+
* @param {BarChartProps} props - the props for the BarChart component
14+
* @returns {React.ReactElement} A React Element.
15+
*/
1116
const BarChart = ({
1217
chartData,
1318
barGap = 50,
@@ -34,7 +39,7 @@ const BarChart = ({
3439
toolTipDataColor,
3540
toolTipHorizontalPadding,
3641
toolTipFadeOutDuration,
37-
displayToolTip = false,
42+
displayTooltip = false,
3843
showAnimation = true,
3944
xLegendStyles = {},
4045
yLegendStyles = {}
@@ -46,9 +51,9 @@ const BarChart = ({
4651
canvasHeightWithHorizontalLabel,
4752
xAxisData,
4853
canvasHeight,
49-
chartBottomMargin,
54+
CHART_BOTTOM_MARGIN,
5055
yScale,
51-
axisPositionValue,
56+
AXIS_POSITION_VALUE,
5257
yLabelMaxLength,
5358
barChartHeight,
5459
barLegendHeight,
@@ -122,9 +127,9 @@ const BarChart = ({
122127
yScale,
123128
font,
124129
canvasHeight,
125-
axisPositionValue,
130+
AXIS_POSITION_VALUE,
126131
labelColor,
127-
chartBottomMargin
132+
CHART_BOTTOM_MARGIN
128133
}}
129134
/>
130135
</Canvas>
@@ -139,7 +144,7 @@ const BarChart = ({
139144
>
140145
<Canvas
141146
style={style.chartCanvasContainer}
142-
onTouch={displayToolTip ? touchHandler : undefined}
147+
onTouch={displayTooltip ? touchHandler : undefined}
143148
>
144149
{showLines && (
145150
<RenderHorizontalGridLines
@@ -148,10 +153,10 @@ const BarChart = ({
148153
xAxisData,
149154
barWidth,
150155
yScale,
151-
axisPositionValue,
156+
AXIS_POSITION_VALUE,
152157
lineHeight,
153158
canvasHeight,
154-
chartBottomMargin,
159+
CHART_BOTTOM_MARGIN,
155160
horizontalGridLineColor,
156161
initialDistance,
157162
yLabelMaxLength
@@ -174,8 +179,8 @@ const BarChart = ({
174179
canvasHeightWithHorizontalLabel
175180
}}
176181
/>
177-
{displayToolTip && (
178-
<ToolTip
182+
{displayTooltip && (
183+
<Tooltip
179184
xForWindow={xForWindow.current}
180185
{...{
181186
xCoordinateForDataPoint,

src/components/bar-chart/BarChartTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type BarChartProps = {
4343
toolTipDataColor?: string;
4444
toolTipHorizontalPadding?: number;
4545
toolTipFadeOutDuration?: number;
46-
displayToolTip?: boolean;
46+
displayTooltip?: boolean;
4747
showAnimation?: boolean;
4848
xLegendStyles?: TextStyle;
4949
yLegendStyles?: TextStyle;

src/components/bar-chart/components/xaxis-label/XAxisLabels.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const XAxisLabels = ({
1616
}: XAxisLabelsPropType) => {
1717
return (
1818
<>
19-
{xAxisData.map((dataPoint, index) => {
19+
{xAxisData?.map((dataPoint, index) => {
2020
const { height, width } = font?.measureText(dataPoint);
2121
const xScaleWidth = (xScale(dataPoint) as number) + barWidth / 2 + initialDistance;
2222
const xPoint = verticalLabel

src/components/bar-chart/components/yaxis-label/YAxisLabels.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ const YAxisLabels = ({
66
yScale,
77
font,
88
canvasHeight,
9-
axisPositionValue,
9+
AXIS_POSITION_VALUE,
1010
labelColor,
11-
chartBottomMargin
11+
CHART_BOTTOM_MARGIN
1212
}: YAxisLabelsPropsType) => {
1313
return (
1414
<>
1515
{yScale.ticks().map((tick: number, index: number) => {
16-
const yPoint = canvasHeight - 2 * chartBottomMargin - yScale(tick) + axisPositionValue;
16+
const yPoint = canvasHeight - 2 * CHART_BOTTOM_MARGIN - yScale(tick) + AXIS_POSITION_VALUE;
1717
return (
1818
<Text
1919
key={`y-label-${index}`}

src/components/bar-chart/components/yaxis-label/YAxisLabelsPropsTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { ScaleLinear } from 'd3';
44
export interface YAxisLabelsPropsType {
55
font: SkFont;
66
canvasHeight: number;
7-
axisPositionValue: number;
7+
AXIS_POSITION_VALUE: number;
88
labelColor: string;
9-
chartBottomMargin: number;
9+
CHART_BOTTOM_MARGIN: number;
1010
yScale: ScaleLinear<number, number>;
1111
}

src/components/bar-chart/components/yref-lines/YRefLines.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const YRefLines = ({
77
xAxisData,
88
barWidth,
99
yScale,
10-
axisPositionValue,
10+
AXIS_POSITION_VALUE,
1111
lineHeight,
1212
canvasHeight,
13-
chartBottomMargin,
13+
CHART_BOTTOM_MARGIN,
1414
horizontalGridLineColor,
1515
initialDistance,
1616
yLabelMaxLength
@@ -23,7 +23,7 @@ const YRefLines = ({
2323
return (
2424
<>
2525
{yScale.ticks().map((tick: number, index: number) => {
26-
const yPoint = canvasHeight - 2 * chartBottomMargin - yScale(tick) + axisPositionValue;
26+
const yPoint = canvasHeight - 2 * CHART_BOTTOM_MARGIN - yScale(tick) + AXIS_POSITION_VALUE;
2727
return (
2828
<Rect
2929
key={`y-grid-${index}`}

src/components/bar-chart/components/yref-lines/YRefLinesTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import type { ScaleLinear, ScalePoint } from 'd3';
33
export interface YRefLinesProps {
44
xAxisData: string[];
55
barWidth: number;
6-
axisPositionValue: number;
6+
AXIS_POSITION_VALUE: number;
77
lineHeight: number;
88
canvasHeight: number;
9-
chartBottomMargin: number;
9+
CHART_BOTTOM_MARGIN: number;
1010
horizontalGridLineColor: string;
1111
initialDistance: number;
1212
yLabelMaxLength: number;

src/components/bar-chart/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { default as BarChart } from './BarChart';
2-
export { default as useBarChart } from './useBarChart';
32
export * from './BarChartTypes';
3+
export { default as useBarChart } from './useBarChart';

src/components/bar-chart/useBarChart.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
SkFont,
3-
Skia,
42
matchFont,
53
runTiming,
4+
SkFont,
5+
Skia,
66
useComputedValue,
77
useFont,
88
useTouchHandler,
@@ -11,10 +11,15 @@ import {
1111
import { max, scaleLinear, scalePoint, type NumberValue } from 'd3';
1212
import { useEffect } from 'react';
1313
import { Easing } from 'react-native';
14-
import { BARGRAPH_TOOLTIP_HITSLOP } from '../../constants';
14+
import {
15+
AXIS_POSITION_VALUE,
16+
BARGRAPH_TOOLTIP_HITSLOP,
17+
CHART_BOTTOM_MARGIN,
18+
INITIAL_SPACE
19+
} from '../../constants';
1520
import { useDefaultFont } from '../../hooks';
16-
import { Colors, chartWidth, horizontalScale, screenHeight } from '../../theme';
17-
import { useToolTipUtils } from '../tooltip';
21+
import { chartWidth, Colors, horizontalScale, screenHeight } from '../../theme';
22+
import { useTooltipUtils } from '../tooltip';
1823
import type { BarChartHookPropType } from './BarChartTypes';
1924

2025
export default function useBarChart({
@@ -35,15 +40,12 @@ export default function useBarChart({
3540
xLegendStyles,
3641
yLegendStyles
3742
}: BarChartHookPropType) {
38-
const chartBottomMargin = 14;
3943
const { fontStyle } = useDefaultFont({ labelSize });
4044
const userAddedFont = useFont(labelFontFamily, labelSize);
4145
const font: SkFont | null = labelFontFamily ? userAddedFont : matchFont(fontStyle);
4246
const animationState = useValue(0);
4347
const canvasHeight = Math.min(screenHeight, chartHeight);
44-
const graphHeight = canvasHeight - 2 * chartBottomMargin;
45-
const axisPositionValue = 25;
46-
const initialSpace = 10;
48+
const graphHeight = canvasHeight - 2 * CHART_BOTTOM_MARGIN;
4749
const xAxisData: string[] = chartData?.xAxis?.labels;
4850
const yAxisData: number[] = chartData?.yAxis?.datasets;
4951
const {
@@ -55,39 +57,39 @@ export default function useBarChart({
5557
yCoordinateForDataPoint,
5658
setXForWindow,
5759
setWindowSize
58-
} = useToolTipUtils();
60+
} = useTooltipUtils();
5961

6062
const yMaxRange = Math.max(...yAxisData?.map((number) => number));
61-
const getMaxWidthLabel: number = xAxisData.reduce((max: number, item) => {
63+
const getMaxWidthLabel: number = xAxisData?.reduce((max: number, item) => {
6264
return Math.max(max, font ? font?.measureText(item).width : 0);
6365
}, 0);
6466

65-
const getMaxHeightLabel = xAxisData.reduce((max: number, item) => {
67+
const getMaxHeightLabel = xAxisData?.reduce((max: number, item) => {
6668
return Math.max(max, font ? font.measureText(item).height : 0);
6769
}, 0);
6870

6971
const canvasHeightWithHorizontalLabel = Math.floor(
70-
canvasHeight + chartBottomMargin + getMaxHeightLabel
72+
canvasHeight + CHART_BOTTOM_MARGIN + getMaxHeightLabel
7173
);
7274
const canvasHeightWithVerticalLabel = Math.floor(
73-
canvasHeight + chartBottomMargin + getMaxWidthLabel
75+
canvasHeight + CHART_BOTTOM_MARGIN + getMaxWidthLabel
7476
);
7577

7678
let yScale = scaleLinear()
7779
.domain([
7880
yAxisMin ?? 0,
79-
(yAxisMax && yAxisMax) ?? Math.max(...yAxisData?.map((yDataPoint: number) => yDataPoint))
81+
yAxisMax ?? Math.max(...yAxisData?.map((yDataPoint: number) => yDataPoint))
8082
])
8183
.range([0, graphHeight]);
8284

8385
const yTicks = yScale.ticks();
84-
const yTrimedArray = yTicks.map((element: number) => {
85-
return element.toString().replace('.', '');
86+
const yTrimmedArray = yTicks?.map((element: number) => {
87+
return element?.toString().replace('.', '');
8688
});
8789

88-
const yLabelMaxLength = Math.max(...yTrimedArray.map((number) => String(number).length));
90+
const yLabelMaxLength = Math.max(...yTrimmedArray?.map((number) => String(number)?.length));
8991

90-
const getMaxWidthForYAxis = yTrimedArray.reduce((max: number, item) => {
92+
const getMaxWidthForYAxis = yTrimmedArray?.reduce((max: number, item) => {
9193
return Math.max(max, (font as SkFont)?.measureText(item.toString()).width);
9294
}, 0);
9395

@@ -139,7 +141,7 @@ export default function useBarChart({
139141
xAxisData?.forEach((dataPoint: string, index) => {
140142
const rect = Skia.XYWHRect(
141143
(xScale(dataPoint) as number) + yLabelMaxLength + initialDistance,
142-
graphHeight + axisPositionValue,
144+
graphHeight + AXIS_POSITION_VALUE,
143145
barWidth,
144146
yScale(yAxisData[index] * animationState.current) * -1
145147
);
@@ -155,7 +157,7 @@ export default function useBarChart({
155157
xAxisData?.forEach((dataPoint: string, index) => {
156158
const rect = Skia.XYWHRect(
157159
(xScale(dataPoint) as number) + yLabelMaxLength + initialDistance,
158-
graphHeight + axisPositionValue,
160+
graphHeight + AXIS_POSITION_VALUE,
159161
barWidth,
160162
(yScale(yAxisData[index] * animationState.current) * -1) / 2
161163
);
@@ -167,9 +169,9 @@ export default function useBarChart({
167169

168170
const barChartHeight: number = verticalLabel
169171
? canvasHeightWithVerticalLabel
170-
: canvasHeightWithHorizontalLabel + initialSpace;
172+
: canvasHeightWithHorizontalLabel + INITIAL_SPACE;
171173
const barLegendHeight: number =
172-
canvasHeight - 2 * chartBottomMargin - yScale.ticks()[0] + axisPositionValue;
174+
canvasHeight - 2 * CHART_BOTTOM_MARGIN - yScale.ticks()[0] + AXIS_POSITION_VALUE;
173175
const yLabelWidth: number = yAxisLegend?.length * legendSize;
174176
const canvasWidth: number = getMaxWidthForYAxis + horizontalScale(20);
175177
const barChartWidth: number = barGap ? checkXWidth() : chartWidth + initialDistance;
@@ -180,7 +182,7 @@ export default function useBarChart({
180182
const touchHandler = useTouchHandler(
181183
{
182184
onStart: ({ x }) => {
183-
xAxisData.forEach((dataPoint, index) => {
185+
xAxisData?.forEach((dataPoint, index) => {
184186
const xForPlottedXLabel =
185187
(xScale(dataPoint) as number) + yLabelMaxLength + initialDistance;
186188

@@ -197,7 +199,7 @@ export default function useBarChart({
197199
(xScale(dataPoint) as number) + (yLabelMaxLength + initialDistance) + barWidth / 2;
198200
yCoordinateForDataPoint.current =
199201
windowSize.current.y -
200-
(windowSize.current.y - (graphHeight + axisPositionValue)) -
202+
(windowSize.current.y - (graphHeight + AXIS_POSITION_VALUE)) -
201203
yScale(yAxisData[index] * animationState.current);
202204
}
203205
});
@@ -270,14 +272,14 @@ export default function useBarChart({
270272
path,
271273
createPath,
272274
canvasHeightWithHorizontalLabel,
273-
initialSpace,
275+
INITIAL_SPACE,
274276
canvasHeightWithVerticalLabel,
275277
getMaxWidthForYAxis,
276278
xAxisData,
277279
canvasHeight,
278-
chartBottomMargin,
280+
CHART_BOTTOM_MARGIN,
279281
yScale,
280-
axisPositionValue,
282+
AXIS_POSITION_VALUE,
281283
yLabelMaxLength,
282284
chartWidth,
283285
barChartHeight,

0 commit comments

Comments
 (0)