-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from lad-tech/feat/169-custom-color-and-multi…
…ple-lines feat(chart): custom colors and multiply lines #169
- Loading branch information
Showing
20 changed files
with
398 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {PathProps, Skia, SkiaDefaultProps} from '@shopify/react-native-skia'; | ||
import {interpolateColor, useDerivedValue} from 'react-native-reanimated'; | ||
|
||
import {IChartTransition, ISharedChartState} from '../types'; | ||
import {IPeriodsWithPaths} from '../utils'; | ||
|
||
import Line from './Line'; | ||
|
||
interface IChartProps | ||
extends Omit<SkiaDefaultProps<PathProps, 'start' | 'end'>, 'path'> { | ||
periodsWithPaths: IPeriodsWithPaths; | ||
index: number; | ||
width: number; | ||
transition: IChartTransition; | ||
state: ISharedChartState; | ||
lineColors?: string[] | undefined; | ||
} | ||
|
||
export const LineOfPeriod = ({ | ||
periodsWithPaths, | ||
index, | ||
width, | ||
transition, | ||
state, | ||
}: IChartProps) => { | ||
const chartPath = useDerivedValue(() => { | ||
const {current, next} = state.value; | ||
|
||
const start = | ||
periodsWithPaths[current]?.lines[index]?.path ?? Skia.Path.Make(); | ||
const end = periodsWithPaths[next]?.lines[index]?.path ?? Skia.Path.Make(); | ||
|
||
if (end.isInterpolatable(start)) { | ||
return end.interpolate(start, transition.value)!; | ||
} | ||
|
||
return end; | ||
}); | ||
|
||
const colors = useDerivedValue(() => { | ||
const {current, next} = state.value; | ||
const start = periodsWithPaths[current]?.lines[index]?.colors ?? []; | ||
const end = periodsWithPaths[next]?.lines[index]?.colors ?? []; | ||
|
||
return end.map((endColor, i) => | ||
interpolateColor( | ||
transition.value, | ||
[0, 1], | ||
[start[i] ?? endColor, endColor], | ||
), | ||
); | ||
}); | ||
|
||
return <Line colors={colors} width={width} chartPath={chartPath} />; | ||
}; | ||
|
||
export default LineOfPeriod; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {SkPath} from '@shopify/react-native-skia'; | ||
import {useDerivedValue} from 'react-native-reanimated'; | ||
|
||
import {IPeriodsWithPaths} from '../utils'; | ||
import {IChartTransition, ISharedChartState} from '../types'; | ||
|
||
import LineOfPeriod from './LineOfPeriod'; | ||
|
||
export interface ILine { | ||
name?: string | undefined; | ||
path: SkPath; | ||
colors?: string[] | undefined; | ||
} | ||
|
||
interface ILinesProps { | ||
periodsWithPaths: IPeriodsWithPaths; | ||
width: number; | ||
transition: IChartTransition; | ||
state: ISharedChartState; | ||
} | ||
|
||
export const Lines = ({ | ||
periodsWithPaths, | ||
width, | ||
state, | ||
transition, | ||
}: ILinesProps) => { | ||
const lines = useDerivedValue(() => { | ||
const {next} = state.value; | ||
|
||
const end = periodsWithPaths[next]?.lines ?? []; | ||
|
||
return end; | ||
}); | ||
|
||
return ( | ||
<> | ||
{lines.value.map(({colors}, index) => ( | ||
<LineOfPeriod | ||
key={index} | ||
index={index} | ||
periodsWithPaths={periodsWithPaths} | ||
width={width} | ||
lineColors={colors} | ||
state={state} | ||
transition={transition} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.