Created
April 7, 2017 14:31
-
-
Save iamdey/4223507da535754228f72ba154b94ff8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// PiGraph/index.spec.jsx | |
const AXE_LENGTH = 100; | |
export function calcXpoint(level, count) { | |
return AXE_LENGTH - (level * Math.sin((count * Math.PI) / 180)); | |
} | |
export function calcYpoint(level, count) { | |
return AXE_LENGTH - (level * Math.cos((count * Math.PI) / 180)); | |
} | |
//-------------- | |
// func à tester | |
// import { axeCoordinates } from './'; | |
// export | |
export function getPolygonPoints(pi) { | |
if (pi.length === 0) { | |
throw "pi should contains values"; | |
} | |
const angle = 360 / pi.length; | |
let count = 0; | |
const polygonPoints = pi.reduce((acc, p) => { | |
const pointX = calcXpoint(p.level, count); | |
const pointY = calcYpoint(p.level, count); | |
count -= angle; | |
return `${acc} ${pointX} ${pointY}`.trim(); | |
}, ''); | |
return polygonPoints; | |
} | |
//---------- | |
describe('comp PiGraph', () => { | |
describe('getPolygonPoints', () => { | |
it('returns normal values', () => { | |
const result = getPolygonPoints([ | |
{ name: 'foo', level: 80 }, | |
{ name: 'bar', level: 50 }, | |
{ name: 'oof', level: 10 }, | |
]); | |
const expected = `${calcXpoint(80, 0)} ${calcYpoint(80, 0)} ${calcXpoint(50, -120)} ${calcYpoint(50, -120)} ${calcXpoint(10, -240)} ${calcYpoint(10, -240)}`; | |
expect(result).toEqual(expected); | |
}); | |
it('what happens when no values ?????', () => { | |
expect(() => { | |
getPolygonPoints([]); | |
}).toThrow(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment