Fix broken balance background position

Fixes #467
This commit is contained in:
Jordan Eldredge 2018-02-08 20:57:25 -08:00
parent b7e8b71097
commit 76f8c1bfdd
3 changed files with 18 additions and 4 deletions

View file

@ -3,10 +3,10 @@ import { connect } from "react-redux";
import Balance from "../Balance";
const offsetFromBalance = balance => {
export const offsetFromBalance = balance => {
const percent = Math.abs(balance) / 100;
const sprite = Math.round(percent * 28);
const offset = (sprite - 1) * 15;
const sprite = Math.floor(percent * 27);
const offset = sprite * 15;
return offset;
};

View file

@ -0,0 +1,14 @@
import { offsetFromBalance } from "./MainBalance";
describe("offsetFromBalance", () => {
it("works for positive numbers", () => {
expect(offsetFromBalance(0)).toBe(0);
expect(offsetFromBalance(50)).toBe(195);
expect(offsetFromBalance(100)).toBe(405);
});
it("works for negative numbers", () => {
expect(offsetFromBalance(-0)).toBe(0);
expect(offsetFromBalance(-50)).toBe(195);
expect(offsetFromBalance(-100)).toBe(405);
});
});

View file

@ -287,7 +287,7 @@ exports[`MainWindow renders to snapshot 1`] = `
step="1"
style={
Object {
"backgroundPosition": "0 --15px",
"backgroundPosition": "0 -0px",
}
}
title="Panning Bar"