Skip to content

Commit 1dc7241

Browse files
committed
fix: protect againts no data provided
1 parent e22fb97 commit 1dc7241

File tree

2 files changed

+24
-97
lines changed

2 files changed

+24
-97
lines changed

docs/src/pages/docs/api.md

Lines changed: 19 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,6 @@ title: API
55

66
> Complete documentation is **coming soon**. For now, please refer to the examples for any missing documentation.
77
8-
React Charts exposes these top-level exports:
9-
10-
- `Chart` - The Chart component used to render charts
11-
- Series Type Components
12-
- `Line`
13-
- `Bar`
14-
- `Bubble`
15-
- `Area`
16-
- Curve Functions
17-
- `curveBasisClosed`
18-
- `curveBasisOpen`
19-
- `curveBasis`
20-
- `curveBundle`
21-
- `curveCardinalClosed`
22-
- `curveCardinalOpen`
23-
- `curveCardinal`
24-
- `curveCatmullRomClosed`
25-
- `curveCatmullRomOpen`
26-
- `curveCatmullRom`
27-
- `curveLinearClosed`
28-
- `curveLinear`
29-
- `curveMonotoneX`
30-
- `curveMonotoneY`
31-
- `curveNatural`
32-
- `curveStep`
33-
- `curveStepAfter`
34-
- `curveStepBefore`
35-
- Position Constants
36-
- `positionTop`
37-
- `positionRight`
38-
- `positionBottom`
39-
- `positionLeft`
40-
- Grouping Constants
41-
- `groupingSingle`
42-
- `groupingSeries`
43-
- `groupingPrimary`
44-
- `groupingSecondary`
45-
- Tooltip Alignment Constants
46-
- `alignAuto`
47-
- `alignRight`
48-
- `alignTopRight`
49-
- `alignBottomRight`
50-
- `alignLeft`
51-
- `alignTopLeft`
52-
- `alignBottomLeft`
53-
- `alignTop`
54-
- `alignBottom`
55-
- Axis Type Constants
56-
- `axisTypeOrdinal`
57-
- `axisTypeTime`
58-
- `axisTypeUtc`
59-
- `axisTypeLinear`
60-
- `axisTypeLog`
61-
- Tooltip Anchor Constants
62-
- `anchorPointer`
63-
- `anchorClosest`
64-
- `anchorCenter`
65-
- `anchorTop`
66-
- `anchorBottom`
67-
- `anchorLeft`
68-
- `anchorRight`
69-
- `anchorGridTop`
70-
- `anchorGridBottom`
71-
- `anchorGridLeft`
72-
- `anchorGridRight`
73-
- Focus Mode Constants
74-
- `focusAuto`
75-
- `focusClosest`
76-
- `focusElement`
77-
788
## Memoize your Props!
799

8010
As you'll see in every example, the React Charts `<Chart>` component expects all props and options to be memoized using either `React.useMemo` or `React.useCallback`. While passing an unmemoized option/prop to the `<Chart>` component won't severly break any visible functionality, your charts will be severly non-performant. Internally, React Charts uses the immutable nature of thes options/props to detect changes to the configuration and update accordingly.
@@ -158,16 +88,17 @@ function MyChart() {
15888
}
15989
```
16090

161-
## Axes & Scales
91+
## Axes
16292

163-
React Charts supports an `axes` prop that handles both the underlying scale and visual rendering. These axes can be combined and configured to plot data in many ways. To date, we have the following scale types available:
93+
React Charts supports an `axes` prop that handles both the underlying scale and visual rendering of all axes. Multiple axes can be combined and configured to plot data however you'd like.
16494

165-
- Cartesian
166-
- `linear` - A continuous axis used for plotting numerical data on an evenly distributed scale. Works well both as a **primary and secondary** axis.
167-
- `ordinal` - A banded axis commonly used to plot categories or ordinal information. Works well as the **primary** axis for bar charts.
168-
- `time` - A continuous axis used for plotting localized times and dates on an evenly distributed scale. Works well as a **primary** axis.
169-
- `utc` - Similar to the `time` scale, but supports UTC datetimes instead of localized datetimes. Works well as a **primary** axis.
170-
- `log` - A continuous axis used for plotting numerical data on a logarithmically distributed scale. Works well as a **secondary** axis
95+
To date, we have the following scale types available:
96+
97+
- `linear` - A continuous axis used for plotting numerical data on an evenly distributed scale. Works well both as a **primary and secondary** axis.
98+
- `ordinal` - A banded axis commonly used to plot categories or ordinal information. Works well as the **primary** axis for bar charts.
99+
- `time` - A continuous axis used for plotting localized times and dates on an evenly distributed scale. Works well as a **primary** axis.
100+
- `utc` - Similar to the `time` scale, but supports UTC datetimes instead of localized datetimes. Works well as a **primary** axis.
101+
- `log` - A continuous axis used for plotting numerical data on a logarithmically distributed scale. Works well as a **secondary** axis
171102

172103
Axes are a required component of a React Chart and can used like so:
173104

@@ -196,8 +127,6 @@ function MyChart() {
196127
}
197128
```
198129

199-
For more information on usage and API, see the [`axes` prop](#axes)
200-
201130
## Series Types
202131

203132
- Cartesian
@@ -222,12 +151,6 @@ function MyChart() {
222151

223152
**`<Chart />` Props**
224153

225-
- `getLabel` - A `memoized` function that returns the series label
226-
- `getSeriesId` - A `memoized` function that returns the series ID
227-
- `getDatums` - A `memoized` function that returns the series' datums array
228-
- `getPrimary` - A `memoized` function that returns the datum's primary value
229-
- `getSecondary` - A `memoized` function that returns the datum's secondary value
230-
- `getR` - A `memoized` function that returns the datum's radius value (where applicable)
231154
- `series({} or function)` - A `memoized` object (or function that returns an object) of series options that correspond to all or each of the series in the dataset.
232155
`type` - **string** - The series type (Line, Bar, Bubble, Area, etc)
233156
`showPoints` - **bool** - If true, will show points for datums where applicable
@@ -237,18 +160,18 @@ function MyChart() {
237160
- `axis{}` - An axis object
238161
- `primary` **bool** - Denotes whether this axis is the primary axis
239162
- `type` **oneOf, required** - The type of scale for this axis
240-
- `axisTypeOrdinal`
241-
- `axisTypeTime`
242-
- `axisTypeUtc`
243-
- `axisTypeLinear`
244-
- `axisTypeLog`
163+
- `ordinal`
164+
- `time`
165+
- `utc`
166+
- `linear`
167+
- `log`
245168
- `position` **oneOf, required** - The cartesian position of this axis
246-
- `positionTop`
247-
- `positionRight`
248-
- `positionBottom`
249-
- `positionLeft`
169+
- `top`
170+
- `right`
171+
- `bottom`
172+
- `left`
250173
- `invert` **bool** - Whether this axis's scale should be inverted
251-
- `primaryAxisID` **string** - If multiple secondary axes are used, which primary axis ID does this axis refer to?
174+
- `primaryAxisID` **string** - If multiple primary axes are used, which primary axis ID does this axis refer to?
252175
- `min` **number** - The suggested minimum for this axis
253176
- `max` **number** - The suggested maximum for this axis
254177
- `hardMin` **number** - The hard/forced minimum for this axis

src/components/AxisLinear.useMeasure.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ export default function useMeasure({
165165
let newTickLabelSkipIndices = []
166166

167167
// Visual Skipping of time-based axis labels if they overlap (rotation not included)
168-
if (!rotation && [axisTypeTime, axisTypeUtc].includes(type)) {
168+
if (
169+
!rotation &&
170+
[axisTypeTime, axisTypeUtc].includes(type) &&
171+
realLabelDims?.length
172+
) {
169173
realLabelDims.reduce((last, d) => {
170174
if (
171175
round(last.right, 5, Math.ceil) >

0 commit comments

Comments
 (0)