@@ -7,13 +7,14 @@ import Chart, {
77 type ErrorSegment ,
88} from 'react-native-d3-chart'
99
10- import { measurementsRecords , Measurement } from './data'
10+ import { buildSlices } from './helpers/buildSlices'
11+ import { generateTimeSeriesData } from './helpers/generateTimeSeriesData'
12+ import { temperatureData , visits } from './mockData'
1113import type { HighlightPayload } from '../../src/types'
1214
1315type TimeDomainType = 'hour' | 'day' | 'week' | 'month'
1416
1517const TIME_DOMAIN_TYPES : TimeDomainType [ ] = [ 'hour' , 'day' , 'week' , 'month' ]
16- const MEASUREMENT_KEYS = Object . values ( Measurement )
1718
1819const chartColors : ChartProps [ 'colors' ] = {
1920 background : '#fff' ,
@@ -24,6 +25,95 @@ const chartColors: ChartProps['colors'] = {
2425 highlightTime : '#444' ,
2526}
2627
28+ enum Measurement {
29+ Temperature = 'Temperature' ,
30+ Blue = 'Blue' ,
31+ Green = 'Green' ,
32+ Pink = 'Pink' ,
33+ Visits = 'Visits' ,
34+ VisitRate = 'Visit Rate' ,
35+ }
36+
37+ const measurementKeys = Object . values ( Measurement )
38+ const measurementsRecords : Record < Measurement , Dataset > = {
39+ [ Measurement . Temperature ] : {
40+ unit : '°C' ,
41+ points : temperatureData ,
42+ decimals : 0 ,
43+ areaColor : '#c4deff' ,
44+ color : {
45+ type : 'thresholds' ,
46+ baseColor : '#3d91ff' ,
47+ gradientBlur : 2 ,
48+ thresholds : [
49+ { value : 32 , color : '#bb2222' } ,
50+ { value : 24 , color : '#ffc400' } ,
51+ { value : 16 , color : '#089851' } ,
52+ { value : 10 , color : '#9ceeff' } ,
53+ { value : 0 , color : '#00d5ff' } ,
54+ ] ,
55+ } ,
56+ measurementName : Measurement . Temperature ,
57+ } ,
58+ [ Measurement . Blue ] : {
59+ unit : 'l' ,
60+ points : generateTimeSeriesData ( {
61+ startingValue : 160 ,
62+ minimum : 50 ,
63+ radomFactor : 6 ,
64+ } ) ,
65+ decimals : 0 ,
66+ color : '#66e' ,
67+ measurementName : Measurement . Blue ,
68+ } ,
69+ [ Measurement . Green ] : {
70+ unit : 'kg' ,
71+ points : generateTimeSeriesData ( ) ,
72+ decimals : 0 ,
73+ color : '#6e6' ,
74+ measurementName : Measurement . Green ,
75+ } ,
76+ [ Measurement . Pink ] : {
77+ unit : 'm/s' ,
78+ points : generateTimeSeriesData ( {
79+ startingValue : 20 ,
80+ minimum : 100 ,
81+ } ) ,
82+ decimals : 1 ,
83+ color : '#e0e' ,
84+ measurementName : Measurement . Pink ,
85+ } ,
86+
87+ [ Measurement . VisitRate ] : {
88+ unit : 'visits/h' ,
89+ points : visits . movingAveregeData ,
90+ slices : buildSlices ( 'horizontal' , {
91+ end : visits . latestTimestamp ,
92+ start : visits . oldestTimestamp ,
93+ yellowThreshold : visits . averageVisitRatePerHour ,
94+ redThreshold : visits . averageVisitRatePerHour * 1.1 ,
95+ } ) ,
96+ decimals : 0 ,
97+ color : '#000' ,
98+ areaColor : null ,
99+ measurementName : Measurement . VisitRate ,
100+ } ,
101+ [ Measurement . Visits ] : {
102+ unit : 'pulses' ,
103+ points : visits . culmulativeData ,
104+ decimals : 0 ,
105+ color : '#000' ,
106+ areaColor : null ,
107+ measurementName : 'Visits cumulative' ,
108+ slices : buildSlices ( 'axial' , {
109+ end : visits . latestTimestamp ,
110+ start : visits . oldestTimestamp ,
111+ yellowThreshold : visits . averageVisitRatePerHour ,
112+ redThreshold : visits . averageVisitRatePerHour * 1.1 ,
113+ } ) ,
114+ } ,
115+ }
116+
27117export default function App ( ) {
28118 const [ width , setWidth ] = useState < number > ( 0 )
29119 const height = width * 1.1
@@ -104,11 +194,6 @@ export default function App() {
104194 [ enabledMeasurements , errorSegments ]
105195 )
106196
107- const xDividerConfig = useMemo < ChartProps [ 'xDividerConfig' ] > (
108- ( ) => ( { type : 'segment' , color : '#F2F2FF' } ) ,
109- [ ]
110- )
111-
112197 return (
113198 < View
114199 style = { styles . holder }
@@ -138,9 +223,9 @@ export default function App() {
138223 timeDomain = { timeDomain }
139224 marginHorizontal = { PADDING }
140225 errorSegments = { errorSegments }
141- xDividerConfig = { xDividerConfig }
142226 noDataString = "No data available"
143227 highlightValuePosition = { highlightValuePosition }
228+ xDividerConfig = { { type : 'segment' , color : '#F2F2FF' } }
144229 onHighlightChanged = { setCurrentHighlight }
145230 />
146231 < View style = { styles . spacer } />
@@ -172,7 +257,7 @@ export default function App() {
172257 ) ) }
173258 </ View >
174259 { /* Measurement toggles */ }
175- { MEASUREMENT_KEYS . map ( ( measurement ) => (
260+ { measurementKeys . map ( ( measurement ) => (
176261 < View key = { measurement } style = { styles . switchContainer } >
177262 < Switch
178263 value = { enabledMeasurements . includes ( measurement ) }
@@ -187,11 +272,11 @@ export default function App() {
187272 return prev . filter ( ( m ) => m !== measurement )
188273
189274 // only one measurement was enabled, switch to next one
190- const currentIndex = MEASUREMENT_KEYS . findIndex (
275+ const currentIndex = measurementKeys . findIndex (
191276 ( m ) => m === measurement
192277 )
193- const nextIndex = ( currentIndex + 1 ) % MEASUREMENT_KEYS . length
194- const nextMeasurement = MEASUREMENT_KEYS [ nextIndex ] !
278+ const nextIndex = ( currentIndex + 1 ) % measurementKeys . length
279+ const nextMeasurement = measurementKeys [ nextIndex ] !
195280
196281 return [ nextMeasurement ]
197282 } )
0 commit comments