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

Fixes #9 of #923, switch income to earned where needed #954

Merged
merged 2 commits into from
Nov 3, 2018
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/forms/Predictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const IncomeForm = function ({ future, time, updateClientValue, snippets }) {
time={ time }
updateClientValue = { updateClientValue }
generic='earned'
labelInfo='(Weekly income = hourly wage times average number of work hours per week)'>
labelInfo='(Weekly pay = hourly wage times average number of work hours per week)'>
{ snippets.i_futureIncomeQuestion }
</CashFlowInputsRow>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/forms/output/BenefitsLineGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BenefitsLineGraph extends Component {
var max = Math.ceil((limits.max * multiplier) / 100) * 100,
interval = Math.ceil((max / 100) / 10) * 10;

var xRange = _.range(limits.min, max, interval), // x-axis/income numbers
var xRange = _.range(limits.min, max, interval), // x-axis/earned income numbers
extraProps = { snap: { fill: false }, section8: { fill: false }},
datasets = getChartData(xRange, multiplier, client, activePrograms, extraProps);

Expand All @@ -58,10 +58,10 @@ class BenefitsLineGraph extends Component {

// react-chartjs-2 keeps references to plugins, so we
// have to mutate that reference
var income = client.future.earned * multiplier,
var earned = client.future.earned * multiplier,
hack = this.state.verticalLine;
hack.xRange = xRange;
hack.income = income;
hack.earned = earned;

var lineProps = {
data: {
Expand All @@ -71,7 +71,7 @@ class BenefitsLineGraph extends Component {
options: {
title: {
display: true,
text: 'Individual Benefit Amounts for Household as Income Changes',
text: 'Individual Benefit Amounts for Household as Pay Changes',
},
showLines: true,
scales: {
Expand All @@ -92,7 +92,7 @@ class BenefitsLineGraph extends Component {
{
scaleLabel: {
display: true,
labelString: timescale + ' Income ($)',
labelString: timescale + ' Pay ($)',
},
ticks: { callback: formatAxis },
},
Expand Down
28 changes: 14 additions & 14 deletions src/forms/output/BenefitsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const BenefitsTable = function ({ client, snippets }) {
var curr = clone.current;

var allData = {},
activeBenefits = [ `income` ];
activeBenefits = [ `earned` ];

if (curr.hasSection8) {
activeBenefits.push(`section8`);
Expand Down Expand Up @@ -54,7 +54,7 @@ const BenefitsTable = function ({ client, snippets }) {
applyAndPushBenefits (futureCalcData);

// @todo Abstract getting values for each row
var income = allData.income,
var earned = allData.earned,
section8 = allData.section8,
snap = allData.snap;

Expand All @@ -78,12 +78,12 @@ const BenefitsTable = function ({ client, snippets }) {
totalBenefitCurrent = SNAPBenefitCurrent + sec8BenefitCurrent,
totalBenefitFuture = SNAPBenefitFuture + sec8BenefitFuture,
totalDiff = SNAPDiff + sec8Diff,
incomeCurrent = Math.round(income[ 0 ]),
incomeFuture = Math.round(income[ 1 ]),
incomeDiff = incomeFuture - incomeCurrent,
netCurrent = totalBenefitCurrent + incomeCurrent,
netFuture = totalBenefitFuture + incomeFuture,
netDiff = totalDiff + incomeDiff;
earnedCurrent = Math.round(earned[ 0 ]),
earnedFuture = Math.round(earned[ 1 ]),
earnedDiff = earnedFuture - earnedCurrent,
netCurrent = totalBenefitCurrent + earnedCurrent,
netFuture = totalBenefitFuture + earnedFuture,
netDiff = totalDiff + earnedDiff;

const columnHeaderStyle = {
background: 'rgba(0, 181, 173, 1)',
Expand Down Expand Up @@ -176,13 +176,13 @@ const BenefitsTable = function ({ client, snippets }) {
);
};

const IncomeRow = function ({ snippets }) {
const EarnedRow = function ({ snippets }) {
return (
<Table.Row>
<Table.Cell style={ rowHeaderStyle }>{ snippets.i_rowIncome }</Table.Cell>
<Table.Cell textAlign='right'>{ snippets.i_beforeMoney }{incomeCurrent}{ snippets.i_afterMoney }</Table.Cell>
<Table.Cell textAlign='right'>{ snippets.i_beforeMoney }{incomeFuture}{ snippets.i_afterMoney }</Table.Cell>
<Table.Cell textAlign='right'>{ getSignSymbol(incomeDiff) } { snippets.i_beforeMoney }{ Math.abs(incomeDiff) }{ snippets.i_afterMoney }</Table.Cell>
<Table.Cell style={ rowHeaderStyle }>{ snippets.i_rowEarned }</Table.Cell>
<Table.Cell textAlign='right'>{ snippets.i_beforeMoney }{earnedCurrent}{ snippets.i_afterMoney }</Table.Cell>
<Table.Cell textAlign='right'>{ snippets.i_beforeMoney }{earnedFuture}{ snippets.i_afterMoney }</Table.Cell>
<Table.Cell textAlign='right'>{ getSignSymbol(earnedDiff) } { snippets.i_beforeMoney }{ Math.abs(earnedDiff) }{ snippets.i_afterMoney }</Table.Cell>
</Table.Row>
);
};
Expand Down Expand Up @@ -247,7 +247,7 @@ const BenefitsTable = function ({ client, snippets }) {
<TotalBenefitsRow
client={ clone }
snippets={ snippets } />
<IncomeRow snippets={ snippets } />
<EarnedRow snippets={ snippets } />
<TotalsRow snippets={ snippets } />
</Table.Body>
</Table>
Expand Down
18 changes: 9 additions & 9 deletions src/forms/output/StackedAreaGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ class StackedAreaGraph extends Component {
const { client, timescale, activePrograms } = this.props;
const multiplier = multipliers[ timescale ];

var withIncome = activePrograms.slice();
withIncome.unshift('income');
var withEarned = activePrograms.slice();
withEarned.unshift('earned');

// Adjust to time-interval, round to hundreds
var income = client.future.earned * multiplier,
max = Math.max(income, limits.max * multiplier),
var earned = client.future.earned * multiplier,
max = Math.max(earned, limits.max * multiplier),
xMax = Math.ceil(max / 100) * 100,
xMin = Math.ceil(limits.min * multiplier / 100) * 100,
interval = Math.ceil(((xMax - xMin) / 100) / 10) * 10,
xRange = _.range(xMin, xMax + interval, interval),
extraProps = { income: { fill: 'origin' }},
datasets = getChartData(xRange, multiplier, client, withIncome, extraProps);
extraProps = { earned: { fill: 'origin' }},
datasets = getChartData(xRange, multiplier, client, withEarned, extraProps);

// react-chartjs-2 keeps references to plugins, so we
// have to mutate that reference
var hack = this.state.verticalLine;
hack.xRange = xRange;
hack.income = income;
hack.earned = earned;

var stackedAreaProps = {
data: {
Expand All @@ -74,7 +74,7 @@ class StackedAreaGraph extends Component {
options: {
title: {
display: true,
text: 'All Money Coming in as Income Changes',
text: 'All Money Coming in as Pay Changes',
}, // end `title`
elements: {
line: { fill: '-1' },
Expand Down Expand Up @@ -103,7 +103,7 @@ class StackedAreaGraph extends Component {
stacked: true,
scaleLabel: {
display: true,
labelString: timescale + ' Income ($)',
labelString: timescale + ' Earned ($)',
},
ticks: { callback: formatAxis },
},
Expand Down
8 changes: 4 additions & 4 deletions src/forms/output/StackedBarGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const StackedBarGraph = function({ client }) {
curr = clone.current;

var allData = {},
activeBenefits = [ `income` ];
activeBenefits = [ `earned` ];

if (curr.hasSection8) {
activeBenefits.push(`section8`);
Expand Down Expand Up @@ -70,7 +70,7 @@ const StackedBarGraph = function({ client }) {
data: allData[ bName ],
};

if (bName === `income`) {
if (bName === `earned`) {
dataset.fill = `origin`;
for (let amount of dataset.data) {
moneyLabels.push(Math.round(amount));
Expand All @@ -88,7 +88,7 @@ const StackedBarGraph = function({ client }) {
options: {
title: {
display: true,
text: 'Money Coming In as Income Changes',
text: 'Money Coming In as Pay Changes',
},
scales: {
yAxes: [
Expand All @@ -109,7 +109,7 @@ const StackedBarGraph = function({ client }) {
stacked: true,
scaleLabel: {
display: true,
labelString: 'Monthly Income ($)',
labelString: 'Monthly Pay ($)',
},
ticks: { callback: formatAxis },
},
Expand Down
32 changes: 16 additions & 16 deletions src/forms/output/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ var totalLastItemsOfArraysInObject = function (accumulated) {
* those benefits.
*
* @param {array} keys Contains keys to use on `sourceObject`.
* @param {object} sourceObject MUST CONTAIN `income` property!
* Contains `income` and benefit keys that each have an
* @param {object} sourceObject MUST CONTAIN `earned` property!
* Contains `earned` and benefit keys that each have an
* array of numerical values (which are meant to be money
* values right now).
* @param {array} sourceObject.income Earned income values.
* @param {array} sourceObject.earned Earned income values.
* @param {int} Which item in each array should be used to
* accumulate values.
*
Expand All @@ -73,7 +73,7 @@ var totalLastItemsOfArraysInObject = function (accumulated) {
* ];
*
* let accumulated = {
* income: [ 450, 500 ],
* earned: [ 450, 500 ],
* benefit1: [ 80, 30 ],
* benefit2: [ 40, 10 ],
* };
Expand Down Expand Up @@ -112,8 +112,8 @@ var totalLastItemsOfArraysInObject = function (accumulated) {
*/
var fillInMoneyValues = (keys, sourceObject, index) => {

if (!Array.isArray(sourceObject.income)) {
throw new TypeError(`The given resources object requires an 'income' property that is an array of numbers.`);
if (!Array.isArray(sourceObject.earned)) {
throw new TypeError(`The given resources object requires an 'earned' property that is an array of numbers.`);
}

var moneyValues = {
Expand All @@ -123,18 +123,18 @@ var fillInMoneyValues = (keys, sourceObject, index) => {
total: 0,
};

// Item names can be `income` or benefit keys
// Item names can be `earned` or benefit keys
for (let itemKey of keys) {
let amount = sourceObject[ itemKey ][ index ];

if (itemKey === `income`) {
if (itemKey === `earned`) {
moneyValues.earned = amount;
} else {
moneyValues.benefits.push({
label: PROGRAM_CHART_VALUES[ itemKey ].name,
amount: amount,
});
// Add up all benefits (we're not including income)
// Add up all benefits (we're not including earned income)
moneyValues.benefitsTotal += amount;
}
} // ends for every item key name
Expand All @@ -155,15 +155,15 @@ var fillInMoneyValues = (keys, sourceObject, index) => {
* @param {Array.<String>} resourceKeys List of...
* 'programs'... in the order in which we eventually
* want to show them. It often also includes
* 'income' as the first value, so it's not a list
* 'earned' as the first value, so it's not a list
* of 'benefit programs' per se.
*
* @example
* // NOTE: an example with a lower dip hasn't been found yet
* // This example uses the sample `client` data from row 3,
* // column 'clientData' here:
* // https://docs.google.com/spreadsheets/d/15LyR9yELAfcngj-c7vMdI630b6DwuuXV-dQEJDvU4gE/edit?usp=sharing
* var items = [ 'income', 'section8', 'snap' ];
* var items = [ 'earned', 'section8', 'snap' ];
* var data = getBenefitData(client, items);
* console.log(data);
* // {
Expand Down Expand Up @@ -214,10 +214,10 @@ var getBenefitData = function(client, resourceKeys) {
applyAndPushBenefits(currentCalcData);
var futureCalcData = { ...defaultProps, timeframe: `future` };
applyAndPushBenefits(futureCalcData);
// Now have: { income: [c, f], n: [c, f], ... }
// Now have: { earned: [c, f], n: [c, f], ... }

// 2. Get totals
// Fill income values for both current and future income objects
// Fill earned values for both current and future earned objects
result.current = fillInMoneyValues(resourceKeys, accumulated, 0);
result.future = fillInMoneyValues(resourceKeys, accumulated, 1);
var resultCurr = result.current,
Expand All @@ -229,7 +229,7 @@ var getBenefitData = function(client, resourceKeys) {

// 4. If implicit taxes > 100% (has dramatic cliff)
let recoveryAmount = 0,
income = accumulated.income;
earned = accumulated.earned;
if (result.diff <= 0) {
// 5. The lowest point in their cliff is behind -
// as is the nature of cliffs. Now try getting raises
Expand All @@ -243,7 +243,7 @@ var getBenefitData = function(client, resourceKeys) {

} // ends while making less money than now
result.recovery.total = recoveryAmount;
result.recovery.earned = income[ income.length - 1 ];
result.recovery.earned = earned[ earned.length - 1 ];

} // ends if hit dramatic cliff

Expand Down Expand Up @@ -271,7 +271,7 @@ var getBenefitData = function(client, resourceKeys) {
*/
const Summary = function ({ client, openFeedback, snippets }) {

var resourceKeys = [ `income` ];
var resourceKeys = [ `earned` ];
// Benefits, in order of appearance
// So can't wait till `.benefits` is an array of benefit names...
if (client.current.hasSection8) {
Expand Down
10 changes: 5 additions & 5 deletions src/forms/output/VerticalLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class VerticalLine {

constructor () {
this.xRange = [];
this.income = 0;
this.earned = 0;
}

afterDatasetsDraw = (chart) => {
const xRange = this.xRange,
income = this.income;
earned = this.earned;

const i = xRange.findIndex((val) => {
return income < val;
return earned < val;
});
const positionBetweenTwoPoints = (income - xRange[ i - 1 ]) / (xRange[ i ] - xRange[ i - 1 ]);
const positionBetweenTwoPoints = (earned - xRange[ i - 1 ]) / (xRange[ i ] - xRange[ i - 1 ]);

const data = chart.getDatasetMeta(0).data;
const prevX = data[ i - 1 ]._model.x;
Expand Down Expand Up @@ -49,7 +49,7 @@ class VerticalLine {
const xMargin = 5;
const yMargin = 200;
ctx.fillText('Future', offset + xMargin, yMargin);
ctx.fillText('Income', offset + xMargin, lineHeight + yMargin);
ctx.fillText('Pay', offset + xMargin, lineHeight + yMargin);

ctx.restore();
};
Expand Down
18 changes: 9 additions & 9 deletions src/localization/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,28 +309,28 @@ export default {
rowSNAP_v1: `SNAP`, // see BenefitsTable.js
rowSection8_v1: `Section 8 Housing`, // see BenefitsTable.js
rowTotalBenefits_v1: `Total Benefits`, // see BenefitsTable.js
rowIncome_v1: `Income`, // see BenefitsTable.js
rowEarned_v2: `Earned`, // see BenefitsTable.js
rowNetTotal_v1: `Net Total`, // see BenefitsTable.js
beforeMoney_v1: `$`, // see BenefitsTable.js multiple lines
afterMoney_v1: ` / month`, // see BenefitsTable.js multiple lines
// Stacked Bar Graph:
stackedBarGraphTitle_v1: `Changes Chart`, // see line 266 above
moneyInAsIncomeChanges_v1: `Money Coming In as Income Changes`, // see StackedBarGraph.js
moneyInAsPayChanges_v2: `Money Coming In as Pay Changes`, // see StackedBarGraph.js
// Stacked Area Graph:
stackedAreaGraphTitle_v1: `Stacked Incomes`, // see line 267 above
allMoneyComingIn_v1: `All Money Coming In as Income Changes`, // see StackedAreaGraph.js
allMoneyComingIn_v2: `All Money Coming In as Pay Changes`, // see StackedAreaGraph.js
// Benefit Programs Graph, showing benefit programs as lines not areas:
benefitProgramsTitle_v1: `Individual Benefit Amounts for Household as Income Changes`, // maybe rename as benefitProgramsSubTitle_v1 ? see also BenefitsLineGraph.js
benefitProgramsTitle_v2: `Individual Benefit Amounts for Household as Pay Changes`, // maybe rename as benefitProgramsSubTitle_v1 ? see also BenefitsLineGraph.js
benefitValue_v1: `Benefit Value ($)`, // see BenefitsLineGraph.js
// Snippets that are used in more than one chart, table, or graph:
totalMoney_v1: `Total Money Coming In ($)`, // see StackedAreaGraph.js, StackedBarGraph.js
weeklyIncome_v1: `Weekly Income ($)`,
monthlyIncome_v1: `Monthly Income ($)`,
yearlyIncome_v1: `Yearly Income ($)`,
hasIncome_v1: `Income`,
weeklyPay_v2: `Weekly Pay ($)`,
monthlyPay_v2: `Monthly Pay ($)`,
yearlyPay_v2: `Yearly Pay ($)`,
hasPay_v2: `Pay`,
hasSNAP_v1: `SNAP`,
hasSection8_v1: `Section 8`,
futureIncomeLine_v1: `Future Income`, // see VerticalLine.js
futurePayLine_v2: `Future Pay`, // see VerticalLine.js
buttonWeekly_v1: `Weekly`, // see cashflow.js, GraphTimeButtons
buttonMonthly_v1: `Monthly`, // see cashflow.js, GraphTimeButtons
buttonYearly_v1: `Yearly`, // see cashflow.js, GraphTimeButtons
Expand Down
Loading