Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculator fixes #656

Merged
merged 4 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/calculators/show/CalculatorShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CalculatorShow extends Component {
}
</div>
</div>
<div className='description'><ReactMarkdown source={content} /></div>
<div className='description'><ReactMarkdown source={content}/></div>
<div className='inputs'>
{_.map(inputs, (metric, i) => (
<Input
Expand Down
3 changes: 2 additions & 1 deletion src/components/calculators/show/input.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {Component} from 'react'

import ReactMarkdown from 'react-markdown'
import Icon from 'react-fa'

import {Guesstimator} from 'lib/guesstimator/index'
Expand Down Expand Up @@ -47,7 +48,7 @@ export class Input extends Component{
<div className='col-xs-12 col-sm-7'>
<div className='name'>{name}</div>
{description &&
<div className='description'>{description}</div>
<div className='description'><ReactMarkdown source={description}/></div>
}
</div>
<div className='col-xs-12 col-sm-5'>
Expand Down
73 changes: 58 additions & 15 deletions src/components/calculators/show/output.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import React, {Component} from 'react'
import Icon from 'react-fa'

import numberShow from 'lib/numberShower/numberShower'

Expand All @@ -17,19 +18,61 @@ const ResultSection = ({length, mean, adjustedConfidenceInterval}) => (
length === 1 ? <PrecisionNumber value={mean} precision={6}/> : <RangeDisplay range={adjustedConfidenceInterval}/>
)

export const Output = ({metric: {name, simulation}}) => (
<div className='output'>
<div className='row'>
<div className='col-xs-12 col-sm-7'>
<div className='name'>
{name}
</div>
</div>
<div className='col-xs-12 col-sm-5'>
<div className={`result-section${!_.isEmpty(_.get(simulation, 'sample.errors')) ? ' has-errors' : ''}`}>
{_.has(simulation, 'stats') && <ResultSection {...simulation.stats} />}
</div>
</div>
</div>
const AnalyticsSection = (stats) => (
<div className='stats-summary'>
{`According to the model, this value has a 90% chance of being between `}
<PrecisionNumber value={stats.adjustedConfidenceInterval[0]}/>
{` and `}
<PrecisionNumber value={stats.adjustedConfidenceInterval[1]}/>
{'.'}
{` The mean value is `}
<PrecisionNumber value={stats.mean}/>
{` and the median is `}
<PrecisionNumber value={stats.percentiles[50]}/>
{`.`}
</div>
)

export class Output extends Component {
state = {
showAnalysis: false
}

toggleAnalysis() {
const showAnalysis = this.state.showAnalysis
this.setState({showAnalysis: !showAnalysis})
}

render() {
const {metric: {name, simulation}} = this.props
const {showAnalysis} = this.state
console.log(simulation.stats)
return (
<div className='output'>
<div className='row'>
<div className='col-xs-12 col-sm-7'>
<div className='name'>
{name}
</div>
</div>
<div className='col-xs-12 col-sm-5'>
<div className={`result-section${!_.isEmpty(_.get(simulation, 'sample.errors')) ? ' has-errors' : ''}`}>
{_.has(simulation, 'stats') && <ResultSection {...simulation.stats} />}

{!showAnalysis && _.has(simulation, 'stats.percentiles.5') &&
Copy link
Contributor

@mmcdermott mmcdermott Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk about this a bit; I don't think you should be using the percentiles here, I think you should be using the adjusted 90% CI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably find this a bit cleaner if you declared a var in the render with the icon content, then used it here.

<div className='icon' onClick={this.toggleAnalysis.bind(this)}> ? </div>
}
{showAnalysis &&
<div className='icon' onClick={this.toggleAnalysis.bind(this)}> <i className={`ion-md-close`}/></div>
}

{showAnalysis && _.has(simulation, 'stats.percentiles.5') &&
<AnalyticsSection {...simulation.stats} />
}
</div>
</div>
</div>
</div>
)
}
}
26 changes: 26 additions & 0 deletions src/components/calculators/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,31 @@
color: #666;
margin-left: .5rem;
font-size: 1.3em;
position: relative;

.result-value {
color: rgba(80, 80, 80, 1);
font-weight: 800;
}

.icon {
position: absolute;
right: -41px;
top: -4px;
background-color: #e0e8ea;
width: 26px;
height: 26px;
text-align: center;
padding-top: 1px;
border-radius: 1em;
font-size: .8em;
color: #88919c;
cursor: pointer;
&:hover {
background-color: #b9c7d0;
color: #5d6c7b;
}
}
}
}
}
Expand Down Expand Up @@ -272,6 +292,12 @@
}
.outputs .output {
padding-bottom: 1.5em;

.stats-summary {
font-size: .63em;
margin-top: .8em;
}

}
.padded-section {
padding: 1em 1em;
Expand Down