Comments (5)
Gonna close this, as I don't foresee it being resolved any time soon.
As Sami suggests, the user-land solution is pretty simple:
data.length > 0
? <Trend data={data} />
: <SomeFallbackComponent />
from react-trend.
Yeah, a flat line would indeed be inaccurate. The correct behaviour as far as I see it is to not render a graph at all if there's less than 2 points, without crashing/erroring. A fallback could be nice, although part of me feels that it's more the end-user's concern.
from react-trend.
Is this an intended use case for react-trend? I know it's typically used for line graphs. This is the source code of Trend.js
on line 118-121 indicating why it won't render:
// We need at least 2 points to draw a graph.
if (!data || data.length < 2) {
return null;
}
from react-trend.
Is this an intended use case for react-trend?
Don't see why it wouldn't be, since I just need a spark line to show up/down trends. Would also be an issue depending on how logging is done for uptime of new servers/activity of new users.
It's more that it has a fairly destructive exit if length < 2
Work around is to just duplicate single values:
return <Trend data={props.data.length > 1 ? props.data : props.data.concat(props.data)}/>
from react-trend.
Ah, right. Yeah, this was an oversight; from a purely mathematical perspective, you can't have a line with only 1 point, so I assumed any attempt to draw a line with a single data point would be a mistake. Never considered data that resets at the start of a period.
That said, I almost feel like a flat line is a little misleading... It gives the impression that the data is flat, when in actuality the trend might be increasing or decreasing from the previous period.
At any rate, I certainly don't think it should crash; my proposed solution would be to just render nothing. We could even have a prop that takes an element to render when not enough data is available, so you could render a fallback:
<Trend
data={...}
fallback={<h1>🚫</h1>}
/>
@samijaber thoughts?
from react-trend.
Related Issues (13)
- React Native compatibility HOT 1
- How to set the background fill along with the stroke? HOT 2
- Events HOT 2
- Error when using with SSR HOT 1
- Add Typescript typings HOT 3
- [Feature Request] Support angle in gradient HOT 1
- Dot on the graph HOT 1
- React dependency warning? HOT 1
- Getting an error while using React Trend with React Starter Kit HOT 2
- unsplash link not working HOT 2
- Gradient props overwritten HOT 1
- Errors when trend is flat HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-trend.