UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

128 lines (127 loc) 7.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSingle3dInternal = void 0; // @ts-ignore var WasmModule3D = require("../../_wasm/scichart3d"); var licenseManager2D_1 = require("../../Charting/Visuals/licenseManager2D"); var SciChartDefaults_1 = require("../../Charting/Visuals/SciChartDefaults"); var sciChartInitCommon_1 = require("../../Charting/Visuals/sciChartInitCommon"); var SciChartSurfaceBase_1 = require("../../Charting/Visuals/SciChartSurfaceBase"); var BuildStamp_1 = require("../../Core/BuildStamp"); var DeletableEntity_1 = require("../../Core/DeletableEntity"); var WebGlHelper_1 = require("../../Core/WebGlHelper"); var logger_1 = require("../../utils/logger"); var performance_1 = require("../../utils/performance"); var licenseManager3D_1 = require("./licenseManager3D"); var SciChart3DSurface_1 = require("./SciChart3DSurface"); var createSingle3dInternal = function (divElement, options) { return new Promise(function (resolve, reject) { var _a, _b, _c, _d, _e, _f; var canvases = sciChartInitCommon_1.default.initCanvas(divElement, (_a = options === null || options === void 0 ? void 0 : options.widthAspect) !== null && _a !== void 0 ? _a : 0, (_b = options === null || options === void 0 ? void 0 : options.heightAspect) !== null && _b !== void 0 ? _b : 0, undefined, (_c = options === null || options === void 0 ? void 0 : options.disableAspect) !== null && _c !== void 0 ? _c : SciChartDefaults_1.SciChartDefaults.disableAspect, options === null || options === void 0 ? void 0 : options.touchAction); var loader = ((_d = options === null || options === void 0 ? void 0 : options.loader) !== null && _d !== void 0 ? _d : SciChartDefaults_1.SciChartDefaults.defaultLoader); var loaderDiv = (_e = loader.addChartLoader) === null || _e === void 0 ? void 0 : _e.call(loader, canvases.domDivContainer, (_f = options === null || options === void 0 ? void 0 : options.theme) !== null && _f !== void 0 ? _f : SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME); var mark = performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.EngineInitStart, { parentContextId: canvases.domCanvas2D.id }); var webGLSupport = WebGlHelper_1.WebGlHelper.getWebGlSupport(); // console.log("webGLSupport", webGLSupport); if (webGLSupport === WebGlHelper_1.EWebGLSupport.WebGL2 || webGLSupport === WebGlHelper_1.EWebGLSupport.WebGL1) { var locateFile = (0, SciChartSurfaceBase_1.getLocateFile)(SciChart3DSurface_1.sciChartConfig3D); // @ts-ignore new WasmModule3D({ locateFile: locateFile, noInitialRun: true }) .then(function (wasmContext) { var _a, _b; (_a = loader.removeChartLoader) === null || _a === void 0 ? void 0 : _a.call(loader, canvases.domDivContainer, loaderDiv); // @ts-ignore wasmContext.doNotCaptureKeyboard = true; var revocable = (0, DeletableEntity_1.createWasmContextRevocableProxy)(wasmContext, canvases.domCanvas2D.id); var customResolve = function (res) { res.sciChart3DSurface.addDeletable({ delete: function () { revocable.revoke(); revocable = undefined; } }); performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.EngineInitEnd, { relatedId: mark === null || mark === void 0 ? void 0 : mark.detail.relatedId, contextId: res.sciChart3DSurface.id, parentContextId: canvases.domCanvas2D.id }); resolve(res); }; initDrawEngineSingleChart(revocable.proxy, canvases, customResolve, (_b = options === null || options === void 0 ? void 0 : options.theme) !== null && _b !== void 0 ? _b : SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME); // initDrawEngineSingleChart( // wasmContext, // canvases, // resolve, // (options?.theme as IThemeProvider) ?? SciChartSurfaceBase.DEFAULT_THEME // ); (0, BuildStamp_1.checkBuildStamp)(wasmContext); }) .catch(function (ex) { var _a; (_a = loader.removeChartLoader) === null || _a === void 0 ? void 0 : _a.call(loader, canvases.domDivContainer, loaderDiv); reject("Could not load SciChart WebAssembly module.\n Check your build process and ensure that your \"scichart3d.wasm\" and \"scichart3d.js\" files are from the same version"); throw ex; }); } else { throw Error("Sorry Your browser does not support WebGL."); } }); }; exports.createSingle3dInternal = createSingle3dInternal; // SINGLE CHART FUNCTIONS /** @ignore */ var initDrawEngineSingleChart = function (wasmContext, canvases, resolve, theme) { // @ts-ignore // wasmContext.preRun.push(() => (ENV.SDL_EMSCRIPTEN_KEYBOARD_ELEMENT = "#chart_WebGL")); var scs; wasmContext.canvas = canvases.domCanvasWebGL; var chartInitializer = { InitializeChart: function () { scs = new SciChart3DSurface_1.SciChart3DSurface(wasmContext, { canvases: canvases }); scs.applyTheme(theme); scs.addDeletable({ delete: function () { // Halt the engine wasmContext.TSRRequestExit(); frameRenderer3D.delete(); wasmContext.SCRTGetGlobalSampleChartInterface().SetFrameRenderer(null); wasmContext.SCRTGetGlobalSampleChartInterface().delete(); wasmContext.SCRTSetGlobalSampleChartInterface(null); licenseManager2D_1.licenseManager.clear(); } }); setTimeout(function () { scs.invalidateElement(); (0, licenseManager3D_1.applyLicense3D)(wasmContext, scs, true); var unsub = sciChartInitCommon_1.default.subscribeToResize(canvases.domChartRoot, canvases.aspect, scs); scs.addDeletable(unsub); scs.setIsInitialized(); resolve({ wasmContext: wasmContext, sciChart3DSurface: scs }); }, 0); }, Draw: function (canvasId) { logger_1.Logger.debug("Draw", canvasId); if (scs.isInitialized) { scs.doDrawingLoop(); } }, Update: function (deltaTime) { //Logger.log("SciChart3DSurface.ts Update()"); }, ShutDownChart: function () { //Logger.log("SciChart3DSurface.ts ShutDownChart"); } }; var chartInitObj = wasmContext.SCRTSampleChartInterface.implement(chartInitializer); var frameRenderer3D = new wasmContext.SCRTFrameRenderer3D(); chartInitObj.SetFrameRenderer(frameRenderer3D); chartInitObj.SetFPSCounterEnabled(false); // This may not be used in the case of 3D charts, but we set the property anyway as its passed down to TSR engine when initialising chartInitObj.SetWasmBufferSizesKb(SciChartDefaults_1.SciChartDefaults.wasmBufferSizesKb); wasmContext.SCRTSetGlobalSampleChartInterface(chartInitObj); // @ts-ignore wasmContext.callMain(); };