UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

61 lines (60 loc) 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.annotationHelpers = void 0; var NativeObject_1 = require("../Helpers/NativeObject"); var DpiHelper_1 = require("../TextureManager/DpiHelper"); var AnnotationBase_1 = require("./AnnotationBase"); /** All svg creation is run through this funciton so it can be mocked for tests */ var createSvg = function (svgString, svgRoot, nextElement) { var svgNode = document.createRange().createContextualFragment(svgString); if (nextElement) { svgRoot.insertBefore(svgNode, nextElement); return nextElement.previousElementSibling; } svgRoot.appendChild(svgNode); return svgRoot.lastChild; }; var createSvgLineAndLabel = function (showLabel) { var svgNs = "http://www.w3.org/2000/svg"; var svgElement = document.createElementNS(svgNs, "svg"); var gElement = document.createElementNS(svgNs, "g"); var svgLine = document.createElementNS(svgNs, "line"); gElement.appendChild(svgLine); var svgLabelsContainer = undefined; if (showLabel) { svgLabelsContainer = document.createElementNS(svgNs, "g"); svgLabelsContainer.setAttribute("class", "scichart__line-annotation-labels"); svgLabelsContainer.setAttribute("pointer-events", "none"); gElement.appendChild(svgLabelsContainer); } svgElement.appendChild(gElement); return { svgElement: svgElement, svgLine: svgLine, svgLabelsContainer: svgLabelsContainer }; }; var calcNewApex = function (x1, y1, x2, y2, isVertical) { var x1y1 = { x: x1, y: y1 }; var x2y1 = isVertical ? { x: x1, y: y2 } : { x: x2, y: y1 }; var x1y2 = isVertical ? { x: x2, y: y1 } : { x: x1, y: y2 }; var x2y2 = { x: x2, y: y2 }; return { x1y1: x1y1, x2y1: x2y1, x1y2: x1y2, x2y2: x2y2 }; }; var convertPolarToCartesian = function (angularAxis, usePixelRatio, wasmContext, coordinateMode, angle, radius) { var transform = angularAxis.getTransform(usePixelRatio); var vec = (0, NativeObject_1.getVector2)(wasmContext); if (usePixelRatio) { var x$ = coordinateMode !== AnnotationBase_1.ECoordinateMode.Pixel ? angle * DpiHelper_1.DpiHelper.PIXEL_RATIO : angle; transform.TransformPoint(radius, x$, vec); } else { var x$ = coordinateMode !== AnnotationBase_1.ECoordinateMode.Pixel ? angle : angle / DpiHelper_1.DpiHelper.PIXEL_RATIO; transform.TransformPoint(radius, x$, vec); } var resX = vec.x; var resY = vec.y; return { x: resX, y: resY }; }; exports.annotationHelpers = { createSvg: createSvg, calcNewApex: calcNewApex, convertPolarToCartesian: convertPolarToCartesian, createSvgLineAndLabel: createSvgLineAndLabel };