@@ -27,7 +27,6 @@ export const remapAndFillData = ({
2727 yMax : number
2828 mainSeriesStartEndLabels : [ string | null , string | null ]
2929 comparisonSeriesStartEndLabels : [ string | null , string | null ]
30- startOfLastPartialSlice : null | number
3130} => {
3231 const totalBucketCount = Math . max (
3332 data . meta . comparison_time_label_result_indices ?. length ?? 0 ,
@@ -41,8 +40,6 @@ export const remapAndFillData = ({
4140 let firstComparisonTimeLabel : null | string = null
4241 let lastComparisonTimeLabel : null | string = null
4342
44- let startOfLastPartialSlice : null | number = null
45-
4643 const remappedData : GraphDatum [ ] = new Array ( totalBucketCount )
4744 . fill ( null )
4845 . map ( ( _ , index ) => {
@@ -75,14 +72,6 @@ export const remapAndFillData = ({
7572 ? true
7673 : false
7774
78- if ( isPartial ) {
79- startOfLastPartialSlice = index
80- } else {
81- // if there is a full period after a partial slice,
82- // it's not a partial slice anchored at the end of the series
83- startOfLastPartialSlice = null
84- }
85-
8675 if ( firstTimeLabel === null ) {
8776 firstTimeLabel = timeLabel
8877 }
@@ -159,7 +148,6 @@ export const remapAndFillData = ({
159148 } )
160149
161150 return {
162- startOfLastPartialSlice,
163151 remappedData,
164152 yMax,
165153 mainSeriesStartEndLabels : [ firstTimeLabel , lastTimeLabel ] ,
@@ -170,21 +158,24 @@ export const remapAndFillData = ({
170158 }
171159}
172160
173- const METRICS_WITH_CHANGE_IN_PERCENTAGE_POINTS = [
161+ export const METRICS_WITH_CHANGE_IN_PERCENTAGE_POINTS = [
174162 'bounce_rate' ,
175163 'exit_rate' ,
176164 'conversion_rate'
177165 // 'group_conversion_rate'
178166]
179167
180- const getChangeInPercentagePoints = (
168+ export const getChangeInPercentagePoints = (
181169 value : number ,
182170 comparisonValue : number
183171) : number => {
184172 return value - comparisonValue
185173}
186174
187- const getRelativeChange = ( value : number , comparisonValue : number ) : number => {
175+ export const getRelativeChange = (
176+ value : number ,
177+ comparisonValue : number
178+ ) : number => {
188179 if ( comparisonValue === 0 && value > 0 ) {
189180 return 100
190181 }
@@ -195,6 +186,49 @@ const getRelativeChange = (value: number, comparisonValue: number): number => {
195186 return Math . round ( ( ( value - comparisonValue ) / comparisonValue ) * 100 )
196187}
197188
189+ type Slice = {
190+ startIndexInclusive : number
191+ endIndexExclusive : number
192+ isPartialLine : boolean
193+ }
194+
195+ // slices [B, A, A, A, A, B, B, B] to [0, 1], [1, 5], [5, 8]
196+ export function getSlices (
197+ data : { value : number | null ; isPartial : boolean | null } [ ]
198+ ) : Slice [ ] {
199+ const slices : Slice [ ] = [ ]
200+ let currentSlice : Slice | null = null
201+
202+ data . forEach ( ( datum , index ) => {
203+ if ( datum . value !== null ) {
204+ if ( ! currentSlice ) {
205+ currentSlice = {
206+ startIndexInclusive : index ,
207+ endIndexExclusive : index + 1 ,
208+ isPartialLine : datum . isPartial ?? false
209+ }
210+ } else {
211+ if ( datum . isPartial === currentSlice . isPartialLine ) {
212+ currentSlice . endIndexExclusive = index + 1
213+ } else {
214+ slices . push ( currentSlice )
215+ currentSlice = {
216+ startIndexInclusive : index ,
217+ endIndexExclusive : index + 1 ,
218+ isPartialLine : datum . isPartial ?? false
219+ }
220+ }
221+ }
222+ }
223+ } )
224+
225+ if ( currentSlice ) {
226+ slices . push ( currentSlice )
227+ }
228+
229+ return slices
230+ }
231+
198232/**
199233 * A data point for the graph and tooltip.
200234 * It's x position is its index in `GraphDatum[]` array.
0 commit comments