@ -34,8 +34,49 @@ export const LoadingState = {
isLoadedOrRefreshing : function ( state ) { return [ this . loaded , this . refreshing ] . includes ( state ) }
}
const truncateToPresentIndex = function ( array , presentIndex ) {
return array . slice ( 0 , presentIndex )
const buildComparisonDataset = function ( comparisonPlot , presentIndex ) {
if ( ! comparisonPlot ) return [ ]
let data = [ ... comparisonPlot ]
if ( presentIndex ) {
const dashedPartIncludedIndex = presentIndex + 1
data = data . slice ( 0 , dashedPartIncludedIndex )
}
return [ {
data : data ,
borderColor : 'rgba(60,70,110,0.2)' ,
pointBackgroundColor : 'rgba(60,70,110,0.2)' ,
pointHoverBackgroundColor : 'rgba(60, 70, 110)' ,
yAxisID : 'yComparison' ,
} ]
}
const buildDashedDataset = function ( plot , presentIndex ) {
if ( ! presentIndex ) return [ ]
const dashedPart = plot . slice ( presentIndex - 1 , presentIndex + 1 ) ;
const dashedPlot = ( new Array ( presentIndex - 1 ) ) . concat ( dashedPart )
return [ {
data : dashedPlot ,
borderDash : [ 3 , 3 ] ,
borderColor : 'rgba(101,116,205)' ,
pointHoverBackgroundColor : 'rgba(71, 87, 193)' ,
yAxisID : 'y' ,
} ]
}
const buildMainPlotDataset = function ( plot , presentIndex ) {
const data = presentIndex ? plot . slice ( 0 , presentIndex ) : plot
return [ {
data : data ,
borderColor : 'rgba(101,116,205)' ,
pointBackgroundColor : 'rgba(101,116,205)' ,
pointHoverBackgroundColor : 'rgba(71, 87, 193)' ,
yAxisID : 'y' ,
} ]
}
export const buildDataSet = ( plot , comparisonPlot , present _index , ctx , label ) => {
@ -46,72 +87,13 @@ export const buildDataSet = (plot, comparisonPlot, present_index, ctx, label) =>
prev _gradient . addColorStop ( 0 , 'rgba(101,116,205, 0.075)' ) ;
prev _gradient . addColorStop ( 1 , 'rgba(101,116,205, 0)' ) ;
let comparisonDataSet = [ ]
if ( comparisonPlot ) {
comparisonDataSet = [
{
label ,
data : truncateToPresentIndex ( comparisonPlot , present _index ) ,
borderWidth : 3 ,
borderColor : 'rgba(60,70,110,0.2)' ,
pointBackgroundColor : 'rgba(60,70,110,0.2)' ,
pointHoverBackgroundColor : 'rgba(60, 70, 110)' ,
pointBorderColor : 'transparent' ,
pointHoverRadius : 4 ,
backgroundColor : gradient ,
fill : true ,
yAxisID : 'yComparison' ,
}
]
}
const defaultOptions = { label , borderWidth : 3 , pointBorderColor : "transparent" , pointHoverRadius : 4 , backgroundColor : gradient , fill : true }
if ( present _index ) {
var dashedPart = plot . slice ( present _index - 1 , present _index + 1 ) ;
var dashedPlot = ( new Array ( present _index - 1 ) ) . concat ( dashedPart )
const _plot = truncateToPresentIndex ( [ ... plot ] , present _index )
return [
{
label ,
data : _plot ,
borderWidth : 3 ,
borderColor : 'rgba(101,116,205)' ,
pointBackgroundColor : 'rgba(101,116,205)' ,
pointHoverBackgroundColor : 'rgba(71, 87, 193)' ,
pointBorderColor : 'transparent' ,
pointHoverRadius : 4 ,
backgroundColor : gradient ,
fill : true ,
yAxisID : 'y' ,
} ,
{
label ,
data : dashedPlot ,
borderWidth : 3 ,
borderDash : [ 3 , 3 ] ,
borderColor : 'rgba(101,116,205)' ,
pointHoverBackgroundColor : 'rgba(71, 87, 193)' ,
pointBorderColor : 'transparent' ,
pointHoverRadius : 4 ,
backgroundColor : gradient ,
fill : true ,
yAxisID : 'y' ,
}
] . concat ( comparisonDataSet )
} else {
return [
{
label ,
data : plot ,
borderWidth : 3 ,
borderColor : 'rgba(101,116,205)' ,
pointHoverBackgroundColor : 'rgba(71, 87, 193)' ,
pointBorderColor : 'transparent' ,
pointHoverRadius : 4 ,
backgroundColor : gradient ,
fill : true ,
yAxisID : 'y' ,
}
] . concat ( comparisonDataSet )
}
const dataset = [
... buildMainPlotDataset ( plot , present _index ) ,
... buildDashedDataset ( plot , present _index ) ,
... buildComparisonDataset ( comparisonPlot , present _index )
]
return dataset . map ( ( item ) => Object . assign ( item , defaultOptions ) )
}