-
Notifications
You must be signed in to change notification settings - Fork 1
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 #75 from geostreams/scatterplot-component
Scatterplot addition
- Loading branch information
Showing
7 changed files
with
252 additions
and
17 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
170 changes: 170 additions & 0 deletions
170
packages/geostreaming/src/components/vega/ScatterPlot.jsx
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,170 @@ | ||
import React from 'react'; | ||
import { VegaLite } from 'react-vega'; | ||
import type { ParameterValue } from '../../../utils/flowtype'; | ||
|
||
type Props = { | ||
data: ParameterValue[]; | ||
width: Number, | ||
height: Number, | ||
startAtZero: Boolean, | ||
startDate?: Date, | ||
endDate?: Date | ||
} | ||
|
||
|
||
function ScatterPlot(props: Props){ | ||
const { data, width, height, startAtZero, startDate, endDate, yLabel, regressionLine } = props; | ||
|
||
let dateRange = {}; | ||
if(startDate && endDate){ | ||
dateRange = { domain: [startDate.getTime(), endDate.getTime()] }; | ||
} | ||
|
||
const spec = { | ||
width, | ||
height, | ||
data: { name: 'table' }, | ||
transform: [ | ||
{ calculate: 'datum.average', as: 'value' } | ||
], | ||
encoding:{ | ||
x:{ | ||
field:'date', | ||
type:'temporal', | ||
timeUnit: 'yearmonthdate', | ||
axis: { grid: false, title: false }, | ||
scale: { ...dateRange } | ||
} | ||
}, | ||
layer:[ | ||
{ | ||
encoding:{ | ||
y:{ | ||
field:'value', | ||
type:'quantitative', | ||
scale: { zero: startAtZero }, | ||
axis: { grid: false }, | ||
title: yLabel | ||
} | ||
}, | ||
layer:[ | ||
{ | ||
mark: { type:'point' , filled: true , size: 35, opacity: 0.4 } | ||
}, | ||
{ | ||
transform:[ | ||
{ | ||
filter:{ | ||
param:'hover', | ||
empty:false | ||
} | ||
} | ||
], | ||
mark:'point' | ||
} | ||
] | ||
}, | ||
{ | ||
mark: { | ||
type: 'boxplot', | ||
extent: 'min-max', | ||
median: { color: 'black' }, | ||
rule: false | ||
}, | ||
encoding: { | ||
y: { | ||
field: 'value', | ||
type: 'quantitative', | ||
scale: { zero: false }, | ||
axis: { grid: false }, | ||
title: yLabel | ||
}, | ||
x: {}, | ||
opacity: { | ||
value: 0.3 | ||
}, | ||
size: { | ||
value: width | ||
} | ||
} | ||
}, | ||
{ | ||
mark:'rule', | ||
encoding:{ | ||
opacity:{ | ||
condition:{ | ||
value:0.3, | ||
param:'hover', | ||
empty:false | ||
}, | ||
value:0 | ||
}, | ||
tooltip:[ | ||
{ | ||
field:'value', | ||
type:'quantitative', | ||
title: yLabel | ||
}, | ||
{ | ||
field:'date', | ||
type:'temporal', | ||
title: 'Date-Time' | ||
} | ||
] | ||
}, | ||
params:[ | ||
{ | ||
name:'hover', | ||
select:{ | ||
type:'point', | ||
fields:[ | ||
'date' | ||
], | ||
nearest:true, | ||
on:'mouseover', | ||
clear:'mouseout' | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
if (regressionLine){ | ||
const line_spec = { | ||
mark: { | ||
type: 'line', | ||
color: 'firebrick' | ||
}, | ||
transform: [ | ||
{ | ||
regression: 'value', | ||
on: 'date' | ||
}], | ||
encoding: { | ||
x: { | ||
field: 'date', | ||
type: 'temporal' | ||
}, | ||
y: { | ||
field: 'value', | ||
type: 'quantitative' | ||
} | ||
} | ||
}; | ||
spec.layer.push(line_spec); | ||
|
||
} | ||
return(<VegaLite spec={spec} data={{ table : data }} actions={{ export: true, source: false, compiled: false }} />); | ||
} | ||
|
||
ScatterPlot.defaultProps = { | ||
width: 800, | ||
height: 300, | ||
keyName: 'key', | ||
startAtZero: false, | ||
yLabel: 'value', | ||
startDate: undefined, | ||
endDate: undefined | ||
}; | ||
|
||
export default ScatterPlot; |
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
56 changes: 56 additions & 0 deletions
56
packages/geostreaming/src/containers/Sensor/Detail/VegaScatterChartWrapper.jsx
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,56 @@ | ||
// @flow | ||
import * as React from 'react'; | ||
import { Grid } from '@material-ui/core'; | ||
import ScatterPlot from '../../../components/vega/ScatterPlot'; | ||
import BoxWhisker from '../../../components/vega/BoxWhisker'; | ||
|
||
import type { ParameterValue } from '../../../utils/flowtype'; | ||
|
||
type Props = { | ||
label: string; | ||
unit: string; | ||
data: ParameterValue[]; | ||
startAtZero: Boolean, | ||
sameTimeScale: Boolean, | ||
startDate: Date, | ||
endDate: Date, | ||
regressionLine: Boolean | ||
} | ||
|
||
|
||
const ScatterChartWrapper = (props : Props) => { | ||
const { | ||
data, | ||
label, | ||
startDate, | ||
endDate, | ||
startAtZero, | ||
regressionLine | ||
} = props; | ||
|
||
const chartData = data.map(({date, average, count})=> ({average, date, count })) | ||
|
||
return ( | ||
<> | ||
<Grid item xs={10}> | ||
<ScatterPlot | ||
startAtZero={startAtZero} | ||
data={chartData} | ||
width={900} | ||
startDate={startDate} | ||
endDate={endDate} | ||
yLabel = {label} | ||
regressionLine = {regressionLine} | ||
/> | ||
</Grid> | ||
<Grid item xs={2}> | ||
<BoxWhisker | ||
data={chartData} | ||
width={130} | ||
/> | ||
</Grid> | ||
</> | ||
); | ||
}; | ||
|
||
export default ScatterChartWrapper; |