/** * Created by mm28969 on 10/24/16. */ import {ScaleTypeEnum} from "../mmviz-layout/scale_container"; import {AxisLocationEnum} from "../mmviz-layout/index"; export enum ComponentTypeEnum { SVG = 1, CANVAS, WEBGL, } export enum OrientationEnum { VERTICAL = 1, HORIZONTAL } /** * Get OrientationEnum that matches provided orientation string * @param orientation */ export function getOrientationEnum(orientation: string): OrientationEnum { let orientationEnum: OrientationEnum; switch (orientation){ case "vertical": orientationEnum = OrientationEnum.VERTICAL; break; case "horizontal": orientationEnum = OrientationEnum.HORIZONTAL; break; default: throw "Invaild orientation"; } return orientationEnum; } export enum ChartWidthSizeEnum { DEFAULT = "default", SMALL = "sm", MEDIUM = "md", LARGE = "lg" } export function convertValueToAttribute(value: string){ return value.trim().replace(/\W+/g, '-').toLowerCase(); } export function convertSelectorToAttribute(selector: string){ return selector.replace(/^(\#|\.)/, "") } export function areaToRadius(area: number) : number { return Math.sqrt(area / Math.PI); } export function distance(p1, p2) : number { let x = p2.x - p1.x, y = p2.y - p1.y; return Math.sqrt( (x*x) + (y*y) ); } export function getDomainUnique(dataModel, key){ let d, value, valueMapper = dataModel[key + "ValueMap"], domain = []; for(d of dataModel.dataArray){ value = valueMapper(d); if(domain.indexOf(value) < 0){ domain.push(value); } } return domain; } export function getChartWidthSize(width): ChartWidthSizeEnum { let wSize = ChartWidthSizeEnum.DEFAULT; if (width >= 300 && width < 500){ wSize = ChartWidthSizeEnum.SMALL; } else if (width >= 500 && width < 700){ wSize = ChartWidthSizeEnum.MEDIUM; } else if (width >= 700){ wSize = ChartWidthSizeEnum.LARGE; } return wSize; } export function getBarPadding(dataSize: number){ return (dataSize > 1) ? (1 / dataSize) : 0.5; } export function getBarWidth(dataSize: number){ return 1 - getBarPadding(dataSize); }