refactor: move endPoint creation to draw-utils

This commit is contained in:
Shivam Mishra 2019-09-27 15:00:43 +05:30
parent 2451e58df9
commit 9053b01462
2 changed files with 35 additions and 30 deletions

View File

@ -25,6 +25,33 @@ export function equilizeNoOfElements(array1, array2,
return [array1, array2]; return [array1, array2];
} }
export function getEndpointsForTrapezoid(startPositions) {
const endPosition = []
let [point_a, point_b] = startPositions
// For an equilateral triangle, the angles are always 60 deg.
// The end points on the polygons can be created using the following formula
//
// end_point_x = start_x +/- height * 1/2
// end_point_y = start_y + height
//
// b
// _______________________________
// \ |_| /
// \ | /
// \ | h /
// \ | /
// \|____________________/
//
// b = h * cos(60 deg)
//
endPosition[0] = [point_a[0] + height * 0.5, point_a[1] + height]
endPosition[1] = [point_b[0] - height * 0.5, point_b[1] + height]
return endPosition
}
export function truncateString(txt, len) { export function truncateString(txt, len) {
if (!txt) { if (!txt) {
return; return;

View File

@ -190,30 +190,8 @@ export function percentageBar(x, y, width, height,
return createSVG("rect", args); return createSVG("rect", args);
} }
export function funnelSlice(className, startPositions, height, fill='none') { export function funnelSlice(className, startPositions, endPosition, height, fill='none') {
const endPosition = [] return createSVG("polygon")
let [point_a, point_b] = startPositions[0]
// For an equilateral triangle, the angles are always 60 deg.
// The end points on the polygons can be created using the following formula
//
// end_point_x = start_x + height
// end_point_y = start_y +/- height * 1/2
//
// b
// _______________________________
// \ |_| /
// \ | /
// \ | h /
// \ | /
// \|____________________/
//
// b = h * cos(60 deg)
//
endPosition[0] = [point_a[0] + height, point_a[1] + height * 0.5]
endPosition[1] = [point_b[0] + height, point_b[1] - height * 0.5]
} }
export function heatSquare(className, x, y, size, fill='none', data={}) { export function heatSquare(className, x, y, size, fill='none', data={}) {