Skip to content

Commit 4e1a183

Browse files
committed
chore: revive maintenance release
1 parent f30a37d commit 4e1a183

15 files changed

Lines changed: 189 additions & 99 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
22+
- name: Install dependencies
23+
run: npm install --legacy-peer-deps --ignore-scripts
24+
25+
- name: Build
26+
run: npm run build

App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default class App extends React.Component {
113113
const height = 256;
114114
return (
115115
<ScrollableTabView renderTabBar={this.renderTabBar}>
116-
{chartConfigs.map(chartConfig => {
116+
{chartConfigs.map((chartConfig, index) => {
117117
const labelStyle = {
118118
color: chartConfig.color(),
119119
marginVertical: 10,
@@ -126,7 +126,7 @@ export default class App extends React.Component {
126126
};
127127
return (
128128
<ScrollView
129-
key={Math.random()}
129+
key={`chart-config-${index}`}
130130
style={{
131131
backgroundColor: chartConfig.backgroundColor
132132
}}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## v6.12.1
4+
5+
- prepare next patch release after v6.12.0
6+
- add GitHub Actions build verification
7+
- replace unstable random React keys in chart renders
8+
- prefix generated SVG definition IDs to avoid collisions across charts
9+
- replace ContributionGraph's unsafe prop lifecycle with componentDidUpdate
10+
- fix stale root source exports
11+
312
## v6.11
413

514
- added a prop to customize vertical labels heigh

contributing.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,43 @@
44

55
Suggestions and pull requests are highly encouraged! Have a look at the [open issues](https://github.com/indiespirit/react-native-chart-kit/issues).
66

7+
## Branch names
8+
9+
Use lowercase kebab-case branch names in this format:
10+
11+
```sh
12+
<type>/<short-summary>
13+
```
14+
15+
Use these branch types:
16+
17+
- `fix/` for user-visible bug fixes
18+
- `feat/` for new public functionality
19+
- `docs/` for documentation-only changes
20+
- `ci/` for automation and CI changes
21+
- `chore/` for maintenance, release hygiene, and dependency upkeep
22+
- `refactor/` for internal changes that do not intentionally change behavior
23+
- `release/` for version bump and publishing prep
24+
25+
Include an issue number when the branch maps to a specific issue, for example `fix/733-svg-gradient-ids`. Keep each branch scoped to one pull request.
26+
727
## Workflow
828

929
First clone:
1030

1131
```sh
1232
git clone git@github.com:indiespirit/react-native-chart-kit.git
1333
cd react-native-chart-kit
14-
yarn install
34+
npm install --legacy-peer-deps
1535
```
1636

17-
In order to run it, you are gonna have to flip values for "main" and "_main" in package json. This is nessesary because both npm and expo have a notion of a main file, but for npm it's the file that you run when you import this library in your app; and for expo it's the file that it uses to display the example app.
37+
In order to run it, you are gonna have to flip values for "main" and "\_main" in package json. This is nessesary because both npm and expo have a notion of a main file, but for npm it's the file that you run when you import this library in your app; and for expo it's the file that it uses to display the example app.
1838

1939
Don't forget to flip it back before commiting.
2040

2141
**After you update fix the package.json**
2242

2343
```sh
24-
yarn start # And get you expo app ready on your phone
44+
npm start # And get your Expo app ready on your phone
45+
npm run build # Verify the package build
2546
```
26-

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import AbstractChart from "./src/abstract-chart";
1+
import AbstractChart from "./src/AbstractChart";
22
import LineChart from "./src/line-chart";
3-
import BarChart from "./src/bar-chart";
4-
import PieChart from "./src/pie-chart";
5-
import ProgressChart from "./src/progress-chart";
3+
import BarChart from "./src/BarChart";
4+
import PieChart from "./src/PieChart";
5+
import ProgressChart from "./src/ProgressChart";
66
import ContributionGraph from "./src/contribution-graph";
7-
import StackedBarChart from "./src/stackedbar-chart";
7+
import StackedBarChart from "./src/StackedBarChart";
88

99
export {
1010
AbstractChart,

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "react-native-chart-kit",
3-
"version": "6.11.0",
3+
"version": "6.12.1",
44
"devDependencies": {
5+
"@types/react": "16.14.8",
56
"@types/react-native": "^0.62.13",
67
"babel-eslint": "10.x",
78
"babel-plugin-module-resolver": "^3.1.1",
@@ -24,7 +25,7 @@
2425
"react-native-scrollable-tab-view": "^1.0.0",
2526
"react-native-svg": "11.0.1",
2627
"react-test-renderer": "16.7.0",
27-
"typescript": "^3.9.5"
28+
"typescript": "^5.4.5"
2829
},
2930
"_main": "./node_modules/expo/AppEntry.js",
3031
"main": "./dist/index.js",
@@ -38,10 +39,10 @@
3839
"android": "expo start --android",
3940
"ios": "expo start --ios",
4041
"test": "jest",
42+
"typecheck": "tsc --noEmit",
4143
"build": "tsc",
4244
"dev": "tsc --watch",
43-
"prepublish": "yarn build",
44-
"prepare": "yarn build"
45+
"prepare": "npm run build"
4546
},
4647
"jest": {
4748
"preset": "jest-expo"
@@ -67,6 +68,9 @@
6768
"type": "git",
6869
"url": "https://github.com/indiespirit/react-native-chart-kit"
6970
},
71+
"overrides": {
72+
"@types/react": "16.14.8"
73+
},
7074
"resolutions": {
7175
"@types/react": "16.14.8"
7276
}

src/AbstractChart.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,27 @@ export type AbstractChartState = {};
3838

3939
export const DEFAULT_X_LABELS_HEIGHT_PERCENTAGE = 0.75;
4040

41+
let nextChartId = 0;
42+
4143
class AbstractChart<
4244
IProps extends AbstractChartProps,
4345
IState extends AbstractChartState
4446
> extends Component<AbstractChartProps & IProps, AbstractChartState & IState> {
47+
private chartId = nextChartId++;
48+
49+
protected getGradientId = (id: string) => {
50+
return `chart-kit-${this.chartId}-${id}`;
51+
};
52+
53+
protected getGradientUrl = (id: string) => {
54+
return `url(#${this.getGradientId(id)})`;
55+
};
56+
4557
calcScaler = (data: number[]) => {
4658
if (this.props.fromZero && this.props.fromNumber) {
47-
return Math.max(...data, this.props.fromNumber) - Math.min(...data, 0) || 1;
59+
return (
60+
Math.max(...data, this.props.fromNumber) - Math.min(...data, 0) || 1
61+
);
4862
} else if (this.props.fromZero) {
4963
return Math.max(...data, 0) - Math.min(...data, 0) || 1;
5064
} else if (this.props.fromNumber) {
@@ -148,7 +162,7 @@ class AbstractChart<
148162
const y = (basePosition / count) * i + paddingTop;
149163
return (
150164
<Line
151-
key={Math.random()}
165+
key={`horizontal-line-${i}`}
152166
x1={paddingRight}
153167
y1={y}
154168
x2={width}
@@ -169,7 +183,7 @@ class AbstractChart<
169183
} = config;
170184
return (
171185
<Line
172-
key={Math.random()}
186+
key="horizontal-line"
173187
x1={paddingRight}
174188
y1={height * verticalLabelsHeightPercentage + paddingTop}
175189
x2={width}
@@ -227,7 +241,7 @@ class AbstractChart<
227241
<Text
228242
rotation={horizontalLabelRotation}
229243
origin={`${x}, ${y}`}
230-
key={Math.random()}
244+
key={`horizontal-label-${i}-${yLabel}`}
231245
x={x}
232246
textAnchor="end"
233247
y={y}
@@ -298,7 +312,7 @@ class AbstractChart<
298312
<Text
299313
origin={`${x}, ${y}`}
300314
rotation={verticalLabelRotation}
301-
key={Math.random()}
315+
key={`vertical-label-${i}-${label}`}
302316
x={x}
303317
y={y}
304318
textAnchor={verticalLabelRotation === 0 ? "middle" : "start"}
@@ -336,7 +350,7 @@ class AbstractChart<
336350
(_, i) => {
337351
return (
338352
<Line
339-
key={Math.random()}
353+
key={`vertical-line-${i}`}
340354
x1={Math.floor(
341355
((width - paddingRight) / (data.length / yAxisInterval)) * i +
342356
paddingRight
@@ -364,7 +378,7 @@ class AbstractChart<
364378
"height" | "paddingRight" | "paddingTop" | "verticalLabelsHeightPercentage"
365379
>) => (
366380
<Line
367-
key={Math.random()}
381+
key="vertical-line"
368382
x1={Math.floor(paddingRight)}
369383
y1={0}
370384
x2={Math.floor(paddingRight)}
@@ -469,7 +483,7 @@ class AbstractChart<
469483
return (
470484
<Defs>
471485
<LinearGradient
472-
id="backgroundGradient"
486+
id={this.getGradientId("backgroundGradient")}
473487
x1={0}
474488
y1={height}
475489
x2={width}
@@ -487,10 +501,10 @@ class AbstractChart<
487501
stopOpacity={toOpacity}
488502
/>
489503
</LinearGradient>
490-
{useShadowColorFromDataset ? (
504+
{useShadowColorFromDataset && data ? (
491505
data.map((dataset, index) => (
492506
<LinearGradient
493-
id={`fillShadowGradientFrom_${index}`}
507+
id={this.getGradientId(`fillShadowGradientFrom_${index}`)}
494508
key={`${index}`}
495509
x1={0}
496510
y1={0}
@@ -518,7 +532,7 @@ class AbstractChart<
518532
))
519533
) : (
520534
<LinearGradient
521-
id="fillShadowGradientFrom"
535+
id={this.getGradientId("fillShadowGradientFrom")}
522536
x1={0}
523537
y1={0}
524538
x2={0}

0 commit comments

Comments
 (0)