Skip to content

Commit baf0f3a

Browse files
committed
Mucho updates
1 parent 10727fe commit baf0f3a

17 files changed

+5823
-279
lines changed

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: react-charts publish
2+
on:
3+
push:
4+
branches:
5+
- 'master'
6+
pull_request:
7+
8+
jobs:
9+
# test:
10+
# name: 'node ${{ matrix.node }} ${{ matrix.os }} '
11+
# runs-on: '${{ matrix.os }}'
12+
# strategy:
13+
# matrix:
14+
# os: [ubuntu-latest]
15+
# node: [12]
16+
# steps:
17+
# - uses: actions/setup-node@v1
18+
# with:
19+
# node-version: ${{ matrix.node }}
20+
# - uses: actions/checkout@v2
21+
# with:
22+
# fetch-depth: 1
23+
# - run: npm i -g yarn
24+
# - run: yarn --frozen-lockfile
25+
# - run: yarn test:ci
26+
27+
publish-module:
28+
name: 'Publish Module to NPM'
29+
# needs: test
30+
if: github.ref == 'refs/heads/master' #publish only when merged in master, not on PR
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v2
34+
with:
35+
fetch-depth: 1
36+
- uses: actions/setup-node@v1
37+
with:
38+
node-version: 12
39+
registry-url: https://registry.npmjs.org/
40+
- run: npm i -g yarn
41+
- run: yarn --frozen-lockfile
42+
- run: npx semantic-release@17
43+
env:
44+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
45+
GH_TOKEN: ${{secrets.GH_TOKEN}}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Enjoy this library? Try them all! [React Table](https://github.com/tannerlinsley
2929

3030
### [Become a Sponsor](https://github.com/sponsors/tannerlinsley/)
3131

32+
### React Charts 2.x.x is under-construction!
33+
34+
> **The `@latest` distribution of the `react-charts` npm package currently points to version `2.0.0-beta.7` and will remain there until 2.x.x is stable. To use the bleeding-edge version of React Charts, please install using the `@next` distribution channel as directed in the docs.**
35+
3236
## Features
3337

3438
- Line, Bar, Bubble, & Area Charts

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-charts",
3-
"version": "2.0.0-beta.6",
3+
"version": "2.0.0-beta.7",
44
"description": "Charts for React",
55
"author": "tannerlinsley",
66
"license": "MIT",
@@ -23,6 +23,12 @@
2323
"format": "prettier {src,src/**,example/src,example/src/**}/*.{md,js,jsx,tsx} --write",
2424
"doctoc": "npx doctoc --maxlevel 2 README.md"
2525
},
26+
"release": {
27+
"branches": [
28+
"master",
29+
"next"
30+
]
31+
},
2632
"files": [
2733
"dist"
2834
],
@@ -40,6 +46,7 @@
4046
"@babel/preset-env": "^7.9.0",
4147
"@babel/preset-react": "^7.9.4",
4248
"@rollup/plugin-node-resolve": "^7.1.1",
49+
"@rollup/plugin-replace": "^2.3.2",
4350
"@svgr/rollup": "^5.3.0",
4451
"babel-core": "7.0.0-bridge.0",
4552
"babel-eslint": "10.1.0",
@@ -57,6 +64,7 @@
5764
"eslint-plugin-react": "7.19.0",
5865
"eslint-plugin-react-hooks": "2.5.1",
5966
"eslint-plugin-standard": "^4.0.1",
67+
"jest": "^26.0.1",
6068
"react": "^16.13.1",
6169
"react-dom": "^16.13.1",
6270
"rollup": "^2.2.0",
@@ -65,6 +73,7 @@
6573
"rollup-plugin-node-resolve": "^5.2.0",
6674
"rollup-plugin-peer-deps-external": "^2.2.2",
6775
"rollup-plugin-size": "^0.2.2",
68-
"rollup-plugin-terser": "^5.3.0"
76+
"rollup-plugin-terser": "^5.3.0",
77+
"rollup-plugin-visualizer": "^4.0.4"
6978
}
7079
}

rollup.config.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import babel from 'rollup-plugin-babel'
22
import { terser } from 'rollup-plugin-terser'
33
import size from 'rollup-plugin-size'
4-
import resolve from '@rollup/plugin-node-resolve'
4+
import externalDeps from 'rollup-plugin-peer-deps-external'
5+
import resolve from 'rollup-plugin-node-resolve'
6+
import commonJS from 'rollup-plugin-commonjs'
7+
import visualizer from 'rollup-plugin-visualizer'
8+
import replace from '@rollup/plugin-replace'
59

610
const external = ['react']
711

@@ -10,6 +14,16 @@ const globals = {
1014
}
1115

1216
export default [
17+
{
18+
input: 'src/index.js',
19+
output: {
20+
file: 'dist/react-charts.mjs',
21+
format: 'es',
22+
sourcemap: true,
23+
},
24+
external,
25+
plugins: [resolve(), babel(), commonJS(), externalDeps()],
26+
},
1327
{
1428
input: 'src/index.js',
1529
output: {
@@ -18,7 +32,7 @@ export default [
1832
sourcemap: true,
1933
},
2034
external,
21-
plugins: [resolve(), babel(), terser()],
35+
plugins: [resolve(), babel(), commonJS(), externalDeps(), terser()],
2236
},
2337
{
2438
input: 'src/index.js',
@@ -30,7 +44,7 @@ export default [
3044
globals,
3145
},
3246
external,
33-
plugins: [resolve(), babel()],
47+
plugins: [resolve(), babel(), commonJS(), externalDeps()],
3448
},
3549
{
3650
input: 'src/index.js',
@@ -42,6 +56,15 @@ export default [
4256
globals,
4357
},
4458
external,
45-
plugins: [resolve(), babel(), terser(), size()],
59+
plugins: [
60+
replace({ 'process.env.NODE_ENV': `"production"`, delimiters: ['', ''] }),
61+
resolve(),
62+
babel(),
63+
commonJS(),
64+
externalDeps(),
65+
terser(),
66+
size(),
67+
visualizer(),
68+
],
4669
},
4770
]

size-plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"timestamp":1585154943498,"files":[{"filename":"react-charts.production.min.js","size":16475,"delta":16475}]}]
1+
[{"timestamp":1590788251975,"files":[{"filename":"react-charts.production.min.js","size":36178,"delta":19703}]},{"timestamp":1585154943498,"files":[{"filename":"react-charts.production.min.js","size":16475,"delta":16475}]}]

src/components/AxisLinear.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export default function AxisLinear({
216216
Math.max(tickSizeInner, tickSizeOuter) + // Add tick size
217217
tickPadding + // Add tick padding
218218
// Add the height of the largest label
219-
Math.max(...labelDims.map(d => Math.ceil(d.height)))
219+
Math.max(0, ...labelDims.map(d => Math.ceil(d.height)))
220220
} else {
221221
// Add height overflow from the first and last ticks
222222
top = Math.ceil(firstLabelDim.height / 2)
@@ -225,7 +225,7 @@ export default function AxisLinear({
225225
Math.max(tickSizeInner, tickSizeOuter) + // Add tick size
226226
tickPadding + // Add tick padding
227227
// Add the width of the largest label
228-
Math.max(...labelDims.map(d => Math.ceil(d.width)))
228+
Math.max(0, ...labelDims.map(d => Math.ceil(d.width)))
229229
}
230230

231231
const newDimensions = {

src/components/Chart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default function Chart({
9090
const onHoverRef = useLatestRef(onHover)
9191

9292
const responsiveElRef = React.useRef()
93-
const [{ width, height }] = useHyperResponsive(responsiveElRef)
93+
const { width, height } = useHyperResponsive(responsiveElRef)
9494

9595
getSeriesID = React.useCallback(Utils.normalizeGetter(getSeriesID), [
9696
getSeriesID,

src/components/TooltipRenderer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function TooltipRenderer(props) {
2727
formatTertiary,
2828
getStyle,
2929
dark,
30+
tooltip,
3031
} = props
3132

3233
if (!datum) {
@@ -65,6 +66,10 @@ export default function TooltipRenderer(props) {
6566
sortedGroupDatums.reverse()
6667
}
6768

69+
if (tooltip.invert) {
70+
sortedGroupDatums.reverse()
71+
}
72+
6873
const resolvedShowCount = showCount % 2 === 0 ? showCount : showCount + 1
6974
const length = sortedGroupDatums.length
7075

src/hooks/useHyperResponsive.js

Lines changed: 29 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,40 @@
1-
import React from "react";
2-
//
3-
import onResize from "../utils/detectElementResize";
1+
import React from 'react'
42

5-
export default function useHyperResponsive(ref) {
6-
const [{ width, height }, setState] = React.useState({
7-
width: 0,
8-
height: 0
9-
});
3+
import observeRect from '@reach/observe-rect'
104

11-
const dimsRef = React.useRef();
12-
dimsRef.current = {
13-
width,
14-
height
15-
};
5+
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect'
166

17-
const resize = React.useCallback(
18-
() => {
19-
if (!ref.current) {
20-
return;
21-
}
7+
export default function useRect(nodeRef) {
8+
const [element, setElement] = React.useState(nodeRef.current?.parentElement)
9+
const [rect, setRect] = React.useState({ width: 0, height: 0 })
10+
const initialRectSet = React.useRef(false)
2211

23-
const computed = window.getComputedStyle(ref.current.parentElement);
12+
useIsomorphicLayoutEffect(() => {
13+
if (nodeRef.current?.parentElement !== element) {
14+
setElement(nodeRef.current?.parentElement)
15+
}
16+
})
2417

25-
const {
26-
paddingTop,
27-
paddingBottom,
28-
paddingLeft,
29-
paddingRight,
30-
boxSizing,
31-
borderTopWidth,
32-
borderLeftWidth,
33-
borderRightWidth,
34-
borderBottomWidth
35-
} = computed;
18+
useIsomorphicLayoutEffect(() => {
19+
if (element && !initialRectSet.current) {
20+
initialRectSet.current = true
21+
setRect(element.getBoundingClientRect())
22+
}
23+
}, [element])
3624

37-
let { width: newWidth, height: newHeight } = computed;
25+
React.useEffect(() => {
26+
if (!element) {
27+
return
28+
}
3829

39-
newWidth = parseInt(newWidth);
40-
newHeight = parseInt(newHeight);
30+
const observer = observeRect(element, setRect)
4131

42-
if (boxSizing === "border-box") {
43-
newWidth -= parseInt(paddingLeft);
44-
newWidth -= parseInt(paddingRight);
45-
newHeight -= parseInt(paddingTop);
46-
newHeight -= parseInt(paddingBottom);
32+
observer.observe()
4733

48-
newWidth -= parseInt(borderLeftWidth);
49-
newWidth -= parseInt(borderRightWidth);
50-
newHeight -= parseInt(borderTopWidth);
51-
newHeight -= parseInt(borderBottomWidth);
52-
}
34+
return () => {
35+
observer.unobserve()
36+
}
37+
}, [element])
5338

54-
if (
55-
newWidth !== dimsRef.current.width ||
56-
newHeight !== dimsRef.current.height
57-
) {
58-
setState(() => ({
59-
width: newWidth,
60-
height: newHeight
61-
}));
62-
}
63-
},
64-
[ref]
65-
);
66-
67-
React.useEffect(
68-
() => {
69-
const stopListening = onResize(ref.current.parentElement, resize);
70-
return () => {
71-
stopListening();
72-
};
73-
},
74-
[ref, resize]
75-
);
76-
77-
return [{ width, height }];
39+
return { width: rect.width, height: rect.height }
7840
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react'
2+
3+
export default typeof window !== 'undefined'
4+
? React.useLayoutEffect
5+
: React.useEffect

0 commit comments

Comments
 (0)