Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to plot non-exact points (checkExactPoints prop) #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/AnimatedLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function AnimatedLineGraph({
verticalPadding = lineThickness,
TopAxisLabel,
BottomAxisLabel,
checkExactPoints = true,
...props
}: AnimatedLineGraphProps): React.ReactElement {
const [width, setWidth] = useState(0)
Expand Down Expand Up @@ -196,6 +197,7 @@ export function AnimatedLineGraph({
verticalPadding,
canvasHeight: height,
canvasWidth: width,
checkExactPoints,
}

if (shouldFillGradient) {
Expand Down
9 changes: 8 additions & 1 deletion src/CreateGraphPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ type GraphPathConfig = {
* Range of the graph's x and y-axis
*/
range: GraphPathRange
/**
* Boolean flag to check if the point is exact.
* If true, only exact points will be drawn. If false, all points will be drawn.
* Default is true.
*/
checkExactPoints: boolean
}

type GraphPathConfigWithGradient = GraphPathConfig & {
Expand Down Expand Up @@ -140,6 +146,7 @@ function createGraphPathBase({
canvasHeight: height,
canvasWidth: width,
shouldFillGradient,
checkExactPoints,
}: GraphPathConfigWithGradient | GraphPathConfigWithoutGradient):
| SkPath
| GraphPathWithGradient {
Expand Down Expand Up @@ -181,7 +188,7 @@ function createGraphPathBase({

if (index === graphData.length - 1 && pixel !== endX) continue

if (index !== 0 && index !== graphData.length - 1) {
if (checkExactPoints && index !== 0 && index !== graphData.length - 1) {
// Only draw point, when the point is exact
const exactPointX =
getXInRange(drawingWidth, graphData[index]!.date, range.x) +
Expand Down
6 changes: 6 additions & 0 deletions src/LineGraphProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ interface BaseLineGraphProps extends ViewProps {
* Enable the Fade-In Gradient Effect at the beginning of the Graph
*/
enableFadeInMask?: boolean
/**
* Boolean flag to check if the point is exact.
* If true, only exact points will be drawn. If false, all points will be drawn.
* Default is true.
*/
checkExactPoints?: boolean
}

export type StaticLineGraphProps = BaseLineGraphProps & {
Expand Down
4 changes: 3 additions & 1 deletion src/StaticLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function StaticLineGraph({
lineThickness = 3,
enableFadeInMask,
style,
checkExactPoints = true,
...props
}: StaticLineGraphProps): React.ReactElement {
const [width, setWidth] = useState(0)
Expand Down Expand Up @@ -49,8 +50,9 @@ export function StaticLineGraph({
canvasWidth: width,
horizontalPadding: lineThickness,
verticalPadding: lineThickness,
checkExactPoints,
}),
[height, lineThickness, pathRange, pointsInRange, width]
[checkExactPoints, height, lineThickness, pathRange, pointsInRange, width]
)

const gradientColors = useMemo(
Expand Down