import { POINT_RADIUS, TimelineEvent } from './types';
import React from 'react';
import { getAttributeValue } from './lib/helpers';
enum Shape {
CIRCLE = 'circle',
SQUARE = 'square',
TRIANGLE = 'triangle',
DIAMOND = 'diamond',
STAR = 'star',
CAMERA = 'camera',
}
function getSpecifiedShapeIfExists(e: TimelineEvent) {
const shape = getAttributeValue(SHAPE_ATTRIBUTE_KEY, e);
if (!shape) {
return undefined;
}
const lcShape = shape.toLowerCase();
switch (lcShape) {
case 'circle':
case 'square':
case 'triangle':
case 'diamond':
case 'star':
case 'camera':
return lcShape as Shape;
default:
return undefined;
}
}
export function renderShape(
e: TimelineEvent,
y: number,
eventColorGetter: (e: TimelineEvent) => string
) {
const shape = getSpecifiedShapeIfExists(e) || Shape.CIRCLE;
const color = eventColorGetter(e);
let sideLength: number;
switch (shape) {
case Shape.CIRCLE:
return ;
case Shape.SQUARE:
sideLength = 0.8 * POINT_RADIUS;
return (
);
case Shape.TRIANGLE:
sideLength = 1.3 * POINT_RADIUS;
return (
);
case Shape.DIAMOND:
sideLength = 0.8 * POINT_RADIUS;
return (
);
case Shape.STAR:
sideLength = 1.3 * POINT_RADIUS;
const angleIncrement = (2 * Math.PI) / 10;
let points = '';
for (let i = 0; i < 10; i++) {
let radius;
if (i % 2 === 0) {
radius = sideLength;
} else {
radius = sideLength / 2;
}
points = `${points} ${radius *
Math.sin(i * angleIncrement)},${y -
radius * Math.cos(i * angleIncrement)}`;
}
return ;
case Shape.CAMERA:
return (
);
}
}
export const COLOR_ATTRIBUTE_KEY = 'STYLE_COLOR';
export const SHAPE_ATTRIBUTE_KEY = 'STYLE_SHAPE';