diff --git a/.gitignore b/.gitignore index 7091c57..843a1db 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,122 @@ Git_History node_modules /C:\nppdf32Log\debuglog.txt -.DS_Store doc/ .idea/ + + Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* \ No newline at end of file diff --git a/.jsbeautifyrc b/.jsbeautifyrc deleted file mode 100644 index 0809af6..0000000 --- a/.jsbeautifyrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "indentSize": 4, - "indentWithTabs": false, - "wrapLineLength": 0, - "eol": "\n" -} diff --git a/.jsdoc.json b/.jsdoc.json index 34236ed..6f7b038 100644 --- a/.jsdoc.json +++ b/.jsdoc.json @@ -1,21 +1,19 @@ { - "tags": { - "allowUnknownTags": true, - "dictionaries": ["jsdoc"] - }, - "source": { - "include": ["js", "package.json", "README.md"], - "includePattern": ".js$", - "excludePattern": "(node_modules/|doc)" - }, - "plugins": [ - "plugins/markdown" - ], - "opts": { - "destination": "./doc", - "encoding": "utf8", - "private": true, - "recurse": true, - "template": "./node_modules/minami" - } + "tags": { + "allowUnknownTags": true, + "dictionaries": ["jsdoc"] + }, + "source": { + "include": ["js", "package.json", "README.md"], + "includePattern": ".js$", + "excludePattern": "(node_modules/|doc)" + }, + "plugins": ["plugins/markdown"], + "opts": { + "destination": "./doc", + "encoding": "utf8", + "private": true, + "recurse": true, + "template": "./node_modules/minami" + } } diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index ffc6211..0000000 --- a/.jshintignore +++ /dev/null @@ -1,6 +0,0 @@ -js/typedarray.js -js/CanvasInput.js -js/spin.js -js/tinycolor.js -js/loglevel.js -js/slider.js diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 8c86fc7..0000000 --- a/.jshintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "curly": true, - "eqeqeq": true, - "immed": true, - "latedef": true, - "newcap": true, - "noarg": true, - "sub": true, - "undef": true, - "unused": true, - "boss": true, - "eqnull": true, - "node": true -} diff --git a/.npmignore b/.npmignore deleted file mode 100644 index e69de29..0000000 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6d82eb4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: node_js -node_js: - - "10.15.1" - -services: - - docker - -before_install: - - rm -rf dist/* - - npm install -g grunt - - npm install -q -script: - - grunt dist - -notifications: - email: - on_success: never - diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index d022682..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,276 +0,0 @@ -'use strict'; - -module.exports = function (grunt) { - - // Project configuration. - grunt.initConfig({ - // Metadata. - pkg: grunt.file.readJSON('package.json'), - jshint: { - options: { - jshintrc: '.jshintrc' - }, - gruntfile: { - src: 'Gruntfile.js' - }, - js: { - options: { - jshintrc: 'js/.jshintrc' - }, - src: ['js/**/*.js', 'test/tests*.js'] - }, - }, - qunit: { - options: { '--web-security': 'no', '--local-to-remote-url-access': 'yes' }, - all: ['test/test.html'] - }, - 'closure-compiler': { - sigplot_debug: { - closurePath: 'support/google-closure-compiler', - js: 'dist/sigplot.js', - maxBuffer: 500, - jsOutputFile: 'dist/sigplot-debug.js', - options: { - formatting: 'PRETTY_PRINT', - compilation_level: 'WHITESPACE_ONLY', - } - }, - sigplot_plugins_debug: { - closurePath: 'support/google-closure-compiler', - js: 'dist/sigplot.plugins.js', - maxBuffer: 500, - jsOutputFile: 'dist/sigplot.plugins-debug.js', - options: { - formatting: 'PRETTY_PRINT', - compilation_level: 'WHITESPACE_ONLY' - } - }, - sigplot_minimized: { - closurePath: 'support/google-closure-compiler', - js: 'dist/sigplot.js', - maxBuffer: 500, - jsOutputFile: 'dist/sigplot-minimized.js', - options: { - compilation_level: 'SIMPLE_OPTIMIZATIONS' - } - }, - sigplot_plugins_minimized: { - closurePath: 'support/google-closure-compiler', - js: 'dist/sigplot.plugins.js', - maxBuffer: 500, - jsOutputFile: 'dist/sigplot.plugins-minimized.js', - options: { - compilation_level: 'SIMPLE_OPTIMIZATIONS' - } - } - }, - jsdoc: { - sigplot: { - src: ['js/*.js'], - options: { - destination: 'doc', - template: './node_modules/minami/', - configure: '.jsdoc.json' - } - } - }, - clean: { - build: ["dist/**/*", "!dist/*.zip"], - doc: ["doc/**/*"] - }, - compress: { - main: { - options: { - archive: "dist/sigplot-<%= pkg.version %>-<%= grunt.template.today('yyyy-mm-dd') %>.zip", - }, - files: [ - {expand: true, cwd: 'dist/', src: ['*-debug.js'], dest: 'sigplot-<%= pkg.version %>'}, - {expand: true, cwd: 'dist/', src: ['*-minimized.js'], dest: 'sigplot-<%= pkg.version %>'}, - {src: ['doc/**/*'], dest: 'sigplot-<%= pkg.version %>'} - ] - } - }, - githash: { - main: { - options: {} - } - }, - replace: { - version: { - src: ["dist/*.js"], - overwrite: true, - replacements: [{ - from: /version-PLACEHOLDER/g, - to: "<%= pkg.version %>-<%= githash.main.short %>", - }], - } - }, - 'http-server': { - 'test': { - cache: 0, - port: 1337 - }, - }, - jsbeautifier: { - check: { - // Only check a subset of the files - src: [ - 'js/m.js', - 'js/mx.js', - 'js/sigplot.layer1d.js', - 'js/sigplot.layer2d.js', - 'js/sigplot.js', - 'js/sigplot.annotations.js', - 'js/sigplot.slider.js', - 'js/sigplot.accordion.js', - 'js/sigplot.boxes.js', - 'js/sigplot.playback.js', - 'js/sigplot.plugin.js', - 'test/tests.js', - 'test/tests.colormap.js', - 'test/tests.interactive-accordion.js', - 'test/tests.interactive-appearance.js', - 'test/tests.interactive-boxes.js', - 'test/tests.interactive-core.js', - 'test/tests.interactive-cuts.js', - 'test/tests.interactive-layer1d.js', - 'test/tests.interactive-layer2d.js', - 'test/tests.interactive-menu.js', - 'test/tests.interactive-mouse.js', - 'test/tests.interactive-slider.js', - 'test/tests.interactive-symbols.js', - 'test/tests.m.js', - 'test/tests.mx.js', - 'test/tests.sigplot.js' - ], - options: { - mode: "VERIFY_ONLY", - config: ".jsbeautifyrc" - } - }, - cleanup: { - // Only cleanup a subset of the files - src: [ - 'js/m.js', - 'js/mx.js', - 'js/sigplot.layer1d.js', - 'js/sigplot.layer2d.js', - 'js/sigplot.js', - 'js/sigplot.annotations.js', - 'js/sigplot.slider.js', - 'js/sigplot.accordion.js', - 'js/sigplot.boxes.js', - 'js/sigplot.playback.js', - 'js/sigplot.plugin.js', - 'test/tests.js', - 'test/tests.colormap.js', - 'test/tests.interactive-accordion.js', - 'test/tests.interactive-appearance.js', - 'test/tests.interactive-boxes.js', - 'test/tests.interactive-core.js', - 'test/tests.interactive-cuts.js', - 'test/tests.interactive-layer1d.js', - 'test/tests.interactive-layer2d.js', - 'test/tests.interactive-menu.js', - 'test/tests.interactive-mouse.js', - 'test/tests.interactive-slider.js', - 'test/tests.interactive-symbols.js', - 'test/tests.m.js', - 'test/tests.mx.js', - 'test/tests.sigplot.js' - ], - options: { - config: ".jsbeautifyrc" - } - } - }, - express: { - test: { - options: { - script: 'benchmark/express.js' - } - } - }, - karma: { - bench: { - configFile: 'karma.conf.js' - } - }, - browserify: { - sigplot: { - src: 'js/sigplot.js', - dest: 'dist/sigplot.js', - options: { - browserifyOptions: { - standalone: 'sigplot', - debug: true - }, - transform: [ - [ - 'babelify', { - "presets": ["@babel/preset-env"] - } - ] - ] - } - }, - plugins: { - src: [ 'js/plugins.js' ], - dest: 'dist/sigplot.plugins.js', - options: { - browserifyOptions: { - standalone: 'sigplot_plugins', - debug: true - }, - transform: [ - [ - 'babelify', { - "presets": ["@babel/preset-env"] - } - ] - ] - } - } - } - }); - - // These plugins provide necessary tasks. - grunt.loadNpmTasks('grunt-closure-compiler'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-qunit'); - grunt.loadNpmTasks('grunt-jsdoc'); - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-contrib-compress'); - grunt.loadNpmTasks('grunt-http-server'); - grunt.loadNpmTasks('grunt-jsbeautifier'); - grunt.loadNpmTasks('grunt-karma'); - grunt.loadNpmTasks('grunt-express-server'); - grunt.loadNpmTasks('grunt-browserify'); - grunt.loadNpmTasks('grunt-text-replace'); - grunt.loadNpmTasks('grunt-githash'); - - grunt.registerTask('build', ['jsbeautifier:check', 'jshint', 'browserify', 'githash', 'replace']); - - // Check everything is good - grunt.registerTask('test', ['build', 'qunit']); - - // Beautify the code - grunt.registerTask('prep', ['jsbeautifier:cleanup']); - - // Generate documentation - grunt.registerTask('generate-docs', ['jsdoc']); - - // Build a distributable release - grunt.registerTask('dist', ['clean', 'test', 'closure-compiler', 'jsdoc', 'compress']); - - // Default task. - grunt.registerTask('default', 'test'); - - // Benchmark in browsers. - grunt.registerTask('benchtest', ['express:test', 'karma:bench']); - grunt.registerTask('build_and_test', ['build', 'benchtest']); - - // for compatibility with the old grunt commands - grunt.registerTask('web_server', 'http-server'); - -}; diff --git a/dist/.gitignore b/dist/.gitignore deleted file mode 100644 index f1a9653..0000000 --- a/dist/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.js.report.txt -*.js diff --git a/dist/.npmignore b/dist/.npmignore deleted file mode 100644 index 50543e5..0000000 --- a/dist/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -*.js.report.txt -*.zip diff --git a/examples/basic/demo.js b/examples/basic/demo.js index c22e2bf..730bb9d 100644 --- a/examples/basic/demo.js +++ b/examples/basic/demo.js @@ -1,18 +1,18 @@ -window.onload = function() { +window.onload = function () { var plot_options = { autohide_panbars: true, - hide_note: true + hide_note: true, }; var data = [1, 2, 3, 4, 5, 4, 3, 2, 1]; // the series of y-values var data_header = { xunits: "Time", - xstart: 100, // the start of the x-axis - xdelta: 50, // the x-axis step between each data point - yunits: "Power" + xstart: 100, // the start of the x-axis + xdelta: 50, // the x-axis step between each data point + yunits: "Power", }; var layer_options = { - name: "Sample Data" + name: "Sample Data", }; - var plot = new sigplot.Plot(document.getElementById('plot'), plot_options); + var plot = new sigplot.Plot(document.getElementById("plot"), plot_options); plot.overlay_array(data, data_header, layer_options); -} +}; diff --git a/js/.jshintrc b/js/.jshintrc deleted file mode 100644 index e19e1bf..0000000 --- a/js/.jshintrc +++ /dev/null @@ -1,21 +0,0 @@ -{ - "curly": true, - "eqeqeq": true, - "immed": true, - "latedef": "nofunc", - "newcap": true, - "noarg": true, - "sub": true, - "undef": true, - "boss": true, - "eqnull": true, - "browser": true, - "shadow": true, - "-W099": true, - "esversion": 6, - "globals": { - "UInt8Array": false, - "BlueHeader": false, - "JSON": true - } -} diff --git a/js/CanvasInput.js b/js/CanvasInput.js index 275cc01..22f9333 100644 --- a/js/CanvasInput.js +++ b/js/CanvasInput.js @@ -17,55 +17,56 @@ /* global module */ /* global require */ -(function() { +(function () { // create a buffer that stores all inputs so that tabbing // between them is made possible. var inputs = []; // initialize the Canvas Input - var CanvasInput = window.CanvasInput = function(o) { + var CanvasInput = (window.CanvasInput = function (o) { var self = this; o = o ? o : {}; // setup the defaults self._canvas = o.canvas || null; - self._ctx = self._canvas ? self._canvas.getContext('2d') : null; + self._ctx = self._canvas ? self._canvas.getContext("2d") : null; self._x = o.x || 0; self._y = o.y || 0; self._extraX = o.extraX || 0; self._extraY = o.extraY || 0; self._fontSize = o.fontSize || 14; - self._fontFamily = o.fontFamily || 'Arial'; - self._fontColor = o.fontColor || '#000'; - self._placeHolderColor = o.placeHolderColor || '#bfbebd'; - self._fontWeight = o.fontWeight || 'normal'; - self._fontStyle = o.fontStyle || 'normal'; + self._fontFamily = o.fontFamily || "Arial"; + self._fontColor = o.fontColor || "#000"; + self._placeHolderColor = o.placeHolderColor || "#bfbebd"; + self._fontWeight = o.fontWeight || "normal"; + self._fontStyle = o.fontStyle || "normal"; self._readonly = o.readonly || false; self._maxlength = o.maxlength || null; self._width = o.width || 150; self._height = o.height || self._fontSize; self._padding = o.padding >= 0 ? o.padding : 5; self._borderWidth = o.borderWidth >= 0 ? o.borderWidth : 1; - self._borderColor = o.borderColor || '#959595'; + self._borderColor = o.borderColor || "#959595"; self._borderRadius = o.borderRadius >= 0 ? o.borderRadius : 3; - self._backgroundImage = o.backgroundImage || ''; - self._boxShadow = o.boxShadow || '1px 1px 0px rgba(255, 255, 255, 1)'; - self._innerShadow = o.innerShadow || '0px 0px 4px rgba(0, 0, 0, 0.4)'; - self._selectionColor = o.selectionColor || 'rgba(179, 212, 253, 0.8)'; - self._placeHolder = o.placeHolder || ''; + self._backgroundImage = o.backgroundImage || ""; + self._boxShadow = o.boxShadow || "1px 1px 0px rgba(255, 255, 255, 1)"; + self._innerShadow = o.innerShadow || "0px 0px 4px rgba(0, 0, 0, 0.4)"; + self._selectionColor = o.selectionColor || "rgba(179, 212, 253, 0.8)"; + self._placeHolder = o.placeHolder || ""; self._value = o.value || self._placeHolder; - self._onsubmit = o.onsubmit || function() {}; - self._onkeydown = o.onkeydown || function() {}; - self._onkeyup = o.onkeyup || function() {}; - self._onfocus = o.onfocus || function() {}; - self._onblur = o.onblur || function() {}; + self._onsubmit = o.onsubmit || function () {}; + self._onkeydown = o.onkeydown || function () {}; + self._onkeyup = o.onkeyup || function () {}; + self._onfocus = o.onfocus || function () {}; + self._onblur = o.onblur || function () {}; self._cursor = false; self._cursorPos = 0; self._hasFocus = false; self._selection = [0, 0]; self._wasOver = false; - self._renderOnReturn = (o.renderOnReturn !== undefined ? o.renderOnReturn : true); + self._renderOnReturn = + o.renderOnReturn !== undefined ? o.renderOnReturn : true; self._disableBlur = o.disableBlur || false; self._tabToClear = o.tabToClear || false; @@ -76,19 +77,25 @@ self._calcWH(); // setup the off-DOM canvas - self._renderCanvas = document.createElement('canvas'); - self._renderCanvas.setAttribute('width', self.outerW); - self._renderCanvas.setAttribute('height', self.outerH); - self._renderCtx = self._renderCanvas.getContext('2d'); + self._renderCanvas = document.createElement("canvas"); + self._renderCanvas.setAttribute("width", self.outerW); + self._renderCanvas.setAttribute("height", self.outerH); + self._renderCtx = self._renderCanvas.getContext("2d"); // setup another off-DOM canvas for inner-shadows - self._shadowCanvas = document.createElement('canvas'); - self._shadowCanvas.setAttribute('width', self._width + self._padding * 2); - self._shadowCanvas.setAttribute('height', self._height + self._padding * 2); - self._shadowCtx = self._shadowCanvas.getContext('2d'); + self._shadowCanvas = document.createElement("canvas"); + self._shadowCanvas.setAttribute( + "width", + self._width + self._padding * 2 + ); + self._shadowCanvas.setAttribute( + "height", + self._height + self._padding * 2 + ); + self._shadowCtx = self._shadowCanvas.getContext("2d"); // setup the background color - if (typeof o.backgroundGradient !== 'undefined') { + if (typeof o.backgroundGradient !== "undefined") { self._backgroundColor = self._renderCtx.createLinearGradient( 0, 0, @@ -98,62 +105,74 @@ self._backgroundColor.addColorStop(0, o.backgroundGradient[0]); self._backgroundColor.addColorStop(1, o.backgroundGradient[1]); } else { - self._backgroundColor = o.backgroundColor || '#fff'; + self._backgroundColor = o.backgroundColor || "#fff"; } // setup main canvas events if (self._canvas) { - self.mousemoveCanvasListener = function(e) { + self.mousemoveCanvasListener = function (e) { e = e || window.event; self.mousemove(e, self); }; - self._canvas.addEventListener('mousemove', self.mousemoveCanvasListener, false); + self._canvas.addEventListener( + "mousemove", + self.mousemoveCanvasListener, + false + ); - self.mousedownCanvasListener = function(e) { + self.mousedownCanvasListener = function (e) { e = e || window.event; self.mousedown(e, self); }; - self._canvas.addEventListener('mousedown', self.mousedownCanvasListener, false); + self._canvas.addEventListener( + "mousedown", + self.mousedownCanvasListener, + false + ); - self.mouseupCanvasListener = function(e) { + self.mouseupCanvasListener = function (e) { e = e || window.event; self.mouseup(e, self); }; - self._canvas.addEventListener('mouseup', self.mouseupCanvasListener, false); + self._canvas.addEventListener( + "mouseup", + self.mouseupCanvasListener, + false + ); } // setup a global mouseup to blur the input outside of the canvas - self.mouseupWindowListener = function(e) { + self.mouseupWindowListener = function (e) { e = e || window.event; if (self._hasFocus && !self._mouseDown) { self.blur(); } }; - window.addEventListener('mouseup', self.mouseupWindowListener, true); + window.addEventListener("mouseup", self.mouseupWindowListener, true); // setup the keydown listener - self.keydownWindowListener = function(e) { + self.keydownWindowListener = function (e) { e = e || window.event; if (self._hasFocus) { self.keydown(e, self); } }; - window.addEventListener('keydown', self.keydownWindowListener, false); + window.addEventListener("keydown", self.keydownWindowListener, false); // setup the keyup listener - self.keyupWindowListener = function(e) { + self.keyupWindowListener = function (e) { e = e || window.event; if (self._hasFocus) { self._onkeyup(e, self); } }; - window.addEventListener('keyup', self.keyupWindowListener, false); + window.addEventListener("keyup", self.keyupWindowListener, false); // setup the 'paste' listener - self.pasteWindowListener = function(e) { + self.pasteWindowListener = function (e) { e = e || window.event; if (self._hasFocus) { - var text = e.clipboardData.getData('text/plain'), + var text = e.clipboardData.getData("text/plain"), startText = self._value.substr(0, self._cursorPos), endText = self._value.substr(self._cursorPos); self._value = startText + text + endText; @@ -162,7 +181,7 @@ self.render(); } }; - window.addEventListener('paste', self.pasteWindowListener, false); + window.addEventListener("paste", self.pasteWindowListener, false); // add this to the buffer inputs.push(self); @@ -170,7 +189,7 @@ // draw the text box self.render(); - }; + }); // setup the prototype CanvasInput.prototype = { @@ -179,12 +198,12 @@ * @param {Object} data Canvas reference. * @return {Mixed} CanvasInput or current canvas. */ - canvas: function(data) { + canvas: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._canvas = data; - self._ctx = self._canvas.getContext('2d'); + self._ctx = self._canvas.getContext("2d"); return self.render(); } else { @@ -197,10 +216,10 @@ * @param {Number} data The pixel position along the x-coordinate. * @return {Mixed} CanvasInput or current x-value. */ - x: function(data) { + x: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._x = data; return self.render(); @@ -214,10 +233,10 @@ * @param {Number} data The pixel position along the y-coordinate. * @return {Mixed} CanvasInput or current y-value. */ - y: function(data) { + y: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._y = data; return self.render(); @@ -231,10 +250,10 @@ * @param {Number} data The pixel position along the x-coordinate. * @return {Mixed} CanvasInput or current x-value. */ - extraX: function(data) { + extraX: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._extraX = data; return self.render(); @@ -248,10 +267,10 @@ * @param {Number} data The pixel position along the y-coordinate. * @return {Mixed} CanvasInput or current y-value. */ - extraY: function(data) { + extraY: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._extraY = data; return self.render(); @@ -265,10 +284,10 @@ * @param {Number} data Font size. * @return {Mixed} CanvasInput or current font size. */ - fontSize: function(data) { + fontSize: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._fontSize = data; return self.render(); @@ -282,10 +301,10 @@ * @param {String} data Font family. * @return {Mixed} CanvasInput or current font family. */ - fontFamily: function(data) { + fontFamily: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._fontFamily = data; return self.render(); @@ -299,10 +318,10 @@ * @param {String} data Font color. * @return {Mixed} CanvasInput or current font color. */ - fontColor: function(data) { + fontColor: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._fontColor = data; return self.render(); @@ -316,10 +335,10 @@ * @param {String} data Font color. * @return {Mixed} CanvasInput or current place holder font color. */ - placeHolderColor: function(data) { + placeHolderColor: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._placeHolderColor = data; return self.render(); @@ -333,10 +352,10 @@ * @param {String} data Font weight. * @return {Mixed} CanvasInput or current font weight. */ - fontWeight: function(data) { + fontWeight: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._fontWeight = data; return self.render(); @@ -350,10 +369,10 @@ * @param {String} data Font style. * @return {Mixed} CanvasInput or current font style. */ - fontStyle: function(data) { + fontStyle: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._fontStyle = data; return self.render(); @@ -367,10 +386,10 @@ * @param {Number} data Width in pixels. * @return {Mixed} CanvasInput or current width. */ - width: function(data) { + width: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._width = data; self._calcWH(); self._updateCanvasWH(); @@ -386,10 +405,10 @@ * @param {Number} data Height in pixels. * @return {Mixed} CanvasInput or current height. */ - height: function(data) { + height: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._height = data; self._calcWH(); self._updateCanvasWH(); @@ -405,10 +424,10 @@ * @param {Number} data Padding in pixels. * @return {Mixed} CanvasInput or current padding. */ - padding: function(data) { + padding: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._padding = data; self._calcWH(); self._updateCanvasWH(); @@ -424,10 +443,10 @@ * @param {Number} data Border width. * @return {Mixed} CanvasInput or current border width. */ - borderWidth: function(data) { + borderWidth: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._borderWidth = data; self._calcWH(); self._updateCanvasWH(); @@ -443,10 +462,10 @@ * @param {String} data Border color. * @return {Mixed} CanvasInput or current border color. */ - borderColor: function(data) { + borderColor: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._borderColor = data; return self.render(); @@ -460,10 +479,10 @@ * @param {Number} data Border radius. * @return {Mixed} CanvasInput or current border radius. */ - borderRadius: function(data) { + borderRadius: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._borderRadius = data; return self.render(); @@ -477,10 +496,10 @@ * @param {Number} data Background color. * @return {Mixed} CanvasInput or current background color. */ - backgroundColor: function(data) { + backgroundColor: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._backgroundColor = data; return self.render(); @@ -494,10 +513,10 @@ * @param {Number} data Background gradient. * @return {Mixed} CanvasInput or current background gradient. */ - backgroundGradient: function(data) { + backgroundGradient: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._backgroundColor = self._renderCtx.createLinearGradient( 0, 0, @@ -519,32 +538,47 @@ * @param {Boolean} doReturn (optional) True to prevent a premature render. * @return {Mixed} CanvasInput or current box shadow. */ - boxShadow: function(data, doReturn) { + boxShadow: function (data, doReturn) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { // parse box shadow - var boxShadow = data.split('px '); + var boxShadow = data.split("px "); self._boxShadow = { - x: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[0], 10), - y: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[1], 10), - blur: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[2], 10), - color: self._boxShadow === 'none' ? '' : boxShadow[3] + x: + self._boxShadow === "none" + ? 0 + : parseInt(boxShadow[0], 10), + y: + self._boxShadow === "none" + ? 0 + : parseInt(boxShadow[1], 10), + blur: + self._boxShadow === "none" + ? 0 + : parseInt(boxShadow[2], 10), + color: self._boxShadow === "none" ? "" : boxShadow[3], }; // take into account the shadow and its direction if (self._boxShadow.x < 0) { - self.shadowL = Math.abs(self._boxShadow.x) + self._boxShadow.blur; + self.shadowL = + Math.abs(self._boxShadow.x) + self._boxShadow.blur; self.shadowR = self._boxShadow.blur + self._boxShadow.x; } else { - self.shadowL = Math.abs(self._boxShadow.blur - self._boxShadow.x); + self.shadowL = Math.abs( + self._boxShadow.blur - self._boxShadow.x + ); self.shadowR = self._boxShadow.blur + self._boxShadow.x; } if (self._boxShadow.y < 0) { - self.shadowT = Math.abs(self._boxShadow.y) + self._boxShadow.blur; + self.shadowT = + Math.abs(self._boxShadow.y) + self._boxShadow.blur; self.shadowB = self._boxShadow.blur + self._boxShadow.y; } else { - self.shadowT = Math.abs(self._boxShadow.blur - self._boxShadow.y); + self.shadowT = Math.abs( + self._boxShadow.blur - self._boxShadow.y + ); self.shadowB = self._boxShadow.blur + self._boxShadow.y; } @@ -568,10 +602,10 @@ * @param {String} data In the format of a CSS box shadow (1px 1px 1px rgba(0, 0, 0.5)). * @return {Mixed} CanvasInput or current inner shadow. */ - innerShadow: function(data) { + innerShadow: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._innerShadow = data; return self.render(); @@ -585,10 +619,10 @@ * @param {String} data Color. * @return {Mixed} CanvasInput or current selection color. */ - selectionColor: function(data) { + selectionColor: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._selectionColor = data; return self.render(); @@ -602,10 +636,10 @@ * @param {String} data Place holder text. * @return {Mixed} CanvasInput or current place holder text. */ - placeHolder: function(data) { + placeHolder: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._placeHolder = data; return self.render(); @@ -619,10 +653,10 @@ * @param {String} data Text value. * @return {Mixed} CanvasInput or current text value. */ - value: function(data) { + value: function (data) { var self = this; - if (typeof data !== 'undefined') { + if (typeof data !== "undefined") { self._value = data; return self.focus(); @@ -635,10 +669,10 @@ * Set or fire the onsubmit event. * @param {Function} fn Custom callback. */ - onsubmit: function(fn) { + onsubmit: function (fn) { var self = this; - if (typeof fn !== 'undefined') { + if (typeof fn !== "undefined") { self._onsubmit = fn; return self; @@ -651,10 +685,10 @@ * Set or fire the onkeydown event. * @param {Function} fn Custom callback. */ - onkeydown: function(fn) { + onkeydown: function (fn) { var self = this; - if (typeof fn !== 'undefined') { + if (typeof fn !== "undefined") { self._onkeydown = fn; return self; @@ -667,10 +701,10 @@ * Set or fire the onkeyup event. * @param {Function} fn Custom callback. */ - onkeyup: function(fn) { + onkeyup: function (fn) { var self = this; - if (typeof fn !== 'undefined') { + if (typeof fn !== "undefined") { self._onkeyup = fn; return self; @@ -685,7 +719,7 @@ * @param {Number} pos (optional) The position to place the cursor. * @return {CanvasInput} */ - focus: function(pos) { + focus: function (pos) { var self = this, input; @@ -707,11 +741,12 @@ } // update the cursor position - self._cursorPos = (typeof pos === 'number') ? pos : self._clipText().length; + self._cursorPos = + typeof pos === "number" ? pos : self._clipText().length; // clear the place holder if (self._placeHolder === self._value) { - self._value = ''; + self._value = ""; } self._hasFocus = true; @@ -721,32 +756,53 @@ if (self._cursorInterval) { clearInterval(self._cursorInterval); } - self._cursorInterval = setInterval(function() { + self._cursorInterval = setInterval(function () { self._cursor = !self._cursor; self.render(); }, 500); // check if this is Chrome for Android (there is a bug with returning incorrect character key codes) var nav = navigator.userAgent.toLowerCase(), - isChromeMobile = (nav.indexOf('chrome') >= 0 && nav.indexOf('mobile') >= 0 && nav.indexOf('android') >= 0); + isChromeMobile = + nav.indexOf("chrome") >= 0 && + nav.indexOf("mobile") >= 0 && + nav.indexOf("android") >= 0; // add support for mobile - var isMobile = (typeof window.orientation !== 'undefined'); - if (isMobile && !isChromeMobile && document && document.createElement && (input = document.createElement('input'))) { - input.type = 'text'; + var isMobile = typeof window.orientation !== "undefined"; + if ( + isMobile && + !isChromeMobile && + document && + document.createElement && + (input = document.createElement("input")) + ) { + input.type = "text"; input.style.opacity = 0; - input.style.position = 'absolute'; - input.style.left = (self._x + self._extraX + (self._canvas ? self._canvas.offsetLeft : 0)) + 'px'; - input.style.top = (self._y + self._extraY + (self._canvas ? self._canvas.offsetTop : 0)) + 'px'; + input.style.position = "absolute"; + input.style.left = + self._x + + self._extraX + + (self._canvas ? self._canvas.offsetLeft : 0) + + "px"; + input.style.top = + self._y + + self._extraY + + (self._canvas ? self._canvas.offsetTop : 0) + + "px"; input.style.width = self._width; input.style.height = 0; document.body.appendChild(input); input.focus(); - input.addEventListener('blur', function() { - self.blur(self); - }, false); + input.addEventListener( + "blur", + function () { + self.blur(self); + }, + false + ); } else if (isMobile) { - self.value(prompt(self._placeHolder) || ''); + self.value(prompt(self._placeHolder) || ""); } return self.render(); @@ -757,7 +813,7 @@ * @param {Object} _this Reference to this. * @return {CanvasInput} */ - blur: function(_this) { + blur: function (_this) { var self = _this || this; if (!self._disableBlur) { @@ -771,7 +827,7 @@ self._selection = [0, 0]; // fill the place holder - if (self._value === '') { + if (self._value === "") { self._value = self._placeHolder; } } @@ -783,7 +839,7 @@ * Maintains continual focus on the CanvasInput by disabling blur. * @param {Object} _this Reference to this. */ - disableBlur: function(_this) { + disableBlur: function (_this) { var self = _this || this; self._disableBlur = true; }, @@ -792,7 +848,7 @@ * Allows the CanvasInput to blur or focus by re-enabling blur. * @param {Object} _this Reference to this. */ - enableBlur: function(_this) { + enableBlur: function (_this) { var self = _this || this; self._disableBlur = false; }, @@ -803,11 +859,12 @@ * @param {CanvasInput} self * @return {CanvasInput} */ - keydown: function(e, self) { + keydown: function (e, self) { var keyCode = e.which, isShift = e.shiftKey, key = null, - startText, endText; + startText, + endText; // make sure the correct text field is being updated if (!self._hasFocus) { @@ -832,43 +889,53 @@ // prevent the default action e.preventDefault(); - if (keyCode === 8) { // backspace + if (keyCode === 8) { + // backspace if (!self._clearSelection()) { if (self._cursorPos > 0) { startText = self._value.substr(0, self._cursorPos - 1); - endText = self._value.substr(self._cursorPos, self._value.length); + endText = self._value.substr( + self._cursorPos, + self._value.length + ); self._value = startText + endText; self._cursorPos--; } } - } else if (keyCode === 37) { // left arrow key + } else if (keyCode === 37) { + // left arrow key if (self._cursorPos > 0) { self._cursorPos--; self._cursor = true; self._selection = [0, 0]; } - } else if (keyCode === 39) { // right arrow key + } else if (keyCode === 39) { + // right arrow key if (self._cursorPos < self._value.length) { self._cursorPos++; self._cursor = true; self._selection = [0, 0]; } - } else if (keyCode === 13) { // enter key + } else if (keyCode === 13) { + // enter key self._onsubmit(e, self); - } else if (keyCode === 9) { // tab key + } else if (keyCode === 9) { + // tab key if (self._tabToClear) { self._value = ""; self._cursorPos = 0; } else { - var next = (inputs[self._inputsIndex + 1]) ? self._inputsIndex + 1 : 0; + var next = inputs[self._inputsIndex + 1] + ? self._inputsIndex + 1 + : 0; if (next !== self._inputsIndex) { self.blur(); - setTimeout(function() { + setTimeout(function () { inputs[next].focus(); }, 10); } } - } else if (key = self._mapCodeToKey(isShift, keyCode)) { + } else if ((key = self._mapCodeToKey(isShift, keyCode))) { self._clearSelection(); // enforce the max length @@ -876,8 +943,12 @@ return; } - startText = (self._value) ? self._value.substr(0, self._cursorPos) : ''; - endText = (self._value) ? self._value.substr(self._cursorPos) : ''; + startText = self._value + ? self._value.substr(0, self._cursorPos) + : ""; + endText = self._value + ? self._value.substr(self._cursorPos) + : ""; self._value = startText + key + endText; self._cursorPos++; } @@ -885,7 +956,7 @@ if ((keyCode == 13 && self._renderOnReturn) || keyCode !== 13) { return self.render(); } else { - return function() {}; + return function () {}; } }, @@ -896,7 +967,7 @@ * @param {CanvasInput} self * @return {CanvasInput} */ - click: function(e, self) { + click: function (e, self) { var mouse = self._mousePos(e), x = mouse.x, y = mouse.y; @@ -907,7 +978,7 @@ return; } - if (self._canvas && self._overInput(x, y) || !self._canvas) { + if ((self._canvas && self._overInput(x, y)) || !self._canvas) { if (self._mouseDown) { self._mouseDown = false; self.click(e, self); @@ -924,17 +995,17 @@ * @param {CanvasInput} self * @return {CanvasInput} */ - mousemove: function(e, self) { + mousemove: function (e, self) { var mouse = self._mousePos(e), x = mouse.x, y = mouse.y, isOver = self._overInput(x, y); if (isOver && self._canvas) { - self._canvas.style.cursor = 'text'; + self._canvas.style.cursor = "text"; self._wasOver = true; } else if (self._wasOver && self._canvas) { - self._canvas.style.cursor = 'default'; + self._canvas.style.cursor = "default"; self._wasOver = false; } @@ -951,7 +1022,10 @@ return; } - if (self._selection[0] !== start || self._selection[1] !== end) { + if ( + self._selection[0] !== start || + self._selection[1] !== end + ) { self._selection = [start, end]; self.render(); } @@ -963,7 +1037,7 @@ * @param {Event} e The mousedown event. * @param {CanvasInput} self */ - mousedown: function(e, self) { + mousedown: function (e, self) { var mouse = self._mousePos(e), x = mouse.x, y = mouse.y, @@ -983,14 +1057,19 @@ * @param {Event} e The mouseup event. * @param {CanvasInput} self */ - mouseup: function(e, self) { + mouseup: function (e, self) { var mouse = self._mousePos(e), x = mouse.x, y = mouse.y; // update selection if a drag has happened var isSelection = self._clickPos(x, y) !== self._selectionStart; - if (self._hasFocus && self._selectionStart >= 0 && self._overInput(x, y) && isSelection) { + if ( + self._hasFocus && + self._selectionStart >= 0 && + self._overInput(x, y) && + isSelection + ) { self._selectionUpdated = true; delete self._selectionStart; self.render(); @@ -1005,7 +1084,7 @@ * Helper method to get the off-DOM canvas. * @return {Object} Reference to the canvas. */ - renderCanvas: function() { + renderCanvas: function () { return this._renderCanvas; }, @@ -1013,18 +1092,46 @@ * Helper method to remove all event listeners, stop the blinking cursor and * reset the cursor style. */ - cleanup: function() { - this._canvas.removeEventListener("mouseup", this.mouseupCanvasListener, false); - this._canvas.removeEventListener("mousedown", this.mousedownCanvasListener, false); - this._canvas.removeEventListener("mousemove", this.mousemoveCanvasListener, false); - window.removeEventListener("keydown", this.keydownWindowListener, false); - window.removeEventListener("keyup", this.keyupWindowListener, false); - window.removeEventListener("mouseup", this.mouseupWindowListener, true); - window.removeEventListener("paste", this.pasteWindowListener, false); + cleanup: function () { + this._canvas.removeEventListener( + "mouseup", + this.mouseupCanvasListener, + false + ); + this._canvas.removeEventListener( + "mousedown", + this.mousedownCanvasListener, + false + ); + this._canvas.removeEventListener( + "mousemove", + this.mousemoveCanvasListener, + false + ); + window.removeEventListener( + "keydown", + this.keydownWindowListener, + false + ); + window.removeEventListener( + "keyup", + this.keyupWindowListener, + false + ); + window.removeEventListener( + "mouseup", + this.mouseupWindowListener, + true + ); + window.removeEventListener( + "paste", + this.pasteWindowListener, + false + ); clearInterval(this._cursorInterval); - this._canvas.style.cursor = 'default'; - for (var i = (inputs.length- 1); i >= 0 ; i--) { + this._canvas.style.cursor = "default"; + for (var i = inputs.length - 1; i >= 0; i--) { if (inputs[i] === this) { inputs.splice(i, 1); } @@ -1036,7 +1143,7 @@ * and if a main canvas is provided, draws it all onto that. * @return {CanvasInput} */ - render: function() { + render: function () { var self = this, ctx = self._renderCtx, w = self.outerW, @@ -1058,7 +1165,14 @@ // draw the border if (self._borderWidth > 0) { ctx.fillStyle = self._borderColor; - self._roundedRect(ctx, self.shadowL, self.shadowT, w - sw, h - sh, br); + self._roundedRect( + ctx, + self.shadowL, + self.shadowT, + w - sw, + h - sh, + br + ); ctx.fill(); ctx.shadowOffsetX = 0; @@ -1067,7 +1181,7 @@ } // draw the text box background - self._drawTextBox(function() { + self._drawTextBox(function () { // make sure all shadows are reset ctx.shadowOffsetX = 0; ctx.shadowOffsetY = 0; @@ -1077,38 +1191,78 @@ var text = self._clipText(); // draw the selection - var paddingBorder = self._padding + self._borderWidth + self.shadowT; + var paddingBorder = + self._padding + self._borderWidth + self.shadowT; if (self._selection[1] > 0) { - var selectOffset = self._textWidth(text.substring(0, self._selection[0])), - selectWidth = self._textWidth(text.substring(self._selection[0], self._selection[1])); + var selectOffset = self._textWidth( + text.substring(0, self._selection[0]) + ), + selectWidth = self._textWidth( + text.substring( + self._selection[0], + self._selection[1] + ) + ); ctx.fillStyle = self._selectionColor; - ctx.fillRect(paddingBorder + selectOffset, paddingBorder, selectWidth, self._height); + ctx.fillRect( + paddingBorder + selectOffset, + paddingBorder, + selectWidth, + self._height + ); } // draw the cursor - ctx.fillStyle = (self._placeHolder === self._value && self._value !== '') ? self._placeHolderColor : self._fontColor; + ctx.fillStyle = + self._placeHolder === self._value && self._value !== "" + ? self._placeHolderColor + : self._fontColor; if (self._cursor) { - var cursorOffset = self._textWidth(text.substring(0, self._cursorPos)); - - ctx.fillRect(paddingBorder + cursorOffset, paddingBorder, 1, self._height); + var cursorOffset = self._textWidth( + text.substring(0, self._cursorPos) + ); + + ctx.fillRect( + paddingBorder + cursorOffset, + paddingBorder, + 1, + self._height + ); } // draw the text var textX = self._padding + self._borderWidth + self.shadowL, textY = Math.round(paddingBorder + self._height / 2); - ctx.font = self._fontStyle + ' ' + self._fontWeight + ' ' + self._fontSize + 'px ' + self._fontFamily; - ctx.textAlign = 'left'; - ctx.textBaseline = 'middle'; + ctx.font = + self._fontStyle + + " " + + self._fontWeight + + " " + + self._fontSize + + "px " + + self._fontFamily; + ctx.textAlign = "left"; + ctx.textBaseline = "middle"; ctx.fillText(text, textX, textY); // parse inner shadow - var innerShadow = self._innerShadow.split('px '), - isOffsetX = self._innerShadow === 'none' ? 0 : parseInt(innerShadow[0], 10), - isOffsetY = self._innerShadow === 'none' ? 0 : parseInt(innerShadow[1], 10), - isBlur = self._innerShadow === 'none' ? 0 : parseInt(innerShadow[2], 10), - isColor = self._innerShadow === 'none' ? '' : innerShadow[3]; + var innerShadow = self._innerShadow.split("px "), + isOffsetX = + self._innerShadow === "none" + ? 0 + : parseInt(innerShadow[0], 10), + isOffsetY = + self._innerShadow === "none" + ? 0 + : parseInt(innerShadow[1], 10), + isBlur = + self._innerShadow === "none" + ? 0 + : parseInt(innerShadow[2], 10), + isColor = + self._innerShadow === "none" ? "" : innerShadow[3]; // draw the inner-shadow (damn you canvas, this should be easier than this...) if (isBlur > 0) { @@ -1141,21 +1295,42 @@ shadowCtx.fillRect(-100, -1 * h, 100, 3 * h); // create a clipping mask on the main canvas - self._roundedRect(ctx, bw + self.shadowL, bw + self.shadowT, w - bw * 2 - sw, h - bw * 2 - sh, br); + self._roundedRect( + ctx, + bw + self.shadowL, + bw + self.shadowT, + w - bw * 2 - sw, + h - bw * 2 - sh, + br + ); ctx.clip(); // draw the inner-shadow from the off-DOM canvas - ctx.drawImage(self._shadowCanvas, 0, 0, scw, sch, bw + self.shadowL, bw + self.shadowT, scw, sch); + ctx.drawImage( + self._shadowCanvas, + 0, + 0, + scw, + sch, + bw + self.shadowL, + bw + self.shadowT, + scw, + sch + ); } // draw to the visible canvas if (self._ctx) { - self._ctx.clearRect(self._x, self._y, ctx.canvas.width, ctx.canvas.height); + self._ctx.clearRect( + self._x, + self._y, + ctx.canvas.width, + ctx.canvas.height + ); self._ctx.drawImage(self._renderCanvas, self._x, self._y); } return self; - }); }, @@ -1163,7 +1338,7 @@ * Draw the text box area with either an image or background color. * @param {Function} fn Callback. */ - _drawTextBox: function(fn) { + _drawTextBox: function (fn) { var self = this, ctx = self._renderCtx, w = self.outerW, @@ -1174,17 +1349,34 @@ sh = self.shadowH; // only draw the background shape if no image is being used - if (self._backgroundImage === '') { + if (self._backgroundImage === "") { ctx.fillStyle = self._backgroundColor; - self._roundedRect(ctx, bw + self.shadowL, bw + self.shadowT, w - bw * 2 - sw, h - bw * 2 - sh, br); + self._roundedRect( + ctx, + bw + self.shadowL, + bw + self.shadowT, + w - bw * 2 - sw, + h - bw * 2 - sh, + br + ); ctx.fill(); fn(); } else { var img = new Image(); img.src = self._backgroundImage; - img.onload = function() { - ctx.drawImage(img, 0, 0, img.width, img.height, bw + self.shadowL, bw + self.shadowT, w, h); + img.onload = function () { + ctx.drawImage( + img, + 0, + 0, + img.width, + img.height, + bw + self.shadowL, + bw + self.shadowT, + w, + h + ); fn(); }; @@ -1195,7 +1387,7 @@ * Deletes selected text in selection range and repositions cursor. * @return {Boolean} true if text removed. */ - _clearSelection: function() { + _clearSelection: function () { var self = this; if (self._selection[1] > 0) { @@ -1203,9 +1395,10 @@ var start = self._selection[0], end = self._selection[1]; - self._value = self._value.substr(0, start) + self._value.substr(end); + self._value = + self._value.substr(0, start) + self._value.substr(end); self._cursorPos = start; - self._cursorPos = (self._cursorPos < 0) ? 0 : self._cursorPos; + self._cursorPos = self._cursorPos < 0 ? 0 : self._cursorPos; self._selection = [0, 0]; return true; @@ -1219,15 +1412,18 @@ * @param {String} value The text to clip. * @return {String} The clipped text. */ - _clipText: function(value) { + _clipText: function (value) { var self = this; - value = (typeof value === 'undefined') ? self._value : value; + value = typeof value === "undefined" ? self._value : value; var textWidth = self._textWidth(value), fillPer = textWidth / (self._width - self._padding), - text = fillPer > 1 ? value.substr(-1 * Math.floor(value.length / fillPer)) : value; + text = + fillPer > 1 + ? value.substr(-1 * Math.floor(value.length / fillPer)) + : value; - return text + ''; + return text + ""; }, /** @@ -1235,12 +1431,19 @@ * @param {String} text The text to measure. * @return {Number} The measured width. */ - _textWidth: function(text) { + _textWidth: function (text) { var self = this, ctx = self._renderCtx; - ctx.font = self._fontStyle + ' ' + self._fontWeight + ' ' + self._fontSize + 'px ' + self._fontFamily; - ctx.textAlign = 'left'; + ctx.font = + self._fontStyle + + " " + + self._fontWeight + + " " + + self._fontSize + + "px " + + self._fontFamily; + ctx.textAlign = "left"; return ctx.measureText(text).width; }, @@ -1248,27 +1451,41 @@ /** * Recalculate the outer with and height of the text box. */ - _calcWH: function() { + _calcWH: function () { var self = this; // calculate the full width and height with padding, borders and shadows - self.outerW = self._width + self._padding * 2 + self._borderWidth * 2 + self.shadowW; - self.outerH = self._height + self._padding * 2 + self._borderWidth * 2 + self.shadowH; + self.outerW = + self._width + + self._padding * 2 + + self._borderWidth * 2 + + self.shadowW; + self.outerH = + self._height + + self._padding * 2 + + self._borderWidth * 2 + + self.shadowH; }, /** * Update the width and height of the off-DOM canvas when attributes are changed. */ - _updateCanvasWH: function() { + _updateCanvasWH: function () { var self = this, oldW = self._renderCanvas.width, oldH = self._renderCanvas.height; // update off-DOM canvas - self._renderCanvas.setAttribute('width', self.outerW); - self._renderCanvas.setAttribute('height', self.outerH); - self._shadowCanvas.setAttribute('width', self._width + self._padding * 2); - self._shadowCanvas.setAttribute('height', self._height + self._padding * 2); + self._renderCanvas.setAttribute("width", self.outerW); + self._renderCanvas.setAttribute("height", self.outerH); + self._shadowCanvas.setAttribute( + "width", + self._width + self._padding * 2 + ); + self._shadowCanvas.setAttribute( + "height", + self._height + self._padding * 2 + ); // clear the main canvas if (self._ctx) { @@ -1286,9 +1503,13 @@ * @param {Number} h Height of rectangle. * @param {Number} r Border radius. */ - _roundedRect: function(ctx, x, y, w, h, r) { - if (w < 2 * r) r = w / 2; - if (h < 2 * r) r = h / 2; + _roundedRect: function (ctx, x, y, w, h, r) { + if (w < 2 * r) { + r = w / 2; + } + if (h < 2 * r) { + r = h / 2; + } ctx.beginPath(); @@ -1311,12 +1532,16 @@ * @param {Number} y y-coordinate position. * @return {Boolean} True if it is over the input box. */ - _overInput: function(x, y) { + _overInput: function (x, y) { var self = this, xLeft = x >= self._x + self._extraX, - xRight = x <= self._x + self._extraX + self._width + self._padding * 2, + xRight = + x <= + self._x + self._extraX + self._width + self._padding * 2, yTop = y >= self._y + self._extraY, - yBottom = y <= self._y + self._extraY + self._height + self._padding * 2; + yBottom = + y <= + self._y + self._extraY + self._height + self._padding * 2; return xLeft && xRight && yTop && yBottom; }, @@ -1328,13 +1553,13 @@ * @param {Number} y Y-coordinate. * @return {Number} Cursor position. */ - _clickPos: function(x, y) { + _clickPos: function (x, y) { var self = this, value = self._value; // don't count placeholder text in this if (self._value === self._placeHolder) { - value = ''; + value = ""; } // determine where the click was made along the string @@ -1361,21 +1586,22 @@ * @param {Event} e * @return {Object} x & y values */ - _mousePos: function(e) { + _mousePos: function (e) { var elm = e.target, style = document.defaultView.getComputedStyle(elm, undefined), - paddingLeft = parseInt(style['paddingLeft'], 10) || 0, - paddingTop = parseInt(style['paddingLeft'], 10) || 0, - borderLeft = parseInt(style['borderLeftWidth'], 10) || 0, - borderTop = parseInt(style['borderLeftWidth'], 10) || 0, + paddingLeft = parseInt(style.paddingLeft, 10) || 0, + paddingTop = parseInt(style.paddingLeft, 10) || 0, + borderLeft = parseInt(style.borderLeftWidth, 10) || 0, + borderTop = parseInt(style.borderLeftWidth, 10) || 0, htmlTop = document.body.parentNode.offsetTop || 0, htmlLeft = document.body.parentNode.offsetLeft || 0, offsetX = 0, offsetY = 0, - x, y; + x, + y; // calculate the total offset - if (typeof elm.offsetParent !== 'unefined') { + if (typeof elm.offsetParent !== "unefined") { do { offsetX += elm.offsetLeft; offsetY += elm.offsetTop; @@ -1388,7 +1614,7 @@ return { x: e.pageX - offsetX, - y: e.pageY - offsetY + y: e.pageY - offsetY, }; }, @@ -1398,10 +1624,10 @@ * @param {Number} keyCode The character code. * @return {String} The translated character. */ - _mapCodeToKey: function(isShift, keyCode) { + _mapCodeToKey: function (isShift, keyCode) { var self = this, blockedKeys = [8, 9, 13, 16, 17, 18, 20, 27, 91, 92], - key = ''; + key = ""; // block keys that we don't want to type for (var i = 0; i < blockedKeys.length; i++) { @@ -1411,92 +1637,95 @@ } // make sure we are getting the correct input - if (typeof isShift !== 'boolean' || typeof keyCode !== 'number') { + if (typeof isShift !== "boolean" || typeof keyCode !== "number") { return; } var charMap = { - 32: ' ', - 48: ')', - 49: '!', - 50: '@', - 51: '#', - 52: '$', - 53: '%', - 54: '^', - 55: '&', - 56: '*', - 57: '(', - 59: ':', - 107: '+', - 173: '_', // firefox uses 173 instead of 189 - 189: '_', - 186: ':', - 187: '+', - 188: '<', - 190: '>', - 191: '?', - 192: '~', - 219: '{', - 220: '|', - 221: '}', - 222: '"' + 32: " ", + 48: ")", + 49: "!", + 50: "@", + 51: "#", + 52: "$", + 53: "%", + 54: "^", + 55: "&", + 56: "*", + 57: "(", + 59: ":", + 107: "+", + 173: "_", // firefox uses 173 instead of 189 + 189: "_", + 186: ":", + 187: "+", + 188: "<", + 190: ">", + 191: "?", + 192: "~", + 219: "{", + 220: "|", + 221: "}", + 222: '"', }; // convert the code to a character if (isShift) { - key = (keyCode >= 65 && keyCode <= 90) ? String.fromCharCode(keyCode) : charMap[keyCode]; + key = + keyCode >= 65 && keyCode <= 90 + ? String.fromCharCode(keyCode) + : charMap[keyCode]; } else { if (keyCode >= 65 && keyCode <= 90) { key = String.fromCharCode(keyCode).toLowerCase(); } else { if (keyCode === 96) { - key = '0'; + key = "0"; } else if (keyCode === 97) { - key = '1'; + key = "1"; } else if (keyCode === 98) { - key = '2'; + key = "2"; } else if (keyCode === 99) { - key = '3'; + key = "3"; } else if (keyCode === 100) { - key = '4'; + key = "4"; } else if (keyCode === 101) { - key = '5'; + key = "5"; } else if (keyCode === 102) { - key = '6'; + key = "6"; } else if (keyCode === 103) { - key = '7'; + key = "7"; } else if (keyCode === 104) { - key = '8'; + key = "8"; } else if (keyCode === 105) { - key = '9'; + key = "9"; } else if (keyCode === 188) { - key = ','; + key = ","; } else if (keyCode === 190) { - key = '.'; + key = "."; } else if (keyCode === 191) { - key = '/'; + key = "/"; } else if (keyCode === 192) { - key = '`'; + key = "`"; } else if (keyCode === 220) { - key = '\\'; + key = "\\"; } else if (keyCode === 187) { - key = '='; - } else if ((keyCode === 189) || (keyCode === 173)) { + key = "="; + } else if (keyCode === 189 || keyCode === 173) { // firefox maps the minus key to 173, rather // then trying to use browser detection we // simply accept 173 as well...which means that // for Chrome using the mute button would // cause minus sign to appear - key = '-'; + key = "-"; } else if (keyCode === 222) { - key = '\''; + key = "'"; } else if (keyCode === 186) { - key = ';'; + key = ";"; } else if (keyCode === 219) { - key = '['; + key = "["; } else if (keyCode === 221) { - key = ']'; + key = "]"; } else { key = String.fromCharCode(keyCode); } @@ -1504,7 +1733,7 @@ } return key; - } + }, }; module.exports = CanvasInput; diff --git a/js/ColorMap.js b/js/ColorMap.js index 03b7ad7..38a31bd 100644 --- a/js/ColorMap.js +++ b/js/ColorMap.js @@ -1,185 +1,220 @@ /* global module */ /* global require */ - (function() { - var tinycolor = require("tinycolor2"); - if (typeof Object.assign !== 'function') { - // Must be writable: true, enumerable: false, configurable: true - Object.defineProperty(Object, "assign", { - value: function assign(target, varArgs) { // .length of function is 2 - 'use strict'; - if (target == null) { // TypeError if undefined or null - throw new TypeError('Cannot convert undefined or null to object'); - } - var to = Object(target); - for (var index = 1; index < arguments.length; index++) { - var nextSource = arguments[index]; - if (nextSource != null) { // Skip over if undefined or null - for (var nextKey in nextSource) { - // Avoid bugs when hasOwnProperty is shadowed - if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { - to[nextKey] = nextSource[nextKey]; - } - } - } - } - return to; - }, - writable: true, - configurable: true - }); - } - var ColorMap = window.ColorMap = function(colors, options) { - this.options = { - ncolors: 500, - alpha: 255 - }; - this.options = Object.assign(this.options, options); - this.map = []; - var _min = 0; - this._low = 0; - this._high = 1; - var ncolors = this.options.ncolors; - this._fscale = ncolors / (this._high - this._low); - var colorindex = 1; - var colorBlockIndex = 1; - colors = JSON.parse(JSON.stringify(colors)); //make a copy so we dont change the original colors - colors = this._parseColors(colors); - this.colors = colors; - var col1 = colors[0]; - var col2 = colors[1]; - // pos is the percentage of scale (0-100), so - // colorStop is how many percentage is allocated - // to this band - var colorStop = colors[1].pos - colors[0].pos; - // now many colors are allocated to this block - var colorsInBlock = ncolors * (colorStop / 100); - // the interpolation step per color number - var factorStep = 1 / colorsInBlock; - for (var n = 0; n < ncolors - 2; n++) { - if (colorBlockIndex > colorsInBlock) { - col1 = colors[colorindex]; - col2 = colors[colorindex + 1]; - // if we are at the end of the color list - if (col2 === undefined) { - break; - } - if ((col1.pos >= 100) && (col2.pos >= 100)) { +(function () { + var tinycolor = require("tinycolor2"); + if (typeof Object.assign !== "function") { + // Must be writable: true, enumerable: false, configurable: true + Object.defineProperty(Object, "assign", { + value: function assign(target, varArgs) { + // .length of function is 2 + "use strict"; + if (target == null) { + // TypeError if undefined or null + throw new TypeError( + "Cannot convert undefined or null to object" + ); + } + var to = Object(target); + for (var index = 1; index < arguments.length; index++) { + var nextSource = arguments[index]; + if (nextSource != null) { + // Skip over if undefined or null + for (var nextKey in nextSource) { + // Avoid bugs when hasOwnProperty is shadowed + if ( + Object.prototype.hasOwnProperty.call( + nextSource, + nextKey + ) + ) { + to[nextKey] = nextSource[nextKey]; + } + } + } + } + return to; + }, + writable: true, + configurable: true, + }); + } + var ColorMap = (window.ColorMap = function (colors, options) { + this.options = { + ncolors: 500, + alpha: 255, + }; + this.options = Object.assign(this.options, options); + this.map = []; + var _min = 0; + this._low = 0; + this._high = 1; + var ncolors = this.options.ncolors; + this._fscale = ncolors / (this._high - this._low); + var colorindex = 1; + var colorBlockIndex = 1; + colors = JSON.parse(JSON.stringify(colors)); //make a copy so we dont change the original colors + colors = this._parseColors(colors); + this.colors = colors; + var col1 = colors[0]; + var col2 = colors[1]; + // pos is the percentage of scale (0-100), so + // colorStop is how many percentage is allocated + // to this band + var colorStop = colors[1].pos - colors[0].pos; + // now many colors are allocated to this block + var colorsInBlock = ncolors * (colorStop / 100); + // the interpolation step per color number + var factorStep = 1 / colorsInBlock; + for (var n = 0; n < ncolors - 2; n++) { + if (colorBlockIndex > colorsInBlock) { + col1 = colors[colorindex]; + col2 = colors[colorindex + 1]; + // if we are at the end of the color list + if (col2 === undefined) { break; } - var colorStop = col2.pos - col1.pos; - var colorsInBlock = ncolors * (colorStop / 100); - var factorStep = 1 / colorsInBlock; - var colorBlockIndex = 1; - colorindex += 1; - } - this._addColor(this.interpolate(col1, col2, factorStep * colorBlockIndex)); - colorBlockIndex += 1; - } - + if (col1.pos >= 100 && col2.pos >= 100) { + break; + } + var colorStop = col2.pos - col1.pos; + var colorsInBlock = ncolors * (colorStop / 100); + var factorStep = 1 / colorsInBlock; + var colorBlockIndex = 1; + colorindex += 1; + } + this._addColor( + this.interpolate(col1, col2, factorStep * colorBlockIndex) + ); + colorBlockIndex += 1; + } + this._addColor(colors[colorindex]); this._addColor(colors[0], true); - - }; - ColorMap.prototype = { - _addColor: function(color, front) { - color.hex = this._rgbToHex(color.red, color.green, color.blue); - color.color = (color.alpha << 24) | // alpha - (color.blue << 16) | // blue - (color.green << 8) | // green - (color.red); - if (front) { - this.map.unshift(color); - } else { - this.map.push(color); - } - }, - _parseColors: function(colors) { - for (var i = 0, c = colors.length; i < c; i++) { - var color = colors[i]; - if (typeof color === "string") { - colors[i] = this._hexToRgb(color); - color = tinycolor(color); - color = color.toRgb(); - colors[i] = {red:color.r,green:color.g,blue:color.b,alpha:this.options.alpha}; - - } else if (color.hasOwnProperty("color")) { - var newColor = tinycolor(color.color); - newColor = newColor.toRgb(); - newColor = {red:newColor.r,green:newColor.g,blue:newColor.b,alpha:this.options.alpha}; - if (color.hasOwnProperty("pos")) { - newColor.pos = color.pos; - } - colors[i] = newColor; - } else { - //assume if it has rgb values it is a percentage - colors[i].red = Math.floor(Math.round(255 * (color.red / 100))); - colors[i].green = Math.floor(Math.round(255 * (color.green / 100))); - colors[i].blue = Math.floor(Math.round(255 * (color.blue / 100))); - } - if (!colors[i].hasOwnProperty("alpha")) { - colors[i].alpha = this.options.alpha; - } - } - return this._checkColorStops(colors); - }, - _checkColorStops: function(colors) { - var lastStop = 0; - var colorsWithNoStops = 0; - for (var i = 0, c = colors.length; i < c; i++) { - var color = colors[i]; - if (!color.hasOwnProperty("pos")) { - colorsWithNoStops += 1; - } else { - if (colorsWithNoStops) { - var stopSize = (color.pos - lastStop) / colorsWithNoStops; - var currentPos = color.pos; - for (var z = 1; z <= colorsWithNoStops; z++) { - colors[i - z].pos = currentPos - stopSize; - currentPos -= stopSize; - } - } - colorsWithNoStops = 0; - } - } - if (colorsWithNoStops) { - var currentPos = 100; - colors[colors.length - 1].pos = currentPos; - if (lastStop === 0) { - colors[0].pos = 0; - colorsWithNoStops -= 1; - } - var stopSize = (currentPos - lastStop) / colorsWithNoStops; - var i = colors.length - 1; - for (var z = 1; z < colorsWithNoStops; z++) { - colors[i - z].pos = currentPos - stopSize; - currentPos -= stopSize; - } - } - return colors; - }, - _componentToHex: function(c) { - var hex = c.toString(16); - return hex.length === 1 ? "0" + hex : hex; - }, - _rgbToHex: function(r, g, b) { - return "#" + this._componentToHex(r) + this._componentToHex(g) + this._componentToHex(b); - }, - _hexToRgb: function(hex) { - var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); - return result ? { - red: parseInt(result[1], 16), - green: parseInt(result[2], 16), - blue: parseInt(result[3], 16) - } : null; - }, - getColor: function(number) { - var colorindex = this.getColorIndex(number); - return this.map[colorindex]; - }, - getColorByIndex: function(colorindex) { + }); + ColorMap.prototype = { + _addColor: function (color, front) { + color.hex = this._rgbToHex(color.red, color.green, color.blue); + color.color = + (color.alpha << 24) | // alpha + (color.blue << 16) | // blue + (color.green << 8) | // green + color.red; + if (front) { + this.map.unshift(color); + } else { + this.map.push(color); + } + }, + _parseColors: function (colors) { + for (var i = 0, c = colors.length; i < c; i++) { + var color = colors[i]; + if (typeof color === "string") { + colors[i] = this._hexToRgb(color); + color = tinycolor(color); + color = color.toRgb(); + colors[i] = { + red: color.r, + green: color.g, + blue: color.b, + alpha: this.options.alpha, + }; + } else if (color.hasOwnProperty("color")) { + var newColor = tinycolor(color.color); + newColor = newColor.toRgb(); + newColor = { + red: newColor.r, + green: newColor.g, + blue: newColor.b, + alpha: this.options.alpha, + }; + if (color.hasOwnProperty("pos")) { + newColor.pos = color.pos; + } + colors[i] = newColor; + } else { + //assume if it has rgb values it is a percentage + colors[i].red = Math.floor( + Math.round(255 * (color.red / 100)) + ); + colors[i].green = Math.floor( + Math.round(255 * (color.green / 100)) + ); + colors[i].blue = Math.floor( + Math.round(255 * (color.blue / 100)) + ); + } + if (!colors[i].hasOwnProperty("alpha")) { + colors[i].alpha = this.options.alpha; + } + } + return this._checkColorStops(colors); + }, + _checkColorStops: function (colors) { + var lastStop = 0; + var colorsWithNoStops = 0; + for (var i = 0, c = colors.length; i < c; i++) { + var color = colors[i]; + if (!color.hasOwnProperty("pos")) { + colorsWithNoStops += 1; + } else { + if (colorsWithNoStops) { + var stopSize = + (color.pos - lastStop) / colorsWithNoStops; + var currentPos = color.pos; + for (var z = 1; z <= colorsWithNoStops; z++) { + colors[i - z].pos = currentPos - stopSize; + currentPos -= stopSize; + } + } + colorsWithNoStops = 0; + } + } + if (colorsWithNoStops) { + var currentPos = 100; + colors[colors.length - 1].pos = currentPos; + if (lastStop === 0) { + colors[0].pos = 0; + colorsWithNoStops -= 1; + } + var stopSize = (currentPos - lastStop) / colorsWithNoStops; + var i = colors.length - 1; + for (var z = 1; z < colorsWithNoStops; z++) { + colors[i - z].pos = currentPos - stopSize; + currentPos -= stopSize; + } + } + return colors; + }, + _componentToHex: function (c) { + var hex = c.toString(16); + return hex.length === 1 ? "0" + hex : hex; + }, + _rgbToHex: function (r, g, b) { + return ( + "#" + + this._componentToHex(r) + + this._componentToHex(g) + + this._componentToHex(b) + ); + }, + _hexToRgb: function (hex) { + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result + ? { + red: parseInt(result[1], 16), + green: parseInt(result[2], 16), + blue: parseInt(result[3], 16), + } + : null; + }, + getColor: function (number) { + var colorindex = this.getColorIndex(number); return this.map[colorindex]; - }, - getColorIndex: function(number) { + }, + getColorByIndex: function (colorindex) { + return this.map[colorindex]; + }, + getColorIndex: function (number) { var n = (number - this._low) * this._fscale; var colorindex = ~~n; //make int fastest method if (colorindex > this.map.length - 1) { @@ -188,26 +223,27 @@ colorindex = 0; } return colorindex; - }, - getNColors : function() { - return this.map.length; - }, - setRange: function(low, high) { - // only recalculate if a value has changed - if ((this._low !== low) || (this._high !== high)) { - this._low = low; - this._high = high; - this._fscale = this.map.length / Math.abs(this._high - this._low); - } - }, - interpolate: function(col1, col2, factor) { - return { - red: col1.red + factor * (col2.red - col1.red), - green: col1.green + factor * (col2.green - col1.green), - blue: col1.blue + factor * (col2.blue - col1.blue), - alpha: col1.alpha + factor * (col2.alpha - col1.alpha) - }; - } - }; - module.exports = ColorMap; - })(); \ No newline at end of file + }, + getNColors: function () { + return this.map.length; + }, + setRange: function (low, high) { + // only recalculate if a value has changed + if (this._low !== low || this._high !== high) { + this._low = low; + this._high = high; + this._fscale = + this.map.length / Math.abs(this._high - this._low); + } + }, + interpolate: function (col1, col2, factor) { + return { + red: col1.red + factor * (col2.red - col1.red), + green: col1.green + factor * (col2.green - col1.green), + blue: col1.blue + factor * (col2.blue - col1.blue), + alpha: col1.alpha + factor * (col2.alpha - col1.alpha), + }; + }, + }; + module.exports = ColorMap; +})(); diff --git a/js/common.js b/js/common.js index a1383c2..fe4f8c6 100644 --- a/js/common.js +++ b/js/common.js @@ -27,373 +27,549 @@ /* global module */ /* global require */ -(function() { +(function () { + module.exports = {}; + + if (window.ArrayBuffer) { + if (!ArrayBuffer.prototype.slice) { + //Monkey Patching for iOS and early Firefox + ArrayBuffer.prototype.slice = function (start, end) { + var that = new Uint8Array(this); + if (end === undefined) { + end = that.length; + } + var result = new ArrayBuffer(end - start); + var resultArray = new Uint8Array(result); + for (var i = 0; i < resultArray.length; i++) { + resultArray[i] = that[i + start]; + } + return result; + }; + } -module.exports = {}; + if (!ArrayBuffer.isView) { + ArrayBuffer.isView = function (a) { + return ( + a !== null && + typeof a === "object" && + a.buffer instanceof ArrayBuffer + ); + }; + } + } -if (window.ArrayBuffer) { - if (!ArrayBuffer.prototype.slice) { - //Monkey Patching for iOS and early Firefox - ArrayBuffer.prototype.slice = function(start, end) { - var that = new Uint8Array(this); - if (end === undefined) { - end = that.length; + // Shim for requestAnimationFrame compatibility + window.requestAnimFrame = (function (callback) { + return ( + window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function (callback) { + return window.setTimeout(callback, 1000 / 60); } - var result = new ArrayBuffer(end - start); - var resultArray = new Uint8Array(result); - for (var i = 0; i < resultArray.length; i++) { - resultArray[i] = that[i + start]; - } - return result; - }; - } + ); + })(); - if (!ArrayBuffer['isView']) { - ArrayBuffer.isView = function(a) { - return a !== null && typeof(a) === "object" && a['buffer'] instanceof ArrayBuffer; - }; - } -} - -// Shim for requestAnimationFrame compatibility -window.requestAnimFrame = (function(callback) { - return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || - function(callback) { - return window.setTimeout(callback, 1000 / 60); - }; -})(); + window.cancelAnimFrame = (function (callback) { + return ( + window.cancelAnimationFrame || + window.webkitCancelAnimationFrame || + window.mozCancelAnimationFrame || + window.oCancelAnimationFrame || + window.msCanelAnimationFrame || + function (timeoutID) { + window.clearTimeout(timeoutID); + } + ); + })(); -window.cancelAnimFrame = (function(callback) { - return window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCanelAnimationFrame || - function(timeoutID) { - window.clearTimeout(timeoutID); + // Handle various ways to draw dashed lines + module.exports.dashOn = function (ctx, on, off) { + if (ctx.setLineDash) { + ctx.setLineDash([on, off]); + return true; + } else if (ctx.mozDash !== undefined) { + // Gecko 7.0+ + ctx.mozDash = [on, off]; + return true; + } else if (ctx.webkitLineDash && ctx.webkitLineDash.length === 0) { + ctx.webkitLineDash = [on, off]; + return true; + } + return false; }; -})(); -// Handle various ways to draw dashed lines -module.exports.dashOn = function(ctx, on, off) { - if (ctx.setLineDash) { - ctx.setLineDash([on, off]); - return true; - } else if (ctx.mozDash !== undefined) { // Gecko 7.0+ - ctx.mozDash = [on, off]; - return true; - } else if (ctx.webkitLineDash && ctx.webkitLineDash.length === 0) { - ctx.webkitLineDash = [on, off]; - return true; - } - return false; -}; - -module.exports.dashOff = function(ctx) { - if (ctx.setLineDash) { - ctx.setLineDash([]); - } else if (ctx.mozDash) { // Gecko 7.0+ - ctx.mozDash = null; - } else if (ctx.webkitLineDash) { - ctx.webkitLineDash = []; - } -}; - -// Firefox behaves differntly for keypress events -module.exports.getKeyCode = function(e) { - e = window.event || e; - e = e.charCode || e.keyCode; - return e; -}; - -module.exports.setKeypressHandler = function(handler) { - if (window.addEventListener) { window.addEventListener('keypress', handler, false); } - else if (window.attachEvent) { - window.attachEvent('onkeypress', handler); - } -}; - -// endsWith() is part of ECMAScript 6, include the Mozilla -// Polyfill from https://developer.mozilla.org -if (!String.prototype.endsWith) { - String.prototype.endsWith = function(search, this_len) { - if (this_len === undefined || this_len > this.length) { - this_len = this.length; + module.exports.dashOff = function (ctx) { + if (ctx.setLineDash) { + ctx.setLineDash([]); + } else if (ctx.mozDash) { + // Gecko 7.0+ + ctx.mozDash = null; + } else if (ctx.webkitLineDash) { + ctx.webkitLineDash = []; } - return this.substring(this_len - search.length, this_len) === search; - }; -} - -if (!Uint8Array.prototype.slice) { - Object.defineProperty(Uint8Array.prototype, 'slice', { - value: Array.prototype.slice - }); -} - -if (!Int8Array.prototype.slice) { - Object.defineProperty(Int8Array.prototype, 'slice', { - value: Array.prototype.slice - }); -} - -if (!Int16Array.prototype.slice) { - Object.defineProperty(Int16Array.prototype, 'slice', { - value: Array.prototype.slice - }); -} - -if (!Int32Array.prototype.slice) { - Object.defineProperty(Int32Array.prototype, 'slice', { - value: Array.prototype.slice - }); -} - -if (!Float32Array.prototype.slice) { - Object.defineProperty(Float32Array.prototype, 'slice', { - value: Array.prototype.slice - }); -} - -if (!Float64Array.prototype.slice) { - Object.defineProperty(Float64Array.prototype, 'slice', { - value: Array.prototype.slice - }); -} - -// Array.isArray -// FF 4+ -// IE 9+ -// SF 5+ -// http://kangax.github.io/es5-compat-table/#Array.isArray -if (!Array.isArray) { - Array.isArray = function(obj) { - return Object.prototype.toString.call(obj) === "[object Array]"; }; -} - -if (!window.Float64Array) { - //Monkey Patching for iOS - // This is essentially ReadOnly because - // if someone does x[i] = 5 - // the value will be set in the array - // but not in the underlying buffer - window.Float64Array = (function() { - return window.Float64Array || - function(buffer, byteOffset, length) { - if (!(buffer instanceof ArrayBuffer)) { - throw "Invalid type"; - } - var dv = new DataView(buffer); - var b = []; - var maxlength = (buffer.byteLength - byteOffset) / 8; - if (length === undefined) { - b.length = maxlength; - } else { - b.length = Math.min(length, maxlength); - } - for (var i = 0; i < b.length; i++) { - b[i] = dv.getFloat64(i * 8 + byteOffset, true); - } - b.subarray = function(begin, end) { - return b.slice(begin, end); - }; - return b; - }; - })(); -} + // Firefox behaves differntly for keypress events + module.exports.getKeyCode = function (e) { + e = window.event || e; + e = e.charCode || e.keyCode; + return e; + }; -// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer -if (!ArrayBuffer.transfer) { - ArrayBuffer.transfer = function(source, length) { - if (!(source instanceof ArrayBuffer)) { - throw new TypeError('Source must be an instance of ArrayBuffer'); + module.exports.setKeypressHandler = function (handler) { + if (window.addEventListener) { + window.addEventListener("keypress", handler, false); + } else if (window.attachEvent) { + window.attachEvent("onkeypress", handler); } - if (length <= source.byteLength) { - return source.slice(0, length); - } - var sourceView = new Uint8Array(source), - destView = new Uint8Array(new ArrayBuffer(length)); - destView.set(sourceView); - return destView.buffer; }; -} - -// Shims -(function() { - /* console shim*/ - var f = function() {}; - if (!window.console) { - window.console = { - log: f, - info: f, - warn: f, - debug: f, - error: f + + // endsWith() is part of ECMAScript 6, include the Mozilla + // Polyfill from https://developer.mozilla.org + if (!String.prototype.endsWith) { + String.prototype.endsWith = function (search, this_len) { + if (this_len === undefined || this_len > this.length) { + this_len = this.length; + } + return ( + this.substring(this_len - search.length, this_len) === search + ); }; } - // Firefox 4 has a glaring subarray bug - // http://ryanberdeen.com/2011/04/16/firefox-subarray-bug.html - if (new Int8Array([0, 1, 0]).subarray(1).subarray(1)[0]) { - var subarray = function(begin, end) { - if (arguments.length === 0) { - begin = 0; - end = this.length; - } else { - if (begin < 0) { - // relative to end - begin += this.length; - } - // clamp to 0, length - begin = Math.max(0, Math.min(this.length, begin)); - if (arguments.length === 1) { - // slice to end - end = this.length; - } else { - if (end < 0) { - // relative to end - end += this.length; - } - // clamp to begin, length - end = Math.max(begin, Math.min(this.length, end)); - } - } + if (!Uint8Array.prototype.slice) { + Object.defineProperty(Uint8Array.prototype, "slice", { + value: Array.prototype.slice, + }); + } - var byteOffset = this.byteOffset + begin * this.BYTES_PER_ELEMENT; - return new this.constructor(this.buffer, byteOffset, end - begin); - }; + if (!Int8Array.prototype.slice) { + Object.defineProperty(Int8Array.prototype, "slice", { + value: Array.prototype.slice, + }); + } - var typedArrays = [Int8Array, Uint8Array, Int16Array, Uint16Array, - Int32Array, Uint32Array, Float32Array, Float64Array - ]; - typedArrays.forEach(function(cls) { - cls.prototype.subarray = subarray; + if (!Int16Array.prototype.slice) { + Object.defineProperty(Int16Array.prototype, "slice", { + value: Array.prototype.slice, }); } -}()); + if (!Int32Array.prototype.slice) { + Object.defineProperty(Int32Array.prototype, "slice", { + value: Array.prototype.slice, + }); + } -// https://developer.mozilla.org/en-US/docs/Web/Reference/Events/wheel?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Fwheel#Listening_to_this_event_across_browser -// creates a global "addWheelListener" method -// example: addWheelListener( elem, function( e ) { console.log( e.deltaY ); e.preventDefault(); } ); -(function(window, document) { + if (!Float32Array.prototype.slice) { + Object.defineProperty(Float32Array.prototype, "slice", { + value: Array.prototype.slice, + }); + } - var prefix = "", - _addEventListener, onwheel, support; + if (!Float64Array.prototype.slice) { + Object.defineProperty(Float64Array.prototype, "slice", { + value: Array.prototype.slice, + }); + } - // detect event model - if (window.addEventListener) { - _addEventListener = "addEventListener"; - } else { - _addEventListener = "attachEvent"; - prefix = "on"; + // Array.isArray + // FF 4+ + // IE 9+ + // SF 5+ + // http://kangax.github.io/es5-compat-table/#Array.isArray + if (!Array.isArray) { + Array.isArray = function (obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + }; } - // detect available wheel event - support = "onwheel" in document.createElement("div") ? "wheel" : // Modern browsers support "wheel" - document.onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel" - "DOMMouseScroll"; // let's assume that remaining browsers are older Firefox + if (!window.Float64Array) { + //Monkey Patching for iOS + // This is essentially ReadOnly because + // if someone does x[i] = 5 + // the value will be set in the array + // but not in the underlying buffer + window.Float64Array = (function () { + return ( + window.Float64Array || + function (buffer, byteOffset, length) { + if (!(buffer instanceof ArrayBuffer)) { + throw "Invalid type"; + } + var dv = new DataView(buffer); + var b = []; + var maxlength = (buffer.byteLength - byteOffset) / 8; + if (length === undefined) { + b.length = maxlength; + } else { + b.length = Math.min(length, maxlength); + } - window.addWheelListener = function(elem, callback, useCapture) { - _addWheelListener(elem, support, callback, useCapture); + for (var i = 0; i < b.length; i++) { + b[i] = dv.getFloat64(i * 8 + byteOffset, true); + } + b.subarray = function (begin, end) { + return b.slice(begin, end); + }; + return b; + } + ); + })(); + } - // handle MozMousePixelScroll in older Firefox - if (support === "DOMMouseScroll") { - _addWheelListener(elem, "MozMousePixelScroll", callback, useCapture); + // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer + if (!ArrayBuffer.transfer) { + ArrayBuffer.transfer = function (source, length) { + if (!(source instanceof ArrayBuffer)) { + throw new TypeError( + "Source must be an instance of ArrayBuffer" + ); + } + if (length <= source.byteLength) { + return source.slice(0, length); + } + var sourceView = new Uint8Array(source), + destView = new Uint8Array(new ArrayBuffer(length)); + destView.set(sourceView); + return destView.buffer; + }; + } + + // Shims + (function () { + /* console shim*/ + var f = function () {}; + if (!window.console) { + window.console = { + log: f, + info: f, + warn: f, + debug: f, + error: f, + }; } - }; - /* jshint -W030 */ - function _addWheelListener(elem, eventName, callback, useCapture) { - elem[_addEventListener](prefix + eventName, support === "wheel" ? callback : function(originalEvent) { - !originalEvent && (originalEvent = window.event); - - // create a normalized event object - var event = { - // keep a ref to the original event object - originalEvent: originalEvent, - target: originalEvent.target || originalEvent.srcElement, - type: "wheel", - deltaMode: originalEvent.type === "MozMousePixelScroll" ? 0 : 1, - deltaX: 0, - delatZ: 0, - preventDefault: function() { - originalEvent.preventDefault ? - originalEvent.preventDefault() : - originalEvent.returnValue = false; + // Firefox 4 has a glaring subarray bug + // http://ryanberdeen.com/2011/04/16/firefox-subarray-bug.html + if (new Int8Array([0, 1, 0]).subarray(1).subarray(1)[0]) { + var subarray = function (begin, end) { + if (arguments.length === 0) { + begin = 0; + end = this.length; + } else { + if (begin < 0) { + // relative to end + begin += this.length; + } + // clamp to 0, length + begin = Math.max(0, Math.min(this.length, begin)); + if (arguments.length === 1) { + // slice to end + end = this.length; + } else { + if (end < 0) { + // relative to end + end += this.length; + } + // clamp to begin, length + end = Math.max(begin, Math.min(this.length, end)); + } } - }; - // calculate deltaY (and deltaX) according to the event - if (support === "mousewheel") { - event.deltaY = -1 / 40 * originalEvent.wheelDelta; - // Webkit also support wheelDeltaX - originalEvent.wheelDeltaX && (event.deltaX = -1 / 40 * originalEvent.wheelDeltaX); - } else { - event.deltaY = originalEvent.detail; - } + var byteOffset = + this.byteOffset + begin * this.BYTES_PER_ELEMENT; + return new this.constructor( + this.buffer, + byteOffset, + end - begin + ); + }; - // it's time to fire the callback - return callback(event); + var typedArrays = [ + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + ]; + typedArrays.forEach(function (cls) { + cls.prototype.subarray = subarray; + }); + } + })(); - }, useCapture || false); - } - /* jshint +W030 */ - -})(window, document); -//Add Proxy poly fill https://github.com/GoogleChrome/proxy-polyfill -if(!window.Proxy){ -/* jshint ignore:start */ -(function(){function l(){function n(a){return a?"object"===typeof a||"function"===typeof a:!1}var p=null;var g=function(a,b){function f(){}if(!n(a)||!n(b))throw new TypeError("Cannot create proxy with a non-object as target or handler");p=function(){f=function(a){throw new TypeError("Cannot perform '"+a+"' on a proxy that has been revoked");}};var e=b;b={get:null,set:null,apply:null,construct:null};for(var k in e){if(!(k in b))throw new TypeError("Proxy polyfill does not support trap '"+k+"'");b[k]=e[k]}"function"=== -typeof e&&(b.apply=e.apply.bind(e));var c=this,g=!1,q=!1;"function"===typeof a?(c=function(){var h=this&&this.constructor===c,d=Array.prototype.slice.call(arguments);f(h?"construct":"apply");return h&&b.construct?b.construct.call(this,a,d):!h&&b.apply?b.apply(a,this,d):h?(d.unshift(a),new (a.bind.apply(a,d))):a.apply(this,d)},g=!0):a instanceof Array&&(c=[],q=!0);var r=b.get?function(a){f("get");return b.get(this,a,c)}:function(a){f("get");return this[a]},v=b.set?function(a,d){f("set");b.set(this, -a,d,c)}:function(a,b){f("set");this[a]=b},t={};Object.getOwnPropertyNames(a).forEach(function(b){if(!((g||q)&&b in c)){var d={enumerable:!!Object.getOwnPropertyDescriptor(a,b).enumerable,get:r.bind(a,b),set:v.bind(a,b)};Object.defineProperty(c,b,d);t[b]=!0}});e=!0;Object.setPrototypeOf?Object.setPrototypeOf(c,Object.getPrototypeOf(a)):c.__proto__?c.__proto__=a.__proto__:e=!1;if(b.get||!e)for(var m in a)t[m]||Object.defineProperty(c,m,{get:r.bind(a,m)});Object.seal(a);Object.seal(c);return c};g.revocable= -function(a,b){return{proxy:new g(a,b),revoke:p}};return g};var u="undefined"!==typeof process&&"[object process]"==={}.toString.call(process)||"undefined"!==typeof navigator&&"ReactNative"===navigator.product?global:self;u.Proxy||(u.Proxy=l(),u.Proxy.revocable=u.Proxy.revocable);})(); -/* jshint ignore:end */ -} - -//Updates destenation object with source values -module.exports.update = function update(dst, src) { - for (var prop in src) { - var val = src[prop]; - if (typeof val === "object") { // recursive - update(dst[prop], val); + // https://developer.mozilla.org/en-US/docs/Web/Reference/Events/wheel?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Fwheel#Listening_to_this_event_across_browser + // creates a global "addWheelListener" method + // example: addWheelListener( elem, function( e ) { console.log( e.deltaY ); e.preventDefault(); } ); + (function (window, document) { + var prefix = "", + _addEventListener, + onwheel, + support; + + // detect event model + if (window.addEventListener) { + _addEventListener = "addEventListener"; } else { - dst[prop] = val; + _addEventListener = "attachEvent"; + prefix = "on"; } - } - return dst; // return dst to allow method chaining -}; - -// From: https://davidwalsh.name/javascript-debounce-function -// Returns a function, that, as long as it continues to be invoked, will not -// be triggered. The function will be called after it stops being called for -// N milliseconds. If `immediate` is passed, trigger the function on the -// leading edge, instead of the trailing. -module.exports.debounce = function debounce(func, wait, immediate) { - var timeout; - return function() { - var context = this, args = arguments; - var later = function() { - timeout = null; - if (!immediate) { - func.apply(context, args); + + // detect available wheel event + support = + "onwheel" in document.createElement("div") + ? "wheel" // Modern browsers support "wheel" + : document.onmousewheel !== undefined + ? "mousewheel" // Webkit and IE support at least "mousewheel" + : "DOMMouseScroll"; // let's assume that remaining browsers are older Firefox + + window.addWheelListener = function (elem, callback, useCapture) { + _addWheelListener(elem, support, callback, useCapture); + + // handle MozMousePixelScroll in older Firefox + if (support === "DOMMouseScroll") { + _addWheelListener( + elem, + "MozMousePixelScroll", + callback, + useCapture + ); } - }; - var callNow = immediate && !timeout; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - if (callNow) { - func.apply(context, args); - } - }; -}; + }; -// From https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript -// consider using the uuid module instead -module.exports.uuidv4 = function uuidv4() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); -}; + /* jshint -W030 */ + function _addWheelListener(elem, eventName, callback, useCapture) { + elem[_addEventListener]( + prefix + eventName, + support === "wheel" + ? callback + : function (originalEvent) { + !originalEvent && (originalEvent = window.event); + + // create a normalized event object + var event = { + // keep a ref to the original event object + originalEvent: originalEvent, + target: + originalEvent.target || + originalEvent.srcElement, + type: "wheel", + deltaMode: + originalEvent.type === "MozMousePixelScroll" + ? 0 + : 1, + deltaX: 0, + delatZ: 0, + preventDefault: function () { + originalEvent.preventDefault + ? originalEvent.preventDefault() + : (originalEvent.returnValue = false); + }, + }; + + // calculate deltaY (and deltaX) according to the event + if (support === "mousewheel") { + event.deltaY = + (-1 / 40) * originalEvent.wheelDelta; + // Webkit also support wheelDeltaX + originalEvent.wheelDeltaX && + (event.deltaX = + (-1 / 40) * originalEvent.wheelDeltaX); + } else { + event.deltaY = originalEvent.detail; + } + + // it's time to fire the callback + return callback(event); + }, + useCapture || false + ); + } + /* jshint +W030 */ + })(window, document); + //Add Proxy poly fill https://github.com/GoogleChrome/proxy-polyfill + if (!window.Proxy) { + /* jshint ignore:start */ + (function () { + function l() { + function n(a) { + return a + ? "object" === typeof a || "function" === typeof a + : !1; + } + var p = null; + var g = function (a, b) { + function f() {} + if (!n(a) || !n(b)) { + throw new TypeError( + "Cannot create proxy with a non-object as target or handler" + ); + } + p = function () { + f = function (a) { + throw new TypeError( + "Cannot perform '" + + a + + "' on a proxy that has been revoked" + ); + }; + }; + var e = b; + b = { get: null, set: null, apply: null, construct: null }; + for (var k in e) { + if (!(k in b)) { + throw new TypeError( + "Proxy polyfill does not support trap '" + + k + + "'" + ); + } + b[k] = e[k]; + } + "function" === typeof e && (b.apply = e.apply.bind(e)); + var c = this, + g = !1, + q = !1; + "function" === typeof a + ? ((c = function () { + var h = this && this.constructor === c, + d = Array.prototype.slice.call(arguments); + f(h ? "construct" : "apply"); + return h && b.construct + ? b.construct.call(this, a, d) + : !h && b.apply + ? b.apply(a, this, d) + : h + ? (d.unshift(a), new (a.bind.apply(a, d))()) + : a.apply(this, d); + }), + (g = !0)) + : a instanceof Array && ((c = []), (q = !0)); + var r = b.get + ? function (a) { + f("get"); + return b.get(this, a, c); + } + : function (a) { + f("get"); + return this[a]; + }, + v = b.set + ? function (a, d) { + f("set"); + b.set(this, a, d, c); + } + : function (a, b) { + f("set"); + this[a] = b; + }, + t = {}; + Object.getOwnPropertyNames(a).forEach(function (b) { + if (!((g || q) && b in c)) { + var d = { + enumerable: !!Object.getOwnPropertyDescriptor( + a, + b + ).enumerable, + get: r.bind(a, b), + set: v.bind(a, b), + }; + Object.defineProperty(c, b, d); + t[b] = !0; + } + }); + e = !0; + Object.setPrototypeOf + ? Object.setPrototypeOf(c, Object.getPrototypeOf(a)) + : c.__proto__ + ? (c.__proto__ = a.__proto__) + : (e = !1); + if (b.get || !e) { + for (var m in a) { + t[m] || + Object.defineProperty(c, m, { + get: r.bind(a, m), + }); + } + } + Object.seal(a); + Object.seal(c); + return c; + }; + g.revocable = function (a, b) { + return { proxy: new g(a, b), revoke: p }; + }; + return g; + } + var u = + ("undefined" !== typeof process && + "[object process]" === {}.toString.call(process)) || + ("undefined" !== typeof navigator && + "ReactNative" === navigator.product) + ? global + : self; + u.Proxy || + ((u.Proxy = l()), (u.Proxy.revocable = u.Proxy.revocable)); + })(); + /* jshint ignore:end */ + } -}()); + //Updates destenation object with source values + module.exports.update = function update(dst, src) { + for (var prop in src) { + var val = src[prop]; + if (typeof val === "object") { + // recursive + update(dst[prop], val); + } else { + dst[prop] = val; + } + } + return dst; // return dst to allow method chaining + }; + // From: https://davidwalsh.name/javascript-debounce-function + // Returns a function, that, as long as it continues to be invoked, will not + // be triggered. The function will be called after it stops being called for + // N milliseconds. If `immediate` is passed, trigger the function on the + // leading edge, instead of the trailing. + module.exports.debounce = function debounce(func, wait, immediate) { + var timeout; + return function () { + var context = this, + args = arguments; + var later = function () { + timeout = null; + if (!immediate) { + func.apply(context, args); + } + }; + var callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) { + func.apply(context, args); + } + }; + }; + // From https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript + // consider using the uuid module instead + module.exports.uuidv4 = function uuidv4() { + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace( + /[xy]/g, + function (c) { + var r = (Math.random() * 16) | 0, + v = c === "x" ? r : (r & 0x3) | 0x8; + return v.toString(16); + } + ); + }; +})(); diff --git a/js/m.js b/js/m.js index 8889aa7..ca656e2 100644 --- a/js/m.js +++ b/js/m.js @@ -31,8 +31,8 @@ /* global module */ /* global require */ -(function() { - 'use strict'; +(function () { + "use strict"; var bluefile = require("sigfile").bluefile; var loglevel = require("loglevel"); @@ -55,17 +55,19 @@ * @memberOf sigplot * @private */ - var iOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/i) ? true : false); - if ((iOS) || // iOS doesn't support Float64 - (typeof Float64Array === 'undefined') || // If it's undefined it's obviously not supported - (Float64Array.emulated) || // If it's emulated, don't waste time on extra precision - (!Float64Array.BYTES_PER_ELEMENT)) { // If bytes per element isn't defined, it's a buggy implementation (i.e. PhantomJS) + var iOS = navigator.userAgent.match(/(iPad|iPhone|iPod)/i) ? true : false; + if ( + iOS || // iOS doesn't support Float64 + typeof Float64Array === "undefined" || // If it's undefined it's obviously not supported + Float64Array.emulated || // If it's emulated, don't waste time on extra precision + !Float64Array.BYTES_PER_ELEMENT + ) { + // If bytes per element isn't defined, it's a buggy implementation (i.e. PhantomJS) m.PointArray = Float32Array; } else { m.PointArray = Float64Array; } - /** UNITS Structure: * 0: ["None", "U"], * 1: ["Time", "sec"], @@ -187,7 +189,7 @@ 60: ["Latitude", "deg", true, false], 61: ["Longitude", "deg", true, false], 62: ["Altitude", "ft", true, false], - 63: ["Altitude", "m", false, false] + 63: ["Altitude", "m", false, false], }; m.UNITS = UNITS; @@ -205,305 +207,464 @@ // are listed here are from xcolordef.prm (use the XCOLORMAP widget). // // The actual values are a result of tribal knowledge and years of experience - colormap: [{ + colormap: [ + { name: "Greyscale", - colors: [{ - pos: 0, - red: 0, - green: 0, - blue: 0 - }, { - pos: 60, - red: 50, - green: 50, - blue: 50 - }, { - pos: 100, - red: 100, - green: 100, - blue: 100 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }] - }, { + colors: [ + { + pos: 0, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 60, + red: 50, + green: 50, + blue: 50, + }, + { + pos: 100, + red: 100, + green: 100, + blue: 100, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + ], + }, + { name: "Ramp Colormap", - colors: [{ - pos: 0, - red: 0, - green: 0, - blue: 15 - }, { - pos: 10, - red: 0, - green: 0, - blue: 50 - }, { - pos: 31, - red: 0, - green: 65, - blue: 75 - }, { - pos: 50, - red: 0, - green: 85, - blue: 0 - }, { - pos: 70, - red: 75, - green: 80, - blue: 0 - }, { - pos: 83, - red: 100, - green: 60, - blue: 0 - }, { - pos: 100, - red: 100, - green: 0, - blue: 0 - }] - }, { + colors: [ + { + pos: 0, + red: 0, + green: 0, + blue: 15, + }, + { + pos: 10, + red: 0, + green: 0, + blue: 50, + }, + { + pos: 31, + red: 0, + green: 65, + blue: 75, + }, + { + pos: 50, + red: 0, + green: 85, + blue: 0, + }, + { + pos: 70, + red: 75, + green: 80, + blue: 0, + }, + { + pos: 83, + red: 100, + green: 60, + blue: 0, + }, + { + pos: 100, + red: 100, + green: 0, + blue: 0, + }, + ], + }, + { name: "Color Wheel", - colors: [{ - pos: 0, - red: 100, - green: 100, - blue: 0 - }, { - pos: 20, - red: 0, - green: 80, - blue: 40 - }, { - pos: 30, - red: 0, - green: 100, - blue: 100 - }, { - pos: 50, - red: 10, - green: 10, - blue: 0 - }, { - pos: 65, - red: 100, - green: 0, - blue: 0 - }, { - pos: 88, - red: 100, - green: 40, - blue: 0 - }, { - pos: 100, - red: 100, - green: 100, - blue: 0 - }] - }, { + colors: [ + { + pos: 0, + red: 100, + green: 100, + blue: 0, + }, + { + pos: 20, + red: 0, + green: 80, + blue: 40, + }, + { + pos: 30, + red: 0, + green: 100, + blue: 100, + }, + { + pos: 50, + red: 10, + green: 10, + blue: 0, + }, + { + pos: 65, + red: 100, + green: 0, + blue: 0, + }, + { + pos: 88, + red: 100, + green: 40, + blue: 0, + }, + { + pos: 100, + red: 100, + green: 100, + blue: 0, + }, + ], + }, + { name: "Spectrum", - colors: [{ - pos: 0, - red: 0, - green: 75, - blue: 0 - }, { - pos: 22, - red: 0, - green: 90, - blue: 90 - }, { - pos: 37, - red: 0, - green: 0, - blue: 85 - }, { - pos: 49, - red: 90, - green: 0, - blue: 85 - }, { - pos: 68, - red: 90, - green: 0, - blue: 0 - }, { - pos: 80, - red: 90, - green: 90, - blue: 0 - }, { - pos: 100, - red: 95, - green: 95, - blue: 95 - }] - }, { + colors: [ + { + pos: 0, + red: 0, + green: 75, + blue: 0, + }, + { + pos: 22, + red: 0, + green: 90, + blue: 90, + }, + { + pos: 37, + red: 0, + green: 0, + blue: 85, + }, + { + pos: 49, + red: 90, + green: 0, + blue: 85, + }, + { + pos: 68, + red: 90, + green: 0, + blue: 0, + }, + { + pos: 80, + red: 90, + green: 90, + blue: 0, + }, + { + pos: 100, + red: 95, + green: 95, + blue: 95, + }, + ], + }, + { name: "calewhite", - colors: [{ - pos: 0, - red: 100, - green: 100, - blue: 100 - }, { - pos: 16.666, - red: 0, - green: 0, - blue: 100 - }, { - pos: 33.333, - red: 0, - green: 100, - blue: 100 - }, { - pos: 50, - red: 0, - green: 100, - blue: 0 - }, { - pos: 66.666, - red: 100, - green: 100, - blue: 0 - }, { - pos: 83.333, - red: 100, - green: 0, - blue: 0 - }, { - pos: 100, - red: 100, - green: 0, - blue: 100 - }] - }, { + colors: [ + { + pos: 0, + red: 100, + green: 100, + blue: 100, + }, + { + pos: 16.666, + red: 0, + green: 0, + blue: 100, + }, + { + pos: 33.333, + red: 0, + green: 100, + blue: 100, + }, + { + pos: 50, + red: 0, + green: 100, + blue: 0, + }, + { + pos: 66.666, + red: 100, + green: 100, + blue: 0, + }, + { + pos: 83.333, + red: 100, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 100, + green: 0, + blue: 100, + }, + ], + }, + { name: "HotDesat", - colors: [{ - pos: 0, - red: 27.84, - green: 27.84, - blue: 85.88 - }, { - pos: 14.2857, - red: 0, - green: 0, - blue: 35.69 - }, { - pos: 28.571, - red: 0, - green: 100, - blue: 100 - }, { - pos: 42.857, - red: 0, - green: 49.8, - blue: 0 - }, { - pos: 57.14286, - red: 100, - green: 100, - blue: 0 - }, { - pos: 71.42857, - red: 100, - green: 37.65, - blue: 0 - }, { - pos: 85.7143, - red: 41.96, - green: 0, - blue: 0 - }, { - pos: 100, - red: 87.84, - green: 29.8, - blue: 29.8 - }] - }, { + colors: [ + { + pos: 0, + red: 27.84, + green: 27.84, + blue: 85.88, + }, + { + pos: 14.2857, + red: 0, + green: 0, + blue: 35.69, + }, + { + pos: 28.571, + red: 0, + green: 100, + blue: 100, + }, + { + pos: 42.857, + red: 0, + green: 49.8, + blue: 0, + }, + { + pos: 57.14286, + red: 100, + green: 100, + blue: 0, + }, + { + pos: 71.42857, + red: 100, + green: 37.65, + blue: 0, + }, + { + pos: 85.7143, + red: 41.96, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 87.84, + green: 29.8, + blue: 29.8, + }, + ], + }, + { name: "Sunset", - colors: [{ - pos: 0, - red: 10, - green: 0, - blue: 23 - }, { - pos: 18, - red: 34, - green: 0, - blue: 60 - }, { - pos: 36, - red: 58, - green: 20, - blue: 47 - }, { - pos: 55, - red: 74, - green: 20, - blue: 28 - }, { - pos: 72, - red: 90, - green: 43, - blue: 0 - }, { - pos: 87, - red: 100, - green: 72, - blue: 0 - }, { - pos: 100, - red: 100, - green: 100, - blue: 76 - }] + colors: [ + { + pos: 0, + red: 10, + green: 0, + blue: 23, + }, + { + pos: 18, + red: 34, + green: 0, + blue: 60, + }, + { + pos: 36, + red: 58, + green: 20, + blue: 47, + }, + { + pos: 55, + red: 74, + green: 20, + blue: 28, + }, + { + pos: 72, + red: 90, + green: 43, + blue: 0, + }, + { + pos: 87, + red: 100, + green: 72, + blue: 0, + }, + { + pos: 100, + red: 100, + green: 100, + blue: 76, + }, + ], }, { name: "Hot", - colors: ["#000000", "#7f0000", "#b30000", "#d7301f", "#ef6548", "#fc8d59", "#fdbb84", "#fdd49e", "#fee8c8", "#fff7ec", "#ffffff"] - }, { + colors: [ + "#000000", + "#7f0000", + "#b30000", + "#d7301f", + "#ef6548", + "#fc8d59", + "#fdbb84", + "#fdd49e", + "#fee8c8", + "#fff7ec", + "#ffffff", + ], + }, + { name: "Cold", - colors: ["#000000", "#023858", "#045a8d", "#0570b0", "#3690c0", "#74a9cf", "#a6bddb", "#d0d1e6", "#ece7f2", "#fff7fb", "#ffffff"] + colors: [ + "#000000", + "#023858", + "#045a8d", + "#0570b0", + "#3690c0", + "#74a9cf", + "#a6bddb", + "#d0d1e6", + "#ece7f2", + "#fff7fb", + "#ffffff", + ], }, { name: "Purple", - colors: ["#230022", "#4d004b", "#810f7c", "#88419d", "#8c6bb1", "#8c96c6", "#9ebcda", "#bfd3e6", "#e0ecf4", "#f7fcfd"] - }, { + colors: [ + "#230022", + "#4d004b", + "#810f7c", + "#88419d", + "#8c6bb1", + "#8c96c6", + "#9ebcda", + "#bfd3e6", + "#e0ecf4", + "#f7fcfd", + ], + }, + { name: "BuGn", - colors: ['#f7fcfd', '#e5f5f9', '#ccece6', '#99d8c9', '#66c2a4', '#41ae76', '#238b45', '#006d2c', '#00441b'] - }, { + colors: [ + "#f7fcfd", + "#e5f5f9", + "#ccece6", + "#99d8c9", + "#66c2a4", + "#41ae76", + "#238b45", + "#006d2c", + "#00441b", + ], + }, + { name: "YlOrBr", - colors: ['#ffffe5', '#fff7bc', '#fee391', '#fec44f', '#fe9929', '#ec7014', '#cc4c02', '#993404', '#662506'] - }, { + colors: [ + "#ffffe5", + "#fff7bc", + "#fee391", + "#fec44f", + "#fe9929", + "#ec7014", + "#cc4c02", + "#993404", + "#662506", + ], + }, + { name: "YlGnBu", - colors: ['#ffffd9', '#edf8b1', '#c7e9b4', '#7fcdbb', '#41b6c4', '#1d91c0', '#225ea8', '#253494', '#081d58'] - }, { + colors: [ + "#ffffd9", + "#edf8b1", + "#c7e9b4", + "#7fcdbb", + "#41b6c4", + "#1d91c0", + "#225ea8", + "#253494", + "#081d58", + ], + }, + { name: "YlOrRd", - colors: ["#000000", "#662506", "#993404", "#cc4c02", "#ec7014", "#fe9929", "#fec44f", "#fee391", "#fff7bc", "#ffffe5", "#ffffff"] - }, { + colors: [ + "#000000", + "#662506", + "#993404", + "#cc4c02", + "#ec7014", + "#fe9929", + "#fec44f", + "#fee391", + "#fff7bc", + "#ffffe5", + "#ffffff", + ], + }, + { name: "GreyNRed", - colors: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#ffffff', '#e0e0e0', '#bababa', '#878787', '#4d4d4d', '#1a1a1a'].reverse() - } - ] + colors: [ + "#67001f", + "#b2182b", + "#d6604d", + "#f4a582", + "#fddbc7", + "#ffffff", + "#e0e0e0", + "#bababa", + "#878787", + "#4d4d4d", + "#1a1a1a", + ].reverse(), + }, + ], }; /** Pipe Size @@ -515,7 +676,7 @@ * Converts unit strings to number code * @param {string} unitInput User unit input */ - m.unit_lookup = function(unitInput) { + m.unit_lookup = function (unitInput) { for (var i = 0; i < 64; i++) { var u; if (UNITS[i] === undefined) { @@ -535,7 +696,7 @@ if (u[3]) { return i; } - } else if ((unitInput === comparer1) || (unitInput === comparer2)) { + } else if (unitInput === comparer1 || unitInput === comparer2) { return i; } } @@ -550,13 +711,13 @@ * @param {array} overrides List of fields/values to be overridden in the bluefile header * @return {header} hcb Return type-1000 bluefile header, filename=null */ - m.initialize = function(data, overrides) { + m.initialize = function (data, overrides) { var hcb = new bluefile.BlueHeader(null); - hcb.version = 'BLUE'; + hcb.version = "BLUE"; hcb.size = 0; hcb.type = 1000; - hcb.format = 'SF'; + hcb.format = "SF"; hcb.timecode = 0.0; hcb.xstart = 0.0; hcb.xdelta = 1.0; @@ -577,26 +738,27 @@ } //Convert xunits and yunits to numbers if they are strings - hcb["xunits"] = m.unit_lookup(hcb["xunits"]); - hcb["yunits"] = m.unit_lookup(hcb["yunits"]); - + hcb.xunits = m.unit_lookup(hcb.xunits); + hcb.yunits = m.unit_lookup(hcb.yunits); // Force type 2000 is subsize is specified - if (hcb["subsize"] > 1) { + if (hcb.subsize > 1) { hcb.type = 2000; - } else if (Array.isArray(data) && (Array.isArray(data[0]) || ArrayBuffer.isView(data[0]))) { + } else if ( + Array.isArray(data) && + (Array.isArray(data[0]) || ArrayBuffer.isView(data[0])) + ) { //If this is a 2-D array automatically set subsize hcb.type = 2000; hcb.subsize = data[0].length; hcb.size = data.length; } - hcb["class"] = hcb.type / 1000; + hcb.class = hcb.type / 1000; // If this is a type 2000 , subsize *must* be provided - if ((hcb["class"] === 2) && (hcb["subsize"] === undefined)) { + if (hcb.class === 2 && hcb.subsize === undefined) { throw "subsize must be provided with type 2000 files"; } - if (!overrides.pipe) { hcb.setData(data); } else { @@ -618,9 +780,9 @@ * Convert type-2000 header internals to force GRAB and FILAD routines to treat file as a 1000-type file. * @param {header} hcb Bluefile header control block */ - m.force1000 = function(hcb) { - if (hcb["class"] === 2) { - if ((hcb.size) && (!hcb.pipe)) { + m.force1000 = function (hcb) { + if (hcb.class === 2) { + if (hcb.size && !hcb.pipe) { hcb.size = hcb.subsize * hcb.size; } else { // assume the size is 0 @@ -639,20 +801,20 @@ * @param {number} nget Number of requested data * @return {number} ngot Number of received data */ - m.grab = function(hcb, bufview, start, nget) { + m.grab = function (hcb, bufview, start, nget) { if (!hcb.dview) { return 0; } // TODO reformat - if (hcb.format[0] === 'C') { + if (hcb.format[0] === "C") { start = start * 2; } nget = hcb.ape * nget; // TODO - this is never used???? //var ngot = Math.min(bufview.length, (hcb.dview.length-start)); //mmm - var ngot = Math.min(bufview.length, (hcb.dview.length - start)); + var ngot = Math.min(bufview.length, hcb.dview.length - start); // iOS doesn't have .set on TypedArrays if (bufview.set === undefined) { for (var i = 0; i < ngot; i++) { @@ -661,7 +823,7 @@ } else { bufview.set(hcb.dview.subarray(start, start + ngot)); } - if (hcb.format[0] === 'C') { + if (hcb.format[0] === "C") { ngot = ngot / 2; } return ngot; @@ -673,12 +835,12 @@ * @param {array} data Data buffer * @param {boolean} [sync=false] dispatch onpipewrite syncronously */ - m.filad = function(hcb, data, sync) { + m.filad = function (hcb, data, sync) { if (hcb.data_free < data.length) { throw "Pipe full"; } var sidx = hcb.in_byte / hcb.dview.BYTES_PER_ELEMENT; - var eidx = (sidx + data.length); + var eidx = sidx + data.length; if (eidx > hcb.dview.length) { var head = hcb.dview.length - sidx; var tail = data.length - head; @@ -689,10 +851,11 @@ hcb.dview.set(data.slice(0, head), sidx); hcb.dview.set(data.slice(head, data.length), 0); } - hcb.in_byte = (tail * hcb.dview.BYTES_PER_ELEMENT); + hcb.in_byte = tail * hcb.dview.BYTES_PER_ELEMENT; } else { hcb.dview.set(data, sidx); - hcb.in_byte = (eidx * hcb.dview.BYTES_PER_ELEMENT) % hcb.buf.byteLength; + hcb.in_byte = + (eidx * hcb.dview.BYTES_PER_ELEMENT) % hcb.buf.byteLength; } hcb.data_free -= data.length; if (hcb.onwritelisteners) { @@ -711,7 +874,7 @@ * @return {number} elements available * @private */ - m.pavail = function(hcb) { + m.pavail = function (hcb) { return hcb.dview.length - hcb.data_free; }; @@ -724,7 +887,7 @@ * @return {number} ngot Number of data values gotten */ // WARNING - nget is number of scalars...which differs from the normal API - m.grabx = function(hcb, dview, nget, offset) { + m.grabx = function (hcb, dview, nget, offset) { var navail = hcb.dview.length - hcb.data_free; if (offset === undefined) { offset = 0; @@ -742,7 +905,7 @@ } var sidx = hcb.out_byte / hcb.dview.BYTES_PER_ELEMENT; - var eidx = (sidx + nget); + var eidx = sidx + nget; if (eidx >= hcb.dview.length) { var head = hcb.dview.length - sidx; eidx = eidx - hcb.dview.length; @@ -751,19 +914,19 @@ } else { dview.set(hcb.dview.subarray(sidx, eidx), offset); } - hcb.out_byte = (eidx * hcb.dview.BYTES_PER_ELEMENT) % hcb.buf.byteLength; + hcb.out_byte = + (eidx * hcb.dview.BYTES_PER_ELEMENT) % hcb.buf.byteLength; hcb.data_free += nget; var ngot = nget; return ngot; }; - /** * @param {header} hcb Bluefile header control block * @param {number} onwrite - * @private */ - m.addPipeWriteListener = function(hcb, onwrite) { + m.addPipeWriteListener = function (hcb, onwrite) { if (!hcb.onwritelisteners) { hcb.onwritelisteners = []; } @@ -778,7 +941,7 @@ * @return {string} ASCII code pair */ // ~= M$UNITS_NAME - m.units_name = function(units) { + m.units_name = function (units) { var u = UNITS[units]; return u[0] + " (" + u[1] + ")"; }; @@ -788,15 +951,15 @@ * @param {string} pathfilename Full path, including filename * @return {string} filename Trimmed filename */ - m.trim_name = function(pathfilename) { - var i = pathfilename.indexOf(']'); + m.trim_name = function (pathfilename) { + var i = pathfilename.indexOf("]"); if (i === -1) { - i = pathfilename.indexOf('/'); + i = pathfilename.indexOf("/"); } if (i === -1) { - i = pathfilename.indexOf(':'); + i = pathfilename.indexOf(":"); } - var j = pathfilename.substr(i + 1, pathfilename.length).indexOf('.'); + var j = pathfilename.substr(i + 1, pathfilename.length).indexOf("."); if (j < 0) { j = pathfilename.length - i; } @@ -812,7 +975,7 @@ * @return {string} representation of units and multiplier */ // ~= M$LABEL - m.label = function(units, mult) { + m.label = function (units, mult) { var u = ["Unknown", "U"]; if (typeof units === "string") { @@ -841,46 +1004,46 @@ * @param b * @param c */ - m.bound = function(a, b, c) { - return a < b ? b : (a > c ? c : a); + m.bound = function (a, b, c) { + return a < b ? b : a > c ? c : a; }; - m.touch_distance = function(touchA, touchB) { - var xd = (touchA.pageX - touchB.pageX); - var yd = (touchA.pageY - touchB.pageY); - return Math.sqrt((xd * xd) + (yd * yd)); + m.touch_distance = function (touchA, touchB) { + var xd = touchA.pageX - touchB.pageX; + var yd = touchA.pageY - touchB.pageY; + return Math.sqrt(xd * xd + yd * yd); }; - m.mult_prefix = function(mult) { + m.mult_prefix = function (mult) { var prefix = "?"; /* jshint -W116 */ if (mult == 1) { prefix = ""; } else if (mult == 10) { - prefix = 'da'; + prefix = "da"; } else if (mult == 0.1) { - prefix = 'd'; + prefix = "d"; } else if (mult == 100) { - prefix = 'h'; + prefix = "h"; } else if (mult == 0.01) { - prefix = 'c'; + prefix = "c"; } else if (mult == 1.0e3) { - prefix = 'K'; + prefix = "K"; } else if (mult == 1.0e-3) { - prefix = 'm'; + prefix = "m"; } else if (mult == 1.0e6) { - prefix = 'M'; + prefix = "M"; } else if (mult == 1.0e-6) { - prefix = 'u'; + prefix = "u"; } else if (mult == 1.0e9) { - prefix = 'G'; + prefix = "G"; } else if (mult == 1.0e-9) { - prefix = 'n'; + prefix = "n"; } else if (mult == 1.0e12) { - prefix = 'T'; + prefix = "T"; } else if (mult == 1.0e-12) { - prefix = 'p'; + prefix = "p"; } /* jshint +W116 */ @@ -891,35 +1054,34 @@ * @private */ var VECTOR = { - MV: 'F', // vector type - MS: 'F', // scalar type...not really necessary in javascript + MV: "F", // vector type + MS: "F", // scalar type...not really necessary in javascript nbpt: 4, - view: undefined + view: undefined, }; - /** * Sets data type for all subsequent calls to vector libraries. Remains in effect until another call to this routine. * @param ctype */ // ~= VSTYPE - not really necessary - m.vstype = function(ctype) { + m.vstype = function (ctype) { VECTOR.MS = ctype; VECTOR.MV = ctype; - if (VECTOR.MV === 'D') { + if (VECTOR.MV === "D") { VECTOR.nbpt = 8; - } else if ((VECTOR.MV === 'L') || (VECTOR.MV === 'F')) { + } else if (VECTOR.MV === "L" || VECTOR.MV === "F") { VECTOR.nbpt = 4; - } else if (VECTOR.MV === 'I') { + } else if (VECTOR.MV === "I") { VECTOR.nbpt = 2; - } else if (VECTOR.MV === 'B') { + } else if (VECTOR.MV === "B") { VECTOR.nbpt = 1; } else { alert("Unsupported vector type"); } }; - m.log10 = function(v, lo_thresh) { + m.log10 = function (v, lo_thresh) { if (lo_thresh === undefined) { lo_thresh = 1.0e-20; } @@ -933,7 +1095,7 @@ * @param {array} dst Ouput vector. If undefined, elements will be overwritten. */ // ~= M$VLOG10- not really necessary - m.vlog10 = function(src, lo_thresh, dst) { + m.vlog10 = function (src, lo_thresh, dst) { if (lo_thresh === undefined) { lo_thresh = 1.0e-20; } @@ -957,7 +1119,7 @@ * @param {array} dst Output vector. If undefined, elements will be overwritten. * @private */ - m.vlogscale = function(src, lo_thresh, dbscale, dst) { + m.vlogscale = function (src, lo_thresh, dbscale, dst) { if (lo_thresh === undefined) { lo_thresh = 1.0e-20; } @@ -971,7 +1133,8 @@ if (dst.length <= i) { break; } - dst[i] = Math.log(Math.abs(Math.max(src[i], lo_thresh))) / Math.log(10); + dst[i] = + Math.log(Math.abs(Math.max(src[i], lo_thresh))) / Math.log(10); dst[i] = dst[i] * dbscale; } }; @@ -986,7 +1149,7 @@ * @param {array} dst Output vector. If undefined, elements will be overwritten. * @private */ - m.cvmag2logscale = function(src, lo_thresh, dbscale, dst) { + m.cvmag2logscale = function (src, lo_thresh, dbscale, dst) { if (lo_thresh === undefined) { lo_thresh = 1.0e-20; } @@ -1002,8 +1165,9 @@ if (j >= src.length) { break; } - dst[i] = (src[j - 1] * src[j - 1]) + (src[j] * src[j]); - dst[i] = Math.log(Math.abs(Math.max(dst[i], lo_thresh))) / Math.log(10); + dst[i] = src[j - 1] * src[j - 1] + src[j] * src[j]; + dst[i] = + Math.log(Math.abs(Math.max(dst[i], lo_thresh))) / Math.log(10); dst[i] = dst[i] * dbscale; } }; @@ -1016,7 +1180,7 @@ * @param {number} count Number of elements to apply multiplier, starting with first element. */ // ~= M$VSMUL - m.vsmul = function(src, mul, dst, count) { + m.vsmul = function (src, mul, dst, count) { if (dst === undefined) { dst = src; } @@ -1041,7 +1205,7 @@ * @return {array} mxmin Index and value of min and max elements in . */ // ~= M$VMXMN - m.vmxmn = function(vec, size) { + m.vmxmn = function (vec, size) { // Originally this code used an object to hold the values // but Chrome 34.0.1847.131 seemed to have a bug where // these values would somehow get messed up...oddly @@ -1066,7 +1230,7 @@ smax: smax, smin: smin, imax: imax, - imin: imin + imin: imin, }; }; @@ -1079,7 +1243,7 @@ * @param {number} count Number of input vector elements to move, starting with 0th element of . Cannot exceed vector lengths, * taking into account the strides. */ - m.vmov = function(src, sstride, dest, dstride, count) { + m.vmov = function (src, sstride, dest, dstride, count) { if (count === undefined) { count = src.length; } @@ -1107,7 +1271,7 @@ */ // ~= M$VFILL // TODO - more optimal version? - m.vfill = function(vec, inpval, count) { + m.vfill = function (vec, inpval, count) { if (count === undefined) { count = vec.length; } @@ -1123,7 +1287,7 @@ * @param {array} dest Ouput vector. If is undefined, overwrite input vector . * @param {number} count Number of elements to write, starting with 0th element of . Cannot exceed vector lengths. */ - m.vabs = function(vec, dest, count) { + m.vabs = function (vec, dest, count) { if (count === undefined) { count = vec.length; } @@ -1136,7 +1300,6 @@ } }; - /** * Computes the magnitude of complex vector elements. Store results in output vector . * @param {array} cxvec Input vector @@ -1144,7 +1307,7 @@ * @param {number} count Number of elements to write, starting with 0th element of . Cannot exceed vector lengths. If undefined, defaults to output vector length. */ // ~= M$CVMAG - m.cvmag = function(cxvec, dest, count) { + m.cvmag = function (cxvec, dest, count) { if (count === undefined) { count = dest.length; } @@ -1156,7 +1319,9 @@ if (j >= cxvec.length) { break; } - dest[i] = Math.sqrt((cxvec[j - 1] * cxvec[j - 1]) + (cxvec[j] * cxvec[j])); + dest[i] = Math.sqrt( + cxvec[j - 1] * cxvec[j - 1] + cxvec[j] * cxvec[j] + ); } }; @@ -1167,7 +1332,7 @@ * @param {number} count Number of elements to write, starting with 0th element of . Cannot exceed vector lengths. If undefined, defaults to output vector length. */ // ~= M$CVMAG2 - m.cvmag2 = function(cxvec, dest, count) { + m.cvmag2 = function (cxvec, dest, count) { if (count === undefined) { count = dest.length; } @@ -1180,7 +1345,7 @@ if (j >= cxvec.length) { break; } - dest[i] = (cxvec[j - 1] * cxvec[j - 1]) + (cxvec[j] * cxvec[j]); + dest[i] = cxvec[j - 1] * cxvec[j - 1] + cxvec[j] * cxvec[j]; } }; @@ -1191,7 +1356,7 @@ * @param {number} count Number of elements to write, starting with 0th element of . Cannot exceed vector lengths. If undefined, defaults to output vector length. */ // ~= M$CVPHA - m.cvpha = function(cxvec, dest, count) { + m.cvpha = function (cxvec, dest, count) { if (count === undefined) { count = dest.length; } @@ -1208,7 +1373,7 @@ } re = cxvec[j - 1]; im = cxvec[j]; - if ((re === 0.0) && (im === 0.0)) { + if (re === 0.0 && im === 0.0) { re = 1.0; } dest[i] = Math.atan2(im, re); @@ -1222,7 +1387,7 @@ * @param {number} count Number of elements to write, starting with 0th element of . Cannot exceed vector lengths. If undefined, defaults to output vector length. */ // ~= M$CVPHAD - m.cvphad = function(cxvec, dest, count) { + m.cvphad = function (cxvec, dest, count) { if (count === undefined) { count = dest.length; } @@ -1238,7 +1403,7 @@ } re = cxvec[j - 1]; im = cxvec[j]; - if ((re === 0.0) && (im === 0.0)) { + if (re === 0.0 && im === 0.0) { re = 1.0; } dest[i] = Math.atan2(im, re) * (180.0 / Math.PI); @@ -1250,8 +1415,8 @@ * @private */ // ~= INT(), DINT - m.trunc = function(n) { - return n - n % 1; + m.trunc = function (n) { + return n - (n % 1); }; /** @@ -1260,7 +1425,7 @@ * @private */ // Transfer of sign function from Fortran - m.sign = function(a1, a2) { + m.sign = function (a1, a2) { if (a2 >= 0) { return Math.abs(a1); } else { @@ -1275,7 +1440,7 @@ */ function pad2(number) { - return (number < 10 ? '0' : '') + number; + return (number < 10 ? "0" : "") + number; } /** @@ -1293,12 +1458,20 @@ * */ - m.sec2tod = function(sec, trim_trailing_zeros) { + m.sec2tod = function (sec, trim_trailing_zeros) { var tod = ""; var j1950 = Date.UTC(1950, 0, 1); //From 1950 to 1970 var j1950Date = new Date(j1950); //debug var var d = new Date(); - var midnightToday = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0); + var midnightToday = new Date( + d.getFullYear(), + d.getMonth(), + d.getDate(), + 0, + 0, + 0, + 0 + ); var diffDaySecs = 86400; // 86400 secs = 24*60*60 var diffYearSecs = 31536000; // 31536000 secs = 365*24*60*60 var negDiffYearSecs = -1 * diffYearSecs; //-31536000 secs @@ -1306,9 +1479,14 @@ if (sec >= 0) { if (sec < diffDaySecs) { // hh:mm:ss - var millisecs = midnightToday.getTime() + (sec * 1000); + var millisecs = midnightToday.getTime() + sec * 1000; var d = new Date(millisecs); - tod = pad2(d.getHours()) + ":" + pad2(d.getMinutes()) + ":" + pad2(d.getSeconds()); + tod = + pad2(d.getHours()) + + ":" + + pad2(d.getMinutes()) + + ":" + + pad2(d.getSeconds()); } else if (sec === 86400) { tod = "24:00:00"; } else if (sec < diffYearSecs) { @@ -1322,19 +1500,36 @@ var minutes = Math.floor((seconds / 60) % 60); seconds %= 60; - tod = days.toString() + "::" + pad2(hours) + ":" + pad2(minutes) + ":" + pad2(seconds); + tod = + days.toString() + + "::" + + pad2(hours) + + ":" + + pad2(minutes) + + ":" + + pad2(seconds); } else { // convert to j1950 var secMilli = Math.floor(sec * 1000) + j1950; d = new Date(secMilli); - tod = d.getUTCFullYear() + ":" + pad2(d.getUTCMonth() + 1) + ":" + pad2(d.getUTCDate()) + "::" + - pad2(d.getUTCHours()) + ":" + pad2(d.getUTCMinutes()) + ":" + pad2(d.getUTCSeconds()); + tod = + d.getUTCFullYear() + + ":" + + pad2(d.getUTCMonth() + 1) + + ":" + + pad2(d.getUTCDate()) + + "::" + + pad2(d.getUTCHours()) + + ":" + + pad2(d.getUTCMinutes()) + + ":" + + pad2(d.getUTCSeconds()); } } else { if (sec > negDiffYearSecs) { // -ddd:hh:mm:ss var days = sec / diffDaySecs; - days = (days <= 0) ? Math.ceil(days) : Math.floor(days); + days = days <= 0 ? Math.ceil(days) : Math.floor(days); // Break down integral seconds in the day into hours, minutes and seconds. var seconds = Math.floor(Math.abs(sec) % diffDaySecs); @@ -1347,13 +1542,30 @@ } else { days = days.toString(); } - tod = days + "::" + pad2(hours) + ":" + pad2(minutes) + ":" + pad2(seconds); + tod = + days + + "::" + + pad2(hours) + + ":" + + pad2(minutes) + + ":" + + pad2(seconds); } else { // convert to j1950 var secMilli = Math.floor(sec * 1000) + j1950; d = new Date(secMilli); - tod = d.getUTCFullYear() + ":" + pad2(d.getUTCMonth() + 1) + ":" + pad2(d.getUTCDate()) + "::" + - pad2(d.getUTCHours()) + ":" + pad2(d.getUTCMinutes()) + ":" + pad2(d.getUTCSeconds()); + tod = + d.getUTCFullYear() + + ":" + + pad2(d.getUTCMonth() + 1) + + ":" + + pad2(d.getUTCDate()) + + "::" + + pad2(d.getUTCHours()) + + ":" + + pad2(d.getUTCMinutes()) + + ":" + + pad2(d.getUTCSeconds()); } } @@ -1361,11 +1573,15 @@ // even if we are on a full second boundary, otherwise // on rising/falling rasters it can look like the display // is flickering - var fractional = (sec % 1); + var fractional = sec % 1; if (fractional === 0.0) { tod += ".000000"; } else { - tod += "." + Math.abs(sec % 1).toPrecision(6).slice(2, 8); + tod += + "." + + Math.abs(sec % 1) + .toPrecision(6) + .slice(2, 8); } if (trim_trailing_zeros) { @@ -1380,7 +1596,6 @@ } } return tod; - }; /** @@ -1397,7 +1612,7 @@ * if modulo <= 0 return m.sec2tod(modulo)+86400 * if module < */ - m.sec2tspec = function(sec, mode, trim_trailing_zeros) { + m.sec2tspec = function (sec, mode, trim_trailing_zeros) { mode = mode || ""; if (sec >= 0 && sec <= 86400) { return m.sec2tod(sec, trim_trailing_zeros); @@ -1418,41 +1633,62 @@ * @return {string} tod Time of day */ - m.sec2tod_j1970 = function(sec) { + m.sec2tod_j1970 = function (sec) { var tod = ""; var d; - if ((sec >= 0) && (sec < 86400)) { + if (sec >= 0 && sec < 86400) { // hh:mm:ss d = new Date(sec * 1000); - tod = pad2(d.getHours()) + ":" + pad2(d.getMinutes()) + ":" + pad2(d.getSeconds()); - - } else if ((sec < 0) && (sec > -31536000)) { + tod = + pad2(d.getHours()) + + ":" + + pad2(d.getMinutes()) + + ":" + + pad2(d.getSeconds()); + } else if (sec < 0 && sec > -31536000) { // -ddd:hh:mm:ss var days = -1 * (sec / (24 * 60 * 60)); d = new Date(sec * 1000); - tod = days.toString() + "::" + pad2(d.getHours()) + ":" + pad2(d.getMinutes()) + ":" + pad2(d.getSeconds()); + tod = + days.toString() + + "::" + + pad2(d.getHours()) + + ":" + + pad2(d.getMinutes()) + + ":" + + pad2(d.getSeconds()); } else { // convert to j1950 d = new Date((sec - j1950offset) * 1000); - tod = d.getFullYear() + ":" + pad2(d.getMonth()) + ":" + pad2(d.getDate()) + "::" + - pad2(d.getHours()) + ":" + pad2(d.getMinutes()) + ":" + pad2(d.getSeconds()); - } - if ((sec % 1) !== 0) { + tod = + d.getFullYear() + + ":" + + pad2(d.getMonth()) + + ":" + + pad2(d.getDate()) + + "::" + + pad2(d.getHours()) + + ":" + + pad2(d.getMinutes()) + + ":" + + pad2(d.getSeconds()); + } + if (sec % 1 !== 0) { tod += "." + (sec % 1).toPrecision(6).slice(2, 8); } return tod; }; - m.j1970toj1950 = function(t) { + m.j1970toj1950 = function (t) { if (t.getTime !== undefined) { - return ((t.getTime() / 1000) + j1950offset); + return t.getTime() / 1000 + j1950offset; } else { - return (t + j1950offset); + return t + j1950offset; } }; - m.j1950toj1970 = function(t) { - return (t - j1950offset); + m.j1950toj1970 = function (t) { + return t - j1950offset; }; /** @@ -1461,9 +1697,9 @@ // Throttle calls to "callback" routine and ensure that it // is not invoked any more often than "delay" milliseconds. // - m.throttle = function(delay, callback) { + m.throttle = function (delay, callback) { var previousCall = new Date().getTime(); - return function() { + return function () { var time = new Date().getTime(); // @@ -1471,18 +1707,18 @@ // the previous call then propagate this call to // "callback" // - if ((time - previousCall) >= delay) { + if (time - previousCall >= delay) { previousCall = time; callback.apply(null, arguments); } }; }; - m.pad = function(value, padamt) { + m.pad = function (value, padamt) { if (!padamt) { return 0; } - if (typeof padamt === 'string') { + if (typeof padamt === "string") { if (padamt.endsWith("%")) { padamt = value * (parseFloat(padamt) / 100.0); } else { @@ -1495,5 +1731,4 @@ // Node: Export function module.exports = m; - -}()); +})(); diff --git a/js/mx.dommenu.js b/js/mx.dommenu.js index 266d853..57545bd 100644 --- a/js/mx.dommenu.js +++ b/js/mx.dommenu.js @@ -1,18 +1,23 @@ /* global module */ /* global require */ -(function() { +(function () { var common = require("./common"); - var DomMenu = function(Mx, menu, options) { + var DomMenu = function (Mx, menu, options) { this.options = { - itemClass: "sigplot-menu-item" + itemClass: "sigplot-menu-item", }; common.update(this.options, options); this._Mx = Mx; this._container = Mx.root; this._menu = document.createElement("div"); - var style = "z-index:2;float:left;position:relative;left:" + Mx.xpos + "px;top:" + Mx.ypos + "px;"; + var style = + "z-index:2;float:left;position:relative;left:" + + Mx.xpos + + "px;top:" + + Mx.ypos + + "px;"; this._menu.classList.add("sigplot-menu"); var d = new Date(); this._menuId = "menu-" + d.getSeconds() + d.getMilliseconds(); @@ -23,31 +28,33 @@ this.createMenu(menu); }; DomMenu.prototype = { - createMenu: function(menu) { + createMenu: function (menu) { var self = this; var Mx = this._Mx; var originalFinalize = menu.finalize; - menu.finalize = function() { + menu.finalize = function () { self.remove(); originalFinalize(); }; this.finalize = menu.finalize; var title = document.createElement("div"); - title.addEventListener("mousedown", function(e) { + title.addEventListener("mousedown", function (e) { e.preventDefault(); self._movingOffsetX = e.offsetX; self._movingOffsetY = e.offsetY; self._moving = true; }); - title.addEventListener("mouseup", function(e) { + title.addEventListener("mouseup", function (e) { e.preventDefault(); self._moving = false; }); - self._moveMenu = function(e) { + self._moveMenu = function (e) { if (self._moving) { - self._menu.style.position = 'fixed'; - self._menu.style.top = e.clientY - self._movingOffsetY + 'px'; - self._menu.style.left = e.clientX - self._movingOffsetX + 'px'; + self._menu.style.position = "fixed"; + self._menu.style.top = + e.clientY - self._movingOffsetY + "px"; + self._menu.style.left = + e.clientX - self._movingOffsetX + "px"; } }; document.body.addEventListener("mousemove", self._moveMenu); @@ -56,23 +63,32 @@ this._menu.append(title); var list = document.createElement("ul"); list.classList.add("sigplot-menu-list"); - menu.items.forEach(function(item) { + menu.items.forEach(function (item) { var li = self._createMenuItem(item, menu); list.append(li); }); this._menu.append(list); this._container.append(this._menu); - this._menu.addEventListener("contextmenu", function(e) { + this._menu.addEventListener("contextmenu", function (e) { e.preventDefault(); self.finalize(); }); Mx.menu = this; Mx.widget = { type: "MENU", - callback: function(event) { + callback: function (event) { if (event.type === "mousedown") { - if (event.which === 1 || event.which === 2 || event.which === 3) { - if ((self._Mx.menu === self) && (!event.target.classList.contains(self.options.itemClass))) { + if ( + event.which === 1 || + event.which === 2 || + event.which === 3 + ) { + if ( + self._Mx.menu === self && + !event.target.classList.contains( + self.options.itemClass + ) + ) { self.finalize(); } if (!self._Mx.menu) { @@ -86,10 +102,10 @@ if (event.type === "keydown") { self._handleKeyEvents(event); } - } + }, }; }, - _handleKeyEvents: function(event) { + _handleKeyEvents: function (event) { var self = this; if (event.key === "ArrowDown") { event.preventDefault(); @@ -131,18 +147,18 @@ } } }, - _setActive: function(li) { + _setActive: function (li) { if (this._active) { this._clearActive(); } this._active = li; - li.classList.add('active'); + li.classList.add("active"); }, - _clearActive: function() { - this._active.classList.remove('active'); + _clearActive: function () { + this._active.classList.remove("active"); this._active = null; }, - _createMenuItem: function(item, menu) { + _createMenuItem: function (item, menu) { var self = this; var Mx = this._Mx; var li = document.createElement("li"); @@ -157,7 +173,7 @@ li.className += " checked"; } } - li.addEventListener("click", function() { + li.addEventListener("click", function () { self.remove(); Mx.menu = undefined; Mx.widget = null; @@ -165,80 +181,112 @@ item.handler(); } else if (item.menu) { var newmenu = item.menu; - if (typeof item.menu === 'function') { + if (typeof item.menu === "function") { newmenu = item.menu(); } newmenu.finalize = menu.finalize; new DomMenu(Mx, newmenu); } - if ((!Mx.menu) && (menu.finalize)) { + if (!Mx.menu && menu.finalize) { menu.finalize(); } }); - li.addEventListener("mouseenter", function(e) { + li.addEventListener("mouseenter", function (e) { self._setActive(e.target); }); - li.addEventListener("mouseleave", function(e) { + li.addEventListener("mouseleave", function (e) { self._clearActive(); }); self._items.push(li); return li; }, - remove: function() { - + remove: function () { var Mx = this._Mx; Mx.menu = undefined; Mx.widget = null; this._menu.remove(); document.body.removeEventListener("mousemove", this._moveMenu); }, - setCSS: function() { + setCSS: function () { var Mx = this._Mx; var cssId = "mx-menu-css"; // id so we can always replace the css if we want to update this with mx.setTheme.. - var style = document.createElement('style'); + var style = document.createElement("style"); var textContent; style.id = cssId; //This really sucks...... and I hate it. -Sean /* jshint ignore:start */ - textContent = "" + - "." + this._menuId + "{\n" + - "background-color: " + Mx.xwbg + ";\n" + - "font: " + Mx.font.font + ";\n" + - "color:" + Mx.xwfg + "\n" + + textContent = + "" + + "." + + this._menuId + + "{\n" + + "background-color: " + + Mx.xwbg + + ";\n" + + "font: " + + Mx.font.font + + ";\n" + + "color:" + + Mx.xwfg + + "\n" + "} \n" + ".sigplot-menu-list {\n" + " margin: 0px;\n" + " list-style: none;\n" + " padding: 0px;\n" + "}\n" + - "." + this._menuId + ">div {\n" + + "." + + this._menuId + + ">div {\n" + " cursor: move;\n" + " text-align: center;\n" + - " border-bottom: 2px solid " + Mx.xwts + ";\n" + + " border-bottom: 2px solid " + + Mx.xwts + + ";\n" + "}\n" + - "." + this._menuId + ">ul>li{\n" + - " border-top: 2px solid " + Mx.bg + ";\n" + - " background-color: " + Mx.xwlo + ";\n" + + "." + + this._menuId + + ">ul>li{\n" + + " border-top: 2px solid " + + Mx.bg + + ";\n" + + " background-color: " + + Mx.xwlo + + ";\n" + " padding: 1px;\n" + " padding-right: 5px;\n" + " padding-left: 5px;\n" + " cursor:default;\n" + "}\n" + - "." + this._menuId + ">ul>li.active{\n" + - " background-color: " + Mx.hi + ";\n" + + "." + + this._menuId + + ">ul>li.active{\n" + + " background-color: " + + Mx.hi + + ";\n" + "}\n" + - "." + this._menuId + " {\n" + + "." + + this._menuId + + " {\n" + " position: relative;\n" + " color: white;\n" + " float: left;\n" + " border-radius: 5px;\n" + " padding: 3px;\n" + - " font: " + Mx.font.font + ";\n" + - " color:" + Mx.xwfg + "\n" + + " font: " + + Mx.font.font + + ";\n" + + " color:" + + Mx.xwfg + + "\n" + "}\n" + - "." + this._menuId + ">ul>li.separator {\n" + - " background-color: " + Mx.xwbs + ";\n" + + "." + + this._menuId + + ">ul>li.separator {\n" + + " background-color: " + + Mx.xwbs + + ";\n" + "}\n" + ".sigplot-menu-checkbox:before{\n" + " margin-right: 3px; \n" + @@ -261,17 +309,15 @@ /* jshint ignore:end */ if (!this._container.getElementsByTagName("style").length) { - var style = document.createElement('style'); + var style = document.createElement("style"); style.textContent = textContent; this._container.appendChild(style); } else { var style = this._container.getElementsByTagName("style")[0]; style.textContent = textContent; } - } + }, }; - module.exports = DomMenu; - -}()); - + module.exports = DomMenu; +})(); diff --git a/js/mx.js b/js/mx.js index af6cbe1..b7f20fd 100644 --- a/js/mx.js +++ b/js/mx.js @@ -40,8 +40,7 @@ /* global requestAnimFrame */ /* global cancelAnimFrame */ -(function() { - +(function () { var tinycolor = require("tinycolor2"); var ColorMap = require("./ColorMap"); var common = require("./common"); @@ -103,7 +102,7 @@ * The zoom stack structure object * @private */ - mx.STKSTRUCT = function() { + mx.STKSTRUCT = function () { this.xmin = 0.0; // real world val at x1(origin=1,4) or x2(origin=2,4) this.xmax = 0.0; // real world val at x2(origin=1,4) or x1(origin=2,4) this.ymin = 0.0; // real world val at y2(origin=1,2) or y1(origin=3,4) @@ -120,7 +119,7 @@ * The scrollbar structure object used to hold state about scrolling * @private */ - mx.SCROLLBAR = function() { + mx.SCROLLBAR = function () { this.flag = null; // int_4 // flag field for MX$SCROLLBAR routine this.action = null; // int_4 // returned action performed (XW_EVENT) this.smin = null; @@ -175,11 +174,12 @@ * @param element * @private */ - function MX(element) { // this is where the canvases are setup/defined + function MX(element) { + // this is where the canvases are setup/defined this.root = element; // Create a div to hold all the various canvas layers - this.parent = document.createElement('div'); + this.parent = document.createElement("div"); this.parent.style.position = "relative"; //this.parent.style.height = "100%"; //element.clientHeight; //this.parent.style.width = "100%"; //element.clientHeight; @@ -189,7 +189,7 @@ element.appendChild(this.parent); // Create the canvas that will hold the plot - this.canvas = document.createElement('canvas'); + this.canvas = document.createElement("canvas"); this.canvas.style.position = "absolute"; this.canvas.style.top = "0px"; this.canvas.style.left = "0px"; @@ -200,7 +200,7 @@ this.active_canvas = this.canvas; // This canvas holds all widgets and reacts to mouse events - this.wid_canvas = document.createElement('canvas'); + this.wid_canvas = document.createElement("canvas"); this.wid_canvas.style.position = "absolute"; this.wid_canvas.style.top = "0px"; this.wid_canvas.style.left = "0px"; @@ -280,7 +280,6 @@ left = true; } - if (ele <= range_end) { right = true; } @@ -297,31 +296,40 @@ * @param {element} element Reference to a DOM window element */ /* Step #5*/ - mx.open = function(element) { + mx.open = function (element) { var Mx = new MX(element); /* Step #6*/ - Mx.wid_canvas.oncontextmenu = function(event) { + Mx.wid_canvas.oncontextmenu = function (event) { event.preventDefault(); return false; }; this._ctx = Mx.active_canvas.getContext("2d"); - Mx.onmousemove = (function(Mx) { - return function(e) { + Mx.onmousemove = (function (Mx) { + return function (e) { var rect = e.target.getBoundingClientRect(); // Screen x/y of mouse Mx.x = e.x || e.clientX; Mx.y = e.y || e.clientY; // Plot relative x/y of mouse - Mx.xpos = (e.offsetX === undefined) ? (e.pageX - rect.left - window.scrollX) : e.offsetX; - Mx.ypos = (e.offsetX === undefined) ? (e.pageY - rect.top - window.scrollY) : e.offsetY; + Mx.xpos = + e.offsetX === undefined + ? e.pageX - rect.left - window.scrollX + : e.offsetX; + Mx.ypos = + e.offsetX === undefined + ? e.pageY - rect.top - window.scrollY + : e.offsetY; // Mx.xpos = (e.offsetX === undefined) ? e.layerX : e.offsetX; // Mx.ypos = (e.offsetY === undefined) ? e.layerY : e.offsetY; if (Mx.warpbox) { - if ((e.ctrlKey || e.metaKey) && (Mx.warpbox.alt_style !== undefined)) { + if ( + (e.ctrlKey || e.metaKey) && + Mx.warpbox.alt_style !== undefined + ) { Mx.warpbox.style = Mx.warpbox.alt_style; } else { Mx.warpbox.style = Mx.warpbox.def_style; @@ -333,10 +341,10 @@ }; })(Mx); - Mx.onmouseup = (function(Mx) { - return function(event) { + Mx.onmouseup = (function (Mx) { + return function (event) { if (Mx.warpbox) { - mx.onWidgetLayer(Mx, function() { + mx.onWidgetLayer(Mx, function () { mx.erase_window(Mx); }); @@ -357,34 +365,41 @@ yo = Mx.t; yl = Mx.b; } // else "box" - old_warpbox.func(event, xo, yo, xl, yl, + old_warpbox.func( + event, + xo, + yo, + xl, + yl, old_warpbox.style.return_value, - old_warpbox.mode); + old_warpbox.mode + ); } } - } mx.widget_callback(Mx, event); }; })(Mx); - Mx.onmousedown = (function(Mx) { - return function(event) { + Mx.onmousedown = (function (Mx) { + return function (event) { event.preventDefault(); mx.widget_callback(Mx, event); return false; }; })(Mx); - Mx.onkeydown = (function(Mx) { - return function(event) { + Mx.onkeydown = (function (Mx) { + return function (event) { if (Mx.warpbox) { var keyCode = common.getKeyCode(event); - if (((keyCode === 17) || // Ctrl - (keyCode === 224) || // Mac Command Firefox - (keyCode === 91) || // Safari/Chrome Left-command - (keyCode === 93)) && // Safari/Chrome Right-command - (Mx.warpbox.style !== Mx.warpbox.alt_style)) { + if ( + (keyCode === 17 || // Ctrl + keyCode === 224 || // Mac Command Firefox + keyCode === 91 || // Safari/Chrome Left-command + keyCode === 93) && // Safari/Chrome Right-command + Mx.warpbox.style !== Mx.warpbox.alt_style + ) { Mx.warpbox.style = Mx.warpbox.alt_style; mx.redraw_warpbox(Mx); } @@ -394,15 +409,17 @@ }; })(Mx); - Mx.onkeyup = (function(Mx) { - return function(event) { + Mx.onkeyup = (function (Mx) { + return function (event) { if (Mx.warpbox) { var keyCode = common.getKeyCode(event); - if (((keyCode === 17) || // Ctrl - (keyCode === 224) || // Mac Command Firefox - (keyCode === 91) || // Safari/Chrome Left-command - (keyCode === 93)) && // Safari/Chrome Right-command - (Mx.warpbox.style !== Mx.warpbox.def_style)) { + if ( + (keyCode === 17 || // Ctrl + keyCode === 224 || // Mac Command Firefox + keyCode === 91 || // Safari/Chrome Left-command + keyCode === 93) && // Safari/Chrome Right-command + Mx.warpbox.style !== Mx.warpbox.def_style + ) { Mx.warpbox.style = Mx.warpbox.def_style; mx.redraw_warpbox(Mx); } @@ -410,16 +427,16 @@ }; })(Mx); - Mx.ontouchend = (function(Mx) { - return function(event) { + Mx.ontouchend = (function (Mx) { + return function (event) { Mx.onmouseup({ - which: 1 + which: 1, }); }; })(Mx); - Mx.ontouchmove = (function(Mx) { - return function(event) { + Mx.ontouchmove = (function (Mx) { + return function (event) { // Compute the total offset - consider caching offset and only calculating on resize var element = Mx.canvas; var offsetX = 0; @@ -446,7 +463,7 @@ * @param Mx * @private */ - mx.enableListeners = function(Mx) { + mx.enableListeners = function (Mx) { mx.addEventListener(Mx, "mousemove", Mx.onmousemove, false); window.addEventListener("mouseup", Mx.onmouseup, false); mx.addEventListener(Mx, "mousedown", Mx.onmousedown, false); @@ -454,14 +471,13 @@ window.addEventListener("keyup", Mx.onkeyup, false); //mx.addEventListener(Mx, "touchend", Mx.ontouchend); //mx.addEventListener(Mx, 'touchmove', Mx.ontouchmove, false); - }; /** * @param Mx * @private */ - mx.disableListeners = function(Mx) { + mx.disableListeners = function (Mx) { mx.removeEventListener(Mx, "mousemove", Mx.onmousemove, false); window.removeEventListener("mouseup", Mx.onmouseup, false); mx.removeEventListener(Mx, "mousedown", Mx.onmousedown, false); @@ -478,7 +494,7 @@ * @param useCapture * @private */ - mx.addEventListener = function(Mx, event, callback, useCapture) { + mx.addEventListener = function (Mx, event, callback, useCapture) { return Mx.wid_canvas.addEventListener(event, callback, useCapture); }; @@ -489,7 +505,7 @@ * @param useCapture * @private */ - mx.removeEventListener = function(Mx, event, callback, useCapture) { + mx.removeEventListener = function (Mx, event, callback, useCapture) { return Mx.wid_canvas.removeEventListener(event, callback, useCapture); }; @@ -498,7 +514,7 @@ * @param event * @private */ - mx.dispatchEvent = function(Mx, event) { + mx.dispatchEvent = function (Mx, event) { return Mx.wid_canvas.dispatchEvent(event); }; @@ -507,7 +523,7 @@ * @param func * @private */ - mx.onWidgetLayer = function(Mx, func) { + mx.onWidgetLayer = function (Mx, func) { mx.onCanvas(Mx, Mx.wid_canvas, func); }; @@ -516,7 +532,7 @@ * @param func * @private */ - mx.onCanvas = function(Mx, canvas, func) { + mx.onCanvas = function (Mx, canvas, func) { var current_active = Mx.active_canvas; Mx.active_canvas = canvas; try { @@ -533,8 +549,8 @@ * @param func * @private */ - mx.withWidgetLayer = function(Mx, func) { - var f = function() { + mx.withWidgetLayer = function (Mx, func) { + var f = function () { mx.onWidgetLayer(Mx, func); }; return f; @@ -545,7 +561,7 @@ * @param func * @private */ - mx.render = function(Mx, func) { + mx.render = function (Mx, func) { if (!func) { return; } @@ -554,10 +570,12 @@ if (Mx._syncRender === false) { if (!active_canvas._animationFrameHandle) { - active_canvas._animationFrameHandle = requestAnimFrame(function() { - active_canvas._animationFrameHandle = undefined; - func(); - }); + active_canvas._animationFrameHandle = requestAnimFrame( + function () { + active_canvas._animationFrameHandle = undefined; + func(); + } + ); } } else { func(); @@ -569,7 +587,7 @@ * @param value * @private */ - mx.fullscreen = function(Mx, value) { + mx.fullscreen = function (Mx, value) { if (value === undefined) { value = !Mx.fullscreen; } @@ -580,7 +598,7 @@ width: Mx.root.style.width, left: Mx.root.style.left, top: Mx.root.style.top, - zIndex: Mx.root.style.zIndex + zIndex: Mx.root.style.zIndex, }; Mx.root.style.position = "fixed"; Mx.root.style.height = "100%"; @@ -604,10 +622,12 @@ * @param Mx * @private */ - mx.checkresize = function(Mx) { + mx.checkresize = function (Mx) { var canvas = Mx.canvas; - if ((canvas.height !== Mx.root.clientHeight) || (canvas.width !== Mx.root.clientWidth)) { - + if ( + canvas.height !== Mx.root.clientHeight || + canvas.width !== Mx.root.clientWidth + ) { Mx.height = Mx.root.clientHeight; Mx.width = Mx.root.clientWidth; @@ -625,7 +645,7 @@ * @param Mx * @private */ - mx.invertbgfg = function(Mx) { + mx.invertbgfg = function (Mx) { mx.setbgfg(Mx, Mx.fg, Mx.bg, !Mx.xi); }; @@ -635,7 +655,7 @@ * @param color3 * @private */ - mx.mixcolor = function(color1, color2, perc1to2) { + mx.mixcolor = function (color1, color2, perc1to2) { var c1 = tinycolor(color1).toRgb(); var c2 = tinycolor(color2).toRgb(); var mix = 1.0 - perc1to2; @@ -654,12 +674,12 @@ * @param fillStyle * @private */ - mx.linear_gradient = function(Mx, x, y, w, h, fillStyle) { + mx.linear_gradient = function (Mx, x, y, w, h, fillStyle) { var ctx = Mx.active_canvas.getContext("2d"); var step_size = 1.0 / fillStyle.length; var lingrad = ctx.createLinearGradient(x, y, w, h); for (var i = 0; i < fillStyle.length - 1; i++) { - lingrad.addColorStop(step_size * (i), fillStyle[i]); + lingrad.addColorStop(step_size * i, fillStyle[i]); } lingrad.addColorStop(1, fillStyle[fillStyle.length - 1]); return lingrad; @@ -675,12 +695,16 @@ * @param xi * @private */ - mx.setbgfg = function(Mx, bg, fg, xi) { + mx.setbgfg = function (Mx, bg, fg, xi) { Mx.bg = tinycolor(bg).toHexString(); Mx.fg = tinycolor(fg).toHexString(); Mx.xi = tinycolor(xi).toHexString(); - if ((tinycolor.equals(Mx.bg, "black")) && (tinycolor.equals(Mx.fg, "white"))) { ///mmm + if ( + tinycolor.equals(Mx.bg, "black") && + tinycolor.equals(Mx.fg, "white") + ) { + ///mmm Mx.xwfg = Mx.fg; // X-Widget Foreground color Mx.xwbg = "rgb(35%,35%,30%)"; // X-Widget Background color Mx.xwts = "rgb(60%,60%,55%)"; // X-Widget top shadow color @@ -688,7 +712,10 @@ Mx.xwms = mx.mixcolor(Mx.xwts, Mx.xwbs, 0.5); // mid shadow Mx.xwlo = "rgb(15%,15%,10%)"; // X-Widget top shadow color Mx.hi = Mx.xwts; // Highlight color - } else if ((tinycolor.equals(Mx.bg, "white")) && (tinycolor.equals(Mx.fg, "black"))) { + } else if ( + tinycolor.equals(Mx.bg, "white") && + tinycolor.equals(Mx.fg, "black") + ) { Mx.xwfg = Mx.fg; // X-Widget Foreground color Mx.xwbg = "rgb(60%,60%,55%)"; // X-Widget Background color Mx.xwts = "rgb(80%,80%,75%)"; // X-Widget top shadow color @@ -698,12 +725,14 @@ Mx.hi = Mx.xwbs; // Highlight color } else { var clr = tinycolor(Mx.bg).toRgb(); - var hsp = Math.sqrt( // HSP equation from http://alienryderflex.com/hsp.html + var hsp = Math.sqrt( + // HSP equation from http://alienryderflex.com/hsp.html 0.299 * (clr.r * clr.r) + - 0.587 * (clr.g * clr.g) + - 0.114 * (clr.b * clr.b) + 0.587 * (clr.g * clr.g) + + 0.114 * (clr.b * clr.b) ); - if (hsp > 127.5) { // light + if (hsp > 127.5) { + // light Mx.xwfg = "black"; Mx.xwbg = "rgb(60%,60%,55%)"; // X-Widget Background color Mx.xwts = "rgb(80%,80%,75%)"; // X-Widget top shadow color @@ -711,7 +740,8 @@ Mx.xwms = mx.mixcolor(Mx.xwts, Mx.xwbs, 0.5); // mid shadow Mx.xwlo = "rgb(70%,70%,65%)"; Mx.hi = Mx.xwts; - } else { // dark + } else { + // dark Mx.xwfg = "white"; Mx.xwbg = "rgb(35%,35%,30%)"; // X-Widget Background color Mx.xwts = "rgb(60%,60%,55%)"; // X-Widget top shadow color @@ -728,7 +758,7 @@ * @param theme * @private */ - mx.settheme = function(Mx, theme) { + mx.settheme = function (Mx, theme) { Mx.bg = theme.bg; Mx.fg = theme.fg; Mx.xi = theme.xi; @@ -744,7 +774,7 @@ * Close graphics windows. * @param Mx */ - mx.close = function(Mx) { + mx.close = function (Mx) { var canvas = Mx.wid_canvas; canvas.removeEventListener("mousemove", Mx.onmousemove, false); //canvas.removeEventListener("touchmove", Mx.ontouchmove); @@ -773,7 +803,19 @@ // // ~= MX$SCROLLBAR // - mx.scrollbar = function(Mx, sb, xs, xe, ys, ye, out, qs, qe, mouseEvent, scrollbarState) { + mx.scrollbar = function ( + Mx, + sb, + xs, + xe, + ys, + ye, + out, + qs, + qe, + mouseEvent, + scrollbarState + ) { // Param types: // mx.SCROLLBAR* sb, // int xs, int xe, int ys, int ye, @@ -789,7 +831,7 @@ var scale; // a real_8 var sblocal = new mx.SCROLLBAR(); // a SCROLLBAR - mode = (sb.flag !== undefined ? sb.flag : sb); // REFACTOR - if user sends in a number instead of a scrollbar + mode = sb.flag !== undefined ? sb.flag : sb; // REFACTOR - if user sends in a number instead of a scrollbar action = Math.abs(mode); if (ye - ys > xe - xs) { @@ -815,7 +857,15 @@ sb.flag = mode; /* Turn off repeated event handling in mx_scroll */ sb.initial_pause = -1.0; - mx.scroll_loc(sb, xs, ys, xe - xs + 1, ye - ys + 1, origin, scrollbarState); + mx.scroll_loc( + sb, + xs, + ys, + xe - xs + 1, + ye - ys + 1, + origin, + scrollbarState + ); } sb.srange = out.pe - out.ps; @@ -843,7 +893,17 @@ default: return 0; } - mx.scroll_vals(sb, out.ps, sb.srange, qs, qe - qs, step, page, scale, scrollbarState); + mx.scroll_vals( + sb, + out.ps, + sb.srange, + qs, + qe - qs, + step, + page, + scale, + scrollbarState + ); if (mode === 0) { mx.scroll(Mx, sb, mx.XW_DRAW, undefined, undefined); // No need for a mouse event @@ -873,7 +933,7 @@ // // ~= mx_scroll // - mx.scroll = function(Mx, sv, op, mouseEvent, scrollbarState) { + mx.scroll = function (Mx, sv, op, mouseEvent, scrollbarState) { var btn; // an int var smin; // a real_8 var srange; // a real_8 @@ -886,7 +946,17 @@ switch (op) { case mx.XW_INIT: mx.scroll_loc(sv, 0, 0, Mx.width, 20, 1, scrollbarState); - mx.scroll_vals(sv, 0.0, 10.0, 0.0, 100.0, 1.0, 10.0, 1.0, scrollbarState); + mx.scroll_vals( + sv, + 0.0, + 10.0, + 0.0, + 100.0, + 1.0, + 10.0, + 1.0, + scrollbarState + ); sv.flag = 0; sv.action = 0; sv.initial_pause = 0.25; @@ -898,9 +968,15 @@ /* Determine which button, if any, was pressed/released */ btn = 0; - if (sv.mxevent) { // TODO make sure mxevent is set properly when an event goes off - how is this supposed to be set? - btn = (Mx.button_release) ? -Mx.button_release : Mx.button_press; - } else if (mouseEvent.type === "mousedown" || mouseEvent.type === "mouseup") { + if (sv.mxevent) { + // TODO make sure mxevent is set properly when an event goes off - how is this supposed to be set? + btn = Mx.button_release + ? -Mx.button_release + : Mx.button_press; + } else if ( + mouseEvent.type === "mousedown" || + mouseEvent.type === "mouseup" + ) { // TODO Does this case ever happen? switch (mouseEvent.which) { case 1: @@ -912,7 +988,7 @@ case 3: btn = 3; break; - /* Add these cases for the mouse wheel */ + /* Add these cases for the mouse wheel */ case 4: btn = 4; break; @@ -923,12 +999,18 @@ if (mouseEvent.type === "mouseup") { btn = -btn; } - } else if (mouseEvent.type === "mousewheel" || mouseEvent.type === "DOM-MouseScroll") { + } else if ( + mouseEvent.type === "mousewheel" || + mouseEvent.type === "DOM-MouseScroll" + ) { // TODO Does this case ever happen? if (mouseEvent.wheelDelta && mouseEvent.wheelDelta > 0) { btn = 4; // TODO is 4 right for negative scroll (aka a scroll forwards away from the user) // TODO Do we need to worry about a release here? - } else if (mouseEvent.wheelDelta && mouseEvent.wheelDelta < 0) { + } else if ( + mouseEvent.wheelDelta && + mouseEvent.wheelDelta < 0 + ) { btn = 5; // TODO is 5 right for negative scroll (aka a scroll backward towards the user) // TODO Do we need to worry about a release here? } @@ -943,11 +1025,14 @@ Mx.xpos = sv.x; } - /* Button !=1,2,4,5 OR NOT on scroll bar */ - if ((btn !== 1 && btn !== 2 && btn !== 4 && btn !== 5) || - Mx.xpos < sv.x || Mx.ypos < sv.y || - Mx.xpos > sv.x + sv.w || Mx.ypos > sv.y + sv.h) { + if ( + (btn !== 1 && btn !== 2 && btn !== 4 && btn !== 5) || + Mx.xpos < sv.x || + Mx.ypos < sv.y || + Mx.xpos > sv.x + sv.w || + Mx.ypos > sv.y + sv.h + ) { return false; } } else if (btn < 0) { @@ -986,118 +1071,132 @@ // UPDATE SCROLLBAR STATE as well sv.smin = scrollbarState.smin = sv.tmin; sv.srange = scrollbarState.srange = 0.0; - } else switch (btn) { - case 1: - if (s > sv.a1 && s < sv.a2) { - /* on scroll trough */ - sv.action = (sv.soff > 0) ? mx.SB_PAGEINC : mx.SB_PAGEDEC; - } else { - /* on arrows */ - sv.action = (sv.soff > 0) ? mx.SB_STEPINC : mx.SB_STEPDEC; - } - break; - case 4: - sv.action = mx.SB_WHEELUP; - break; - case 5: - sv.action = mx.SB_WHEELDOWN; - break; - } + } else + switch (btn) { + case 1: + if (s > sv.a1 && s < sv.a2) { + /* on scroll trough */ + sv.action = + sv.soff > 0 + ? mx.SB_PAGEINC + : mx.SB_PAGEDEC; + } else { + /* on arrows */ + sv.action = + sv.soff > 0 + ? mx.SB_STEPINC + : mx.SB_STEPDEC; + } + break; + case 4: + sv.action = mx.SB_WHEELUP; + break; + case 5: + sv.action = mx.SB_WHEELDOWN; + break; + } } else { /* We're repeating sv.action */ switch (sv.action) { case mx.SB_WHEELUP: case mx.SB_WHEELDOWN: case mx.SB_EXPAND: - /* we don't want to repeat these */ + /* we don't want to repeat these */ case mx.SB_SHRINK: case mx.SB_FULL: sv.action = sv.repeat_count = 0; } } - /* FALL THROUGH!!! */ - /* jshint -W086 */ - case mx.XW_COMMAND: - /* jshint +W086 */ + /* FALL THROUGH!!! */ + /* jshint -W086 */ + case mx.XW_COMMAND: + /* jshint +W086 */ - smin = sv.smin; - srange = sv.srange; + smin = sv.smin; + srange = sv.srange; - switch (sv.action) { - case mx.SB_STEPINC: - smin += sv.step; - break; - case mx.SB_STEPDEC: - smin -= sv.step; - break; - case mx.SB_PAGEINC: - smin += sv.page; - break; - case mx.SB_PAGEDEC: - smin -= sv.page; - break; - case mx.SB_FULL: - smin = sv.tmin; - srange = sv.trange; - break; - case mx.SB_EXPAND: - srange = srange * sv.scale; - if (smin <= 0 && smin + sv.srange >= 0) { - smin *= sv.scale; - } else { - smin -= (srange - sv.srange) / 2.0; - } - break; - case mx.SB_SHRINK: - srange = srange / sv.scale; - if (smin < 0 && smin + sv.srange >= 0) { - smin += srange / sv.scale; /* Plot crosses axis */ - } else if (smin === 0 && smin + sv.srange >= 0) { - smin = srange / sv.scale; /* Plot touches axis */ - } else { - smin += (sv.srange - srange) / 2.0; /* Plot is completely contained on positive side of axis */ - } - break; - /* The mouse wheel needs to scroll 1 page at a time, if you want an + switch (sv.action) { + case mx.SB_STEPINC: + smin += sv.step; + break; + case mx.SB_STEPDEC: + smin -= sv.step; + break; + case mx.SB_PAGEINC: + smin += sv.page; + break; + case mx.SB_PAGEDEC: + smin -= sv.page; + break; + case mx.SB_FULL: + smin = sv.tmin; + srange = sv.trange; + break; + case mx.SB_EXPAND: + srange = srange * sv.scale; + if (smin <= 0 && smin + sv.srange >= 0) { + smin *= sv.scale; + } else { + smin -= (srange - sv.srange) / 2.0; + } + break; + case mx.SB_SHRINK: + srange = srange / sv.scale; + if (smin < 0 && smin + sv.srange >= 0) { + smin += srange / sv.scale; /* Plot crosses axis */ + } else if (smin === 0 && smin + sv.srange >= 0) { + smin = srange / sv.scale; /* Plot touches axis */ + } else { + smin += + (sv.srange - srange) / + 2.0; /* Plot is completely contained on positive side of axis */ + } + break; + /* The mouse wheel needs to scroll 1 page at a time, if you want an application to scroll differently, change sv.page with mx_scroll_vals in the application code */ - case mx.SB_WHEELUP: - smin -= sv.page; - break; - case mx.SB_WHEELDOWN: - smin += sv.page; - break; - } - - if (sv.trange > 0) { - smin = Math.max(sv.tmin, Math.min(smin, sv.tmin + sv.trange - srange)); - srange = Math.min(srange, sv.trange); - } else { - smin = Math.min(sv.tmin, Math.max(smin, sv.tmin + sv.trange - srange)); - srange = Math.max(srange, sv.trange); - } + case mx.SB_WHEELUP: + smin -= sv.page; + break; + case mx.SB_WHEELDOWN: + smin += sv.page; + break; + } - if (sv.smin === smin && sv.srange === srange) { - if (sv.action !== mx.SB_DRAG) { - sv.action = sv.repeat_count = 0; - } - } else { - // UPDATE SCROLLBAR STATE as well - sv.smin = scrollbarState.smin = smin; - sv.srange = scrollbarState.srange = srange; - sv.repeat_count++; - } + if (sv.trange > 0) { + smin = Math.max( + sv.tmin, + Math.min(smin, sv.tmin + sv.trange - srange) + ); + srange = Math.min(srange, sv.trange); + } else { + smin = Math.min( + sv.tmin, + Math.max(smin, sv.tmin + sv.trange - srange) + ); + srange = Math.max(srange, sv.trange); + } - if (op === mx.XW_COMMAND) { - mx.scroll(Mx, sv, mx.XW_UPDATE, undefined); - sv.action = 0; + if (sv.smin === smin && sv.srange === srange) { + if (sv.action !== mx.SB_DRAG) { + sv.action = sv.repeat_count = 0; } + } else { + // UPDATE SCROLLBAR STATE as well + sv.smin = scrollbarState.smin = smin; + sv.srange = scrollbarState.srange = srange; + sv.repeat_count++; + } - break; - case mx.XW_DRAW: - case mx.XW_UPDATE: - mx.redrawScrollbar(sv, Mx, op); + if (op === mx.XW_COMMAND) { + mx.scroll(Mx, sv, mx.XW_UPDATE, undefined); + sv.action = 0; + } + break; + case mx.XW_DRAW: + case mx.XW_UPDATE: + mx.redrawScrollbar(sv, Mx, op); } /* switch */ return true; }; @@ -1115,7 +1214,7 @@ // // ~= mx_scroll_loc // - mx.scroll_loc = function(sv, x, y, w, h, origin, scrollbarState) { + mx.scroll_loc = function (sv, x, y, w, h, origin, scrollbarState) { // UPDATE local scrollbar and SCROLLBAR STATE if (sv === undefined) { return; /* mx.SCROLLBAR */ @@ -1128,10 +1227,16 @@ if (sv.origin & 1) { sv.a2 = scrollbarState.a2 = sv.w; - sv.arrow = scrollbarState.arrow = Math.min(m.trunc((sv.w - m.trunc(2 * mx.GBorder)) / 3), sv.h + mx.GBorder); + sv.arrow = scrollbarState.arrow = Math.min( + m.trunc((sv.w - m.trunc(2 * mx.GBorder)) / 3), + sv.h + mx.GBorder + ); } else { sv.a2 = scrollbarState.a2 = sv.h; - sv.arrow = scrollbarState.arrow = Math.min(m.trunc((sv.h - m.trunc(2 * mx.GBorder)) / 3), sv.w + mx.GBorder); + sv.arrow = scrollbarState.arrow = Math.min( + m.trunc((sv.h - m.trunc(2 * mx.GBorder)) / 3), + sv.w + mx.GBorder + ); } sv.a1 = scrollbarState.a1 = sv.arrow + mx.GBorder; sv.a2 -= sv.arrow + mx.GBorder; @@ -1157,7 +1262,17 @@ // // ~= mx_scroll_vals // - mx.scroll_vals = function(sv, smin, srange, tmin, trange, step, page, scale, scrollbarState) { + mx.scroll_vals = function ( + sv, + smin, + srange, + tmin, + trange, + step, + page, + scale, + scrollbarState + ) { // UPDATE SCROLLBAR STATE as well if (sv === undefined) { return; /* an mx.SCROLLBAR */ @@ -1183,7 +1298,7 @@ // // ~= MX$DRAW_SYMBOL // - mx.draw_symbol = function(Mx, ic, x, y, symbol, rr, n) { + mx.draw_symbol = function (Mx, ic, x, y, symbol, rr, n) { var ctx = Mx.active_canvas.getContext("2d"); var r = 0; // int @@ -1192,14 +1307,15 @@ var rmode = false; // bool var fill = false; // bool var tri = []; // XPoint array of size 4 - for (var cnt = 0; cnt < 4; cnt++) { // initializing 4 points in the array + for (var cnt = 0; cnt < 4; cnt++) { + // initializing 4 points in the array tri[cnt] = { x: 0, - y: 0 + y: 0, }; } - var c = ''; // char + var c = ""; // char fill = rr < 0; r = Math.abs(rr); @@ -1239,11 +1355,11 @@ break; case mx.L_ITriangleSymbol: r = -r; // TODO Refactor without switch fall-through? - /* jshint -W086 */ + /* jshint -W086 */ case mx.L_TriangleSymbol: /* jshint +W086 */ d = m.trunc(r * 1.5); - d2 = m.trunc(r * 0.80); + d2 = m.trunc(r * 0.8); // Coordinates of just the triangle itself tri[1].x = -d2; @@ -1254,10 +1370,11 @@ tri[3].y = -d; var tempTri = []; // XPoint array of size 4 - for (var cnt = 0; cnt < 4; cnt++) { // initializing 4 points in the array + for (var cnt = 0; cnt < 4; cnt++) { + // initializing 4 points in the array tempTri[cnt] = { x: 0, - y: 0 + y: 0, }; } @@ -1328,7 +1445,7 @@ // // ~= MX$DRAW_SYMBOLS // - mx.draw_symbols = function(Mx, ic, pixx, pixy, npix, symbol, rr, istart) { + mx.draw_symbols = function (Mx, ic, pixx, pixy, npix, symbol, rr, istart) { for (var i = 0; i < npix; i++) { mx.draw_symbol(Mx, ic, pixx[i], pixy[i], symbol, rr, i + istart); } @@ -1351,7 +1468,7 @@ * @private */ function isLeft(p_x, p_y, e_x1, e_y1, e_x2, e_y2) { - return ((e_x1 - p_x) * (e_y2 - p_y) - (e_x2 - p_x) * (e_y1 - p_y)); + return (e_x1 - p_x) * (e_y2 - p_y) - (e_x2 - p_x) * (e_y1 - p_y); } /** @@ -1366,14 +1483,18 @@ * @private */ function update_winding_number(wn, p_x, p_y, e_x1, e_y1, e_x2, e_y2) { - if (e_y1 <= p_y) { // start y <= P.y - if (e_y2 > p_y) { // an upward crossing + if (e_y1 <= p_y) { + // start y <= P.y + if (e_y2 > p_y) { + // an upward crossing if (isLeft(p_x, p_y, e_x1, e_y1, e_x2, e_y2) > 0) { wn += 1; } } - } else { // start y > P.y (no test needed) - if (e_y2 <= p_y) { // a downward crossing + } else { + // start y > P.y (no test needed) + if (e_y2 <= p_y) { + // a downward crossing if (isLeft(p_x, p_y, e_x1, e_y1, e_x2, e_y2) < 0) { wn -= 1; } @@ -1398,8 +1519,20 @@ // // ~= MX$TRACE // - mx.trace = function(Mx, color, xpoint, ypoint, npts, istart, skip, line, symb, rad, options) { - if ((xpoint === undefined) || (ypoint === undefined)) { + mx.trace = function ( + Mx, + color, + xpoint, + ypoint, + npts, + istart, + skip, + line, + symb, + rad, + options + ) { + if (xpoint === undefined || ypoint === undefined) { throw "mx.trace requires xpoint and ypoint"; } @@ -1428,7 +1561,7 @@ return; } - if ((line === 0) && (symb === 0)) { + if (line === 0 && symb === 0) { m.log.warn("No line or symbol to draw"); return; } @@ -1438,12 +1571,12 @@ style = { mode: "dashed", on: 4, - off: 4 + off: 4, }; } var stk4 = mx.origin(Mx.origin, 4, Mx.stk[Mx.level]); - if ((stk4.xscl === 0.0) || (stk4.yscl === 0.0)) { + if (stk4.xscl === 0.0 || stk4.yscl === 0.0) { // the min and max are the same return; } @@ -1476,7 +1609,6 @@ ymin = 0; xmax = Math.round(Mx.r - Mx.l); ymax = Math.round(Mx.b - Mx.t); - } //dx = dx * 0.5; //if ((line == -1) || (line == 1)) { @@ -1496,53 +1628,77 @@ var pixy = new Int32Array(new ArrayBuffer(bufsize)); var ib = 0; - if ((line === 0) && (symb !== 0)) { + if (line === 0 && symb !== 0) { // We are drawing symbols only - for (var n = (skip - 1); n < npts; n += skip) { + for (var n = skip - 1; n < npts; n += skip) { var x = xpoint[n]; var y = ypoint[n]; - var lvisible = ((x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)); + var lvisible = x >= xmin && x <= xmax && y >= ymin && y <= ymax; if (lvisible) { pixx[0] = Math.round((x - xxmin) * xscl) + left; pixy[0] = Math.round((y - yymin) * yscl) + top; - mx.draw_symbol(Mx, color, pixx[0], pixy[0], symb, rad, istart + n); + mx.draw_symbol( + Mx, + color, + pixx[0], + pixy[0], + symb, + rad, + istart + n + ); } } } if (options.vertsym === true) { // we are drawing verticle lines on each symbol - for (var n = (skip - 1); n < npts; n += skip) { + for (var n = skip - 1; n < npts; n += skip) { var x = xpoint[n]; var y = ypoint[n]; - if ((x >= xmin) && (x <= xmax)) { + if (x >= xmin && x <= xmax) { var i = Math.round((x - xxmin) * xscl) + left; mx.draw_line(Mx, color, i, 0, i, Mx.height); - if ((y >= ymin) && (y <= ymax)) { + if (y >= ymin && y <= ymax) { pixx[0] = i; pixy[0] = Math.round((y - yymin) * yscl) + top; - mx.draw_symbol(Mx, color, pixx[0], pixy[0], symb, rad, istart + n); + mx.draw_symbol( + Mx, + color, + pixx[0], + pixy[0], + symb, + rad, + istart + n + ); } } } } if (options.horzsym === true) { // we are drawing horizontal lines on each symbol - for (var n = (skip - 1); n < npts; n += skip) { + for (var n = skip - 1; n < npts; n += skip) { var x = xpoint[n]; var y = ypoint[n]; - if ((y >= ymin) && (y <= ymax)) { + if (y >= ymin && y <= ymax) { var i = Math.round((y - yymin) * yscl) + top; mx.draw_line(Mx, color, 0, i, Mx.width, i); - if ((x >= xmin) && (x <= xmax)) { + if (x >= xmin && x <= xmax) { pixx[0] = Math.round((x - xxmin) * xscl) + left; pixy[0] = i; - mx.draw_symbol(Mx, color, pixx[0], pixy[0], symb, rad, istart + n); + mx.draw_symbol( + Mx, + color, + pixx[0], + pixy[0], + symb, + rad, + istart + n + ); } } } } else if (line !== 0) { var colors; - if ((options) && (options.highlight)) { + if (options && options.highlight) { colors = []; for (var sn = 0; sn < options.highlight.length; sn++) { if (options.highlight[sn].xstart >= xmax) { @@ -1562,25 +1718,36 @@ for (var cn = colors.length - 1; cn >= 0; cn--) { // This highlight overlaps the entire range of a previous // highlight...we can thus remove the color - if ((rxs <= colors[cn].start) && (rxe >= colors[cn].end)) { + if ( + rxs <= colors[cn].start && + rxe >= colors[cn].end + ) { colors.splice(cn, 1); continue; } // This highlight splits a previous highlight...we need // to create a new color range - else if ((rxs >= colors[cn].start) && (rxe <= colors[cn].end)) { + else if ( + rxs >= colors[cn].start && + rxe <= colors[cn].end + ) { colors.push({ start: rxe, end: colors[cn].end, - color: colors[cn].color + color: colors[cn].color, }); colors[cn].end = rxs; - } // This highlight overlaps partially - else if ((rxs <= colors[cn].start) && (rxe >= colors[cn].start)) { + else if ( + rxs <= colors[cn].start && + rxe >= colors[cn].start + ) { colors[cn].start = rxe; - } else if ((rxs <= colors[cn].end) && (rxe >= colors[cn].end)) { + } else if ( + rxs <= colors[cn].end && + rxe >= colors[cn].end + ) { colors[cn].end = rxs; } @@ -1593,7 +1760,7 @@ colors.push({ start: rxs, end: rxe, - color: options.highlight[sn].color + color: options.highlight[sn].color, }); } } @@ -1602,13 +1769,12 @@ // in the base-line color colors.push({ start: left, - color: color + color: color, }); - colors.sort(function(a, b) { + colors.sort(function (a, b) { return a.start - b.start; }); - } else { colors = color; } @@ -1620,16 +1786,33 @@ var x = xpoint[0]; var y = ypoint[0]; - wn = update_winding_number(wn, mid_x, mid_y, Mx.stk[Mx.level].xmin, Mx.stk[Mx.level].ymin, x, y); + wn = update_winding_number( + wn, + mid_x, + mid_y, + Mx.stk[Mx.level].xmin, + Mx.stk[Mx.level].ymin, + x, + y + ); - var lvisible = ((x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)); + var lvisible = x >= xmin && x <= xmax && y >= ymin && y <= ymax; // The first point is visible if (lvisible) { pixx[ib] = Math.round((x - xxmin) * xscl) + left; pixy[ib] = Math.round((y - yymin) * yscl) + top; ib += 1; if (symb !== 0) { - mx.draw_symbols(Mx, color, pixx, pixy, 1, symb, rad, istart); + mx.draw_symbols( + Mx, + color, + pixx, + pixy, + 1, + symb, + rad, + istart + ); } } else { ib = 0; @@ -1637,8 +1820,7 @@ var ie = 0; var visible = false; - for (var n = skip; n <= (skip * (npts - 1)); n += skip) { - + for (var n = skip; n <= skip * (npts - 1); n += skip) { var lx = x; var ly = y; x = xpoint[n]; @@ -1646,8 +1828,8 @@ wn = update_winding_number(wn, mid_x, mid_y, lx, ly, x, y); - visible = ((x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)); - if ((lvisible) && (visible)) { + visible = x >= xmin && x <= xmax && y >= ymin && y <= ymax; + if (lvisible && visible) { // both the left point and right point are visible, so we can draw the trace pixx[ib] = Math.round((x - xxmin) * xscl) + left; pixy[ib] = Math.round((y - yymin) * yscl) + top; @@ -1658,10 +1840,10 @@ // calculate the difference between the last point and this point dx = lx - x; dy = ly - y; - if ((dx !== 0.0) || (dy !== 0.0)) { + if (dx !== 0.0 || dy !== 0.0) { var o = { tL: 1.0, - tE: 0.0 + tE: 0.0, }; // Between the last point and the current point, // determine the ratio of the x and y porionts @@ -1674,32 +1856,69 @@ if (clipt(-dy, y - ymax, o)) { // If this point is starting the on-screen portion, start the line if (o.tL < 1) { - pixx[ib] = Math.round((x - xxmin + o.tL * dx) * xscl) + left; - pixy[ib] = Math.round((y - yymin + o.tL * dy) * yscl) + top; + pixx[ib] = + Math.round( + (x - xxmin + o.tL * dx) * + xscl + ) + left; + pixy[ib] = + Math.round( + (y - yymin + o.tL * dy) * + yscl + ) + top; ib += 1; } // If this point is ending the on-screen portion draw the line if (o.tE > 0) { - pixx[ib] = Math.round((x - xxmin + o.tE * dx) * xscl) + left; - pixy[ib] = Math.round((y - yymin + o.tE * dy) * yscl) + top; + pixx[ib] = + Math.round( + (x - xxmin + o.tE * dx) * + xscl + ) + left; + pixy[ib] = + Math.round( + (y - yymin + o.tE * dy) * + yscl + ) + top; ib += 1; - mx.draw_lines(Mx, colors, pixx.subarray(ie, ib), pixy.subarray(ie, ib), (ib - ie), line, style); - - if (symb !== 0 && (ib - ie) > 2) { - mx.draw_symbols(Mx, + mx.draw_lines( + Mx, + colors, + pixx.subarray(ie, ib), + pixy.subarray(ie, ib), + ib - ie, + line, + style + ); + + if (symb !== 0 && ib - ie > 2) { + mx.draw_symbols( + Mx, color, - pixx.subarray(ie + 1, ib - 1), - pixy.subarray(ie + 1, ib - 1), (ib - ie - 2), + pixx.subarray( + ie + 1, + ib - 1 + ), + pixy.subarray( + ie + 1, + ib - 1 + ), + ib - ie - 2, symb, rad, - istart + n - (ib - ie - 2)); + istart + n - (ib - ie - 2) + ); } ie = ib; } else { // otherwise add it to the line to be drawn - pixx[ib] = Math.round((x - xxmin) * xscl) + left; - pixy[ib] = Math.round((y - yymin) * yscl) + top; + pixx[ib] = + Math.round((x - xxmin) * xscl) + + left; + pixy[ib] = + Math.round((y - yymin) * yscl) + + top; ib += 1; } } @@ -1709,27 +1928,53 @@ } } } - wn = update_winding_number(wn, mid_x, mid_y, x, y, Mx.stk[Mx.level].xmax, Mx.stk[Mx.level].ymin); - wn = update_winding_number(wn, mid_x, mid_y, Mx.stk[Mx.level].xmax, Mx.stk[Mx.level].ymin, Mx.stk[Mx.level].xmin, Mx.stk[Mx.level].ymin); - if ((ib - ie) > 0) { - mx.draw_lines(Mx, colors, pixx.subarray(ie, ib), pixy.subarray(ie, ib), (ib - ie), line, style); + wn = update_winding_number( + wn, + mid_x, + mid_y, + x, + y, + Mx.stk[Mx.level].xmax, + Mx.stk[Mx.level].ymin + ); + wn = update_winding_number( + wn, + mid_x, + mid_y, + Mx.stk[Mx.level].xmax, + Mx.stk[Mx.level].ymin, + Mx.stk[Mx.level].xmin, + Mx.stk[Mx.level].ymin + ); + if (ib - ie > 0) { + mx.draw_lines( + Mx, + colors, + pixx.subarray(ie, ib), + pixy.subarray(ie, ib), + ib - ie, + line, + style + ); if (visible) { ie = ie + 1; } - if (symb !== 0 && (ib - ie) > 1) { - mx.draw_symbols(Mx, + if (symb !== 0 && ib - ie > 1) { + mx.draw_symbols( + Mx, color, pixx.subarray(ie, ib), pixy.subarray(ie, ib), ib - ie, symb, rad, - n - ib + istart); + n - ib + istart + ); } } if (options.fillStyle && !Mx.fillMin && !Mx.fillMax) { - if ((ib > 1) || (wn !== 0)) { + if (ib > 1 || wn !== 0) { // if we have at least one point // or the entire plot area is in the fill zone mx.fill_trace(Mx, options.fillStyle, pixx, pixy, ib); @@ -1756,9 +2001,12 @@ continue; } - if ((ib > 1) || (wn !== 0)) { - - var xstart_pixel_value = mx.real_to_pixel(Mx, x_start, 0); + if (ib > 1 || wn !== 0) { + var xstart_pixel_value = mx.real_to_pixel( + Mx, + x_start, + 0 + ); var xend_pixel_value = mx.real_to_pixel(Mx, x_end, 0); var pi_start = xstart_pixel_value.x; @@ -1770,25 +2018,35 @@ var this_point = pixx[q]; var this_point_y = pixy[q]; //console.log(this_point); - if (in_fill_range(this_point, pi_start, pi_end) === true) { + if ( + in_fill_range(this_point, pi_start, pi_end) === + true + ) { //console.log('in range: ', this_point); pixx_new.push(this_point); pixy_new.push(this_point_y); - } } - if ((pixx_new.length > 0) || (wn !== 0)) { + if (pixx_new.length > 0 || wn !== 0) { pi_start = Math.max(pi_start, pixx_new[0]); - pi_end = Math.min(pi_end, pixx_new[pixx_new.length - 1]); - mx.fill_trace(Mx, highlight.fill, pixx_new, pixy_new, pixx_new.length, pi_start, pi_end); + pi_end = Math.min( + pi_end, + pixx_new[pixx_new.length - 1] + ); + mx.fill_trace( + Mx, + highlight.fill, + pixx_new, + pixy_new, + pixx_new.length, + pi_start, + pi_end + ); } } - } } - - } if (!options.noclip) { @@ -1805,8 +2063,8 @@ // // ~= MX$DRAW_MODE // - mx.draw_mode = function(Mx, linewidth, style) { - Mx.linewidth = (linewidth === undefined) ? 1 : linewidth; + mx.draw_mode = function (Mx, linewidth, style) { + Mx.linewidth = linewidth === undefined ? 1 : linewidth; Mx.style = style; }; @@ -1823,7 +2081,7 @@ // // ~= MX$DRAW_LINES // - mx.draw_line = function(Mx, color, x1, y1, x2, y2, linewidth, style) { + mx.draw_line = function (Mx, color, x1, y1, x2, y2, linewidth, style) { var ctx = Mx.active_canvas.getContext("2d"); if (linewidth === undefined) { linewidth = Mx.linewidth; @@ -1834,7 +2092,9 @@ // Look up the color in Mx.pixels if (typeof color === "number") { if (!Mx.pixel) { - m.log.warn("COLORMAP not initialized, defaulting to foreground"); + m.log.warn( + "COLORMAP not initialized, defaulting to foreground" + ); color = Mx.fg; } else { if (isNaN(color)) { @@ -1842,10 +2102,7 @@ } var cidx = Math.max(0, Math.min(Mx.pixel.map.length, color)); color = Mx.pixel.getColor(color); - color = to_rgb( - color.red, - color.green, - color.blue); + color = to_rgb(color.red, color.green, color.blue); } } draw_line(ctx, x1, y1, x2, y2, style, color, linewidth); @@ -1861,11 +2118,20 @@ // // ~= MX$RUBBERLINE // - mx.rubberline = function(Mx, x1, y1, x2, y2) { + mx.rubberline = function (Mx, x1, y1, x2, y2) { var ctx = Mx.active_canvas.getContext("2d"); - draw_line(ctx, x1, y1, x2, y2, { - mode: "xor" - }, "white", 1); + draw_line( + ctx, + x1, + y1, + x2, + y2, + { + mode: "xor", + }, + "white", + 1 + ); }; /** @@ -1876,16 +2142,23 @@ * @param npts * @private */ - mx.fill_trace = function(Mx, fillStyle, pixx, pixy, npts, l, r) { + mx.fill_trace = function (Mx, fillStyle, pixx, pixy, npts, l, r) { var ctx = Mx.active_canvas.getContext("2d"); if (Array.isArray(fillStyle)) { - ctx.fillStyle = mx.linear_gradient(Mx, 0, 0, 0, Mx.b - Mx.t, fillStyle); + ctx.fillStyle = mx.linear_gradient( + Mx, + 0, + 0, + 0, + Mx.b - Mx.t, + fillStyle + ); } else { ctx.fillStyle = fillStyle; } if (npts < 1) { - ctx.fillRect(Mx.l, Mx.t, (Mx.r - Mx.l), (Mx.b - Mx.t)); + ctx.fillRect(Mx.l, Mx.t, Mx.r - Mx.l, Mx.b - Mx.t); return; } @@ -1907,11 +2180,8 @@ ctx.lineTo(l, Mx.b); } - ctx.lineTo(x, y); - - for (var i = 1; i < npts; i++) { x = pixx[i]; y = pixy[i]; @@ -1943,7 +2213,7 @@ // // ~= MX$DRAW_LINES // - mx.draw_lines = function(Mx, colors, pixx, pixy, npts, linewidth, style) { + mx.draw_lines = function (Mx, colors, pixx, pixy, npts, linewidth, style) { var ctx = Mx.active_canvas.getContext("2d"); if (npts < 1) { @@ -1960,10 +2230,12 @@ style = Mx.style; } - if ((style) && (style.mode === "dashed")) { + if (style && style.mode === "dashed") { var dash_supported = common.dashOn(ctx, style.on, style.off); if (!dash_supported) { - m.log.warn("WARNING: Dashed lines aren't supported on your browser"); + m.log.warn( + "WARNING: Dashed lines aren't supported on your browser" + ); } } @@ -1971,10 +2243,12 @@ var current_color = 0; if (typeof colors === "string") { - colors = [{ - start: 0, - color: colors - }]; + colors = [ + { + start: 0, + color: colors, + }, + ]; } else if (!(colors instanceof Array)) { if (colors.start === undefined) { colors.start = 0; @@ -1983,8 +2257,8 @@ } var n; - for (n = (colors.length - 1); n >= 0; n--) { - if ((colors[n].end != null) && (colors[n].end < x)) { + for (n = colors.length - 1; n >= 0; n--) { + if (colors[n].end != null && colors[n].end < x) { colors.splice(n, 1); } } @@ -2001,16 +2275,23 @@ ctx.moveTo(x, y); for (var i = 0; i < npts; i++) { - if ((x === pixx[i]) && (y === pixy[i])) { + if (x === pixx[i] && y === pixy[i]) { continue; } x = pixx[i]; y = pixy[i]; var newcolor = false; - if ((current_color > 0) && (colors[current_color].end != null) && (colors[current_color].end < x)) { + if ( + current_color > 0 && + colors[current_color].end != null && + colors[current_color].end < x + ) { newcolor = true; - while ((colors[current_color].end != null) && (colors[current_color].end < x)) { + while ( + colors[current_color].end != null && + colors[current_color].end < x + ) { colors.splice(current_color, 1); current_color -= 1; if (current_color === 0) { @@ -2019,9 +2300,15 @@ } } - if (((current_color + 1) < colors.length) && (colors[current_color + 1].start <= x)) { + if ( + current_color + 1 < colors.length && + colors[current_color + 1].start <= x + ) { newcolor = true; - while (((current_color + 1) < colors.length) && (colors[current_color + 1].start <= x)) { + while ( + current_color + 1 < colors.length && + colors[current_color + 1].start <= x + ) { current_color++; } } @@ -2049,10 +2336,10 @@ // // ~= MX$CLIP // - mx.clip = function(Mx, left, top, width, height) { + mx.clip = function (Mx, left, top, width, height) { var ctx = Mx.active_canvas.getContext("2d"); - if ((left === 0) && (top === 0) && (width === 0) && (height === 0)) { + if (left === 0 && top === 0 && width === 0 && height === 0) { ctx.restore(); return; } @@ -2068,7 +2355,7 @@ // // ~= MX$CLEAR_WINDOW // - mx.clear_window = function(Mx) { + mx.clear_window = function (Mx) { var ctx = Mx.active_canvas.getContext("2d"); ctx.fillStyle = Mx.bg; @@ -2079,7 +2366,7 @@ * @param Mx * @private */ - mx.erase_window = function(Mx) { + mx.erase_window = function (Mx) { var ctx = Mx.active_canvas.getContext("2d"); ctx.clearRect(0, 0, Mx.width, Mx.height); @@ -2098,8 +2385,22 @@ // // When CTRL is pressed, alt_style is used // - mx.rubberbox = function(Mx, func, mode, def_style, alt_style) { - mx.warpbox(Mx, Mx.xpos, Mx.ypos, Mx.xpos, Mx.ypos, 0, Mx.width, 0, Mx.height, func, mode, def_style, alt_style); + mx.rubberbox = function (Mx, func, mode, def_style, alt_style) { + mx.warpbox( + Mx, + Mx.xpos, + Mx.ypos, + Mx.xpos, + Mx.ypos, + 0, + Mx.width, + 0, + Mx.height, + func, + mode, + def_style, + alt_style + ); }; /** @@ -2121,7 +2422,21 @@ // ~= MX$WARPBOX // Unlike MX$WARPBOX, this is a non-blocking call. As such the 'func' is a callback for then the rubberbox is finished. // - mx.warpbox = function(Mx, xo, yo, xl, yl, xmin, xmax, ymin, ymax, func, mode, def_style, alt_style) { + mx.warpbox = function ( + Mx, + xo, + yo, + xl, + yl, + xmin, + xmax, + ymin, + ymax, + func, + mode, + def_style, + alt_style + ) { if (!def_style) { def_style = {}; } @@ -2151,7 +2466,7 @@ // // ~= M$ORIGIN // - mx.origin = function(inorigin, outorigin, instk) { + mx.origin = function (inorigin, outorigin, instk) { inorigin = Math.max(1, inorigin); outorigin = Math.max(1, outorigin); @@ -2171,12 +2486,14 @@ if (inorigin !== outorigin) { var diff = Math.abs(outorigin - inorigin); // used to simplify boolean logic var sum = outorigin + inorigin; - if (diff === 2 || sum !== 5) { // (1<->3) (2<->4) (1<->2) (3<->4) + if (diff === 2 || sum !== 5) { + // (1<->3) (2<->4) (1<->2) (3<->4) outstk.xmin = instk.xmax; outstk.xmax = instk.xmin; outstk.xscl = -instk.xscl; } - if (diff === 2 || sum === 5) { // (1<->3) (2<->4) (1<->4) (2<->3) + if (diff === 2 || sum === 5) { + // (1<->3) (2<->4) (1<->4) (2<->3) outstk.ymin = instk.ymax; outstk.ymax = instk.ymin; outstk.yscl = -instk.yscl; @@ -2192,7 +2509,7 @@ // // ~= MX$MULT // - mx.mult = function(end1, end2) { + mx.mult = function (end1, end2) { var absmax = Math.max(Math.abs(end1), Math.abs(end2)); if (absmax === 0) { return 1.0; @@ -2203,9 +2520,9 @@ kengr = kengr - 1; } if (kengr < 0) { - return 1.0 / Math.pow(10, (-3 * kengr)); + return 1.0 / Math.pow(10, -3 * kengr); } else { - return Math.pow(10, (3 * kengr)); + return Math.pow(10, 3 * kengr); } }; @@ -2216,7 +2533,7 @@ */ // // event may be undefined or null - mx.widget_callback = function(Mx, event) { + mx.widget_callback = function (Mx, event) { if (Mx.prompt) { if (event.which === 3) { Mx.prompt.input.onsubmit(); @@ -2230,7 +2547,6 @@ Mx.widget.callback(event); } } - }; /** @@ -2246,25 +2562,41 @@ */ // // ~= MX$DPROMPT - only higher-level - mx.prompt = function(Mx, promptText, isValid, onSuccess, refresh, inputValue, xpos, ypos, errorTimeout) { + mx.prompt = function ( + Mx, + promptText, + isValid, + onSuccess, + refresh, + inputValue, + xpos, + ypos, + errorTimeout + ) { if (inputValue !== undefined) { var inputValid = isValid(inputValue); if (!inputValid.valid) { - throw "Prompt default input value not valid due to '" + inputValid.reason + "'"; + throw ( + "Prompt default input value not valid due to '" + + inputValid.reason + + "'" + ); } } // TODO Validation - make sure promptText is not too long and isn't multi-line... - mx.onWidgetLayer(Mx, function() { + mx.onWidgetLayer(Mx, function () { var ctx = Mx.active_canvas.getContext("2d"); var maxNumChars = 30; // Construct the input box - var pxIndex = ctx.font.indexOf('px'); + var pxIndex = ctx.font.indexOf("px"); var fontIndex = pxIndex + 3; var fontSize = ctx.font.substr(0, pxIndex); - var fontFamily = ctx.font.substr(fontIndex, ctx.font.length).toString(); + var fontFamily = ctx.font + .substr(fontIndex, ctx.font.length) + .toString(); /* TODO Note: There is a scrolling bug - you can scroll to the right, but not the left of the value And... when truncating the width of an input field - it shows the value as though truncated @@ -2285,35 +2617,48 @@ boxShadow: "none", innerShadow: "none", width: Mx.text_w * maxNumChars, - value: (inputValue !== undefined ? inputValue.toString() : ""), + value: inputValue !== undefined ? inputValue.toString() : "", disableBlur: true, renderOnReturn: false, - tabToClear: true + tabToClear: true, }); - var subHandlerCreator = function(messageX, messageY) { - return function() { + var subHandlerCreator = function (messageX, messageY) { + return function () { var newValue = this.value(); var inputValid = isValid(newValue); if (!inputValid.valid) { - mx.message(Mx, "Value: '" + newValue + "' isn't valid due to '" + inputValid.reason + "' - RETRY", undefined, messageX, messageY); + mx.message( + Mx, + "Value: '" + + newValue + + "' isn't valid due to '" + + inputValid.reason + + "' - RETRY", + undefined, + messageX, + messageY + ); // Clear error message - setTimeout(function() { - mx.onWidgetLayer(Mx, function() { - mx.erase_window(Mx); - }); - Mx.widget = null; - //refresh(); - }, errorTimeout != null ? errorTimeout : 4000); + setTimeout( + function () { + mx.onWidgetLayer(Mx, function () { + mx.erase_window(Mx); + }); + Mx.widget = null; + //refresh(); + }, + errorTimeout != null ? errorTimeout : 4000 + ); } else { Mx.prompt = undefined; // clear state variable // Kill CanvasInput this.cleanup(); - mx.onWidgetLayer(Mx, function() { + mx.onWidgetLayer(Mx, function () { mx.erase_window(Mx); }); @@ -2323,9 +2668,9 @@ }; // Create redraw method - var redrawPromptCreator = function(Mx, input, promptText) { - return function(xpos, ypos) { - mx.onWidgetLayer(Mx, function() { + var redrawPromptCreator = function (Mx, input, promptText) { + return function (xpos, ypos) { + mx.onWidgetLayer(Mx, function () { var GBorder = 3; // Calculate the position variables @@ -2379,7 +2724,7 @@ // Set state variable Mx.prompt = { redraw: redrawPrompt, - input: canvasInput + input: canvasInput, }; }); }; @@ -2391,18 +2736,21 @@ * @param strict If strict is set to true - does not consider empty strings as valid floating point numbers. * @private */ - mx.floatValidator = function(value, strict) { - if (!(((strict === undefined || strict === false) && value === "")) && - isNaN(parseFloat(value)) || !isFinite(value)) { + mx.floatValidator = function (value, strict) { + if ( + (!((strict === undefined || strict === false) && value === "") && + isNaN(parseFloat(value))) || + !isFinite(value) + ) { return { valid: false, - reason: "Failed float validation: not a valid floating point number" + reason: "Failed float validation: not a valid floating point number", }; } return { valid: true, - reason: "" + reason: "", }; }; @@ -2413,33 +2761,37 @@ * @param strict If strict is set to true - does not consider empty strings as valid integers. * @private */ - mx.intValidator = function(value, strict) { - if (((strict === undefined || strict === false) && value === "") || - ((parseFloat(value) === parseInt(value, 10)) && !isNaN(value))) { + mx.intValidator = function (value, strict) { + if ( + ((strict === undefined || strict === false) && value === "") || + (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) + ) { return { valid: true, - reason: "" + reason: "", }; } else { return { valid: false, - reason: "Failed integer validation: not a valid integer" + reason: "Failed integer validation: not a valid integer", }; } }; - mx.hexValidator = function(value, strict) { + mx.hexValidator = function (value, strict) { var regColorcode = /^(#)?([0-9a-fA-F]{3})([0-9a-fA-F]{3})?$/; - if (((strict === undefined || strict === false) && value === "") || - (regColorcode.test(value) !== false)) { + if ( + ((strict === undefined || strict === false) && value === "") || + regColorcode.test(value) !== false + ) { return { valid: true, - reason: "" + reason: "", }; } else { return { valid: false, - reason: "Failed hexcode validation: not a valid hexcode" + reason: "Failed hexcode validation: not a valid hexcode", }; } }; @@ -2454,26 +2806,28 @@ // // ~= MX$MESSAGE // - mx.message = function(Mx, msg, time, xpos, ypos, type) { - mx.onWidgetLayer(Mx, function() { - + mx.message = function (Mx, msg, time, xpos, ypos, type) { + mx.onWidgetLayer(Mx, function () { mx.render_message_box(Mx, msg, xpos, ypos); Mx.widget = { type: type || "ONESHOT", - callback: function(event) { - if ((event.type === "mousedown") || (event.type === "keydown")) { + callback: function (event) { + if ( + event.type === "mousedown" || + event.type === "keydown" + ) { Mx.widget = null; - mx.onWidgetLayer(Mx, function() { + mx.onWidgetLayer(Mx, function () { mx.erase_window(Mx); }); } - } + }, }; }); }; - mx.render_message_box = function(Mx, msg, xpos, ypos, textColor) { + mx.render_message_box = function (Mx, msg, xpos, ypos, textColor) { var GBorder = 3; // Unlike MX$MESSAGE, this implementaion if the message @@ -2486,11 +2840,17 @@ beg = []; var MESSWIDTH = 40; - linel = Math.min((((Mx.width - 2 * GBorder) / Mx.text_w) - 2), msg.length); + linel = Math.min( + (Mx.width - 2 * GBorder) / Mx.text_w - 2, + msg.length + ); if (linel <= 0) { return; } - while ((linel > MESSWIDTH) && (2.5 * Mx.text_h * msg.length < Mx.height * linel)) { + while ( + linel > MESSWIDTH && + 2.5 * Mx.text_h * msg.length < Mx.height * linel + ) { linel -= 5; } @@ -2509,21 +2869,21 @@ var endinreturn = false; for (cur = bg; cur <= end && !endinreturn; cur++) { switch (msg[cur]) { - case ',': - case ';': - case ' ': - case ':': + case ",": + case ";": + case " ": + case ":": brk = cur; break; - case '-': - case '/': + case "-": + case "/": if (brk !== cur - 1) { brk = cur; } break; - case '@': - case '\n': - case '\r': + case "@": + case "\n": + case "\r": center = false; endinreturn = true; brk = cur; @@ -2545,7 +2905,10 @@ } } else { for (var i = 0; i < beg.length; i++) { - linel = Math.min((((Mx.width - 2 * GBorder) / Mx.text_w) - 2), Math.max(linel, beg[i].length)); + linel = Math.min( + (Mx.width - 2 * GBorder) / Mx.text_w - 2, + Math.max(linel, beg[i].length) + ); } } @@ -2580,7 +2943,7 @@ while (cur < lastline) { j += Mx.text_h; if (center) { - i = xc + xs / 2 - ((beg[cur].length * Mx.text_w) / 2); + i = xc + xs / 2 - (beg[cur].length * Mx.text_w) / 2; } mx.text(Mx, i, j, beg[cur], textColor); cur++; @@ -2600,7 +2963,17 @@ * @param fill_color * @param {Number} radius The corner radius. Defaults to 5; */ - mx.draw_round_box = function(Mx, color, x, y, w, h, fill_opacity, fill_color, radius) { + mx.draw_round_box = function ( + Mx, + color, + x, + y, + w, + h, + fill_opacity, + fill_color, + radius + ) { var ctx = Mx.active_canvas.getContext("2d"); if (!radius) { @@ -2623,7 +2996,7 @@ ctx.strokeStyle = color; ctx.stroke(); - if ((fill_opacity !== undefined) && (fill_opacity > 0)) { + if (fill_opacity !== undefined && fill_opacity > 0) { var oldAlpha = ctx.globalAlpha; ctx.globalAlpha = fill_opacity; if (fill_color) { @@ -2649,7 +3022,7 @@ // // ~= MX$DRAW_BOX // - mx.draw_box = function(Mx, color, x, y, w, h, fill_opacity, fill_color) { + mx.draw_box = function (Mx, color, x, y, w, h, fill_opacity, fill_color) { var ctx = Mx.active_canvas.getContext("2d"); if (color !== "xor") { @@ -2657,7 +3030,7 @@ ctx.strokeStyle = color; ctx.strokeRect(x, y, w, h); } else { - if (typeof Uint8ClampedArray === 'undefined') { + if (typeof Uint8ClampedArray === "undefined") { // we don't have typed arrays, so canvas getImageData operations // will be very slow, so use Mx.fg instead ctx.lineWidth = 1; @@ -2716,7 +3089,7 @@ } } - if ((fill_opacity !== undefined) && (fill_opacity > 0)) { + if (fill_opacity !== undefined && fill_opacity > 0) { var oldAlpha = ctx.globalAlpha; ctx.globalAlpha = fill_opacity; if (fill_color) { @@ -2734,11 +3107,11 @@ * @param width */ // ~= MX$SETFONT - mx.set_font = function(Mx, width) { + mx.set_font = function (Mx, width) { var ctx = Mx.canvas.getContext("2d"); var ctx_wid = Mx.wid_canvas.getContext("2d"); - if ((Mx.font) && (Mx.font.width === width)) { + if (Mx.font && Mx.font.width === width) { // use the cached font ctx.font = Mx.font.font; ctx_wid.font = Mx.font.font; @@ -2749,18 +3122,17 @@ text_h = text_h + 1; ctx.font = text_h + "px " + Mx.font_family; ctx_wid.font = text_h + "px " + Mx.font_family; - var font_size = ctx.measureText('M'); // the capital M is typically the same height and width + var font_size = ctx.measureText("M"); // the capital M is typically the same height and width Mx.text_w = font_size.width; Mx.text_h = text_h; } while (Mx.text_w < width); Mx.font = { font: text_h + "px " + Mx.font_family, - width: width + width: width, }; } }; - /** * @param Mx * @param xstart @@ -2770,7 +3142,7 @@ * @param style */ // ~= MX$FTEXTLINE - mx.textline = function(Mx, xstart, ystart, xend, yend, style) { + mx.textline = function (Mx, xstart, ystart, xend, yend, style) { var ctx = Mx.active_canvas.getContext("2d"); if (!style) { style = {}; @@ -2781,7 +3153,16 @@ if (!style.width) { style.width = 1; } - draw_line(ctx, xstart, ystart, xend, yend, style, style.color, style.width); + draw_line( + ctx, + xstart, + ystart, + xend, + yend, + style, + style.color, + style.width + ); }; /** @@ -2790,7 +3171,7 @@ * @param ndiv */ // ~= MX$TICS - mx.tics = function(dmin, dmax, ndiv, timecode) { + mx.tics = function (dmin, dmax, ndiv, timecode) { var dtic = 1; var dtic1 = dmin; @@ -2798,7 +3179,7 @@ if (dmax === dmin) { return { dtic: 1, - dtic1: dmin + dtic1: dmin, }; } @@ -2815,12 +3196,12 @@ nsig = Math.floor(sig); } - var ddf = df * Math.pow(10.0, (-nsig)); + var ddf = df * Math.pow(10.0, -nsig); sig = Math.pow(10.0, nsig); var dft = ddf * sig; // If timecode has been requested and it looks like // timecode - if (timecode && (dft >= 5.0 && dft <= 59.5 * 3600 * 24)) { + if (timecode && dft >= 5.0 && dft <= 59.5 * 3600 * 24) { var dscl; if (dft < 17.5) { dscl = 5.0; // align to 5 sec tics @@ -2852,7 +3233,7 @@ } else if (ddf < 2.25) { dtic = 2.0 * sig; } else if (ddf < 3.5) { - dtic = 2.50 * sig; + dtic = 2.5 * sig; } else if (ddf < 7.0) { dtic = 5.0 * sig; } else { @@ -2889,7 +3270,7 @@ return { dtic: dtic, - dtic1: dtic1 + dtic1: dtic1, }; }; @@ -2902,7 +3283,7 @@ * @param flags */ // ~= MX$FDRAWAXIS - mx.drawaxis = function(Gx, Mx, xdiv, ydiv, xlab, ylab, flags) { + mx.drawaxis = function (Gx, Mx, xdiv, ydiv, xlab, ylab, flags) { var stk1 = mx.origin(Mx.origin, 1, Mx.stk[Mx.level]); var iscl = 0; var isct = 0; @@ -2911,9 +3292,8 @@ var width = 0; var height = 0; - xlab = (xlab === undefined) ? 30 : xlab; - ylab = (ylab === undefined) ? 30 : ylab; - + xlab = xlab === undefined ? 30 : xlab; + ylab = ylab === undefined ? 30 : ylab; if (flags.exactbox) { iscl = Math.floor(stk1.x1); @@ -2934,7 +3314,14 @@ var ctx = Mx.active_canvas.getContext("2d"); if (flags.fillStyle) { if (Array.isArray(flags.fillStyle)) { - ctx.fillStyle = mx.linear_gradient(Mx, 0, 0, 0, iscb - isct, flags.fillStyle); + ctx.fillStyle = mx.linear_gradient( + Mx, + 0, + 0, + 0, + iscb - isct, + flags.fillStyle + ); } else { ctx.fillStyle = flags.fillStyle; } @@ -2952,11 +3339,11 @@ var xTIC = { dtic: 0, - dtic1: 0 + dtic1: 0, }; var yTIC = { dtic: 0, - dtic1: 0 + dtic1: 0, }; if (xdiv < 0) { @@ -2966,9 +3353,9 @@ xTIC = mx.tics(stk1.xmin, stk1.xmax, xdiv, flags.xtimecode); } - var _xmult = 1.0; - if (flags.xmult) { // if xmult was provided + if (flags.xmult) { + // if xmult was provided _xmult = flags.xmult; } else if (!flags.xtimecode) { _xmult = mx.mult(stk1.xmin, stk1.xmax); @@ -2980,7 +3367,8 @@ yTIC = mx.tics(stk1.ymin, stk1.ymax, ydiv, flags.ytimecode); } var _ymult = 1.0; - if (flags.ymult) { // if ymult was provided + if (flags.ymult) { + // if ymult was provided _ymult = flags.ymult; } else if (!flags.ytimecode) { _ymult = mx.mult(stk1.ymin, stk1.ymax); @@ -3061,7 +3449,10 @@ } // Figure out how many characters can fit between tics - var xlbl_maxlen = Math.min(12, Math.round(fact * xTIC.dtic) / Mx.text_w); + var xlbl_maxlen = Math.min( + 12, + Math.round(fact * xTIC.dtic) / Mx.text_w + ); // The sp flag decides if all tics should be labeled, or just the first tic. // in LEGACY rendering when sp=0 you should get one tic at the start @@ -3080,7 +3471,7 @@ if (flags.xtimecode) { xlbl = m.sec2tod(xTIC.dtic1); // If the label is no longer than half of the total width display multiple labels - sp = (xlbl.length * Mx.text_w < (iscr - iscl) / 2); + sp = xlbl.length * Mx.text_w < (iscr - iscl) / 2; } else { // Ensure that all of the tic labels will render uniquely var last_xlbl; @@ -3112,14 +3503,14 @@ flags.gridStyle = { mode: "dashed", on: 1, - off: 3 + off: 3, }; } else { flags.gridStyle = { - "color": Mx.xwms, + color: Mx.xwms, mode: "dashed", on: 1, - off: 3 + off: 3, }; } } @@ -3135,10 +3526,14 @@ // If we have enough space to draw the next tic label if (i > ix) { xlbl = m.sec2tod(x, true); - ix = i + (Mx.text_w * (xlbl.length + 1)); + ix = i + Mx.text_w * (xlbl.length + 1); } } else { - xlbl = mx.format_f(x * fmul, xlbl_maxlen, xlbl_maxlen / 2); + xlbl = mx.format_f( + x * fmul, + xlbl_maxlen, + xlbl_maxlen / 2 + ); xlbl = trimlabel(xlbl, true); } if (xlbl) { @@ -3157,22 +3552,36 @@ if (flags.inside) { i = Math.floor(Math.max(iscl + itext, i)); } - mx.text(Mx, i - itext, jtext, xlbl + " +\u0394 " + m.sec2tod(xTIC.dtic)); + mx.text( + Mx, + i - itext, + jtext, + xlbl + " +\u0394 " + m.sec2tod(xTIC.dtic) + ); } else { xlbl = (xTIC.dtic1 * fmul).toString(); if (flags.inside) { i = Math.floor(Math.max(iscl + itext, i)); } - mx.text(Mx, i - itext, jtext, xlbl + " +\u0394 " + (xTIC.dtic * fmul)); + mx.text( + Mx, + i - itext, + jtext, + xlbl + " +\u0394 " + xTIC.dtic * fmul + ); } } } } // Add y-tick marks - if (flags.yonright) { // TODO - yonright probably doesn't work + if (flags.yonright) { + // TODO - yonright probably doesn't work if (flags.inside) { - itext = Math.min(iscr - 6 * Mx.text_w, Mx.width - 5 * Mx.text_w); + itext = Math.min( + iscr - 6 * Mx.text_w, + Mx.width - 5 * Mx.text_w + ); } else { itext = Math.min(iscr + Mx.text_w, Mx.width - 5 * Mx.text_w); } @@ -3180,7 +3589,10 @@ if (flags.inside) { itext = Math.max(0, iscl + Mx.text_w); } else { - itext = Math.max(0, Math.floor(iscl - (Mx.l - 0.5) * Mx.text_w)); + itext = Math.max( + 0, + Math.floor(iscl - (Mx.l - 0.5) * Mx.text_w) + ); } } jtext = 0.4 * Mx.text_h; @@ -3199,12 +3611,12 @@ ytic = stk1.ymax - ytic1 + 1.0; } if (stk1.ymax >= stk1.ymin) { - endtic = function(val) { - return (val <= stk1.ymax); + endtic = function (val) { + return val <= stk1.ymax; }; } else { - endtic = function(val) { - return (val >= stk1.ymax); + endtic = function (val) { + return val >= stk1.ymax; }; } var ylbl; @@ -3218,7 +3630,7 @@ flags.gridStyle = { mode: "dashed", on: 1, - off: 3 + off: 3, }; } mx.textline(Mx, iscl, i, iscr, i, flags.gridStyle); @@ -3228,8 +3640,10 @@ } if (yticlabels) { // TODO - if (flags.inside && - ((i < isct + Mx.text_h) || (i > iscb - Mx.text_h * 2))) { + if ( + flags.inside && + (i < isct + Mx.text_h || i > iscb - Mx.text_h * 2) + ) { // out of range for inside labels } else if (flags.ytimecode) { ylbl = m.sec2tod(y); // don't trim zeros because we use them later @@ -3248,17 +3662,27 @@ sep += 1; // adjust for the next stage } // The draw the primary portion - mx.text(Mx, itext, Math.min(iscb, i + jtext), ylbl.substring(sep + 1, sep + 6)); + mx.text( + Mx, + itext, + Math.min(iscb, i + jtext), + ylbl.substring(sep + 1, sep + 6) + ); // Finally the sections portion if it fits on the screen // and is necessary k = i + jtext + Mx.text_h; - if ((k > isct && k < iscb)) { + if (k > isct && k < iscb) { if (ylbl.substring(sep + 7, sep + 9) !== "00") { // add the .00 which is safe to do unconditionally because // we truncate on the following line and we know that // sec2tod either returns no decimal places or 6 decimal places ylbl = ylbl + ".00"; - mx.text(Mx, itext, k, ylbl.substring(sep + 7, sep + 12)); + mx.text( + Mx, + itext, + k, + ylbl.substring(sep + 7, sep + 12) + ); } } } else { @@ -3279,9 +3703,13 @@ * @param rect_height * @private */ - mx.inrect = function(x, y, rect_x, rect_y, rect_width, rect_height) { - return (x >= rect_x && x <= rect_x + rect_width && - y >= rect_y && y <= rect_y + rect_height); + mx.inrect = function (x, y, rect_x, rect_y, rect_width, rect_height) { + return ( + x >= rect_x && + x <= rect_x + rect_width && + y >= rect_y && + y <= rect_y + rect_height + ); }; /** * @private @@ -3290,7 +3718,7 @@ GBorder: 3, sidelab: 0, toplab: 1, - n_show: 0 + n_show: 0, }; /** @@ -3318,135 +3746,202 @@ MENU_CONSTANTS.n_show = n_items; } + menu.animationFrameHandle = requestAnimFrame( + mx.withWidgetLayer(Mx, function () { + mx.erase_window(Mx); - menu.animationFrameHandle = requestAnimFrame(mx.withWidgetLayer(Mx, function() { - mx.erase_window(Mx); - - menu.animationFrameHandle = undefined; - var yb = Mx.text_h * 1.5; - menu.x = Math.max(menu.x, 0); - menu.y = Math.max(menu.y, 0); - menu.x = Math.min(menu.x, Mx.width - menu.w); - menu.y = Math.min(menu.y, Mx.height - menu.h); - - var xcc = menu.x + MENU_CONSTANTS.GBorder + Math.max(0, MENU_CONSTANTS.sidelab); - var ycc = menu.y + MENU_CONSTANTS.GBorder + MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder); - - var xss = menu.w - 2 * MENU_CONSTANTS.GBorder - Math.abs(MENU_CONSTANTS.sidelab); - var yss = menu.h - 2 * MENU_CONSTANTS.GBorder - MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder); - - mx.widgetbox(Mx, menu.x, menu.y, menu.w, menu.h, xcc, ycc, xss, yss, menu.title); - - //ctx.fillStyle = xwlo; - //ctx.fillRect(xcc, ycc, xss, yss); - - var ctx = Mx.wid_canvas.getContext("2d"); - ctx.lineWidth = 1; + menu.animationFrameHandle = undefined; + var yb = Mx.text_h * 1.5; + menu.x = Math.max(menu.x, 0); + menu.y = Math.max(menu.y, 0); + menu.x = Math.min(menu.x, Mx.width - menu.w); + menu.y = Math.min(menu.y, Mx.height - menu.h); + + var xcc = + menu.x + + MENU_CONSTANTS.GBorder + + Math.max(0, MENU_CONSTANTS.sidelab); + var ycc = + menu.y + + MENU_CONSTANTS.GBorder + + MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder); + + var xss = + menu.w - + 2 * MENU_CONSTANTS.GBorder - + Math.abs(MENU_CONSTANTS.sidelab); + var yss = + menu.h - + 2 * MENU_CONSTANTS.GBorder - + MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder); + + mx.widgetbox( + Mx, + menu.x, + menu.y, + menu.w, + menu.h, + xcc, + ycc, + xss, + yss, + menu.title + ); + + //ctx.fillStyle = xwlo; + //ctx.fillRect(xcc, ycc, xss, yss); + + var ctx = Mx.wid_canvas.getContext("2d"); + ctx.lineWidth = 1; - ctx.strokeStyle = Mx.xwbs; // xwbs - ctx.beginPath(); - ctx.moveTo(xcc, ycc - 4 + 0.5); - ctx.lineTo(xcc + xss - 1, ycc - 4 + 0.5); - ctx.stroke(); + ctx.strokeStyle = Mx.xwbs; // xwbs + ctx.beginPath(); + ctx.moveTo(xcc, ycc - 4 + 0.5); + ctx.lineTo(xcc + xss - 1, ycc - 4 + 0.5); + ctx.stroke(); - ctx.strokeStyle = Mx.xwts; // xwts - ctx.beginPath(); - ctx.moveTo(xcc, ycc - 3 + 0.5); - ctx.lineTo(xcc + xss - 1, ycc - 3 + 0.5); - ctx.stroke(); + ctx.strokeStyle = Mx.xwts; // xwts + ctx.beginPath(); + ctx.moveTo(xcc, ycc - 3 + 0.5); + ctx.lineTo(xcc + xss - 1, ycc - 3 + 0.5); + ctx.stroke(); - var i_begin = menu.queue[0]; - var i_end = menu.queue[MENU_CONSTANTS.n_show - 1]; - if (i_end === 0) { - // now we are starting over - for (var q = 0; q < MENU_CONSTANTS.n_show; q++) { - menu.queue[q] = q; + var i_begin = menu.queue[0]; + var i_end = menu.queue[MENU_CONSTANTS.n_show - 1]; + if (i_end === 0) { + // now we are starting over + for (var q = 0; q < MENU_CONSTANTS.n_show; q++) { + menu.queue[q] = q; + } + i_begin = menu.queue[0]; + i_end = menu.queue[MENU_CONSTANTS.n_show - 1]; } - i_begin = menu.queue[0]; - i_end = menu.queue[MENU_CONSTANTS.n_show - 1]; - } - var menu_counter = 0; - for (var i = i_begin; i <= i_end; i++) { - var item = menu.items[i]; - var y = ycc + yb * menu_counter; - menu_counter = menu_counter + 1; - - if (item.style === "separator") { - ctx.fillStyle = Mx.xwbs; - ctx.fillRect(xcc, y, xss, yb); + var menu_counter = 0; + for (var i = i_begin; i <= i_end; i++) { + var item = menu.items[i]; + var y = ycc + yb * menu_counter; + menu_counter = menu_counter + 1; - ctx.beginPath(); - ctx.moveTo(xcc, y + 0.5); - ctx.lineTo(xcc + xss, y + 0.5); - ctx.stroke(); - - ctx.textBaseline = "middle"; - ctx.textAlign = "left"; - ctx.fillStyle = Mx.xwfg; - ctx.fillText(" " + item.text + " ", xcc + Mx.text_w * 2, y + yb / 2); - } else { - if (mx.LEGACY_RENDER) { - ctx.fillStyle = Mx.xwlo; + if (item.style === "separator") { + ctx.fillStyle = Mx.xwbs; ctx.fillRect(xcc, y, xss, yb); + ctx.beginPath(); ctx.moveTo(xcc, y + 0.5); ctx.lineTo(xcc + xss, y + 0.5); ctx.stroke(); - if (item.selected) { - mx.shadowbox(Mx, xcc - 1, y, xss + 2, yb, 1, 2, "", 0.75); - } + + ctx.textBaseline = "middle"; + ctx.textAlign = "left"; + ctx.fillStyle = Mx.xwfg; + ctx.fillText( + " " + item.text + " ", + xcc + Mx.text_w * 2, + y + yb / 2 + ); } else { - ctx.save(); - ctx.globalAlpha = 0.75; - if (item.selected) { - ctx.fillStyle = Mx.xwts; - } else { + if (mx.LEGACY_RENDER) { ctx.fillStyle = Mx.xwlo; - } - ctx.fillRect(xcc, y, xss, yb); - ctx.restore(); - ctx.strokeStyle = Mx.bg; - ctx.beginPath(); - ctx.moveTo(xcc, y + 0.5); - ctx.lineTo(xcc + xss, y + 0.5); - ctx.stroke(); - } - - ctx.textBaseline = "middle"; - ctx.textAlign = "left"; - ctx.fillStyle = Mx.xwfg; - if (item.style === "checkbox") { - ctx.fillText(" " + item.text + " ", xcc + Mx.text_w * 2, y + yb / 2); - ctx.strokeStyle = Mx.xwfg; - ctx.strokeRect(xcc + 1 + Mx.text_w, y + ((yb - Mx.text_w) / 2), Mx.text_w, Mx.text_w); - if (item.checked) { + ctx.fillRect(xcc, y, xss, yb); ctx.beginPath(); - ctx.moveTo(xcc + 1 + Mx.text_w, y + ((yb - Mx.text_w) / 2)); - ctx.lineTo(xcc + 1 + Mx.text_w + Mx.text_w, y + ((yb - Mx.text_w) / 2) + Mx.text_w); + ctx.moveTo(xcc, y + 0.5); + ctx.lineTo(xcc + xss, y + 0.5); ctx.stroke(); + if (item.selected) { + mx.shadowbox( + Mx, + xcc - 1, + y, + xss + 2, + yb, + 1, + 2, + "", + 0.75 + ); + } + } else { + ctx.save(); + ctx.globalAlpha = 0.75; + if (item.selected) { + ctx.fillStyle = Mx.xwts; + } else { + ctx.fillStyle = Mx.xwlo; + } + ctx.fillRect(xcc, y, xss, yb); + ctx.restore(); + ctx.strokeStyle = Mx.bg; ctx.beginPath(); - ctx.moveTo(xcc + 1 + Mx.text_w + Mx.text_w, y + ((yb - Mx.text_w) / 2)); - ctx.lineTo(xcc + 1 + Mx.text_w, y + ((yb - Mx.text_w) / 2) + Mx.text_w); + ctx.moveTo(xcc, y + 0.5); + ctx.lineTo(xcc + xss, y + 0.5); ctx.stroke(); } - } else { - ctx.fillText(" " + item.text + " ", xcc, y + yb / 2); - // draw the triangle - if (item.checked) { - ctx.beginPath(); - ctx.moveTo(xcc + 1, y + Mx.text_h / 4); - ctx.lineTo(xcc + 1 + Mx.text_w - 2, y + Mx.text_h / 4 + Mx.text_h / 2); - ctx.lineTo(xcc + 1, y + Mx.text_h / 4 + Mx.text_h); - ctx.lineTo(xcc + 1, y + Mx.text_h / 4); - ctx.fill(); + ctx.textBaseline = "middle"; + ctx.textAlign = "left"; + ctx.fillStyle = Mx.xwfg; + if (item.style === "checkbox") { + ctx.fillText( + " " + item.text + " ", + xcc + Mx.text_w * 2, + y + yb / 2 + ); + ctx.strokeStyle = Mx.xwfg; + ctx.strokeRect( + xcc + 1 + Mx.text_w, + y + (yb - Mx.text_w) / 2, + Mx.text_w, + Mx.text_w + ); + if (item.checked) { + ctx.beginPath(); + ctx.moveTo( + xcc + 1 + Mx.text_w, + y + (yb - Mx.text_w) / 2 + ); + ctx.lineTo( + xcc + 1 + Mx.text_w + Mx.text_w, + y + (yb - Mx.text_w) / 2 + Mx.text_w + ); + ctx.stroke(); + ctx.beginPath(); + ctx.moveTo( + xcc + 1 + Mx.text_w + Mx.text_w, + y + (yb - Mx.text_w) / 2 + ); + ctx.lineTo( + xcc + 1 + Mx.text_w, + y + (yb - Mx.text_w) / 2 + Mx.text_w + ); + ctx.stroke(); + } + } else { + ctx.fillText( + " " + item.text + " ", + xcc, + y + yb / 2 + ); + + // draw the triangle + if (item.checked) { + ctx.beginPath(); + ctx.moveTo(xcc + 1, y + Mx.text_h / 4); + ctx.lineTo( + xcc + 1 + Mx.text_w - 2, + y + Mx.text_h / 4 + Mx.text_h / 2 + ); + ctx.lineTo( + xcc + 1, + y + Mx.text_h / 4 + Mx.text_h + ); + ctx.lineTo(xcc + 1, y + Mx.text_h / 4); + ctx.fill(); + } } } } - } - - - })); + }) + ); } /** @@ -3456,7 +3951,7 @@ * @private */ function _menu_takeaction(Mx, menu) { - mx.onWidgetLayer(Mx, function() { + mx.onWidgetLayer(Mx, function () { mx.erase_window(Mx); }); Mx.menu = undefined; @@ -3469,7 +3964,7 @@ item.handler(); } else if (item.menu) { var newmenu = item.menu; - if (typeof item.menu === 'function') { + if (typeof item.menu === "function") { newmenu = item.menu(); } newmenu.finalize = menu.finalize; @@ -3478,7 +3973,7 @@ break; } } - if ((!Mx.menu) && (menu.finalize)) { + if (!Mx.menu && menu.finalize) { menu.finalize(); } } @@ -3490,7 +3985,7 @@ * @private */ function _menu_dismiss(Mx, menu) { - mx.onWidgetLayer(Mx, function() { + mx.onWidgetLayer(Mx, function () { mx.erase_window(Mx); }); if (Mx.useDomMenu) { @@ -3499,7 +3994,7 @@ Mx.menu = undefined; Mx.widget = null; - if ((!Mx.menu) && (menu.finalize)) { + if (!Mx.menu && menu.finalize) { menu.finalize(); } } @@ -3520,7 +4015,12 @@ _menu_redraw(Mx, menu); } else if (event.type === "mousemove") { // Update position - if (menu.drag_x !== undefined && menu.drag_y !== undefined && Math.abs(Mx.xpos - menu.drag_x) > 2 && Math.abs(Mx.ypos - menu.drag_y) > 2) { + if ( + menu.drag_x !== undefined && + menu.drag_y !== undefined && + Math.abs(Mx.xpos - menu.drag_x) > 2 && + Math.abs(Mx.ypos - menu.drag_y) > 2 + ) { menu.x += Mx.xpos - menu.drag_x; menu.y += Mx.ypos - menu.drag_y; menu.drag_x = Mx.xpos; @@ -3528,10 +4028,19 @@ } // All of these variables suck and are common in other places...refactoring is necessary - var xcc = menu.x + MENU_CONSTANTS.GBorder + Math.max(0, MENU_CONSTANTS.sidelab); - var xss = menu.w - 2 * MENU_CONSTANTS.GBorder - Math.abs(MENU_CONSTANTS.sidelab); + var xcc = + menu.x + + MENU_CONSTANTS.GBorder + + Math.max(0, MENU_CONSTANTS.sidelab); + var xss = + menu.w - + 2 * MENU_CONSTANTS.GBorder - + Math.abs(MENU_CONSTANTS.sidelab); var yb = Mx.text_h * 1.5; - var ycc = menu.y + MENU_CONSTANTS.GBorder + MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder); + var ycc = + menu.y + + MENU_CONSTANTS.GBorder + + MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder); for (var i = i_begin; i <= i_end; i++) { var y = ycc + yb * i; @@ -3545,7 +4054,7 @@ } else if (event.type === "mouseup") { // No longer dragging menu if (event.which === 1) { - if ((menu.drag_x !== undefined) && (menu.drag_y !== undefined)) { + if (menu.drag_x !== undefined && menu.drag_y !== undefined) { menu.drag_x = undefined; menu.drag_y = undefined; } else { @@ -3557,7 +4066,12 @@ } else if (event.type === "mousedown") { event.preventDefault(); if (event.which === 1) { - if (Mx.xpos > menu.x && Mx.xpos < (menu.x + menu.w) && Mx.ypos > menu.y && Mx.ypos < (menu.y + Mx.text_h * 1.5)) { + if ( + Mx.xpos > menu.x && + Mx.xpos < menu.x + menu.w && + Mx.ypos > menu.y && + Mx.ypos < menu.y + Mx.text_h * 1.5 + ) { menu.drag_x = Mx.xpos; menu.drag_y = Mx.ypos; } @@ -3570,9 +4084,11 @@ var menu = Mx.menu; event.preventDefault(); var keyCode = common.getKeyCode(event); - if (keyCode === 13) { // enter + if (keyCode === 13) { + // enter _menu_takeaction(Mx, menu); - } else if (keyCode === 38) { // up arrow + } else if (keyCode === 38) { + // up arrow for (var i = i_begin; i < i_end; i++) { var item = menu.items[i]; if (item.selected) { @@ -3588,14 +4104,17 @@ menu.queue.unshift(i_begin - 1); _menu_redraw(Mx, menu); menu.items[i_end - 1].selected = true; - - } else if (i_begin === 0 && menu.items[i_begin].selected === true) { + } else if ( + i_begin === 0 && + menu.items[i_begin].selected === true + ) { _menu_redraw(Mx, menu); menu.items[0].selected = true; } } _menu_redraw(Mx, menu); - } else if (keyCode === 40) { // down arrow + } else if (keyCode === 40) { + // down arrow for (var i = i_begin; i < i_end; i++) { var item = menu.items[i]; if (item.selected) { @@ -3604,7 +4123,7 @@ menu.items[i + 1].selected = true; } break; - } else if (i === (i_end - 1)) { + } else if (i === i_end - 1) { // nothing was selected so select the top var next_item = i_end + 1; @@ -3620,7 +4139,10 @@ } } _menu_redraw(Mx, menu); - } else if ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90)) { + } else if ( + (keyCode >= 48 && keyCode <= 57) || + (keyCode >= 65 && keyCode <= 90) + ) { var inp = String.fromCharCode(keyCode).toUpperCase(); if (menu.keypresses === undefined) { @@ -3637,7 +4159,10 @@ continue; } - if (item.text.toUpperCase().indexOf(menu.keypresses) === 0) { + if ( + item.text.toUpperCase().indexOf(menu.keypresses) === + 0 + ) { if (matches === 0) { item.selected = true; } @@ -3663,7 +4188,7 @@ * @param menu * @private */ - mx.menu = function(Mx, menu) { + mx.menu = function (Mx, menu) { if (Mx.useDomMenu) { new mx.DomMenu(Mx, menu); return; @@ -3689,8 +4214,17 @@ menu.y = Mx.ypos; menu.val = 0; - menu.h = MENU_CONSTANTS.GBorder * 2 + yb * MENU_CONSTANTS.n_show + MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder) - 1; - menu.y = menu.y - ((MENU_CONSTANTS.toplab + (Math.max(1, menu.val)) - 0.5) * yb + (1 + MENU_CONSTANTS.toplab) * MENU_CONSTANTS.GBorder) + 1; + menu.h = + MENU_CONSTANTS.GBorder * 2 + + yb * MENU_CONSTANTS.n_show + + MENU_CONSTANTS.toplab * (yb + MENU_CONSTANTS.GBorder) - + 1; + menu.y = + menu.y - + ((MENU_CONSTANTS.toplab + Math.max(1, menu.val) - 0.5) * + yb + + (1 + MENU_CONSTANTS.toplab) * MENU_CONSTANTS.GBorder) + + 1; var xb = menu.title.length; var yadj = 0; @@ -3712,23 +4246,26 @@ for (var q = 0; q < MENU_CONSTANTS.n_show; q++) { menu.queue.push(q); - } menu.y = menu.y - yadj; xb += 2; xb = xb * Mx.text_w; - menu.w = MENU_CONSTANTS.GBorder * 2 + Math.abs(MENU_CONSTANTS.sidelab) + xb - 1; + menu.w = + MENU_CONSTANTS.GBorder * 2 + + Math.abs(MENU_CONSTANTS.sidelab) + + xb - + 1; menu.x = menu.x - menu.w / 2; Mx.menu = menu; Mx.widget = { type: "MENU", - callback: function(event) { + callback: function (event) { _menu_callback(Mx, menu, event); - } + }, }; } _menu_redraw(Mx, menu); @@ -3748,7 +4285,7 @@ * @param name * @private */ - mx.widgetbox = function(Mx, x, y, w, h, inx, iny, inw, inh, name) { + mx.widgetbox = function (Mx, x, y, w, h, inx, iny, inw, inh, name) { var GBorder = 3; mx.shadowbox(Mx, x, y, w, h, 1, 2, "", 0.75); if (name) { @@ -3787,12 +4324,12 @@ // // ~= MX$TEXT // - mx.text = function(Mx, x, y, lbl, color) { + mx.text = function (Mx, x, y, lbl, color) { var ctx = Mx.active_canvas.getContext("2d"); x = Math.max(0, x); y = Math.max(0, y); - if ((x < 0) || (y < 0)) { + if (x < 0 || y < 0) { throw "On No!"; } ctx.textBaseline = "bottom"; @@ -3919,7 +4456,7 @@ ctx.moveTo(x, y1); ctx.lineTo(x + style.on, y1); ctx.stroke(); - x += (style.on + style.off); + x += style.on + style.off; } } else if (x1 === x2) { // vertical line @@ -3929,7 +4466,7 @@ ctx.moveTo(x1, y); ctx.lineTo(x1, y + style.on); ctx.stroke(); - y += (style.on + style.off); + y += style.on + style.off; } } else { throw "Only horizontal or vertical dashed lines are supported"; @@ -3937,7 +4474,7 @@ ctx.beginPath(); } } else if (style.mode === "xor") { - if (typeof Uint8ClampedArray === 'undefined') { + if (typeof Uint8ClampedArray === "undefined") { // we don't have typed arrays, so canvas getImageData operations // will be very slow, so use color instead ctx.beginPath(); @@ -3961,7 +4498,7 @@ throw "Only horizontal and vertical lines can be drawn with XOR"; } - if ((w === 0) || (h === 0)) { + if (w === 0 || h === 0) { return; } @@ -3995,7 +4532,8 @@ * @param width - The line width to set. * @private */ - function draw_poly(ctx, pix, color, width) { // TODO Should this be a public method? + function draw_poly(ctx, pix, color, width) { + // TODO Should this be a public method? start_poly(ctx, pix, width); if (color) { @@ -4024,7 +4562,8 @@ * @param lineWidth - The line width to set * @private */ - function fill_poly(ctx, pix, lineColor, fillColor, width) { // TODO Should this be a public method? + function fill_poly(ctx, pix, lineColor, fillColor, width) { + // TODO Should this be a public method? start_poly(ctx, pix, width); if (lineColor) { @@ -4089,7 +4628,8 @@ * @param lineWidth - The line width to set. * @private */ - function draw_rectangle(ctx, x, y, width, height, color, lineWidth) { // TODO Should this be a public method? + function draw_rectangle(ctx, x, y, width, height, color, lineWidth) { + // TODO Should this be a public method? if (lineWidth) { ctx.lineWidth = lineWidth; } @@ -4115,7 +4655,17 @@ * @param lineWidth - The line width to set. * @private */ - function fill_rectangle(ctx, x, y, width, height, fillColor, strokeColor, lineWidth) { // TODO Should this be a public method? + function fill_rectangle( + ctx, + x, + y, + width, + height, + fillColor, + strokeColor, + lineWidth + ) { + // TODO Should this be a public method? if (lineWidth) { ctx.lineWidth = lineWidth; } @@ -4146,7 +4696,15 @@ * @private */ function to_rgb(red, green, blue) { - return "rgb(" + Math.round(red) + ", " + Math.round(green) + ", " + Math.round(blue) + ")"; + return ( + "rgb(" + + Math.round(red) + + ", " + + Math.round(green) + + ", " + + Math.round(blue) + + ")" + ); } /** @@ -4158,26 +4716,30 @@ * @param z * @private */ - mx.getcolor = function(Mx, map, z) { + mx.getcolor = function (Mx, map, z) { var iz = 0; for (; iz < 6 && map[iz + 1].pos === 0; iz++) {} while (z > map[iz].pos && iz < 6) { iz++; } - if ((iz === 0) || (z >= map[iz].pos)) { + if (iz === 0 || z >= map[iz].pos) { // above, below, or directly on boundry return to_rgb( pc2px(map[iz].red), pc2px(map[iz].green), - pc2px(map[iz].blue)); + pc2px(map[iz].blue) + ); } else { // interpolation my dear watson var pf = (z - map[iz - 1].pos) / (map[iz].pos - map[iz - 1].pos); var zf = pc2px(pf * 100); var zf1 = 255 - zf; return to_rgb( - (zf * (map[iz].red / 100) + zf1 * (map[iz - 1].red / 100)), (zf * (map[iz].green / 100) + zf1 * (map[iz - 1].green / 100)), (zf * (map[iz].blue / 100) + zf1 * (map[iz - 1].blue / 100))); + zf * (map[iz].red / 100) + zf1 * (map[iz - 1].red / 100), + zf * (map[iz].green / 100) + zf1 * (map[iz - 1].green / 100), + zf * (map[iz].blue / 100) + zf1 * (map[iz - 1].blue / 100) + ); } }; @@ -4191,7 +4753,8 @@ function trimlabel(lbl, inside) { var k; var j; - if (lbl.substring(5, 8) === ".000000") { // this line seems to always evaluate to false + if (lbl.substring(5, 8) === ".000000") { + // this line seems to always evaluate to false k = 4; } else { k = lbl.length - 1; @@ -4200,7 +4763,7 @@ } } j = 0; - while ((lbl[j] === " ") && ((k - j + 1 > 5) || inside)) { + while (lbl[j] === " " && (k - j + 1 > 5 || inside)) { j = j + 1; } var res = lbl.substring(j, k + 1); @@ -4214,12 +4777,12 @@ * @param Mx * @private */ - mx.redraw_warpbox = function(Mx) { + mx.redraw_warpbox = function (Mx) { if (Mx.warpbox) { if (Mx._animationFrameHandle) { cancelAnimFrame(Mx._animationFrameHandle); } - Mx._animationFrameHandle = requestAnimFrame(function() { + Mx._animationFrameHandle = requestAnimFrame(function () { display_warpbox(Mx); }); } @@ -4239,9 +4802,12 @@ return; } - if (((Mx.xpos >= warpbox.xmin) && (Mx.xpos <= warpbox.xmax)) && - ((Mx.ypos >= warpbox.ymin) && (Mx.ypos <= warpbox.ymax))) { - + if ( + Mx.xpos >= warpbox.xmin && + Mx.xpos <= warpbox.xmax && + Mx.ypos >= warpbox.ymin && + Mx.ypos <= warpbox.ymax + ) { // Update the position warpbox.xl = Mx.xpos; warpbox.yl = Mx.ypos; @@ -4252,7 +4818,7 @@ var w = Math.abs(warpbox.xl - warpbox.xo); var h = Math.abs(warpbox.yl - warpbox.yo); - if ((w === 0) || (h === 0)) { + if (w === 0 || h === 0) { // Nothing to draw return; } @@ -4265,12 +4831,20 @@ h = Mx.b - Mx.t; } // else box - mx.onWidgetLayer(Mx, function() { + mx.onWidgetLayer(Mx, function () { mx.erase_window(Mx); - mx.draw_box(Mx, "xor", x, y, w, h, warpbox.style.opacity, warpbox.style.fill_color); + mx.draw_box( + Mx, + "xor", + x, + y, + w, + h, + warpbox.style.opacity, + warpbox.style.fill_color + ); }); } - } /** @@ -4282,7 +4856,6 @@ return Math.log(val) / Math.log(10); } - /** * Attempts to format a number in the same manner * as the FORTRAN format code 1p1g16.9 @@ -4313,7 +4886,7 @@ * @param leading_nonzer * @private */ - mx.format_g = function(num, w, d, leading_nonzero) { + mx.format_g = function (num, w, d, leading_nonzero) { var w = Math.min(w, d + 7); var f = Math.abs(num).toString(); @@ -4389,10 +4962,10 @@ * @param d number of digits after the decimal * @private */ - mx.format_f = function(num, s, d) { + mx.format_f = function (num, s, d) { d = Math.max(Math.min(d, 20), 0); var f = num.toFixed(d).toString(); - f = mx.pad(f, (s + d), " "); + f = mx.pad(f, s + d, " "); return f; }; @@ -4402,7 +4975,7 @@ * @param c * @private */ - mx.pad = function(s, size, c) { + mx.pad = function (s, size, c) { while (s.length < size) { s = c + s; } @@ -4421,7 +4994,7 @@ * @private */ // ~= MX$SHADOWBOX - mx.legacy_shadowbox = function(Mx, x, y, w, h, shape, func, label) { + mx.legacy_shadowbox = function (Mx, x, y, w, h, shape, func, label) { var length = label.length; // Original method declaration includes a length - but it only represents the length of the label var xt = 0; // Originally an int @@ -4429,10 +5002,11 @@ var bw = 0; // Originally an int var pix = []; // Originally declared as a size 11 XPoint array - for (var cnt = 0; cnt < 11; cnt++) { // initializing 11 points in the array + for (var cnt = 0; cnt < 11; cnt++) { + // initializing 11 points in the array pix[cnt] = { x: 0, - y: 0 + y: 0, }; } @@ -4440,7 +5014,7 @@ // Removed the G.BW section - since we don't need to support black & white displays - var j = (shape === mx.L_ArrowLeft || shape === mx.L_ArrowUp) ? 1 : 2; + var j = shape === mx.L_ArrowLeft || shape === mx.L_ArrowUp ? 1 : 2; if (func !== 0 && mx.GBorder > 0) { bw = m.trunc(Math.min(w, h) / 3); @@ -4509,11 +5083,11 @@ var ctx = Mx.active_canvas.getContext("2d"); if (bw > 0) { - ctx.fillStyle = (func > 0) ? Mx.xwts : Mx.xwbs; // Set foreground color + ctx.fillStyle = func > 0 ? Mx.xwts : Mx.xwbs; // Set foreground color fill_poly(ctx, pix.slice(0, 7)); // if (shape !== 1) { draw_poly(ctx, pix.slice(0,7)); } // TODO what shape is this neccessary with - causes an issue with arrows - ctx.fillStyle = (func < 0) ? Mx.xwts : Mx.xwbs; // Set foreground color + ctx.fillStyle = func < 0 ? Mx.xwts : Mx.xwbs; // Set foreground color fill_poly(ctx, pix.slice(5, 11)); //if (shape !== 1) { draw_poly(ctx, pix.slice(5, 11)); } // TODO what shape is this neccessary with - causes an issue with arrows } @@ -4548,35 +5122,56 @@ * @private */ // ~= MX$SHADOWBOX - mx.sigplot_shadowbox = function(Mx, x, y, w, h, shape, func, label, alpha) { + mx.sigplot_shadowbox = function ( + Mx, + x, + y, + w, + h, + shape, + func, + label, + alpha + ) { var ctx = Mx.active_canvas.getContext("2d"); var length = label.length; // Original method declaration includes a length - but it only represents the length of the label - var color = (func < 0) ? Mx.xwts : Mx.xwbs; + var color = func < 0 ? Mx.xwts : Mx.xwbs; alpha = alpha || 1.0; var pix = []; // Originally declared as a size 11 XPoint array - for (var cnt = 0; cnt < 11; cnt++) { // initializing 11 points in the array + for (var cnt = 0; cnt < 11; cnt++) { + // initializing 11 points in the array pix[cnt] = { x: 0, - y: 0 + y: 0, }; } - switch (shape) { case mx.L_ArrowLeft: case mx.L_ArrowRight: case mx.L_ArrowUp: case mx.L_ArrowDown: var pix = mx.chevron(shape, x, y, w, h); - ctx.fillStyle = (func > 0) ? Mx.xwts : Mx.xwbs; + ctx.fillStyle = func > 0 ? Mx.xwts : Mx.xwbs; fill_poly(ctx, pix.slice(0, 6)); break; default: - mx.draw_round_box(Mx, color, x, y, w, h, alpha, Mx.xwbg, 5, Mx.xwbs); + mx.draw_round_box( + Mx, + color, + x, + y, + w, + h, + alpha, + Mx.xwbg, + 5, + Mx.xwbs + ); break; } @@ -4593,13 +5188,14 @@ } }; - if (mx.LEGACY_RENDER) { // TODO new-style conditional + if (mx.LEGACY_RENDER) { + // TODO new-style conditional mx.shadowbox = mx.legacy_shadowbox; } else { mx.shadowbox = mx.sigplot_shadowbox; } - mx.chevron = function(shape, x, y, w, h, e) { + mx.chevron = function (shape, x, y, w, h, e) { // Figure out the largest square dimension var q = Math.min(w, h); @@ -4608,20 +5204,18 @@ e = q * 0.25; } - - // Initialize the pixel array var pix = []; - for (var cnt = 0; cnt < 6; cnt++) { // initializing 11 points in the array + for (var cnt = 0; cnt < 6; cnt++) { + // initializing 11 points in the array pix[cnt] = { x: 0, - y: 0 + y: 0, }; } - - var x_offset = m.trunc(((w - q) / 2) + (q / 4) - (e / (2 * 1.414))); - var y_offset = m.trunc(((h - q) / 2) + (q / 4) - (e / (2 * 1.414))); + var x_offset = m.trunc((w - q) / 2 + q / 4 - e / (2 * 1.414)); + var y_offset = m.trunc((h - q) / 2 + q / 4 - e / (2 * 1.414)); switch (shape) { case mx.L_ArrowLeft: // Chevron points from the tip around the edge clockwise @@ -4629,11 +5223,11 @@ pix[0].y = y + m.trunc(q / 2); pix[1].x = x + x_offset + m.trunc(q / 2); pix[1].y = y; - pix[2].x = x + x_offset + m.trunc((q / 2) + (e / 1.414)); + pix[2].x = x + x_offset + m.trunc(q / 2 + e / 1.414); pix[2].y = y + m.trunc(e / 1.414); pix[3].x = x + x_offset + m.trunc((2 * e) / 1.414); pix[3].y = y + m.trunc(q / 2); - pix[4].x = x + x_offset + m.trunc((q / 2) + (e / 1.414)); + pix[4].x = x + x_offset + m.trunc(q / 2 + e / 1.414); pix[4].y = y + h - m.trunc(e / 1.414); pix[5].x = x + x_offset + m.trunc(q / 2); pix[5].y = y + q; @@ -4644,11 +5238,11 @@ pix[0].y = y + m.trunc(q / 2); pix[1].x = x + w - x_offset - m.trunc(q / 2); pix[1].y = y; - pix[2].x = x + w - x_offset - m.trunc((q / 2) + (e / 1.414)); + pix[2].x = x + w - x_offset - m.trunc(q / 2 + e / 1.414); pix[2].y = y + m.trunc(e / 1.414); pix[3].x = x + w - x_offset - m.trunc((2 * e) / 1.414); pix[3].y = y + m.trunc(q / 2); - pix[4].x = x + w - x_offset - m.trunc((q / 2) + (e / 1.414)); + pix[4].x = x + w - x_offset - m.trunc(q / 2 + e / 1.414); pix[4].y = y + h - m.trunc(e / 1.414); pix[5].x = x + w - x_offset - m.trunc(q / 2); pix[5].y = y + q; @@ -4660,11 +5254,11 @@ pix[1].x = x; pix[1].y = y + y_offset + m.trunc(q / 2); pix[2].x = x + m.trunc(e / 1.414); - pix[2].y = y + y_offset + m.trunc((q / 2) + (e / 1.414)); + pix[2].y = y + y_offset + m.trunc(q / 2 + e / 1.414); pix[3].x = x + m.trunc(q / 2); pix[3].y = y + y_offset + m.trunc((2 * e) / 1.414); pix[4].x = x + w - m.trunc(e / 1.414); - pix[4].y = y + y_offset + m.trunc((q / 2) + (e / 1.414)); + pix[4].y = y + y_offset + m.trunc(q / 2 + e / 1.414); pix[5].x = x + q; pix[5].y = y + y_offset + m.trunc(q / 2); break; @@ -4675,11 +5269,11 @@ pix[1].x = x; pix[1].y = y + h - y_offset - m.trunc(q / 2); pix[2].x = x + m.trunc(e / 1.414); - pix[2].y = y + h - y_offset - m.trunc((q / 2) + (e / 1.414)); + pix[2].y = y + h - y_offset - m.trunc(q / 2 + e / 1.414); pix[3].x = x + m.trunc(q / 2); pix[3].y = y + h - y_offset - m.trunc((2 * e) / 1.414); pix[4].x = x + w - m.trunc(e / 1.414); - pix[4].y = y + h - y_offset - m.trunc((q / 2) + (e / 1.414)); + pix[4].y = y + h - y_offset - m.trunc(q / 2 + e / 1.414); pix[5].x = x + q; pix[5].y = y + h - y_offset - m.trunc(q / 2); break; @@ -4694,14 +5288,20 @@ * @private */ // ~= mx_ifevent - mx.ifevent = function(Mx, mouseEvent) { + mx.ifevent = function (Mx, mouseEvent) { Mx.button_press = 0; Mx.button_release = 0; Mx.state_mask = 0; var rect = mouseEvent.target.getBoundingClientRect(); - var eventXPos = (mouseEvent.offsetX === undefined) ? (mouseEvent.pageX - rect.left - window.scrollX) : mouseEvent.offsetX; - var eventYPos = (mouseEvent.offsetX === undefined) ? (mouseEvent.pageY - rect.top - window.scrollY) : mouseEvent.offsetY; + var eventXPos = + mouseEvent.offsetX === undefined + ? mouseEvent.pageX - rect.left - window.scrollX + : mouseEvent.offsetX; + var eventYPos = + mouseEvent.offsetX === undefined + ? mouseEvent.pageY - rect.top - window.scrollY + : mouseEvent.offsetY; // var eventXPos = (mouseEvent.offsetX === undefined) ? mouseEvent.layerX : mouseEvent.offsetX; // var eventYPos = (mouseEvent.offsetY === undefined) ? mouseEvent.layerY : mouseEvent.offsetY; @@ -4760,14 +5360,14 @@ // ~= scroll_real2pix // // TODO Refactor real2pix to return an object instead of sending in reference vars? - mx.scroll_real2pix = function(sv) { + mx.scroll_real2pix = function (sv) { // Param types: // sv - mx.SCROLLBAR if (sv.range === 0.0) { return { s1: sv.a1, - sw: sv.a2 - sv.a1 + sw: sv.a2 - sv.a1, }; // out.s1 = sv.a1; // out.sw = sv.a2 - sv.a1; @@ -4795,7 +5395,7 @@ return { s1: ts1, - sw: Math.max(ts2 - ts1, sv.swmin) + sw: Math.max(ts2 - ts1, sv.swmin), }; // out.s1 = ts1; // out.sw = Math.max(ts2 - ts1, sv.swmin); @@ -4809,7 +5409,7 @@ * @param op Optional op-code for XW_DRAW * @private */ - mx.redrawScrollbar = function(sv, Mx, op) { + mx.redrawScrollbar = function (sv, Mx, op) { var x; var y; var xcc; @@ -4845,17 +5445,41 @@ if (op === mx.XW_DRAW) { var arrow = sv.arrow; // int - mx.shadowbox(Mx, xcc, ycc, arrow, yss - 1, mx.L_ArrowLeft, 2, "", 0); - mx.shadowbox(Mx, xcc + xss - arrow, ycc, arrow - 1, yss, mx.L_ArrowRight, 2, "", 0); + mx.shadowbox( + Mx, + xcc, + ycc, + arrow, + yss - 1, + mx.L_ArrowLeft, + 2, + "", + 0 + ); + mx.shadowbox( + Mx, + xcc + xss - arrow, + ycc, + arrow - 1, + yss, + mx.L_ArrowRight, + 2, + "", + 0 + ); } - if (mx.LEGACY_RENDER) { mx.draw_line(Mx, Mx.fg, xcc + sv.a1, y, xcc + sv.a2, y); mx.shadowbox(Mx, xcc + p1, ycc, sw + 1, yss, 1, 2, "", 0); } else { // Veritical gradiant - var lingrad = ctx.createLinearGradient(xcc + sv.a1, 0, xcc + sv.a2, 0); + var lingrad = ctx.createLinearGradient( + xcc + sv.a1, + 0, + xcc + sv.a2, + 0 + ); lingrad.addColorStop(0, Mx.xwbs); lingrad.addColorStop(0.5, Mx.xwts); lingrad.addColorStop(1, Mx.xwbs); @@ -4864,7 +5488,18 @@ var lingrad = ctx.createLinearGradient(0, ycc, 0, ycc + yss); lingrad.addColorStop(0.1, Mx.xwts); lingrad.addColorStop(0.75, Mx.xwbs); - mx.draw_round_box(Mx, Mx.xwbg, xcc + p1, ycc, sw + 1, yss, 1, lingrad, 8, Mx.xwbs); + mx.draw_round_box( + Mx, + Mx.xwbg, + xcc + p1, + ycc, + sw + 1, + yss, + 1, + lingrad, + 8, + Mx.xwbs + ); } // else vertical scroll bar @@ -4876,8 +5511,28 @@ } if (op === mx.XW_DRAW) { var arrow = sv.arrow; // int - mx.shadowbox(Mx, xcc, ycc, xss - 1, arrow, mx.L_ArrowUp, 2, "", 0); - mx.shadowbox(Mx, xcc, ycc + yss - arrow, xss - 1, arrow, mx.L_ArrowDown, 2, "", 0); + mx.shadowbox( + Mx, + xcc, + ycc, + xss - 1, + arrow, + mx.L_ArrowUp, + 2, + "", + 0 + ); + mx.shadowbox( + Mx, + xcc, + ycc + yss - arrow, + xss - 1, + arrow, + mx.L_ArrowDown, + 2, + "", + 0 + ); } if (mx.LEGACY_RENDER) { @@ -4885,7 +5540,12 @@ mx.shadowbox(Mx, xcc, ycc + p1, xss, sw + 1, 1, 2, "", 0); } else { // Horizontal gradiant - var lingrad = ctx.createLinearGradient(0, ycc + sv.a1, 0, ycc + sv.a2); + var lingrad = ctx.createLinearGradient( + 0, + ycc + sv.a1, + 0, + ycc + sv.a2 + ); lingrad.addColorStop(0, Mx.xwbs); lingrad.addColorStop(0.5, Mx.xwts); lingrad.addColorStop(1, Mx.xwbs); @@ -4894,9 +5554,19 @@ var lingrad = ctx.createLinearGradient(xcc, 0, xcc + xss, 0); lingrad.addColorStop(0.1, Mx.xwts); lingrad.addColorStop(0.75, Mx.xwbs); - mx.draw_round_box(Mx, Mx.xwbg, xcc - 1, ycc + p1, xss, sw + 1, 1, lingrad, 8, Mx.xwbs); + mx.draw_round_box( + Mx, + Mx.xwbg, + xcc - 1, + ycc + p1, + xss, + sw + 1, + 1, + lingrad, + 8, + Mx.xwbs + ); } - } sv.s1 = s1; @@ -4912,12 +5582,12 @@ * @returns {number} pixel.clipped - true if the point would have or has been clipped * @private */ - mx.real_to_pixel = function(Mx, x, y, clip) { + mx.real_to_pixel = function (Mx, x, y, clip) { var stk4 = mx.origin(Mx.origin, 4, Mx.stk[Mx.level]); - if ((stk4.xscl === 0.0) || (stk4.yscl === 0.0)) { + if (stk4.xscl === 0.0 || stk4.yscl === 0.0) { return { x: 0, - y: 0 + y: 0, }; } @@ -4934,7 +5604,7 @@ var clipped_y = false; if (x !== null) { - clipped_x = ((x > stk4.xmax) || (x < stk4.xmin)); + clipped_x = x > stk4.xmax || x < stk4.xmin; if (clip) { x = Math.min(x, stk4.xmax); x = Math.max(x, stk4.xmin); @@ -4942,7 +5612,7 @@ x = Math.round((x - xxmin) * xscl) + left; } if (y !== null) { - clipped_y = ((y > stk4.ymin) || (y < stk4.ymax)); + clipped_y = y > stk4.ymin || y < stk4.ymax; if (clip) { y = Math.min(y, stk4.ymin); y = Math.max(y, stk4.ymax); @@ -4958,7 +5628,7 @@ y: y, clipped_x: clipped_x, clipped_y: clipped_y, - clipped: (clipped_x || clipped_y) + clipped: clipped_x || clipped_y, }; }; @@ -4968,14 +5638,14 @@ * @param ypos * @private */ - mx.pixel_to_real = function(Mx, xpos, ypos) { + mx.pixel_to_real = function (Mx, xpos, ypos) { var iretx = Math.min(Mx.r, Math.max(Mx.l, xpos)); var irety = Math.min(Mx.b, Math.max(Mx.t, ypos)); var retx; var rety; var k = Mx.level; - if ((Mx.origin !== 2) && (Mx.origin !== 3)) { + if (Mx.origin !== 2 && Mx.origin !== 3) { retx = Mx.stk[k].xmin + (iretx - Mx.stk[k].x1) * Mx.stk[k].xscl; } else { retx = Mx.stk[k].xmin + (Mx.stk[k].x2 - iretx) * Mx.stk[k].xscl; @@ -4988,7 +5658,7 @@ return { x: retx, - y: rety + y: rety, }; }; @@ -4998,9 +5668,9 @@ * @param ncolors * @private */ - mx.colormap = function(Mx, map, ncolors) { + mx.colormap = function (Mx, map, ncolors) { Mx.pixel = new ColorMap(map, { - ncolors: ncolors + ncolors: ncolors, }); return; }; @@ -5013,14 +5683,14 @@ * @param h * @private */ - mx.colorbar = function(Mx, x, y, w, h) { + mx.colorbar = function (Mx, x, y, w, h) { if (!Mx.pixel) { m.log.warn("COLORMAP not initialized, cannot draw colorbar"); return; } Mx.pixel.setRange(0, Mx.pixel.map.length); for (var j = 1; j < h; j++) { - var cidx = Math.floor(Mx.pixel.map.length * (j - 1) / h); + var cidx = Math.floor((Mx.pixel.map.length * (j - 1)) / h); mx.draw_line(Mx, cidx, x, y + h - j, x + w, y + h - j); } mx.draw_box(Mx, Mx.fg, x + 0.5, y, w, h); @@ -5034,14 +5704,14 @@ * @param h * @private */ - mx.legend_colorbar = function(Mx, x, y, w, h) { + mx.legend_colorbar = function (Mx, x, y, w, h) { if (!Mx.pixel) { m.log.warn("COLORMAP not initialized, cannot draw colorbar"); return; } Mx.pixel.setRange(0, Mx.pixel.map.length); for (var j = 1; j < w; j++) { - var cidx = Math.floor(Mx.pixel.map.length * (j - 1) / w); + var cidx = Math.floor((Mx.pixel.map.length * (j - 1)) / w); mx.draw_line(Mx, cidx, x + w - j, y, x + w - j, y + h); } mx.draw_box(Mx, Mx.fg, x + 0.5, y, w, h); @@ -5080,7 +5750,22 @@ * @param h * optional height */ - function renderImageNoTypedArrays(Mx, ctx, buf, opacity, downscaling, smoothing, x, y, w, h, sx, sy, sw, sh) { + function renderImageNoTypedArrays( + Mx, + ctx, + buf, + opacity, + downscaling, + smoothing, + x, + y, + w, + h, + sx, + sy, + sw, + sh + ) { if (sx === undefined) { sx = 0; } @@ -5099,7 +5784,10 @@ Mx._renderCanvas.height = buf.height; var imgctx = Mx._renderCanvas.getContext("2d"); - var imgd = imgctx.createImageData(Mx._renderCanvas.width, Mx._renderCanvas.height); + var imgd = imgctx.createImageData( + Mx._renderCanvas.width, + Mx._renderCanvas.height + ); var src = new Uint32Array(buf); for (var ii = 0; ii < src.length; ++ii) { var index = ii * 4; @@ -5151,7 +5839,22 @@ * @param h * optional height */ - function renderImageTypedArrays(Mx, ctx, buf, opacity, downscaling, smoothing, x, y, w, h, sx, sy, sw, sh) { + function renderImageTypedArrays( + Mx, + ctx, + buf, + opacity, + downscaling, + smoothing, + x, + y, + w, + h, + sx, + sy, + sw, + sh + ) { if (sx === undefined) { sx = 0; } @@ -5165,13 +5868,16 @@ sh = buf.height - sy; } - if ((buf.width < 32768) && (buf.height < 32768)) { + if (buf.width < 32768 && buf.height < 32768) { // If the source buffer is small enough to be directly rendered, do that Mx._renderCanvas.width = buf.width; Mx._renderCanvas.height = buf.height; var imgctx = Mx._renderCanvas.getContext("2d"); - var imgd = imgctx.createImageData(Mx._renderCanvas.width, Mx._renderCanvas.height); + var imgd = imgctx.createImageData( + Mx._renderCanvas.width, + Mx._renderCanvas.height + ); // TODO - This may not be portable to all browsers, if not // we need to choose between this approach and the traditional @@ -5191,7 +5897,7 @@ imgctx.putImageData(imgd, 0, 0); } else { if (!downscaling) { - if ((sw < 32767) && (sh < 32767)) { + if (sw < 32767 && sh < 32767) { // The clipped image is small enough to directly render Mx._renderCanvas.width = sw; Mx._renderCanvas.height = sh; @@ -5208,7 +5914,16 @@ // Downscale to the destination size Mx._renderCanvas.width = w; Mx._renderCanvas.height = h; - scaleImage(Mx, Mx._renderCanvas, buf, sx, sy, sw, sh, downscaling); + scaleImage( + Mx, + Mx._renderCanvas, + buf, + sx, + sy, + sw, + sh, + downscaling + ); sw = Mx._renderCanvas.width; sh = Mx._renderCanvas.height; } @@ -5266,14 +5981,18 @@ // Destination element var imgctx = img.getContext("2d"); - if (!Mx.scaledImgd || Mx.scaledImgd.width !== w || Mx.scaledImgd.height !== h) { + if ( + !Mx.scaledImgd || + Mx.scaledImgd.width !== w || + Mx.scaledImgd.height !== h + ) { Mx.scaledImgd = imgctx.createImageData(w, h); } var dest = new Uint32Array(Mx.scaledImgd.data.buffer); // Scaling factor - var width_scaling = (sw / w); - var height_scaling = (sh / h); + var width_scaling = sw / w; + var height_scaling = sh / h; // Perform the scaling var xx = 0; @@ -5290,7 +6009,7 @@ for (var ii = 0; ii < dest.length; ii++) { xx = Math.round(Math.floor(ii % w) * width_scaling) + sx; yy = Math.round(Math.floor(ii / w) * height_scaling) + sy; - jj = Math.floor((yy * buf.width) + xx); + jj = Math.floor(yy * buf.width + xx); value = src[jj]; if (buf.contents !== "rgba") { @@ -5303,25 +6022,33 @@ for (var ii = 0; ii < dest.length; ii++) { xx = Math.round(Math.floor(ii % w) * width_scaling) + sx; yy = Math.round(Math.floor(ii / w) * height_scaling) + sy; - jj = Math.floor((yy * buf.width) + xx); + jj = Math.floor(yy * buf.width + xx); value = src[jj]; - if (downscaling === "avg") { // average + if (downscaling === "avg") { + // average for (var j = 1; j < width_scaling; j++) { value += src[jj + j]; } value = Math.round(value / width_scaling); - } else if (downscaling === "min") { // min + } else if (downscaling === "min") { + // min for (var j = 1; j < width_scaling; j++) { value = Math.min(value, src[jj + j]); } - } else if (downscaling === "max") { // max + } else if (downscaling === "max") { + // max for (var j = 1; j < width_scaling; j++) { value = Math.max(value, src[jj + j]); } - } else if (downscaling === "minmax") { // min/max + } else if (downscaling === "minmax") { + // min/max for (var j = 1; j < width_scaling; j++) { - value = (Math.abs(value - colorOffset) > Math.abs(src[jj + j] - colorOffset)) ? value : src[jj + j]; + value = + Math.abs(value - colorOffset) > + Math.abs(src[jj + j] - colorOffset) + ? value + : src[jj + j]; } } @@ -5333,7 +6060,10 @@ imgctx.putImageData(Mx.scaledImgd, 0, 0); } - var renderImage = (typeof Uint8ClampedArray === 'undefined') ? renderImageNoTypedArrays : renderImageTypedArrays; + var renderImage = + typeof Uint8ClampedArray === "undefined" + ? renderImageNoTypedArrays + : renderImageTypedArrays; /** * @param Mx @@ -5341,15 +6071,17 @@ * @param shift * @private */ - mx.shift_image_rows = function(Mx, buf, shift, zerofill) { + mx.shift_image_rows = function (Mx, buf, shift, zerofill) { var imgd = new Uint32Array(buf); - if (shift > 0) { // shift down + if (shift > 0) { + // shift down shift = shift * buf.width; imgd.set(imgd.subarray(0, imgd.length - shift), shift); if (zerofill) { imgd.fill(0, 0, shift); } - } else if (shift < 0) { // shift up + } else if (shift < 0) { + // shift up shift = Math.abs(shift) * buf.width; imgd.set(imgd.subarray(shift)); if (zerofill) { @@ -5369,7 +6101,15 @@ * @param zmax * @private */ - mx.update_image_row = function(Mx, buf, data, row, zmin, zmax, xcompression) { + mx.update_image_row = function ( + Mx, + buf, + data, + row, + zmin, + zmax, + xcompression + ) { var imgd = new Uint32Array(buf, row * buf.width * 4, buf.width); Mx.pixel.setRange(zmin, zmax); @@ -5379,24 +6119,32 @@ var didx = Math.floor(i * xc); var value = data[didx]; if (xc > 1) { - if (xcompression === 1) { // average + if (xcompression === 1) { + // average for (var j = 1; j < xc; j++) { value += data[didx + j]; } - value = (value / xc); - } else if (xcompression === 2) { // min + value = value / xc; + } else if (xcompression === 2) { + // min for (var j = 1; j < xc; j++) { value = Math.min(value, data[didx + j]); } - } else if (xcompression === 3) { // max + } else if (xcompression === 3) { + // max for (var j = 1; j < xc; j++) { value = Math.max(value, data[didx + j]); } - } else if (xcompression === 4) { // first + } else if (xcompression === 4) { + // first value = data[i]; - } else if (xcompression === 5) { // max abs + } else if (xcompression === 5) { + // max abs for (var j = 1; j < xc; j++) { - value = Math.max(Math.abs(value), Math.abs(data[didx + j])); + value = Math.max( + Math.abs(value), + Math.abs(data[didx + j]) + ); } } } @@ -5417,7 +6165,16 @@ * @param zmax * @private */ - mx.create_image = function(Mx, data, subsize, w, h, zmin, zmax, xcompression) { + mx.create_image = function ( + Mx, + data, + subsize, + w, + h, + zmin, + zmax, + xcompression + ) { var ctx = Mx.active_canvas.getContext("2d"); if (!Mx.pixel) { @@ -5425,7 +6182,6 @@ Mx.pixel = new ColorMap(m.Mc.colormap[1].colors); } - Mx.pixel.setRange(zmin, zmax); w = Math.ceil(w); h = Math.ceil(h); @@ -5440,12 +6196,12 @@ for (var i = 0; i < imgd.length; i++) { var ix; var iy; - if ((Mx.origin === 1) || (Mx.origin === 4)) { + if (Mx.origin === 1 || Mx.origin === 4) { ix = Math.floor(i % w); } else { ix = w - Math.floor(i % w) - 1; } - if ((Mx.origin === 3) || (Mx.origin === 4)) { + if (Mx.origin === 3 || Mx.origin === 4) { iy = Math.floor(i / w); } else { iy = h - Math.floor(i / w) - 1; @@ -5453,32 +6209,39 @@ if (iy === 1) { var test = 1; } - var didx = (iy * subsize) + Math.floor(ix * nxc); + var didx = iy * subsize + Math.floor(ix * nxc); var value = data[didx]; if (nxc > 1) { - if (xcompression === 1) { // average + if (xcompression === 1) { + // average for (var j = 1; j < nxc; j++) { value += data[didx + j]; } value = value / nxc; - } else if (xcompression === 2) { // min + } else if (xcompression === 2) { + // min for (var j = 1; j < nxc; j++) { value = Math.min(value, data[didx + j]); } - } else if (xcompression === 3) { // max + } else if (xcompression === 3) { + // max for (var j = 1; j < nxc; j++) { value = Math.max(value, data[didx + j]); } - } else if (xcompression === 4) { // first + } else if (xcompression === 4) { + // first value = data[didx]; - } else if (xcompression === 5) { // max abs + } else if (xcompression === 5) { + // max abs for (var j = 1; j < nxc; j++) { - value = Math.max(Math.abs(value), Math.abs(data[didx + j])); + value = Math.max( + Math.abs(value), + Math.abs(data[didx + j]) + ); } } } - var colorIdx = Mx.pixel.getColorIndex(value); imgd[i] = colorIdx; } @@ -5488,12 +6251,12 @@ return buf; }; - mx.resize_image_height = function(Mx, buf, h) { + mx.resize_image_height = function (Mx, buf, h) { if (buf.height === h) { return buf; } - var buf2 = ArrayBuffer.transfer(buf, (buf.width * h * 4)); + var buf2 = ArrayBuffer.transfer(buf, buf.width * h * 4); Object.assign(buf2, buf); buf2.height = h; @@ -5514,7 +6277,20 @@ * @param smoothing * @private */ - mx.put_image = function(Mx, data, nx, ny, nex, ney, xd, yd, level, opacity, smoothing, downscaling) { + mx.put_image = function ( + Mx, + data, + nx, + ny, + nex, + ney, + xd, + yd, + level, + opacity, + smoothing, + downscaling + ) { var ctx = Mx.active_canvas.getContext("2d"); if (!Mx.pixel) { @@ -5546,7 +6322,18 @@ } //render the buffered canvas onto the original canvas element - renderImage(Mx, ctx, buf, opacity, downscaling, smoothing, xd, yd, w, h); + renderImage( + Mx, + ctx, + buf, + opacity, + downscaling, + smoothing, + xd, + yd, + w, + h + ); // Return the image in case the caller wishes to cache it return buf; @@ -5563,17 +6350,26 @@ * @param smoothing * @private */ - mx.draw_image = function(Mx, buf, xmin, ymin, xmax, ymax, opacity, smoothing, downscaling) { + mx.draw_image = function ( + Mx, + buf, + xmin, + ymin, + xmax, + ymax, + opacity, + smoothing, + downscaling + ) { var view_xmin = Math.max(xmin, Mx.stk[Mx.level].xmin); var view_xmax = Math.min(xmax, Mx.stk[Mx.level].xmax); var view_ymin = Math.max(ymin, Mx.stk[Mx.level].ymin); var view_ymax = Math.min(ymax, Mx.stk[Mx.level].ymax); - - if ((buf.width <= 1) || Math.abs(xmax - xmin) === 0) { + if (buf.width <= 1 || Math.abs(xmax - xmin) === 0) { return; } - if ((buf.height <= 1) || Math.abs(ymax - ymin) === 0) { + if (buf.height <= 1 || Math.abs(ymax - ymin) === 0) { return; } var rx = buf.width / (xmax - xmin); @@ -5591,36 +6387,60 @@ if (Mx.origin === 1) { // regular x, regular y sy = Math.max(0, Math.floor((ymax - view_ymax) * ry)); - sh = Math.min(buf.height - sy, Math.floor((view_ymax - view_ymin) * ry)); + sh = Math.min( + buf.height - sy, + Math.floor((view_ymax - view_ymin) * ry) + ); sx = Math.max(0, Math.floor((view_xmin - xmin) * rx)); - sw = Math.min(buf.width - sx, Math.floor((view_xmax - view_xmin) * rx)); + sw = Math.min( + buf.width - sx, + Math.floor((view_xmax - view_xmin) * rx) + ); ul = mx.real_to_pixel(Mx, view_xmin, view_ymax); lr = mx.real_to_pixel(Mx, view_xmax, view_ymin); } else if (Mx.origin === 2) { // inverted x, regular y sy = Math.max(0, Math.floor((ymax - view_ymax) * ry)); - sh = Math.min(buf.height - sy, Math.floor((view_ymax - view_ymin) * ry)); + sh = Math.min( + buf.height - sy, + Math.floor((view_ymax - view_ymin) * ry) + ); sx = Math.max(0, Math.ceil((view_xmin - xmin) * rx)); - sw = Math.min(buf.width - sx, Math.floor((view_xmax - view_xmin) * rx)); + sw = Math.min( + buf.width - sx, + Math.floor((view_xmax - view_xmin) * rx) + ); ul = mx.real_to_pixel(Mx, view_xmax, view_ymax); lr = mx.real_to_pixel(Mx, view_xmin, view_ymin); } else if (Mx.origin === 3) { // inverted x, inverted y sy = Math.max(0, Math.ceil((view_ymin - ymin) * ry)); - sh = Math.min(buf.height - sy, Math.floor((view_ymax - view_ymin) * ry)); + sh = Math.min( + buf.height - sy, + Math.floor((view_ymax - view_ymin) * ry) + ); sx = Math.max(0, Math.ceil((view_xmin - xmin) * rx)); - sw = Math.min(buf.width - sx, Math.floor((view_xmax - view_xmin) * rx)); + sw = Math.min( + buf.width - sx, + Math.floor((view_xmax - view_xmin) * rx) + ); ul = mx.real_to_pixel(Mx, view_xmax, view_ymin); lr = mx.real_to_pixel(Mx, view_xmin, view_ymax); } else if (Mx.origin === 4) { // regular x, inverted y sy = Math.max(0, Math.ceil((view_ymin - ymin) * ry)); - sh = Math.min(buf.height - sy, Math.floor((view_ymax - view_ymin) * ry)); + sh = Math.min( + buf.height - sy, + Math.floor((view_ymax - view_ymin) * ry) + ); sx = Math.max(0, Math.floor((view_xmin - xmin) * rx)); - sw = Math.min(buf.width - sx, Math.floor((view_xmax - view_xmin) * rx)); + sw = Math.min( + buf.width - sx, + Math.floor((view_xmax - view_xmin) * rx) + ); ul = mx.real_to_pixel(Mx, view_xmin, view_ymin); lr = mx.real_to_pixel(Mx, view_xmax, view_ymax); @@ -5640,7 +6460,7 @@ var ratio = (Mx.r - Mx.l) / sw; // if the ratio is greater than the smoothing value // turn on smoothing - smoothing = (ratio <= smoothing); + smoothing = ratio <= smoothing; } //render the buffered canvas onto the original canvas element @@ -5649,13 +6469,27 @@ ctx.beginPath(); ctx.rect(Mx.l, Mx.t, Mx.r - Mx.l, Mx.b - Mx.t); ctx.clip(); - renderImage(Mx, ctx, buf, opacity, downscaling, smoothing, ul.x, ul.y, iw, ih, sx, sy, sw, sh); + renderImage( + Mx, + ctx, + buf, + opacity, + downscaling, + smoothing, + ul.x, + ul.y, + iw, + ih, + sx, + sy, + sw, + sh + ); ctx.restore(); }; // Node: Export function module.exports = mx; - -}()); +})(); /////////////////////////////////////////////////////////////////////////////// diff --git a/js/plugins.js b/js/plugins.js index 3f0a35b..220fddf 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -23,19 +23,9 @@ * under the License. */ -/* global module */ -/* global require */ - -(function() { - -// Bundle all the standard-plugins into this module -module.exports = { - Plugin : require("./sigplot.plugin"), - AccordionPlugin : require("./sigplot.accordion"), - AnnotationPlugin : require("./sigplot.annotations"), - BoxesPlugin : require("./sigplot.boxes"), - PlaybackControlsPlugin : require("./sigplot.playback"), - SliderPlugin : require("./sigplot.slider") -}; - -}()); +export {default as Plugin} from "./sigplot.plugin"; +export {default as AccordionPlugin} from "./sigplot.accordion"; +export {default as AnnotationPlugin} from "./sigplot.annotations"; +export {default as BoxesPlugin} from "./sigplot.boxes"; +export {default as PlaybackControlsPlugin} from "./sigplot.playback"; +export {default as SliderPlugin} from "./sigplot.slider"; \ No newline at end of file diff --git a/js/sigplot.accordion.js b/js/sigplot.accordion.js index f00a7e1..2900dcf 100644 --- a/js/sigplot.accordion.js +++ b/js/sigplot.accordion.js @@ -24,7 +24,7 @@ */ /* global module */ /* global require */ -(function() { +(function () { var m = require("./m"); var mx = require("./mx"); var plugin = require("./sigplot.plugin"); @@ -37,97 +37,97 @@ pluginSetup() { this.defineProperty("center_line_style", { defaultValue: {}, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("edge_line_style", { defaultValue: {}, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("fill_style", { defaultValue: {}, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("direction", { defaultValue: "vertical", - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("mode", { defaultValue: "absolute", - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("draw_center_line", { defaultValue: true, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("prevent_drag", { defaultValue: false, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("prevent_move", { defaultValue: false, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("prevent_resize", { defaultValue: false, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("discrete_widths", { defaultValue: undefined, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("min_width", { defaultValue: undefined, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("max_width", { defaultValue: undefined, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("shade_area", { defaultValue: undefined, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("draw_edge_lines", { defaultValue: true, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("draw_center_line", { defaultValue: true, - refreshOnChange: true + refreshOnChange: true, }); this.defineProperty("center", { refreshOnChange: true, callback: (value) => { this._onCenterChange(value); }, - help: "center of the accordion in plot units (not pixels)" + help: "center of the accordion in plot units (not pixels)", }); this.defineProperty("highlight", { refreshOnChange: true, - help: "highlight the center of the accordion" + help: "highlight the center of the accordion", }); this.defineProperty("edge_highlight", { refreshOnChange: true, - help: "highlight the edges of the accordion" + help: "highlight the edges of the accordion", }); this.defineProperty("width", { refreshOnChange: true, callback: (value) => { this._onWidthChange(value); }, - help: "width of the accordion in plot units (not pixels)" + help: "width of the accordion in plot units (not pixels)", }); this.defineProperty("center_location", { refreshOnChange: true, - help: "center of the accordion in pixels" + help: "center of the accordion in pixels", }); this.defineProperty("loc_1", { refreshOnChange: true, - help: "location of one of the accordion bars in pixels" + help: "location of one of the accordion bars in pixels", }); this.defineProperty("loc_2", { refreshOnChange: true, - help: "location of one of the accordion bars in pixels" + help: "location of one of the accordion bars in pixels", }); } @@ -138,15 +138,22 @@ this.addListener("mdown", (evt) => { this._onMouseDown(evt); }); - document.addEventListener("mouseup", () => { - this._onDocMouseUp(); - }, false); + document.addEventListener( + "mouseup", + () => { + this._onDocMouseUp(); + }, + false + ); } pluginDispose() {} pluginRefresh() { - if ((this.properties.center === undefined) || (this.properties.width === undefined)) { + if ( + this.properties.center === undefined || + this.properties.width === undefined + ) { return; } let Mx = this.Mx; @@ -155,31 +162,55 @@ let center_pxl; if (this.properties.mode === "absolute") { - center_pxl = mx.real_to_pixel(Mx, this.properties.center, this.properties.center); + center_pxl = mx.real_to_pixel( + Mx, + this.properties.center, + this.properties.center + ); } else if (this.properties.mode === "relative") { if (this.properties.direction === "vertical") { - let c = Mx.stk[0].x1 + (Mx.stk[0].x2 - Mx.stk[0].x1) * this.properties.center; - center_pxl = mx.real_to_pixel(Mx, mx.pixel_to_real(Mx, c, c).x, mx.pixel_to_real(Mx, c, c).y); + let c = + Mx.stk[0].x1 + + (Mx.stk[0].x2 - Mx.stk[0].x1) * this.properties.center; + center_pxl = mx.real_to_pixel( + Mx, + mx.pixel_to_real(Mx, c, c).x, + mx.pixel_to_real(Mx, c, c).y + ); } else if (this.properties.direction === "horizontal") { - let c = Mx.stk[0].y1 + (Mx.stk[0].y2 - Mx.stk[0].y1) * this.properties.center; - center_pxl = mx.real_to_pixel(Mx, mx.pixel_to_real(Mx, c, c).x, mx.pixel_to_real(Mx, c, c).y); + let c = + Mx.stk[0].y1 + + (Mx.stk[0].y2 - Mx.stk[0].y1) * this.properties.center; + center_pxl = mx.real_to_pixel( + Mx, + mx.pixel_to_real(Mx, c, c).x, + mx.pixel_to_real(Mx, c, c).y + ); } } let pxl_1, pxl_2; if (this.properties.mode === "absolute") { - pxl_1 = mx.real_to_pixel(Mx, this.properties.center - (this.properties.width / 2), this.properties.center - (this.properties.width / 2)); - pxl_2 = mx.real_to_pixel(Mx, this.properties.center + (this.properties.width / 2), this.properties.center + (this.properties.width / 2)); - } else if (this.properties.mode === 'relative') { + pxl_1 = mx.real_to_pixel( + Mx, + this.properties.center - this.properties.width / 2, + this.properties.center - this.properties.width / 2 + ); + pxl_2 = mx.real_to_pixel( + Mx, + this.properties.center + this.properties.width / 2, + this.properties.center + this.properties.width / 2 + ); + } else if (this.properties.mode === "relative") { let w = Mx.stk[0].x2 - Mx.stk[0].x1; let h = Mx.stk[0].y2 - Mx.stk[0].y1; pxl_1 = { - x: center_pxl.x - (this.properties.width * w / 2), - y: center_pxl.y - (this.properties.width * h / 2) + x: center_pxl.x - (this.properties.width * w) / 2, + y: center_pxl.y - (this.properties.width * h) / 2, }; pxl_2 = { - x: center_pxl.x + (this.properties.width * w / 2), - y: center_pxl.y + (this.properties.width * h / 2) + x: center_pxl.x + (this.properties.width * w) / 2, + y: center_pxl.y + (this.properties.width * h) / 2, }; } if (this.properties.direction === "vertical") { @@ -192,22 +223,54 @@ this.properties.loc_2 = Math.min(Mx.b, pxl_1.y); } - if (this.properties.shade_area && (Math.abs(this.properties.loc_2 - this.properties.loc_1) > 0)) { + if ( + this.properties.shade_area && + Math.abs(this.properties.loc_2 - this.properties.loc_1) > 0 + ) { let oldAlpha = ctx.globalAlpha; - ctx.globalAlpha = (this.properties.fill_style.opacity !== undefined) ? this.properties.fill_style.opacity : 0.4; - ctx.fillStyle = (this.properties.fill_style.fillStyle !== undefined) ? this.properties.fill_style.fillStyle : Mx.hi; + ctx.globalAlpha = + this.properties.fill_style.opacity !== undefined + ? this.properties.fill_style.opacity + : 0.4; + ctx.fillStyle = + this.properties.fill_style.fillStyle !== undefined + ? this.properties.fill_style.fillStyle + : Mx.hi; if (this.properties.direction === "vertical") { - ctx.fillRect(this.properties.loc_1, Mx.t, this.properties.loc_2 - this.properties.loc_1, Mx.b - Mx.t); + ctx.fillRect( + this.properties.loc_1, + Mx.t, + this.properties.loc_2 - this.properties.loc_1, + Mx.b - Mx.t + ); } else if (this.properties.direction === "horizontal") { - ctx.fillRect(Mx.l, this.properties.loc_1, Mx.r - Mx.l, this.properties.loc_2 - this.properties.loc_1); + ctx.fillRect( + Mx.l, + this.properties.loc_1, + Mx.r - Mx.l, + this.properties.loc_2 - this.properties.loc_1 + ); } ctx.globalAlpha = oldAlpha; } - if (this.properties.draw_edge_lines || this.properties.edge_highlight || this.edge_dragging) { - ctx.lineWidth = (this.properties.edge_line_style.lineWidth !== undefined) ? this.properties.edge_line_style.lineWidth : 1; - ctx.lineCap = (this.properties.edge_line_style.lineCap !== undefined) ? this.properties.edge_line_style.lineCap : "square"; - ctx.strokeStyle = (this.properties.edge_line_style.strokeStyle !== undefined) ? this.properties.edge_line_style.strokeStyle : Mx.fg; + if ( + this.properties.draw_edge_lines || + this.properties.edge_highlight || + this.edge_dragging + ) { + ctx.lineWidth = + this.properties.edge_line_style.lineWidth !== undefined + ? this.properties.edge_line_style.lineWidth + : 1; + ctx.lineCap = + this.properties.edge_line_style.lineCap !== undefined + ? this.properties.edge_line_style.lineCap + : "square"; + ctx.strokeStyle = + this.properties.edge_line_style.strokeStyle !== undefined + ? this.properties.edge_line_style.strokeStyle + : Mx.fg; if (this.edge_dragging || this.properties.edge_highlight) { ctx.lineWidth = Math.ceil(ctx.lineWidth * 1.2); } @@ -233,9 +296,18 @@ } if (this.properties.draw_center_line) { - ctx.lineWidth = (this.properties.center_line_style.lineWidth !== undefined) ? this.properties.center_line_style.lineWidth : 1; - ctx.lineCap = (this.properties.center_line_style.lineCap !== undefined) ? this.properties.center_line_style.lineCap : "square"; - ctx.strokeStyle = (this.properties.center_line_style.strokeStyle !== undefined) ? this.properties.center_line_style.strokeStyle : Mx.fg; + ctx.lineWidth = + this.properties.center_line_style.lineWidth !== undefined + ? this.properties.center_line_style.lineWidth + : 1; + ctx.lineCap = + this.properties.center_line_style.lineCap !== undefined + ? this.properties.center_line_style.lineCap + : "square"; + ctx.strokeStyle = + this.properties.center_line_style.strokeStyle !== undefined + ? this.properties.center_line_style.strokeStyle + : Mx.fg; if (this.dragging || this.properties.highlight) { ctx.lineWidth = Math.ceil(ctx.lineWidth * 1.2); } @@ -275,31 +347,47 @@ return; } // Ignore if the mouse is outside of the plot area - if ((evt.xpos < Mx.l) || (evt.xpos > Mx.r)) { + if (evt.xpos < Mx.l || evt.xpos > Mx.r) { this.properties.highlight = false; return; } - if ((evt.ypos > Mx.b) || (evt.ypos < Mx.t)) { + if (evt.ypos > Mx.b || evt.ypos < Mx.t) { this.properties.highlight = false; return; } // If the mouse is close, "highlight" the line - let lineWidth = (this.properties.center_line_style.lineWidth !== undefined) ? this.properties.center_line_style.lineWidth : 1; - let elineWidth = (this.properties.edge_line_style.lineWidth !== undefined) ? this.properties.edge_line_style.lineWidth : 1; + let lineWidth = + this.properties.center_line_style.lineWidth !== undefined + ? this.properties.center_line_style.lineWidth + : 1; + let elineWidth = + this.properties.edge_line_style.lineWidth !== undefined + ? this.properties.edge_line_style.lineWidth + : 1; if (!this.dragging && !this.edge_dragging) { if (Mx.warpbox) { return; } // Don't highlight if a warpbox is being drawn if (this.properties.direction === "vertical") { if (!this.properties.prevent_move) { - if (Math.abs(this.properties.center_location - evt.xpos) < (lineWidth + 5)) { + if ( + Math.abs( + this.properties.center_location - evt.xpos + ) < + lineWidth + 5 + ) { this.properties.highlight = true; } else { this.properties.highlight = false; } } if (!this.properties.prevent_resize) { - if ((Math.abs(this.properties.loc_1 - evt.xpos) < (elineWidth + 5)) || (Math.abs(this.properties.loc_2 - evt.xpos) < (elineWidth + 5))) { + if ( + Math.abs(this.properties.loc_1 - evt.xpos) < + elineWidth + 5 || + Math.abs(this.properties.loc_2 - evt.xpos) < + elineWidth + 5 + ) { this.properties.edge_highlight = true; } else { this.properties.edge_highlight = false; @@ -307,14 +395,24 @@ } } else if (this.properties.direction === "horizontal") { if (!this.properties.prevent_move) { - if (Math.abs(this.properties.center_location - evt.ypos) < (lineWidth + 5)) { + if ( + Math.abs( + this.properties.center_location - evt.ypos + ) < + lineWidth + 5 + ) { this.properties.highlight = true; } else { this.properties.highlight = false; } } if (!this.properties.prevent_resize) { - if ((Math.abs(this.properties.loc_1 - evt.ypos) < (elineWidth + 5)) || (Math.abs(this.properties.loc_2 - evt.ypos) < (elineWidth + 5))) { + if ( + Math.abs(this.properties.loc_1 - evt.ypos) < + elineWidth + 5 || + Math.abs(this.properties.loc_2 - evt.ypos) < + elineWidth + 5 + ) { this.properties.edge_highlight = true; } else { this.properties.edge_highlight = false; @@ -328,17 +426,19 @@ var pos = mx.pixel_to_real(Mx, evt.xpos, evt.ypos); if (this.properties.direction === "vertical") { this.properties.center_location = evt.xpos; - if (this.properties.mode === 'absolute') { + if (this.properties.mode === "absolute") { this.properties.center = pos.x; - } else if (this.properties.mode === 'relative') { - this.properties.center = (evt.xpos - Mx.l) / (Mx.r - Mx.l); + } else if (this.properties.mode === "relative") { + this.properties.center = + (evt.xpos - Mx.l) / (Mx.r - Mx.l); } } else if (this.properties.direction === "horizontal") { this.properties.center_location = evt.ypos; - if (this.properties.mode === 'absolute') { + if (this.properties.mode === "absolute") { this.properties.center = pos.y; - } else if (this.properties.mode === 'relative') { - this.properties.center = (evt.ypos - Mx.t) / (Mx.b - Mx.t); + } else if (this.properties.mode === "relative") { + this.properties.center = + (evt.ypos - Mx.t) / (Mx.b - Mx.t); } } } @@ -346,16 +446,28 @@ // If we are dragging, update the slider location var pos = mx.pixel_to_real(Mx, evt.xpos, evt.ypos); if (this.properties.direction === "vertical") { - if (this.properties.mode === 'absolute') { - this.properties.width = 2 * Math.abs(this.properties.center - pos.x); - } else if (this.properties.mode === 'relative') { - this.properties.width = (2 * Math.abs(this.properties.center_location - evt.xpos)) / (Mx.r - Mx.l); + if (this.properties.mode === "absolute") { + this.properties.width = + 2 * Math.abs(this.properties.center - pos.x); + } else if (this.properties.mode === "relative") { + this.properties.width = + (2 * + Math.abs( + this.properties.center_location - evt.xpos + )) / + (Mx.r - Mx.l); } } else if (this.properties.direction === "horizontal") { - if (this.properties.mode === 'absolute') { - this.properties.width = 2 * Math.abs(this.properties.center - pos.y); - } else if (this.properties.mode === 'relative') { - this.properties.width = (2 * Math.abs(this.properties.center_location - evt.ypos)) / (Mx.b - Mx.t); + if (this.properties.mode === "absolute") { + this.properties.width = + 2 * Math.abs(this.properties.center - pos.y); + } else if (this.properties.mode === "relative") { + this.properties.width = + (2 * + Math.abs( + this.properties.center_location - evt.ypos + )) / + (Mx.b - Mx.t); } } // See if the width needs to be constrained @@ -363,10 +475,20 @@ // If the user wants to restrict the accordion to a set of // discrete widths, find the closest match let nearestIdx = 0; - let minDiff = Math.abs(this.properties.width - this.properties.discrete_widths[0]); + let minDiff = Math.abs( + this.properties.width - + this.properties.discrete_widths[0] + ); let tmpDiff = 0; - for (let idx = 1; idx < this.properties.discrete_widths.length; idx++) { - tmpDiff = Math.abs(this.properties.width - this.properties.discrete_widths[idx]); + for ( + let idx = 1; + idx < this.properties.discrete_widths.length; + idx++ + ) { + tmpDiff = Math.abs( + this.properties.width - + this.properties.discrete_widths[idx] + ); if (tmpDiff < minDiff) { nearestIdx = idx; minDiff = tmpDiff; @@ -374,10 +496,16 @@ } // Otherwise, apply min_width/max_width if defined if (this.properties.min_width) { - this.properties.width = Math.max(this.properties.width, this.properties.min_width); + this.properties.width = Math.max( + this.properties.width, + this.properties.min_width + ); } if (this.properties.max_width) { - this.properties.width = Math.min(this.properties.width, this.properties.max_width); + this.properties.width = Math.min( + this.properties.width, + this.properties.max_width + ); } } } @@ -395,31 +523,51 @@ if (this.properties.center_location === undefined) { return; } - if ((evt.xpos < Mx.l) || (evt.xpos > Mx.r)) { + if (evt.xpos < Mx.l || evt.xpos > Mx.r) { return; } - if ((evt.ypos > Mx.b) || (evt.ypos < Mx.t)) { + if (evt.ypos > Mx.b || evt.ypos < Mx.t) { return; } if (this.properties.prevent_drag) { return; } - let lineWidth = (this.properties.center_line_style.lineWidth !== undefined) ? this.properties.center_line_style.lineWidth : 1; - let elineWidth = (this.properties.edge_line_style.lineWidth !== undefined) ? this.properties.edge_line_style.lineWidth : 1; + let lineWidth = + this.properties.center_line_style.lineWidth !== undefined + ? this.properties.center_line_style.lineWidth + : 1; + let elineWidth = + this.properties.edge_line_style.lineWidth !== undefined + ? this.properties.edge_line_style.lineWidth + : 1; if (this.properties.direction === "vertical") { // prefer edge drag over center drag - if ((Math.abs(this.properties.loc_1 - evt.xpos) < (elineWidth + 5)) || (Math.abs(this.properties.loc_2 - evt.xpos) < (elineWidth + 5))) { + if ( + Math.abs(this.properties.loc_1 - evt.xpos) < + elineWidth + 5 || + Math.abs(this.properties.loc_2 - evt.xpos) < elineWidth + 5 + ) { this.edge_dragging = !this.properties.prevent_resize; evt.preventDefault(); - } else if (Math.abs(this.properties.center_location - evt.xpos) < (lineWidth + 5)) { + } else if ( + Math.abs(this.properties.center_location - evt.xpos) < + lineWidth + 5 + ) { this.dragging = !this.properties.prevent_move; evt.preventDefault(); } } else if (this.properties.direction === "horizontal") { - if ((Math.abs(this.properties.loc_1 - evt.ypos) < (elineWidth + 5)) || (Math.abs(this.properties.loc_2 - evt.ypos) < (elineWidth + 5))) { + if ( + Math.abs(this.properties.loc_1 - evt.ypos) < + elineWidth + 5 || + Math.abs(this.properties.loc_2 - evt.ypos) < elineWidth + 5 + ) { this.edge_dragging = !this.properties.prevent_resize; evt.preventDefault(); - } else if (Math.abs(this.properties.center_location - evt.ypos) < (lineWidth + 5)) { + } else if ( + Math.abs(this.properties.center_location - evt.ypos) < + lineWidth + 5 + ) { this.dragging = !this.properties.prevent_move; evt.preventDefault(); } @@ -439,14 +587,14 @@ } // Issue a slider tag event - let evt = document.createEvent('Event'); - evt.initEvent('accordiontag', true, true); + let evt = document.createEvent("Event"); + evt.initEvent("accordiontag", true, true); evt.center = this.properties.center; evt.width = this.properties.width; mx.dispatchEvent(Mx, evt); - this.emit('change', { + this.emit("change", { center: this.properties.center, - width: this.properties.width + width: this.properties.width, }); } @@ -454,11 +602,11 @@ if (this.plot) { var Mx = this.Mx; // Issue a slider tag event - var evt = document.createEvent('Event'); - evt.initEvent('accordiontag', true, true); - this.emit('change', { + var evt = document.createEvent("Event"); + evt.initEvent("accordiontag", true, true); + this.emit("change", { center: this.properties.center, - width: this.properties.width + width: this.properties.width, }); evt.center = this.properties.center; evt.width = this.properties.width; @@ -471,11 +619,11 @@ if (this.plot) { var Mx = this.Mx; // Issue a slider tag event - var evt = document.createEvent('Event'); - evt.initEvent('accordiontag', true, true); - this.emit('change', { + var evt = document.createEvent("Event"); + evt.initEvent("accordiontag", true, true); + this.emit("change", { center: this.properties.center, - width: this.properties.width + width: this.properties.width, }); evt.center = this.properties.center; evt.width = this.properties.width; @@ -529,17 +677,19 @@ /** * @deprecated use .center() */ - get_center() { // In real units + get_center() { + // In real units return this.properties.center(); } /** * @deprecated use .width() */ - get_width() { // Pixels + get_width() { + // Pixels return this.properties.width(); } } module.exports = AccordionPlugin; -}()); +})(); diff --git a/js/sigplot.annotations.js b/js/sigplot.annotations.js index f904617..baf6f54 100644 --- a/js/sigplot.annotations.js +++ b/js/sigplot.annotations.js @@ -26,8 +26,7 @@ /* global module */ /* global require */ -(function() { - +(function () { var m = require("./m"); var mx = require("./mx"); @@ -36,8 +35,8 @@ * @param options * @returns {AnnotationPlugin} */ - var AnnotationPlugin = function(options) { - this.options = (options === undefined) ? {} : options; + var AnnotationPlugin = function (options) { + this.options = options === undefined ? {} : options; if (this.options.display === undefined) { this.options.display = true; @@ -50,12 +49,12 @@ }; AnnotationPlugin.prototype = { - init: function(plot) { + init: function (plot) { var self = this; this.plot = plot; var Mx = this.plot._Mx; - this.onmousemove = function(evt) { + this.onmousemove = function (evt) { // Ignore if there are no annotations if (self.annotations.length === 0) { return; @@ -67,11 +66,11 @@ } // Ignore if the mouse is outside of the plot area, clear the highlights - if ((evt.xpos < Mx.l) || (evt.xpos > Mx.r)) { + if (evt.xpos < Mx.l || evt.xpos > Mx.r) { self.set_highlight(false); return; } - if ((evt.ypos > Mx.b) || (evt.ypos < Mx.t)) { + if (evt.ypos > Mx.b || evt.ypos < Mx.t) { self.set_highlight(false); return; } @@ -83,7 +82,7 @@ var pxl = { x: undefined, - y: undefined + y: undefined, }; // Perserve the legacy API for now if (annotation.absolute_placement) { @@ -108,11 +107,14 @@ var rect_upperleft = { x: pxl.x, - y: pxl.y + y: pxl.y, }; - if ((annotation.value instanceof HTMLImageElement) || - (annotation.value instanceof HTMLCanvasElement) || - ((typeof HTMLVideoElement !== 'undefined') && annotation.value instanceof HTMLVideoElement)) { + if ( + annotation.value instanceof HTMLImageElement || + annotation.value instanceof HTMLCanvasElement || + (typeof HTMLVideoElement !== "undefined" && + annotation.value instanceof HTMLVideoElement) + ) { // For image, pxl.x and pxl.y are center rect_upperleft.x -= annotation.width / 2; rect_upperleft.y -= annotation.height / 2; @@ -121,9 +123,23 @@ rect_upperleft.y -= annotation.height; } - if (mx.inrect(evt.xpos, evt.ypos, rect_upperleft.x, rect_upperleft.y, annotation.width, annotation.height)) { + if ( + mx.inrect( + evt.xpos, + evt.ypos, + rect_upperleft.x, + rect_upperleft.y, + annotation.width, + annotation.height + ) + ) { if (!annotation.highlight) { - self.set_highlight(true, [annotation], pxl.x, pxl.y); + self.set_highlight( + true, + [annotation], + pxl.x, + pxl.y + ); need_refresh = true; } } else { @@ -142,7 +158,7 @@ }; this.plot.addListener("mmove", this.onmousemove); - this.onmousedown = function(evt) { + this.onmousedown = function (evt) { for (var i = 0; i < self.annotations.length; i++) { // leverage the fact that annotation.highlight is // set when the mouse is over the annotation @@ -153,17 +169,20 @@ }; this.plot.addListener("mdown", this.onmousedown); - this.onmouseup = function(evt) { + this.onmouseup = function (evt) { for (var i = 0; i < self.annotations.length; i++) { // leverage the fact that annotation.highlight is // set when the mouse is over the annotation if (self.annotations[i].selected) { // Issue a highlight event - var evt = document.createEvent('Event'); - evt.initEvent('annotationclick', true, true); + var evt = document.createEvent("Event"); + evt.initEvent("annotationclick", true, true); evt.annotation = self.annotations[i]; - var executeDefault = mx.dispatchEvent(self.plot._Mx, evt); - if ((executeDefault) && (self.annotations[i].onclick)) { + var executeDefault = mx.dispatchEvent( + self.plot._Mx, + evt + ); + if (executeDefault && self.annotations[i].onclick) { self.annotations[i].onclick(); } } @@ -173,12 +192,12 @@ document.addEventListener("mouseup", this.onmouseup, false); }, - set_highlight: function(state, annotations, x, y) { + set_highlight: function (state, annotations, x, y) { var _annotations = annotations || this.annotations; for (var i = 0; i < _annotations.length; i++) { // Issue a highlight event - var evt = document.createEvent('Event'); - evt.initEvent('annotationhighlight', true, true); + var evt = document.createEvent("Event"); + evt.initEvent("annotationhighlight", true, true); evt.annotation = _annotations[i]; evt.state = state; evt.x = x; @@ -190,52 +209,55 @@ } }, - menu: function() { - var _display_handler = (function(self) { - return function() { + menu: function () { + var _display_handler = (function (self) { + return function () { self.options.display = !self.options.display; self.plot.redraw(); }; - }(this)); + })(this); - var _clearall_handler = (function(self) { - return function() { + var _clearall_handler = (function (self) { + return function () { self.annotations = []; self.plot.redraw(); }; - }(this)); + })(this); return { text: "Annotations...", menu: { title: "ANNOTATIONS", - items: [{ - text: "Display", - checked: this.options.display, - style: "checkbox", - handler: _display_handler - }, { - text: "Clear All", - handler: _clearall_handler - }] - } + items: [ + { + text: "Display", + checked: this.options.display, + style: "checkbox", + handler: _display_handler, + }, + { + text: "Clear All", + handler: _clearall_handler, + }, + ], + }, }; }, - add_annotation: function(annotation) { + add_annotation: function (annotation) { this.annotations.push(annotation); this.plot.redraw(); return this.annotations.length; }, - clear_annotations: function() { + clear_annotations: function () { this.annotations = []; this.plot.redraw(); }, - refresh: function(canvas) { + refresh: function (canvas) { if (!this.options.display) { return; } @@ -250,8 +272,7 @@ ctx.rect(Mx.l, Mx.t, Mx.r - Mx.l, Mx.b - Mx.t); ctx.clip(); - mx.onCanvas(Mx, canvas, function() { - + mx.onCanvas(Mx, canvas, function () { // iterate backwards so we can remove from the end...in the future // if we decide to have annotations auto-remove for (var i = self.annotations.length - 1; i >= 0; i--) { @@ -259,7 +280,7 @@ var pxl = { x: undefined, - y: undefined + y: undefined, }; // Perserve the legacy API for now if (annotation.absolute_placement) { @@ -282,21 +303,39 @@ pxl.y = res.y; } - if (!mx.inrect(pxl.x, pxl.y, Mx.l, Mx.t, Mx.r - Mx.l, Mx.b - Mx.t)) { + if ( + !mx.inrect( + pxl.x, + pxl.y, + Mx.l, + Mx.t, + Mx.r - Mx.l, + Mx.b - Mx.t + ) + ) { // do we want to auto-remove? //self.annotations.splice(i,1); continue; } - if ((annotation.value instanceof HTMLImageElement) || - (annotation.value instanceof HTMLCanvasElement) || - ((typeof HTMLVideoElement !== 'undefined') && annotation.value instanceof HTMLVideoElement)) { + if ( + annotation.value instanceof HTMLImageElement || + annotation.value instanceof HTMLCanvasElement || + (typeof HTMLVideoElement !== "undefined" && + annotation.value instanceof HTMLVideoElement) + ) { annotation.width = annotation.value.width; annotation.height = annotation.value.height; - ctx.drawImage(annotation.value, pxl.x - (annotation.width / 2), pxl.y - (annotation.height / 2)); + ctx.drawImage( + annotation.value, + pxl.x - annotation.width / 2, + pxl.y - annotation.height / 2 + ); } else { // Setup the text styles - ctx.font = annotation.font || "bold italic 20px new century schoolbook"; + ctx.font = + annotation.font || + "bold italic 20px new century schoolbook"; if (!annotation.highlight) { ctx.fillStyle = annotation.color || Mx.fg; } else { @@ -304,32 +343,40 @@ } ctx.globalAlpha = 1; // Measure the text - annotation.width = ctx.measureText(annotation.value).width; + annotation.width = ctx.measureText( + annotation.value + ).width; annotation.height = ctx.measureText("M").width; // approximation of height // Render the text - ctx.textBaseline = annotation.textBaseline || self.options.textBaseline; - ctx.textAlign = annotation.textAlign || self.options.textAlign; + ctx.textBaseline = + annotation.textBaseline || + self.options.textBaseline; + ctx.textAlign = + annotation.textAlign || self.options.textAlign; ctx.fillText(annotation.value, pxl.x, pxl.y); } - if (annotation.highlight && annotation.popup) { - mx.render_message_box(Mx, annotation.popup, pxl.x + 5, pxl.y + 5, annotation.popupTextColor); + mx.render_message_box( + Mx, + annotation.popup, + pxl.x + 5, + pxl.y + 5, + annotation.popupTextColor + ); } } - }); ctx.restore(); }, - dispose: function() { + dispose: function () { this.plot = undefined; this.annotations = undefined; - } + }, }; module.exports = AnnotationPlugin; - -}()); +})(); diff --git a/js/sigplot.boxes.js b/js/sigplot.boxes.js index bc909a2..d4b15cb 100644 --- a/js/sigplot.boxes.js +++ b/js/sigplot.boxes.js @@ -26,8 +26,7 @@ /* global module */ /* global require */ -(function() { - +(function () { var m = require("./m"); var mx = require("./mx"); @@ -36,8 +35,8 @@ * @param options * @returns {BoxesPlugin} */ - var BoxesPlugin = function(options) { - this.options = (options === undefined) ? {} : options; + var BoxesPlugin = function (options) { + this.options = options === undefined ? {} : options; if (this.options.display === undefined) { this.options.display = true; @@ -47,55 +46,58 @@ }; BoxesPlugin.prototype = { - init: function(plot) { + init: function (plot) { this.plot = plot; }, - menu: function() { - var _display_handler = (function(self) { - return function() { + menu: function () { + var _display_handler = (function (self) { + return function () { self.options.display = !self.options.display; self.plot.redraw(); }; - }(this)); + })(this); - var _clearall_handler = (function(self) { - return function() { + var _clearall_handler = (function (self) { + return function () { self.boxes = []; self.plot.redraw(); }; - }(this)); + })(this); return { text: "Boxes...", menu: { title: "BOXES", - items: [{ - text: "Display", - checked: this.options.display, - style: "checkbox", - handler: _display_handler - }, { - text: "Clear All", - handler: _clearall_handler - }] - } + items: [ + { + text: "Display", + checked: this.options.display, + style: "checkbox", + handler: _display_handler, + }, + { + text: "Clear All", + handler: _clearall_handler, + }, + ], + }, }; }, - add_box: function(box) { + add_box: function (box) { this.boxes.push(box); this.plot.redraw(); return this.boxes.length; }, - clear_boxes: function() { + clear_boxes: function () { this.boxes = []; this.plot.redraw(); }, - refresh: function(canvas) { + refresh: function (canvas) { if (!this.options.display) { return; } @@ -107,7 +109,6 @@ var x, y, w, h; var ul, lr; - ctx.save(); ctx.beginPath(); ctx.rect(Mx.l, Mx.t, Mx.r - Mx.l, Mx.b - Mx.t); @@ -122,7 +123,11 @@ h = box.h; } else { ul = mx.real_to_pixel(Mx, box.x, box.y); - lr = pxl = mx.real_to_pixel(Mx, box.x + box.w, box.y + box.h); + lr = pxl = mx.real_to_pixel( + Mx, + box.x + box.w, + box.y + box.h + ); x = ul.x; y = ul.y; w = lr.x - ul.x; @@ -143,14 +148,12 @@ ctx.fillRect(x, y, w, h); ctx.globalAlpha = 1; } - ctx.strokeRect(x, - y, - w, - h); + ctx.strokeRect(x, y, w, h); if (box.text) { ctx.save(); - ctx.font = box.font || Mx.text_H + "px Courier New, monospace"; + ctx.font = + box.font || Mx.text_H + "px Courier New, monospace"; ctx.globalAlpha = 1; ctx.textAlign = "end"; ctx.fillStyle = ctx.strokeStyle; @@ -159,12 +162,12 @@ } x = x - Mx.text_w; - y = y - (Mx.text_h / 3); + y = y - Mx.text_h / 3; var text_w = ctx.measureText(box.text).width; - if ((x - text_w) < Mx.l) { - x = (x + w); + if (x - text_w < Mx.l) { + x = x + w; } ctx.fillText(box.text, x, y); @@ -175,12 +178,11 @@ ctx.restore(); }, - dispose: function() { + dispose: function () { this.plot = undefined; this.boxes = []; - } + }, }; module.exports = BoxesPlugin; - -}()); +})(); diff --git a/js/sigplot.js b/js/sigplot.js index ff4e065..f8a8f3f 100644 --- a/js/sigplot.js +++ b/js/sigplot.js @@ -23,4459 +23,4856 @@ * under the License. */ -/*jslint nomen: true, browser: true, devel: true */ +import {clone, has, mapObject, indexOf, size} from "underscore"; +import Spinner from "spin"; +import sigfile from "sigfile"; + +import common from "./common"; +import m from "./m"; +import mx from "./mx"; +import Layer1D from "./sigplot.layer1d"; +import Layer2D from "./sigplot.layer2d"; +import Layer1DSDS from "./sigplot.layer1dSDS"; +import Layer2DSDS from "./sigplot.layer2dSDS"; +import {version} from './package.json'; + +const bluefile = sigfile.bluefile; +const matfile = sigfile.matfile; -/* global module */ -/* global require */ +/** + * Text of the keypress help dialog. + * + * @memberOf sigplot + * @private + */ +const KEYPRESS_HELP = + "Keypress Table:\n" + + "--------------\n" + + "? - Main help box.\n" + + "A - Toggle display x,y readouts:\n" + + " (absc) -> (index) -> (1/absc) -> (time).\n" + + "B - Toggle LM Drag Mode:\n" + + " (box) -> (horizontal) -> (vertical).\n" + + "C - Toggle controls.\n" + + "K - Show Marker.\n" + + "L - Toggle legend.\n" + + "M - Pops up main menu\n" + + "R - Toggle display specs (x/y readout)\n" + + "S - Toggle display specs and axes.\n" + + "T - Popup box with timecode value at mouse.\n" + + "X - In 1D mode, popup box with X value at mouse.\n" + + " - In 2D mode, toggle x-cut display.\n" + + "Y - In 1D mode, popup box with Y value at mouse.\n" + + " - In 2D mode, toggle y-cut display.\n" + + "P - In 2D mode, displays p-cuts along side and bottom.\n" + + "F - Toggle fullscreen.\n" + + "Cntrl+I - Invert colors."; -(function() { +/** + * Text of the main help dialog. + * + * @memberOf sigplot + * @private + */ +const MAIN_HELP = + "To zoom, press and drag the left mouse (LM) over the region of interest and release. " + + "To unzoom, press right mouse (RM). Press the middle mouse (MM) button or press the 'M' key to open the main menu." + + "View the function of all keypresses by selecting 'Keypress Info' from the main menu."; - var version = "version-PLACEHOLDER"; +/** + * Options used when displaying the spinner. + * + * @memberOf sigplot + * @private + */ +const SPINNER_OPTS = { + lines: 13, // The number of lines to draw + length: 7, // The length of each line + width: 4, // The line thickness + radius: 10, // The radius of the inner circle + corners: 1, // Corner roundness (0..1) + rotate: 0, // The rotation offset + color: "#FFF", // #rgb or #rrggbb + speed: 1, // Rounds per second + trail: 60, // Afterglow percentage + shadow: false, // Whether to render a shadow + hwaccel: false, // Whether to use hardware acceleration + className: "spinner", // The CSS class to assign to the spinner + zIndex: 2e9, // The z-index (defaults to 2000000000) + top: "auto", // Top position relative to parent in px + left: "auto", // Left position relative to parent in px +}; - var _ = require("underscore"); - var Spinner = require("spin"); - var common = require("./common"); - var sigfile = require("sigfile"); - var bluefile = sigfile.bluefile; - var matfile = sigfile.matfile; - var m = require("./m"); - var mx = require("./mx"); - var Layer1D = require("./sigplot.layer1d"); - var Layer2D = require("./sigplot.layer2d"); - var Layer1DSDS = require("./sigplot.layer1dSDS"); - var Layer2DSDS = require("./sigplot.layer2dSDS"); +/** + * Attempts basic checks to determine if the browser is compatible with + * sigplot. + * + * @memberOf sigplot + * @private + */ +const browserIsCompatible = function () { + // We need a Canvas + const test_canvas = document.createElement("canvas"); + const hascanvas = test_canvas.getContext ? true : false; - function sigplot(element, options) { - if (!(this instanceof sigplot)) { - return new sigplot.Plot(element, options); - } - } + // We need ArrayBuffer + const hasarraybuf = "ArrayBuffer" in window; - sigplot.bluefile = bluefile; - sigplot.matfile = matfile; - sigplot.m = m; - sigplot.mx = mx; - sigplot.Layer1D = Layer1D; - sigplot.Layer2D = Layer2D; - sigplot.version = version; + // File and FileReader are optional...and only + // required if the user wants to plot local files + return hascanvas && hasarraybuf; +}; - /** - * Text of the keypress help dialog. - * - * @memberOf sigplot - * @private - */ - var KEYPRESS_HELP = "Keypress Table:\n" + - "--------------\n" + - "? - Main help box.\n" + - "A - Toggle display x,y readouts:\n" + - " (absc) -> (index) -> (1/absc) -> (time).\n" + - "B - Toggle LM Drag Mode:\n" + - " (box) -> (horizontal) -> (vertical).\n" + - "C - Toggle controls.\n" + - "K - Show Marker.\n" + - "L - Toggle legend.\n" + - "M - Pops up main menu\n" + - "R - Toggle display specs (x/y readout)\n" + - "S - Toggle display specs and axes.\n" + - "T - Popup box with timecode value at mouse.\n" + - "X - In 1D mode, popup box with X value at mouse.\n" + - " - In 2D mode, toggle x-cut display.\n" + - "Y - In 1D mode, popup box with Y value at mouse.\n" + - " - In 2D mode, toggle y-cut display.\n" + - "P - In 2D mode, displays p-cuts along side and bottom.\n" + - "F - Toggle fullscreen.\n" + - "Cntrl+I - Invert colors."; +/** + * Construct and render a plot. + * + * @memberOf sigplot + * @constructor + * + * @example plot = new sigplot.Plot(document.getElementById('plot'), {[options]}); + * + * @param element + * a 'div' DOM element + * @param [options] + * Key-value pairs whose values alter the behavior of the plot. + * + * @param {String} + * options.cmode the plot rendering mode "IN" = Index, "AB" = + * Abscissa (both of these, along with "__" can be added as prefixes to the other modes), + * "MA", "Magnitude" = Magnitude, "PH", "Phase" = Phase, "RE", "Real" = Real, + * "IM","Imaginary" = Imaginary, "LO", "D1", "10*log10" = 10*log, "L2" or "D2" + * , "20*log10" = 20*log, "RI", "Real/Imag", "Imag/Real","IR" = Real vs. Imaginary + * + * @param {String} + * options.phunits the phase units "D" = Degrees, "R" = Radians, + * "C" = Cycles + * + * @param {Boolean} + * options.cross display cross hairs on the plot + * + * @param {Boolean} + * options.nogrid hide the background grid + * + * @param {Boolean} + * options.legend set to false to hide the legend + * + * @param {Boolean} + * options.no_legend_button set to true to hide the legend button + * + * @param {Boolean} + * options.nopan disable panning on the plot + * + * @param {Boolean} + * options.nomenu disable the middle-click menu + * + * @param {Boolean} + * options.nospec hide all plot specification displays + * + * @param {Boolean} + * options.noxaxis hide the x-axis + * + * @param {Boolean} + * options.noyaxis hide the y-axis + * + * @param {Boolean} + * options.noreadout hide the plot readout area + * + * @param {Boolean} + * options.nodragdrop prevent file drag drop + * + * @param {Number} + * options.scroll_time_interval set the time interval for scrolling + * + * @param {Boolean} + * options.index use the data-index in the X axis + * + * @param {Number} + * options.autox auto-scaling settings for X axis !!!!CHANGED + * + * @param {Number} + * options.xmin the minimum range to display on the X axis + * + * @param {Number} + * options.xmax the maximum range to display on the X axis + * + * @param {Number} + * options.xlab the units that X-axis uses (see m.UNITS) + * + * @param {Object} + * options.xlabel function or string for custom X-axis label + * + * @param {Number} + * options.xdiv the number of divisions on the X axis + * + * @param {Number} + * options.xcnt configure the mtag mouse controls 0 = Off, 1 + * (default) = LM Click, 2 = Continuous + * + * @param {String} + * options.rubberbox_mode controls the behavior of the rubberbox + * "zoom" (default) = zoom to the selected area "box" = trigger + * an mtag action on the selected area + * + * @param {String} + * options.rightclick_rubberbox_mode controls the behavior of the rubberbox + * "zoom" = zoom to the selected area "box" = trigger + * an mtag action on the selected area. By default is null to disable + * right-click boxes + * + * @param {Number} + * options.line the line type to draw 0 = None, 1 = Verticals, 2 = + * Horizontals, 3 (default) = Connecting + * + * @param {Number} + * options.autoy auto-scaling settings for Y axis !!!! CHANGED + * 0 = Fix , 1 = Auto Min , 2 = Auto Max, 3 = Full Auto + * + * @param {Number} + * options.ylab the units that Y-axis uses (see m.UNITS) + * + * @param {Object} + * options.ylabel function or string for custom Y-axis label + * + * @param {Number} + * options.ymin the minimum range to display on the Y axis + * + * @param {Number} + * options.ymax the maximum range to display on the Y axis + * + * @param {Number} + * options.ydiv the number of divisions on the Y axis + * + * @param {Number} + * options.zmin the minimum range to display on the Z axis + * + * @param {Number} + * options.zmax the maximum range to display on the Z axis + * + * @param {Boolean} + * options.yinv invert the y-axis + * + * @param {String} + * options.colors.fg the foreground color as a CSS color + * + * @param {String} + * options.colors.bg the background color as a CSS color + * + * @param {Boolean} + * options.xi invert the foreground/background colors + * + * @param {Boolean} + * options.all show all of the data on the plot instead of just + * one buffer + * + * @param {Boolean} + * options.expand auto-scale the plot based on all the data (when + * combined with the all option) + * + * @param {Number} + * options.origin 1 = x1:xmin, x2:xmax, y1:ymax, y2:ymin + * (default), 2 = x1:xmax, x2:xmin, y1:ymax, y2:ymin (x + * inverted), 3 = x1:xmax, x2:xmin, y1:ymin, y2:ymax (x & y + * inverted), 4 = x1:xmin, x2:xmax, y1:ymin, y2:ymax (y inverted) + * + * @param {Number} + * options.bufmax the buffer size to use + * + * @param {Boolean} + * options.nokeypress disable key press actions + * + * @param options.font_family + * the font family to use for text rendered on the plot. Monospace + * font will generally work best. + * + * @param {Boolean} + * options.font_scaled mimic the MIDAS plotting behaviour where the + * plot font-size is scaled relative to the width of the + * + * @param {Boolean} + * options.font_width sets the font width (default=8); if scaled_font + * is set to true, then the font width will be the minimum of font_width + * or plot width/64. + * + * @param {Number} + * options.panxpad + * Pad the x-axis panning with this amount. If a string in the form of + * "XX%" the padding will be a percentage. + * + * @param {Number} + * options.panypad + * Pad the y-axis panning with this amount. If a string in the form of + * "XX%" the padding will be a percentage. + * + * @returns {Plot} + */ +const Plot = function (element, options) { + if (!browserIsCompatible()) { + throw "Browser is not compatible"; + } + // Register with the Mx structure - Step #4 + this._Mx = mx.open(element); + var Mx = this._Mx; - /** - * Text of the main help dialog. - * - * @memberOf sigplot - * @private - */ - var MAIN_HELP = "To zoom, press and drag the left mouse (LM) over the region of interest and release. " + - "To unzoom, press right mouse (RM). Press the middle mouse (MM) button or press the 'M' key to open the main menu." + - "View the function of all keypresses by selecting 'Keypress Info' from the main menu."; + this._Gx = new GX(); + this._Gx.parent = element; - /** - * Options used when displaying the spinner. - * - * @memberOf sigplot - * @private - */ - var SPINNER_OPTS = { - lines: 13, // The number of lines to draw - length: 7, // The length of each line - width: 4, // The line thickness - radius: 10, // The radius of the inner circle - corners: 1, // Corner roundness (0..1) - rotate: 0, // The rotation offset - color: '#FFF', // #rgb or #rrggbb - speed: 1, // Rounds per second - trail: 60, // Afterglow percentage - shadow: false, // Whether to render a shadow - hwaccel: false, // Whether to use hardware acceleration - className: 'spinner', // The CSS class to assign to the spinner - zIndex: 2e9, // The z-index (defaults to 2000000000) - top: 'auto', // Top position relative to parent in px - left: 'auto' // Left position relative to parent in px - }; + // Variable which stores state of mouse position relative to the canvas + this.mouseOnCanvas = false; - /** - * Attempts basic checks to determine if the browser is compatible with - * sigplot. - * - * @memberOf sigplot - * @private - */ - sigplot.browserIsCompatible = function browserIsCompatible() { - // We need a Canvas - var test_canvas = document.createElement('canvas'); - var hascanvas = (test_canvas.getContext) ? true : false; + if (!options) { + options = {}; + } - // We need ArrayBuffer - var hasarraybuf = ("ArrayBuffer" in window); + plot_init(this, options); - // File and FileReader are optional...and only - // required if the user wants to plot local files - return (hascanvas && hasarraybuf); + this.mimicListeners = { + other: null, + listeners: { + zoom: null, + unzoom: null, + xpan: null, + ypan: null, + }, }; + this._refresh(); // Draw immediately + this.onmousemove = (function (plot) { + return function (e) { + var Mx = plot._Mx; + var Gx = plot._Gx; - /** - * Construct and render a plot. - * - * @memberOf sigplot - * @constructor - * - * @example plot = new sigplot.Plot(document.getElementById('plot'), {[options]}); - * - * @param element - * a 'div' DOM element - * @param [options] - * Key-value pairs whose values alter the behavior of the plot. - * - * @param {String} - * options.cmode the plot rendering mode "IN" = Index, "AB" = - * Abscissa (both of these, along with "__" can be added as prefixes to the other modes), - * "MA", "Magnitude" = Magnitude, "PH", "Phase" = Phase, "RE", "Real" = Real, - * "IM","Imaginary" = Imaginary, "LO", "D1", "10*log10" = 10*log, "L2" or "D2" - * , "20*log10" = 20*log, "RI", "Real/Imag", "Imag/Real","IR" = Real vs. Imaginary - * - * @param {String} - * options.phunits the phase units "D" = Degrees, "R" = Radians, - * "C" = Cycles - * - * @param {Boolean} - * options.cross display cross hairs on the plot - * - * @param {Boolean} - * options.nogrid hide the background grid - * - * @param {Boolean} - * options.legend set to false to hide the legend - * - * @param {Boolean} - * options.no_legend_button set to true to hide the legend button - * - * @param {Boolean} - * options.nopan disable panning on the plot - * - * @param {Boolean} - * options.nomenu disable the middle-click menu - * - * @param {Boolean} - * options.nospec hide all plot specification displays - * - * @param {Boolean} - * options.noxaxis hide the x-axis - * - * @param {Boolean} - * options.noyaxis hide the y-axis - * - * @param {Boolean} - * options.noreadout hide the plot readout area - * - * @param {Boolean} - * options.nodragdrop prevent file drag drop - * - * @param {Number} - * options.scroll_time_interval set the time interval for scrolling - * - * @param {Boolean} - * options.index use the data-index in the X axis - * - * @param {Number} - * options.autox auto-scaling settings for X axis !!!!CHANGED - * - * @param {Number} - * options.xmin the minimum range to display on the X axis - * - * @param {Number} - * options.xmax the maximum range to display on the X axis - * - * @param {Number} - * options.xlab the units that X-axis uses (see m.UNITS) - * - * @param {Object} - * options.xlabel function or string for custom X-axis label - * - * @param {Number} - * options.xdiv the number of divisions on the X axis - * - * @param {Number} - * options.xcnt configure the mtag mouse controls 0 = Off, 1 - * (default) = LM Click, 2 = Continuous - * - * @param {String} - * options.rubberbox_mode controls the behavior of the rubberbox - * "zoom" (default) = zoom to the selected area "box" = trigger - * an mtag action on the selected area - * - * @param {String} - * options.rightclick_rubberbox_mode controls the behavior of the rubberbox - * "zoom" = zoom to the selected area "box" = trigger - * an mtag action on the selected area. By default is null to disable - * right-click boxes - * - * @param {Number} - * options.line the line type to draw 0 = None, 1 = Verticals, 2 = - * Horizontals, 3 (default) = Connecting - * - * @param {Number} - * options.autoy auto-scaling settings for Y axis !!!! CHANGED - * 0 = Fix , 1 = Auto Min , 2 = Auto Max, 3 = Full Auto - * - * @param {Number} - * options.ylab the units that Y-axis uses (see m.UNITS) - * - * @param {Object} - * options.ylabel function or string for custom Y-axis label - * - * @param {Number} - * options.ymin the minimum range to display on the Y axis - * - * @param {Number} - * options.ymax the maximum range to display on the Y axis - * - * @param {Number} - * options.ydiv the number of divisions on the Y axis - * - * @param {Number} - * options.zmin the minimum range to display on the Z axis - * - * @param {Number} - * options.zmax the maximum range to display on the Z axis - * - * @param {Boolean} - * options.yinv invert the y-axis - * - * @param {String} - * options.colors.fg the foreground color as a CSS color - * - * @param {String} - * options.colors.bg the background color as a CSS color - * - * @param {Boolean} - * options.xi invert the foreground/background colors - * - * @param {Boolean} - * options.all show all of the data on the plot instead of just - * one buffer - * - * @param {Boolean} - * options.expand auto-scale the plot based on all the data (when - * combined with the all option) - * - * @param {Number} - * options.origin 1 = x1:xmin, x2:xmax, y1:ymax, y2:ymin - * (default), 2 = x1:xmax, x2:xmin, y1:ymax, y2:ymin (x - * inverted), 3 = x1:xmax, x2:xmin, y1:ymin, y2:ymax (x & y - * inverted), 4 = x1:xmin, x2:xmax, y1:ymin, y2:ymax (y inverted) - * - * @param {Number} - * options.bufmax the buffer size to use - * - * @param {Boolean} - * options.nokeypress disable key press actions - * - * @param options.font_family - * the font family to use for text rendered on the plot. Monospace - * font will generally work best. - * - * @param {Boolean} - * options.font_scaled mimic the MIDAS plotting behaviour where the - * plot font-size is scaled relative to the width of the - * - * @param {Boolean} - * options.font_width sets the font width (default=8); if scaled_font - * is set to true, then the font width will be the minimum of font_width - * or plot width/64. - * - * @param {Number} - * options.panxpad - * Pad the x-axis panning with this amount. If a string in the form of - * "XX%" the padding will be a percentage. - * - * @param {Number} - * options.panypad - * Pad the y-axis panning with this amount. If a string in the form of - * "XX%" the padding will be a percentage. - * - * @returns {Plot} - */ - var Plot = function(element, options) { - if (!sigplot.browserIsCompatible()) { - throw "Browser is not compatible"; - } - // Register with the Mx structure - Step #4 - this._Mx = mx.open(element); - var Mx = this._Mx; - - this._Gx = new GX(); - this._Gx.parent = element; - - // Variable which stores state of mouse position relative to the canvas - this.mouseOnCanvas = false; - - if (!options) { - options = {}; - } - - plot_init(this, options); + var rect = e.target.getBoundingClientRect(); + var xpos = + e.offsetX === undefined + ? e.pageX - rect.left - window.scrollX + : e.offsetX; + var ypos = + e.offsetX === undefined + ? e.pageY - rect.top - window.scrollY + : e.offsetY; + + // var xpos = (e.offsetX === undefined) ? e.layerX : e.offsetX; + // var ypos = (e.offsetY === undefined) ? e.layerY : e.offsetY; + var re = pixel_to_real(plot, xpos, ypos); + Gx.retx = re.x; + Gx.rety = re.y; - this.mimicListeners = { - other: null, - listeners: { - zoom: null, - unzoom: null, - xpan: null, - ypan: null + if (Mx.widget) { + return; } - }; - - this._refresh(); // Draw immediately - - this.onmousemove = (function(plot) { - return function(e) { - var Mx = plot._Mx; - var Gx = plot._Gx; - - var rect = e.target.getBoundingClientRect(); - var xpos = (e.offsetX === undefined) ? (e.pageX - rect.left - window.scrollX) : e.offsetX; - var ypos = (e.offsetX === undefined) ? (e.pageY - rect.top - window.scrollY) : e.offsetY; - - // var xpos = (e.offsetX === undefined) ? e.layerX : e.offsetX; - // var ypos = (e.offsetY === undefined) ? e.layerY : e.offsetY; - var re = pixel_to_real(plot, xpos, ypos); - Gx.retx = re.x; - Gx.rety = re.y; - - if (Mx.widget) { - return; - } - display_specs(plot); + display_specs(plot); - var evt = document.createEvent('Event'); - evt.initEvent('mmove', true, true); - evt.originalEvent = e; - evt.xpos = xpos; - evt.ypos = ypos; - evt.x = Gx.retx; - evt.y = Gx.rety; - var executeDefault = mx.dispatchEvent(Mx, evt); - if (!executeDefault) { - return; - } + var evt = document.createEvent("Event"); + evt.initEvent("mmove", true, true); + evt.originalEvent = e; + evt.xpos = xpos; + evt.ypos = ypos; + evt.x = Gx.retx; + evt.y = Gx.rety; + var executeDefault = mx.dispatchEvent(Mx, evt); + if (!executeDefault) { + return; + } - // The crosshair logic in websigplot is different - // because we need to clear the previous position - // of the line (via XOR) and then draw the new line - // - // The Mx.xpos and Mx.ypos may have already been - // updated to their new location so we need to store - // the crosshair position in the Gx structure - if (Gx.cross) { - if (Mx.warpbox) { - // during zoom operations undraw the crosshairs - if (Gx.cross_xpos !== undefined) { - mx.rubberline(Mx, Gx.cross_xpos, Mx.t, - Gx.cross_xpos, Mx.b); - } - if (Gx.cross_ypos !== undefined) { - mx.rubberline(Mx, Mx.l, Gx.cross_ypos, Mx.r, - Gx.cross_ypos); - } - Gx.cross_xpos = undefined; - Gx.cross_ypos = undefined; - } else { - if (plot.mouseOnCanvas) { - draw_crosshairs(plot); - if (Gx.p_cuts && (Gx.lyr.length === 1) && (Gx.lyr[0].hcb["class"] === 2)) { - if (!Gx.y_cut_press_on && !Gx.x_cut_press_on) { - draw_p_cuts(plot); - } + // The crosshair logic in websigplot is different + // because we need to clear the previous position + // of the line (via XOR) and then draw the new line + // + // The Mx.xpos and Mx.ypos may have already been + // updated to their new location so we need to store + // the crosshair position in the Gx structure + if (Gx.cross) { + if (Mx.warpbox) { + // during zoom operations undraw the crosshairs + if (Gx.cross_xpos !== undefined) { + mx.rubberline( + Mx, + Gx.cross_xpos, + Mx.t, + Gx.cross_xpos, + Mx.b + ); + } + if (Gx.cross_ypos !== undefined) { + mx.rubberline( + Mx, + Mx.l, + Gx.cross_ypos, + Mx.r, + Gx.cross_ypos + ); + } + Gx.cross_xpos = undefined; + Gx.cross_ypos = undefined; + } else { + if (plot.mouseOnCanvas) { + draw_crosshairs(plot); + if ( + Gx.p_cuts && + Gx.lyr.length === 1 && + Gx.lyr[0].hcb["class"] === 2 + ) { + if (!Gx.y_cut_press_on && !Gx.x_cut_press_on) { + draw_p_cuts(plot); } } } } + } - if (Gx.cntrls === 2) { - var evt = document.createEvent('Event'); - evt.initEvent('mtag', true, true); - evt.originalEvent = e; - evt.x = Gx.retx; - evt.y = Gx.rety; - evt.xpos = xpos; - evt.ypos = ypos; - mx.dispatchEvent(Mx, evt); - } - }; - }(this)); + if (Gx.cntrls === 2) { + var evt = document.createEvent("Event"); + evt.initEvent("mtag", true, true); + evt.originalEvent = e; + evt.x = Gx.retx; + evt.y = Gx.rety; + evt.xpos = xpos; + evt.ypos = ypos; + mx.dispatchEvent(Mx, evt); + } + }; + })(this); - this.throttledOnMouseMove = m.throttle(this._Gx.scroll_time_interval, - this.onmousemove); + this.throttledOnMouseMove = m.throttle( + this._Gx.scroll_time_interval, + this.onmousemove + ); - mx.addEventListener(Mx, "mousemove", this.throttledOnMouseMove, false); + mx.addEventListener(Mx, "mousemove", this.throttledOnMouseMove, false); - this.onmouseout = (function(plot) { - return function(event) { - var Gx = plot._Gx; - var Mx = plot._Mx; - if (plot.mouseOnCanvas) { - plot.mouseOnCanvas = false; + this.onmouseout = (function (plot) { + return function (event) { + var Gx = plot._Gx; + var Mx = plot._Mx; + if (plot.mouseOnCanvas) { + plot.mouseOnCanvas = false; - if (Gx.autohide_readout) { - display_specs(plot); - } - if (Gx.autohide_panbars) { - draw_panbars(plot); - } - if (Mx.prompt) { - Mx.prompt.input.enableBlur(); - } + if (Gx.autohide_readout) { + display_specs(plot); } - }; - }(this)); - mx.addEventListener(Mx, "mouseout", this.onmouseout, false); - - this.onmouseover = (function(plot) { - return function(event) { - var Gx = plot._Gx; - var Mx = plot._Mx; - plot.mouseOnCanvas = true; if (Gx.autohide_panbars) { draw_panbars(plot); } if (Mx.prompt) { - Mx.prompt.input.disableBlur(); + Mx.prompt.input.enableBlur(); } - }; - }(this)); - mx.addEventListener(Mx, "mouseover", this.onmouseover, false); + } + }; + })(this); + mx.addEventListener(Mx, "mouseout", this.onmouseout, false); - this.onmousedown = (function(plot) { - return function(event) { - event.preventDefault(); // mouse down on the canvas should never do a browser default action + this.onmouseover = (function (plot) { + return function (event) { + var Gx = plot._Gx; + var Mx = plot._Mx; + plot.mouseOnCanvas = true; + if (Gx.autohide_panbars) { + draw_panbars(plot); + } + if (Mx.prompt) { + Mx.prompt.input.disableBlur(); + } + }; + })(this); + mx.addEventListener(Mx, "mouseover", this.onmouseover, false); - var Mx = plot._Mx; - var Gx = plot._Gx; + this.onmousedown = (function (plot) { + return function (event) { + event.preventDefault(); // mouse down on the canvas should never do a browser default action - if (Mx.widget && (Mx.widget.type === "ONESHOT")) { - Mx.widget = null; - plot.refresh(); - } + var Mx = plot._Mx; + var Gx = plot._Gx; - // Update Mx event fields - mx.ifevent(Mx, event); + if (Mx.widget && Mx.widget.type === "ONESHOT") { + Mx.widget = null; + plot.refresh(); + } - var evt = document.createEvent('Event'); - evt.initEvent('mdown', true, true); - evt.originalEvent = event; - evt.xpos = Mx.xpos; - evt.ypos = Mx.ypos; - evt.x = Gx.retx; - evt.y = Gx.rety; - evt.which = event.which; - var executeDefault = mx.dispatchEvent(Mx, evt); - if (!executeDefault) { - return false; - } + // Update Mx event fields + mx.ifevent(Mx, event); - // Check if event occured in the pan region - var inPan = inPanRegion(plot); + var evt = document.createEvent("Event"); + evt.initEvent("mdown", true, true); + evt.originalEvent = event; + evt.xpos = Mx.xpos; + evt.ypos = Mx.ypos; + evt.x = Gx.retx; + evt.y = Gx.rety; + evt.which = event.which; + var executeDefault = mx.dispatchEvent(Mx, evt); + if (!executeDefault) { + return false; + } - // Event processing - if (inPan.inPanRegion) { // Mouse position lies in a pan - // region - event.preventDefault(); - if (inPan.command !== ' ') { - var scrollbar = null; - var position = null; - if (inPan.command === "XPAN") { - scrollbar = Mx.scrollbar_x; - } else if (inPan.command === "YPAN") { - scrollbar = Mx.scrollbar_y; - } + // Check if event occured in the pan region + var inPan = inPanRegion(plot); - if (event.which === 2) { + // Event processing + if (inPan.inPanRegion) { + // Mouse position lies in a pan + // region + event.preventDefault(); + if (inPan.command !== " ") { + var scrollbar = null; + var position = null; + if (inPan.command === "XPAN") { + scrollbar = Mx.scrollbar_x; + } else if (inPan.command === "YPAN") { + scrollbar = Mx.scrollbar_y; + } + + if (event.which === 2) { + position = { + x: Mx.xpos, + y: Mx.ypos, + }; + if ( + scrollbar !== undefined && + onScrollbar(position, scrollbar) + ) { + // Only show menu if on the scrollbar itself + sigplot_scrollScaleMenu(plot, inPan.command); + } + } else { + if (inPan.command !== " ") { position = { x: Mx.xpos, - y: Mx.ypos + y: Mx.ypos, }; - if ((scrollbar !== undefined) && (onScrollbar(position, scrollbar))) { - // Only show menu if on the scrollbar itself - sigplot_scrollScaleMenu(plot, inPan.command); - } - } else { - if (inPan.command !== ' ') { - position = { - x: Mx.xpos, - y: Mx.ypos - }; - if (!onScrollbar(position, scrollbar) && event.which === 1) { // Left-clicking - // not on a - // scrollbar - - // handle - // typical pan - pan(plot, inPan.command, 0, event); // Execute - // the - // first - // pan - var repeatPan = function() { - if (!onScrollbar({ - "x": Mx.xpos, - "y": Mx.ypos - }, scrollbar)) { - pan(plot, inPan.command, 0, event); - // execute - // a - // pan - // on - // every - // interval - } else { - // stop - // panning - // once you - // hit the - // scrollbar - if (Gx.stillPanning) { - window.clearInterval(Gx.stillPanning); - Gx.repeatPanning = undefined; - } + if ( + !onScrollbar(position, scrollbar) && + event.which === 1 + ) { + // Left-clicking + // not on a + // scrollbar - + // handle + // typical pan + pan(plot, inPan.command, 0, event); // Execute + // the + // first + // pan + var repeatPan = function () { + if ( + !onScrollbar( + { + x: Mx.xpos, + y: Mx.ypos, + }, + scrollbar + ) + ) { + pan(plot, inPan.command, 0, event); + // execute + // a + // pan + // on + // every + // interval + } else { + // stop + // panning + // once you + // hit the + // scrollbar + if (Gx.stillPanning) { + window.clearInterval( + Gx.stillPanning + ); + Gx.repeatPanning = undefined; } - }; - - // Make scrolling smooth, the longer initial prevents - // a single click from counting twice - Gx.stillPanning = window.setTimeout( + } + }; - function() { - Gx.repeatPanning = window.setInterval(repeatPan, 50); - }, 250); - } + // Make scrolling smooth, the longer initial prevents + // a single click from counting twice + Gx.stillPanning = window.setTimeout( + function () { + Gx.repeatPanning = + window.setInterval( + repeatPan, + 50 + ); + }, + 250 + ); } } } - } else { // Mouse not in a pan region, handle other cases - if (event.which === 1 || event.which === 3) { - var lButtonPressed = false; - if (Gx.legendBtnLocation) { - lButtonPressed = coordsInRectangle(Mx.xpos, - Mx.ypos, Gx.legendBtnLocation.x, - Gx.legendBtnLocation.y, - Gx.legendBtnLocation.width, - Gx.legendBtnLocation.height); - } - - // a variable to hold the legend y positon of each layer - if (Gx.legend) { - var legendPos = get_legend_pos(plot); - var layerheight = legendPos.height / Gx.lyr.length; - - for (var i = 0; i < Gx.lyr.length; i++) { - if ((legendPos.x <= Mx.xpos) && ((legendPos.x + legendPos.width) >= Mx.xpos) && - ((legendPos.y <= Mx.ypos)) && (legendPos.y + layerheight) >= Mx.ypos) { - //find a way to pull up the menu - Mx.mouseUpLatch = true; - sigplot_legend_menu(plot, i); - return false; - } - legendPos.y += layerheight; + } + } else { + // Mouse not in a pan region, handle other cases + if (event.which === 1 || event.which === 3) { + var lButtonPressed = false; + if (Gx.legendBtnLocation) { + lButtonPressed = coordsInRectangle( + Mx.xpos, + Mx.ypos, + Gx.legendBtnLocation.x, + Gx.legendBtnLocation.y, + Gx.legendBtnLocation.width, + Gx.legendBtnLocation.height + ); + } + + // a variable to hold the legend y positon of each layer + if (Gx.legend) { + var legendPos = get_legend_pos(plot); + var layerheight = legendPos.height / Gx.lyr.length; + + for (var i = 0; i < Gx.lyr.length; i++) { + if ( + legendPos.x <= Mx.xpos && + legendPos.x + legendPos.width >= Mx.xpos && + legendPos.y <= Mx.ypos && + legendPos.y + layerheight >= Mx.ypos + ) { + //find a way to pull up the menu + Mx.mouseUpLatch = true; + sigplot_legend_menu(plot, i); + return false; } + legendPos.y += layerheight; } + } - // If we have a large colorbar, we also have buttons: - if (Gx.lg_colorbar && (Gx.lyr[0].hcb["class"] === 2)) { - if (event.which === 1 || event.which === 3) { - var mouse_x = Mx.xpos; - var mouse_y = Mx.ypos; - - // Find vertex positions of top and bottom buttons - var top_x1 = Gx.cbb_top_x1; - var top_y1 = Gx.cbb_top_y1; - var top_x2 = top_x1 + Gx.cbb_width; - var top_y2 = top_y1; - var top_x3 = top_x1 + (1 / 2) * Gx.cbb_width; - var top_y3 = top_y1 - Gx.cbb_height; - - var topButtonPressed = coordsInTriangle(mouse_x, mouse_y, top_x1, top_y1, top_x2, top_y2, top_x3, top_y3); - //console.log("Top ", topButtonPressed); - - if (topButtonPressed) { - var cur_cmap = Gx.cmap; - plot.get_layer(0).img = undefined; - var current_map = m.Mc.colormap[cur_cmap]; - - for (var i = 0; i < current_map.colors.length; i++) { - current_map.colors[i].pos += 5.0; - } - mx.colormap(Mx, current_map.colors, 16); - //Gx.zoff += (1/10)*(Gx.zmax - Gx.zmin); - plot.refresh(); - } - - // bottom - var bot_x1 = Gx.cbb_bot_x1; - var bot_y1 = Gx.cbb_bot_y1; - var bot_x2 = bot_x1 + Gx.cbb_width; - var bot_y2 = bot_y1; - var bot_x3 = bot_x1 + (1 / 2) * Gx.cbb_width; - var bot_y3 = bot_y1 + Gx.cbb_height; - - var botButtonPressed = coordsInTriangle(mouse_x, mouse_y, bot_x1, bot_y1, bot_x2, bot_y2, bot_x3, bot_y3); - - if (botButtonPressed) { - //Gx.zoff -= (1/10)*(Gx.zmax - Gx.zmin); - var cur_cmap = Gx.cmap; - var current_map = m.Mc.colormap[cur_cmap]; - plot.get_layer(0).img = undefined; - for (var i = 0; i < current_map.colors.length; i++) { - current_map.colors[i].pos -= 5.0; - } - mx.colormap(Mx, current_map.colors, 16); - plot.refresh(); + // If we have a large colorbar, we also have buttons: + if (Gx.lg_colorbar && Gx.lyr[0].hcb["class"] === 2) { + if (event.which === 1 || event.which === 3) { + var mouse_x = Mx.xpos; + var mouse_y = Mx.ypos; + + // Find vertex positions of top and bottom buttons + var top_x1 = Gx.cbb_top_x1; + var top_y1 = Gx.cbb_top_y1; + var top_x2 = top_x1 + Gx.cbb_width; + var top_y2 = top_y1; + var top_x3 = top_x1 + (1 / 2) * Gx.cbb_width; + var top_y3 = top_y1 - Gx.cbb_height; + + var topButtonPressed = coordsInTriangle( + mouse_x, + mouse_y, + top_x1, + top_y1, + top_x2, + top_y2, + top_x3, + top_y3 + ); + //console.log("Top ", topButtonPressed); + + if (topButtonPressed) { + var cur_cmap = Gx.cmap; + plot.get_layer(0).img = undefined; + var current_map = m.Mc.colormap[cur_cmap]; + + for ( + var i = 0; + i < current_map.colors.length; + i++ + ) { + current_map.colors[i].pos += 5.0; } - + mx.colormap(Mx, current_map.colors, 16); + //Gx.zoff += (1/10)*(Gx.zmax - Gx.zmin); + plot.refresh(); } - } - - if (lButtonPressed) { - plot.change_settings({ - legend: !Gx.legend - }); // toggle the legend - } else { - display_specs(plot); - - // Styles for rubberbox - var zoom_style = { - opacity: 0, - return_value: "zoom" - }; - - var select_style = { - opacity: 0.4, - fill_color: Mx.hi, - return_value: "select" - }; - - if (event.which === 1) { - if (Gx.default_rubberbox_action === "zoom") { - mx.rubberbox(Mx, rubberbox_cb(plot, event.which), - Gx.default_rubberbox_mode, zoom_style, - select_style); - } else if (Gx.default_rubberbox_action === "select") { - mx.rubberbox(Mx, rubberbox_cb(plot, event.which), - Gx.default_rubberbox_mode, - select_style, zoom_style); - } // otherwise rubber-box is considered disabled - } else if (event.which === 3) { - if (Gx.default_rightclick_rubberbox_action === "zoom") { - mx.rubberbox(Mx, rubberbox_cb(plot, event.which), - Gx.default_rightclick_rubberbox_mode, zoom_style, - select_style); - } else if (Gx.default_rightclick_rubberbox_action === "select") { - mx.rubberbox(Mx, rubberbox_cb(plot, event.which), - Gx.default_rightclick_rubberbox_mode, - select_style, zoom_style); - } // otherwise right-click rubber-box is considered disabled + // bottom + var bot_x1 = Gx.cbb_bot_x1; + var bot_y1 = Gx.cbb_bot_y1; + var bot_x2 = bot_x1 + Gx.cbb_width; + var bot_y2 = bot_y1; + var bot_x3 = bot_x1 + (1 / 2) * Gx.cbb_width; + var bot_y3 = bot_y1 + Gx.cbb_height; + + var botButtonPressed = coordsInTriangle( + mouse_x, + mouse_y, + bot_x1, + bot_y1, + bot_x2, + bot_y2, + bot_x3, + bot_y3 + ); + + if (botButtonPressed) { + //Gx.zoff -= (1/10)*(Gx.zmax - Gx.zmin); + var cur_cmap = Gx.cmap; + var current_map = m.Mc.colormap[cur_cmap]; + plot.get_layer(0).img = undefined; + for ( + var i = 0; + i < current_map.colors.length; + i++ + ) { + current_map.colors[i].pos -= 5.0; + } + mx.colormap(Mx, current_map.colors, 16); + plot.refresh(); } } - } else if (event.which === 2) { - if (!Gx.nomenu) { - sigplot_mainmenu(plot); - } } - } - return false; - }; - }(this)); - mx.addEventListener(Mx, "mousedown", this.onmousedown, false); - // Putting a finger on the screen and moving it, simulates - // pan. - this.ontouchstart = (function(plot) { - return function(event) { - event.preventDefault(); - - // See how many fingers are on the screen - // 1 finger == pan and/or unzoom - if (event.targetTouches.length === 1) { - - // See if this is a double-tap - if (Mx.touchClear && Mx.touches) { - // Double tap unzooms to L=0 and fully expands the plot - window.clearTimeout(Mx.touchClear); - plot.unzoom(); - middleClickScrollMenuAction(plot, mx.SB_FULL, "XPAN"); - middleClickScrollMenuAction(plot, mx.SB_FULL, "YPAN"); + if (lButtonPressed) { + plot.change_settings({ + legend: !Gx.legend, + }); // toggle the legend } else { - // Normal touch prepares for panning - var touchEvent = event.targetTouches[0]; - // Determine the touch position, relative to the canvas - var rect = touchEvent.target.getBoundingClientRect(); - var position = { - x: (touchEvent.pageX - rect.left - window.scrollX), - y: (touchEvent.pageY - rect.top - window.scrollY) + display_specs(plot); + + // Styles for rubberbox + var zoom_style = { + opacity: 0, + return_value: "zoom", }; - // Update the Mx coordinates - Mx.xpos = m.bound(position.x, 0, Mx.width); - Mx.ypos = m.bound(position.y, 0, Mx.height); + var select_style = { + opacity: 0.4, + fill_color: Mx.hi, + return_value: "select", + }; - // See if the finger lies on the pan-bars - var inPan = inPanRegion(plot, position); - if (!inPan.inPanRegion) { - Mx.touches = event.targetTouches; - } // TODO support touch 'pan' on the panbars + if (event.which === 1) { + if (Gx.default_rubberbox_action === "zoom") { + mx.rubberbox( + Mx, + rubberbox_cb(plot, event.which), + Gx.default_rubberbox_mode, + zoom_style, + select_style + ); + } else if ( + Gx.default_rubberbox_action === "select" + ) { + mx.rubberbox( + Mx, + rubberbox_cb(plot, event.which), + Gx.default_rubberbox_mode, + select_style, + zoom_style + ); + } // otherwise rubber-box is considered disabled + } else if (event.which === 3) { + if ( + Gx.default_rightclick_rubberbox_action === + "zoom" + ) { + mx.rubberbox( + Mx, + rubberbox_cb(plot, event.which), + Gx.default_rightclick_rubberbox_mode, + zoom_style, + select_style + ); + } else if ( + Gx.default_rightclick_rubberbox_action === + "select" + ) { + mx.rubberbox( + Mx, + rubberbox_cb(plot, event.which), + Gx.default_rightclick_rubberbox_mode, + select_style, + zoom_style + ); + } // otherwise right-click rubber-box is considered disabled + } + } + } else if (event.which === 2) { + if (!Gx.nomenu) { + sigplot_mainmenu(plot); } - } else if (event.targetTouches.length === 2) { - Mx.touch_distance = m.touch_distance(event.targetTouches[0], event.targetTouches[1]); } - }; - }(this)); - - mx.addEventListener(Mx, "touchstart", this.ontouchstart, false); - - this.ontouchmove = (function(plot) { - return function(event) { - var Mx = plot._Mx; - var Gx = plot._Gx; - var k = Mx.level; - - event.preventDefault(); - if (event.targetTouches.length === 1) { - // Determine the touch event position - var touchStart = Mx.touches[0]; - var rect = touchStart.target.getBoundingClientRect(); - var startPosition = { - x: (touchStart.pageX - rect.left - window.scrollX), - y: (touchStart.pageY - rect.top - window.scrollY) - }; - + } + return false; + }; + })(this); + mx.addEventListener(Mx, "mousedown", this.onmousedown, false); + + // Putting a finger on the screen and moving it, simulates + // pan. + this.ontouchstart = (function (plot) { + return function (event) { + event.preventDefault(); + + // See how many fingers are on the screen + // 1 finger == pan and/or unzoom + if (event.targetTouches.length === 1) { + // See if this is a double-tap + if (Mx.touchClear && Mx.touches) { + // Double tap unzooms to L=0 and fully expands the plot + window.clearTimeout(Mx.touchClear); + plot.unzoom(); + middleClickScrollMenuAction(plot, mx.SB_FULL, "XPAN"); + middleClickScrollMenuAction(plot, mx.SB_FULL, "YPAN"); + } else { + // Normal touch prepares for panning var touchEvent = event.targetTouches[0]; + // Determine the touch position, relative to the canvas var rect = touchEvent.target.getBoundingClientRect(); var position = { - x: (touchEvent.pageX - rect.left - window.scrollX), - y: (touchEvent.pageY - rect.top - window.scrollY) + x: touchEvent.pageX - rect.left - window.scrollX, + y: touchEvent.pageY - rect.top - window.scrollY, }; - var new_xpos = m.bound(position.x, 0, Mx.width); - var new_ypos = m.bound(position.y, 0, Mx.height); - var delta_xpos = new_xpos - Mx.xpos; - var delta_ypos = new_ypos - Mx.ypos; - Mx.xpos = new_xpos; - Mx.ypos = new_ypos; + // Update the Mx coordinates + Mx.xpos = m.bound(position.x, 0, Mx.width); + Mx.ypos = m.bound(position.y, 0, Mx.height); + // See if the finger lies on the pan-bars var inPan = inPanRegion(plot, position); - // If we are in the pan region, don't take any action - if (inPan.inPanRegion) { - return; - } + if (!inPan.inPanRegion) { + Mx.touches = event.targetTouches; + } // TODO support touch 'pan' on the panbars + } + } else if (event.targetTouches.length === 2) { + Mx.touch_distance = m.touch_distance( + event.targetTouches[0], + event.targetTouches[1] + ); + } + }; + })(this); - // Pan proportionally to the movement of the touch - var xdelta = (Mx.stk[k].xscl * delta_xpos); - var ydelta = (Mx.stk[k].yscl * delta_ypos); - - if (Mx.origin === 1) { - // regular x, regular y - xdelta *= -1; - } else if (Mx.origin === 2) { - // inverted x, regular y - ydelta *= -1; - } else if (Mx.origin === 3) { - // inverted x, inverted y - ydelta *= -1; - } else if (Mx.origin === 4) { - // regular x, inverted y - xdelta *= -1; - ydelta *= -1; - } + mx.addEventListener(Mx, "touchstart", this.ontouchstart, false); - var xmin = Mx.stk[k].xmin + xdelta; - var xmax = Mx.stk[k].xmax + xdelta; - var ymin = Mx.stk[k].ymin + ydelta; - var ymax = Mx.stk[k].ymax + ydelta; + this.ontouchmove = (function (plot) { + return function (event) { + var Mx = plot._Mx; + var Gx = plot._Gx; + var k = Mx.level; - if ((xmin >= Gx.xmin) && (xmax <= Gx.xmax)) { - Mx.stk[k].xmin = xmin; - Mx.stk[k].xmax = xmax; - } + event.preventDefault(); + if (event.targetTouches.length === 1) { + // Determine the touch event position + var touchStart = Mx.touches[0]; + var rect = touchStart.target.getBoundingClientRect(); + var startPosition = { + x: touchStart.pageX - rect.left - window.scrollX, + y: touchStart.pageY - rect.top - window.scrollY, + }; - if ((ymin >= Gx.ymin) && (ymax <= Gx.ymax)) { - Mx.stk[k].ymin = ymin; - Mx.stk[k].ymax = ymax; - } + var touchEvent = event.targetTouches[0]; + var rect = touchEvent.target.getBoundingClientRect(); + var position = { + x: touchEvent.pageX - rect.left - window.scrollX, + y: touchEvent.pageY - rect.top - window.scrollY, + }; - if (Gx.cmode === Gx.basemode && Mx.level === 1) { - Gx.xmin = Math.min(Gx.xmin, xmin); - Gx.xmax = Math.max(Gx.xmax, xmax); - Gx.ymin = Math.min(Gx.ymin, ymin); - Gx.ymax = Math.max(Gx.ymax, ymax); - } - plot.refresh(); - } else if (event.targetTouches.length === 2) { - var cur_distance = m.touch_distance(event.targetTouches[0], event.targetTouches[1]); - var scaling = (1 - (Mx.touch_distance / cur_distance)) * 0.05; + var new_xpos = m.bound(position.x, 0, Mx.width); + var new_ypos = m.bound(position.y, 0, Mx.height); + var delta_xpos = new_xpos - Mx.xpos; + var delta_ypos = new_ypos - Mx.ypos; + Mx.xpos = new_xpos; + Mx.ypos = new_ypos; + + var inPan = inPanRegion(plot, position); + // If we are in the pan region, don't take any action + if (inPan.inPanRegion) { + return; + } - var xran = Mx.stk[k].xmax - Mx.stk[k].xmin; - var yran = Mx.stk[k].ymax - Mx.stk[k].ymin; + // Pan proportionally to the movement of the touch + var xdelta = Mx.stk[k].xscl * delta_xpos; + var ydelta = Mx.stk[k].yscl * delta_ypos; - var xmin = Mx.stk[k].xmin + (scaling * xran); - var xmax = Mx.stk[k].xmax - (scaling * xran); - var ymin = Mx.stk[k].ymin + (scaling * yran); - var ymax = Mx.stk[k].ymax - (scaling * yran); + if (Mx.origin === 1) { + // regular x, regular y + xdelta *= -1; + } else if (Mx.origin === 2) { + // inverted x, regular y + ydelta *= -1; + } else if (Mx.origin === 3) { + // inverted x, inverted y + ydelta *= -1; + } else if (Mx.origin === 4) { + // regular x, inverted y + xdelta *= -1; + ydelta *= -1; + } - Mx.stk[k].xmin = Math.max(Gx.xmin, xmin); - Mx.stk[k].xmax = Math.min(Gx.xmax, xmax); - Mx.stk[k].ymin = Math.max(Gx.ymin, ymin); - Mx.stk[k].ymax = Math.min(Gx.ymax, ymax); + var xmin = Mx.stk[k].xmin + xdelta; + var xmax = Mx.stk[k].xmax + xdelta; + var ymin = Mx.stk[k].ymin + ydelta; + var ymax = Mx.stk[k].ymax + ydelta; - plot.refresh(); + if (xmin >= Gx.xmin && xmax <= Gx.xmax) { + Mx.stk[k].xmin = xmin; + Mx.stk[k].xmax = xmax; } - }; - }(this)); - this.throttledOnTouchMove = m.throttle( - this._Gx.scroll_time_interval, - this.ontouchmove); + if (ymin >= Gx.ymin && ymax <= Gx.ymax) { + Mx.stk[k].ymin = ymin; + Mx.stk[k].ymax = ymax; + } - mx.addEventListener(Mx, "touchmove", this.throttledOnTouchMove, false); + if (Gx.cmode === Gx.basemode && Mx.level === 1) { + Gx.xmin = Math.min(Gx.xmin, xmin); + Gx.xmax = Math.max(Gx.xmax, xmax); + Gx.ymin = Math.min(Gx.ymin, ymin); + Gx.ymax = Math.max(Gx.ymax, ymax); + } + plot.refresh(); + } else if (event.targetTouches.length === 2) { + var cur_distance = m.touch_distance( + event.targetTouches[0], + event.targetTouches[1] + ); + var scaling = (1 - Mx.touch_distance / cur_distance) * 0.05; - this.ontouchend = (function(plot) { - return function(event) { - var Gx = plot._Gx; - var Mx = plot._Mx; + var xran = Mx.stk[k].xmax - Mx.stk[k].xmin; + var yran = Mx.stk[k].ymax - Mx.stk[k].ymin; - event.preventDefault(); - console.log("on touch end ", event.targetTouches.length); - Gx.panning = undefined; - plot._Mx.scrollbar_x.action = 0; - plot._Mx.scrollbar_y.action = 0; - Mx.touch_distance = undefined; + var xmin = Mx.stk[k].xmin + scaling * xran; + var xmax = Mx.stk[k].xmax - scaling * xran; + var ymin = Mx.stk[k].ymin + scaling * yran; + var ymax = Mx.stk[k].ymax - scaling * yran; - mx.widget_callback(Mx, event); - // Only clear the touches after a slight delay so we can - // detect double-tap - Mx.touchClear = window.setTimeout( + Mx.stk[k].xmin = Math.max(Gx.xmin, xmin); + Mx.stk[k].xmax = Math.min(Gx.xmax, xmax); + Mx.stk[k].ymin = Math.max(Gx.ymin, ymin); + Mx.stk[k].ymax = Math.min(Gx.ymax, ymax); - function() { - Mx.touches = undefined; - Mx.touchClear = undefined; - }, 100); - }; - }(this)); + plot.refresh(); + } + }; + })(this); - mx.addEventListener(Mx, "touchend", this.ontouchend, false); + this.throttledOnTouchMove = m.throttle( + this._Gx.scroll_time_interval, + this.ontouchmove + ); - this.docMouseUp = (function(plot) { - return function(event) { - var Gx = plot._Gx; + mx.addEventListener(Mx, "touchmove", this.throttledOnTouchMove, false); - if (event.which === 1) { - // in general, you shouldn't put anything in here - // ...instead it should go into rubberbox_cb - Gx.panning = undefined; - plot._Mx.scrollbar_x.action = 0; // TODO Is this - // necessary? - plot._Mx.scrollbar_y.action = 0; - } //else if (event.which === 2) { - // nothing - //} else if (event.which === 3) { - // nothing - //} - if (Gx.stillPanning) { - window.clearTimeout(Gx.stillPanning); - Gx.stillPanning = undefined; - } - if (Gx.repeatPanning) { // Clear the panning interval on any - // mouse up in the document - window.clearInterval(Gx.repeatPanning); - Gx.repeatPanning = undefined; - } - return false; - }; - }(this)); - document.addEventListener("mouseup", this.docMouseUp, false); + this.ontouchend = (function (plot) { + return function (event) { + var Gx = plot._Gx; + var Mx = plot._Mx; - this.mouseup = (function(plot) { - return function(event) { - event.preventDefault(); // mouse up on the canvas should never do a browser default action + event.preventDefault(); + console.log("on touch end ", event.targetTouches.length); + Gx.panning = undefined; + plot._Mx.scrollbar_x.action = 0; + plot._Mx.scrollbar_y.action = 0; + Mx.touch_distance = undefined; + + mx.widget_callback(Mx, event); + // Only clear the touches after a slight delay so we can + // detect double-tap + Mx.touchClear = window.setTimeout(function () { + Mx.touches = undefined; + Mx.touchClear = undefined; + }, 100); + }; + })(this); - var Gx = plot._Gx; - var Mx = plot._Mx; + mx.addEventListener(Mx, "touchend", this.ontouchend, false); - // Update Mx event fields - mx.ifevent(plot._Mx, event); + this.docMouseUp = (function (plot) { + return function (event) { + var Gx = plot._Gx; - var evt = document.createEvent('Event'); - evt.initEvent('mup', true, true); - evt.originalEvent = event; - evt.xpos = Mx.xpos; - evt.ypos = Mx.ypos; - evt.x = Gx.retx; - evt.y = Gx.rety; - evt.which = event.which; - var executeDefault = mx.dispatchEvent(Mx, evt); - - if (executeDefault) { - if (Mx.warpbox || Mx.widget || Mx.prompt) { - // If any of these are true, the mouseup is going - // to be handled by them...but this is a fragile approach - // because it relies upon implicit ordering of event dispatch - // for mouseup events. It should be improved/refactored at some point - return; - } + if (event.which === 1) { + // in general, you shouldn't put anything in here + // ...instead it should go into rubberbox_cb + Gx.panning = undefined; + plot._Mx.scrollbar_x.action = 0; // TODO Is this + // necessary? + plot._Mx.scrollbar_y.action = 0; + } //else if (event.which === 2) { + // nothing + //} else if (event.which === 3) { + // nothing + //} + if (Gx.stillPanning) { + window.clearTimeout(Gx.stillPanning); + Gx.stillPanning = undefined; + } + if (Gx.repeatPanning) { + // Clear the panning interval on any + // mouse up in the document + window.clearInterval(Gx.repeatPanning); + Gx.repeatPanning = undefined; + } + return false; + }; + })(this); + document.addEventListener("mouseup", this.docMouseUp, false); - // Normal mouse up handling - if (event.which === 1) { - // If we are in the pan region, perform the pan - // otherwise emit an mtag - var inCenter = inPanCenterRegion(plot); - if (inCenter.inCenterRegion) { - if (inCenter.command !== ' ') { - pan(plot, inCenter.command, 0, event); // pan - } - } else if (Gx.cntrls === 1) { - // Update the mark - Gx.xmrk = Gx.retx; - Gx.ymrk = Gx.rety; - - var mtagevt = document.createEvent('Event'); - mtagevt.initEvent('mtag', true, true); - mtagevt.originalEvent = event; - mtagevt.x = Gx.xmrk; - mtagevt.y = Gx.ymrk; - mtagevt.xpos = event.x || event.clientX; - mtagevt.ypos = event.y || event.clientY; - mtagevt.w = undefined; - mtagevt.h = undefined; - mtagevt.shift = event.shiftKey; - mx.dispatchEvent(Mx, mtagevt); - - // Refresh to draw the new marker position - //if (Gx.always_show_marker || Gx.show_marker) { - plot.redraw(); - //} + this.mouseup = (function (plot) { + return function (event) { + event.preventDefault(); // mouse up on the canvas should never do a browser default action + + var Gx = plot._Gx; + var Mx = plot._Mx; + + // Update Mx event fields + mx.ifevent(plot._Mx, event); + + var evt = document.createEvent("Event"); + evt.initEvent("mup", true, true); + evt.originalEvent = event; + evt.xpos = Mx.xpos; + evt.ypos = Mx.ypos; + evt.x = Gx.retx; + evt.y = Gx.rety; + evt.which = event.which; + var executeDefault = mx.dispatchEvent(Mx, evt); + + if (executeDefault) { + if (Mx.warpbox || Mx.widget || Mx.prompt) { + // If any of these are true, the mouseup is going + // to be handled by them...but this is a fragile approach + // because it relies upon implicit ordering of event dispatch + // for mouseup events. It should be improved/refactored at some point + return; + } + + // Normal mouse up handling + if (event.which === 1) { + // If we are in the pan region, perform the pan + // otherwise emit an mtag + var inCenter = inPanCenterRegion(plot); + if (inCenter.inCenterRegion) { + if (inCenter.command !== " ") { + pan(plot, inCenter.command, 0, event); // pan } - } else if (event.which === 2) { - if (Gx.nomenu) { - // Send an event so that a custom menu can be displayed - // if desired - var evt = document.createEvent('Event'); - evt.initEvent('showmenu', true, true); - evt.originalEvent = event; - evt.x = event.x || event.clientX; - evt.y = event.y || event.clientY; - var executeDefault = mx.dispatchEvent(Mx, evt); + } else if (Gx.cntrls === 1) { + // Update the mark + Gx.xmrk = Gx.retx; + Gx.ymrk = Gx.rety; + + var mtagevt = document.createEvent("Event"); + mtagevt.initEvent("mtag", true, true); + mtagevt.originalEvent = event; + mtagevt.x = Gx.xmrk; + mtagevt.y = Gx.ymrk; + mtagevt.xpos = event.x || event.clientX; + mtagevt.ypos = event.y || event.clientY; + mtagevt.w = undefined; + mtagevt.h = undefined; + mtagevt.shift = event.shiftKey; + mx.dispatchEvent(Mx, mtagevt); + + // Refresh to draw the new marker position + //if (Gx.always_show_marker || Gx.show_marker) { + plot.redraw(); + //} + } + } else if (event.which === 2) { + if (Gx.nomenu) { + // Send an event so that a custom menu can be displayed + // if desired + var evt = document.createEvent("Event"); + evt.initEvent("showmenu", true, true); + evt.originalEvent = event; + evt.x = event.x || event.clientX; + evt.y = event.y || event.clientY; + var executeDefault = mx.dispatchEvent(Mx, evt); - if (executeDefault) { - if (event.stopPropagation) { - event.stopPropagation(); - } - event.cancelBubble = true; - mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); - - var emit_hidemenu = function() { - try { - var hideMenuEvt = document.createEvent('Event'); - hideMenuEvt.initEvent('hidemenu', true, true); - if (mx.dispatchEvent(Mx, hideMenuEvt)) { - mx.addEventListener(Mx, "mousedown", plot.onmousedown, false); - } - } finally { - document.removeEventListener("mouseup", emit_hidemenu, false); - } - }; - document.addEventListener("mouseup", emit_hidemenu, false); + if (executeDefault) { + if (event.stopPropagation) { + event.stopPropagation(); } + event.cancelBubble = true; + mx.removeEventListener( + Mx, + "mousedown", + plot.onmousedown, + false + ); + + var emit_hidemenu = function () { + try { + var hideMenuEvt = + document.createEvent("Event"); + hideMenuEvt.initEvent( + "hidemenu", + true, + true + ); + if (mx.dispatchEvent(Mx, hideMenuEvt)) { + mx.addEventListener( + Mx, + "mousedown", + plot.onmousedown, + false + ); + } + } finally { + document.removeEventListener( + "mouseup", + emit_hidemenu, + false + ); + } + }; + document.addEventListener( + "mouseup", + emit_hidemenu, + false + ); } - } else if (event.which === 3) { // unzoom only happens on - // right-clicks on plot - // unzoom/expand - event.preventDefault(); - - plot.unzoom(1); - plot.refresh(); } - } + } else if (event.which === 3) { + // unzoom only happens on + // right-clicks on plot + // unzoom/expand + event.preventDefault(); - }; - }(this)); + plot.unzoom(1); + plot.refresh(); + } + } + }; + })(this); - mx.addEventListener(Mx, "mouseup", this.mouseup, false); + mx.addEventListener(Mx, "mouseup", this.mouseup, false); - this.mouseclick = (function(plot) { - return function(event) { - event.preventDefault(); // alway prevent any default browser actions on the plot + this.mouseclick = (function (plot) { + return function (event) { + event.preventDefault(); // alway prevent any default browser actions on the plot - var Gx = plot._Gx; - var Mx = plot._Mx; + var Gx = plot._Gx; + var Mx = plot._Mx; - // Update Mx event fields - mx.ifevent(plot._Mx, event); + // Update Mx event fields + mx.ifevent(plot._Mx, event); - var evt = document.createEvent('Event'); - evt.initEvent('mclick', true, true); - evt.originalEvent = event; - evt.xpos = Mx.xpos; - evt.ypos = Mx.ypos; - evt.x = Gx.retx; - evt.y = Gx.rety; - evt.which = event.which; // not always available on all browser - if (mx.dispatchEvent(Mx, evt)) { - // currently there isn't a default for mouseclick to cancel - } - return false; - }; - }(this)); - mx.addEventListener(Mx, "click", this.mouseclick, false); + var evt = document.createEvent("Event"); + evt.initEvent("mclick", true, true); + evt.originalEvent = event; + evt.xpos = Mx.xpos; + evt.ypos = Mx.ypos; + evt.x = Gx.retx; + evt.y = Gx.rety; + evt.which = event.which; // not always available on all browser + if (mx.dispatchEvent(Mx, evt)) { + // currently there isn't a default for mouseclick to cancel + } + return false; + }; + })(this); + mx.addEventListener(Mx, "click", this.mouseclick, false); - this.mousedblclick = (function(plot) { - return function(event) { - event.preventDefault(); // alway prevent any default browser actions on the plot + this.mousedblclick = (function (plot) { + return function (event) { + event.preventDefault(); // alway prevent any default browser actions on the plot - var Gx = plot._Gx; - var Mx = plot._Mx; + var Gx = plot._Gx; + var Mx = plot._Mx; - // Update Mx event fields - mx.ifevent(plot._Mx, event); + // Update Mx event fields + mx.ifevent(plot._Mx, event); - var evt = document.createEvent('Event'); - evt.initEvent('mdblclick', true, true); - evt.originalEvent = event; - evt.xpos = Mx.xpos; - evt.ypos = Mx.ypos; - evt.x = Gx.retx; - evt.y = Gx.rety; - evt.which = event.which; // not always available on all browser - if (mx.dispatchEvent(Mx, evt)) { - // currently there isn't a default for mouseclick to cancel - } - return false; - }; - }(this)); - mx.addEventListener(Mx, "dblclick", this.mousedblclick, false); + var evt = document.createEvent("Event"); + evt.initEvent("mdblclick", true, true); + evt.originalEvent = event; + evt.xpos = Mx.xpos; + evt.ypos = Mx.ypos; + evt.x = Gx.retx; + evt.y = Gx.rety; + evt.which = event.which; // not always available on all browser + if (mx.dispatchEvent(Mx, evt)) { + // currently there isn't a default for mouseclick to cancel + } + return false; + }; + })(this); + mx.addEventListener(Mx, "dblclick", this.mousedblclick, false); - // PANBAR DRAGGING mouse event handlers: - this.dragMouseDownHandler = (function(plot) { - return function(event) { - var Mx = plot._Mx; - var Gx = plot._Gx; + // PANBAR DRAGGING mouse event handlers: + this.dragMouseDownHandler = (function (plot) { + return function (event) { + var Mx = plot._Mx; + var Gx = plot._Gx; - // Check if event occured in the pan region - var inPan = inPanRegion(plot); + // Check if event occured in the pan region + var inPan = inPanRegion(plot); - // Event processing - if (inPan.inPanRegion) { // Mouse position lies in a pan - // region - event.preventDefault(); - if (inPan.command !== ' ') { - var scrollbar; - if (inPan.command === "XPAN") { - scrollbar = Mx.scrollbar_x; - } else if (inPan.command === "YPAN") { - scrollbar = Mx.scrollbar_y; - } + // Event processing + if (inPan.inPanRegion) { + // Mouse position lies in a pan + // region + event.preventDefault(); + if (inPan.command !== " ") { + var scrollbar; + if (inPan.command === "XPAN") { + scrollbar = Mx.scrollbar_x; + } else if (inPan.command === "YPAN") { + scrollbar = Mx.scrollbar_y; + } - var position = { - x: Mx.xpos, - y: Mx.ypos + var position = { + x: Mx.xpos, + y: Mx.ypos, + }; + if ( + scrollbar !== undefined && + onScrollbar(position, scrollbar) && + event.which === 1 + ) { + // On scrollbar, set up + // a DRAG + Gx.panning = { + axis: inPan.command, + xpos: event.screenX, // Use screen-relative + // values here instead + // of div/page-relative + // values + ypos: event.screenY, + xmin: Mx.stk[Mx.level].xmin, + xmax: Mx.stk[Mx.level].xmax, + ymin: Mx.stk[Mx.level].ymin, + ymax: Mx.stk[Mx.level].ymax, }; - if (scrollbar !== undefined && onScrollbar(position, scrollbar) && event.which === 1) { // On scrollbar, set up - // a DRAG - Gx.panning = { - axis: inPan.command, - xpos: event.screenX, // Use screen-relative - // values here instead - // of div/page-relative - // values - ypos: event.screenY, - xmin: Mx.stk[Mx.level].xmin, - xmax: Mx.stk[Mx.level].xmax, - ymin: Mx.stk[Mx.level].ymin, - ymax: Mx.stk[Mx.level].ymax - }; - } } } - }; - }(this)); - window.addEventListener("mousedown", this.dragMouseDownHandler, false); + } + }; + })(this); + window.addEventListener("mousedown", this.dragMouseDownHandler, false); - this.dragMouseMoveHandler = (function(plot) { - return function(e) { - var Gx = plot._Gx; + this.dragMouseMoveHandler = (function (plot) { + return function (e) { + var Gx = plot._Gx; - if (Gx.panning !== undefined) { // execute a scrollbar DRAG - try { - drag_scrollbar(plot, Gx.panning.axis, e); - } catch (err) { - console.log("Error: " + err); // TODO Eventually come - // up with better error - // handling here - } + if (Gx.panning !== undefined) { + // execute a scrollbar DRAG + try { + drag_scrollbar(plot, Gx.panning.axis, e); + } catch (err) { + console.log("Error: " + err); // TODO Eventually come + // up with better error + // handling here } - }; - }(this)); + } + }; + })(this); - this.throttledDragOnMouseMove = m.throttle(this._Gx.scroll_time_interval, - this.dragMouseMoveHandler); + this.throttledDragOnMouseMove = m.throttle( + this._Gx.scroll_time_interval, + this.dragMouseMoveHandler + ); - window.addEventListener("mousemove", this.throttledDragOnMouseMove, - false); + window.addEventListener( + "mousemove", + this.throttledDragOnMouseMove, + false + ); - this.dragMouseUpHandler = (function(plot) { - return function(event) { - var Gx = plot._Gx; + this.dragMouseUpHandler = (function (plot) { + return function (event) { + var Gx = plot._Gx; - if (event.which === 1) { - Gx.panning = undefined; // Panbar dragging completed - clear - // the state variable - } - }; - }(this)); - window.addEventListener("mouseup", this.dragMouseUpHandler, false); + if (event.which === 1) { + Gx.panning = undefined; // Panbar dragging completed - clear + // the state variable + } + }; + })(this); + window.addEventListener("mouseup", this.dragMouseUpHandler, false); - // TODO this may need to be throttled or debounced - this.onresize = (function(plot) { - return function(event) { - if (mx.checkresize(plot._Mx)) { - plot.refresh(); - } - }; - }(this)); + // TODO this may need to be throttled or debounced + this.onresize = (function (plot) { + return function (event) { + if (mx.checkresize(plot._Mx)) { + plot.refresh(); + } + }; + })(this); - // Mouse Wheel logic - this.wheelHandler = (function(plot) { + // Mouse Wheel logic + this.wheelHandler = (function (plot) { + var Mx = plot._Mx; + var Gx = plot._Gx; - var Mx = plot._Mx; - var Gx = plot._Gx; + var throttledPan = m.throttle(100, function (inPan) { + // Mouse wheel + // event over a + // panning + // region + + var scrollbar; + if (inPan.command === "XPAN") { + scrollbar = Mx.scrollbar_x; + } else if (inPan.command === "YPAN") { + scrollbar = Mx.scrollbar_y; + } + + // For now, vertical mouse scrolling is the only action that + // will trigger a pan + // Later, we can add horizontal mouse scrolling if we choose + if (Gx.wheelscroll_mode_natural) { + // Original Sig-Plot + // orientation + scrollbar.action = + event.deltaY < 0 ? mx.SB_WHEELDOWN : mx.SB_WHEELUP; + } else { + // Inverted/"un-natural" orientation + scrollbar.action = + event.deltaY < 0 ? mx.SB_WHEELUP : mx.SB_WHEELDOWN; + } - var throttledPan = m.throttle(100, function(inPan) { - // Mouse wheel - // event over a - // panning - // region + scrollbar.step = 0.1 * scrollbar.srange; + scrollbar.page = 9 * scrollbar.step; - var scrollbar; - if (inPan.command === "XPAN") { - scrollbar = Mx.scrollbar_x; - } else if (inPan.command === "YPAN") { - scrollbar = Mx.scrollbar_y; - } + // Execute wheel action on the scrollbar + mx.scroll(Mx, scrollbar, mx.XW_COMMAND, undefined, scrollbar); - // For now, vertical mouse scrolling is the only action that - // will trigger a pan - // Later, we can add horizontal mouse scrolling if we choose - if (Gx.wheelscroll_mode_natural) { // Original Sig-Plot - // orientation - scrollbar.action = (event.deltaY < 0 ? mx.SB_WHEELDOWN : mx.SB_WHEELUP); - } else { // Inverted/"un-natural" orientation - scrollbar.action = (event.deltaY < 0 ? mx.SB_WHEELUP : mx.SB_WHEELDOWN); + // Update the viewbox + updateViewbox( + plot, + scrollbar.smin, + scrollbar.smin + scrollbar.srange, + inPan.command.slice(0, 1) + ); + }); + + var throttledZoom = m.throttle(100, function () { + var zoomperc = Gx.wheelZoomPercent || 0.2; + if (Gx.wheelscroll_mode_natural) { + if (event.deltaY > 0) { + zoomperc = -1 * zoomperc; + } + } else { + // Inverted/"un-natural" orientation + if (event.deltaY < 0) { + zoomperc = -1 * zoomperc; } + } - scrollbar.step = 0.1 * scrollbar.srange; - scrollbar.page = 9 * scrollbar.step; + if (Gx.wheelZoom === "x") { + plot.percent_zoom(zoomperc, 1, true); + } else if (Gx.wheelZoom === "y") { + plot.percent_zoom(1, zoomperc, true); + } else { + plot.percent_zoom(zoomperc, zoomperc, true); + } + }); - // Execute wheel action on the scrollbar - mx.scroll(Mx, scrollbar, mx.XW_COMMAND, undefined, - scrollbar); + return function (event) { + // Update Mx event fields + mx.ifevent(Mx, event); - // Update the viewbox - updateViewbox(plot, scrollbar.smin, scrollbar.smin + scrollbar.srange, inPan.command.slice(0, 1)); - }); + // Check if event occured in the pan region + var inPan = inPanRegion(plot); - var throttledZoom = m.throttle(100, function() { - var zoomperc = Gx.wheelZoomPercent || 0.2; - if (Gx.wheelscroll_mode_natural) { - if (event.deltaY > 0) { - zoomperc = -1 * zoomperc; - } - } else { // Inverted/"un-natural" orientation - if (event.deltaY < 0) { - zoomperc = -1 * zoomperc; - } - } + // Event processing + if (plot.mouseOnCanvas) { + event.preventDefault(); - if (Gx.wheelZoom === "x") { - plot.percent_zoom(zoomperc, 1, true); - } else if (Gx.wheelZoom === "y") { - plot.percent_zoom(1, zoomperc, true); - } else { - plot.percent_zoom(zoomperc, zoomperc, true); + if (inPan.inPanRegion) { + throttledPan(inPan); + } else if (Gx.wheelZoom) { + throttledZoom(); } - }); + } + }; + })(this); - return function(event) { - // Update Mx event fields - mx.ifevent(Mx, event); + window.addWheelListener(window, this.wheelHandler, false); - // Check if event occured in the pan region - var inPan = inPanRegion(plot); + window.addEventListener("resize", this.onresize, false); - // Event processing + // If multiple plots are in the same window, then it + // may be desired to disable keypress behavior and implement + // it at a higher-level...by default keypress behavior + // is enabled and only works if the mouse if over the plot + if (!options.nokeypress) { + this.onkeypress = (function (plot) { + return function (event) { + var Mx = plot._Mx; + var Gx = plot._Gx; if (plot.mouseOnCanvas) { - event.preventDefault(); - - if (inPan.inPanRegion) { - throttledPan(inPan); - } else if (Gx.wheelZoom) { - throttledZoom(); + if (Mx.widget && Mx.widget.type === "MENU") { + return; // The menu absorbs the keypress } - } - }; - }(this)); - - window.addWheelListener(window, this.wheelHandler, false); - window.addEventListener("resize", this.onresize, false); - - // If multiple plots are in the same window, then it - // may be desired to disable keypress behavior and implement - // it at a higher-level...by default keypress behavior - // is enabled and only works if the mouse if over the plot - if (!options.nokeypress) { - this.onkeypress = (function(plot) { - return function(event) { - var Mx = plot._Mx; - var Gx = plot._Gx; - if (plot.mouseOnCanvas) { - - if (Mx.widget && (Mx.widget.type === "MENU")) { - return; // The menu absorbs the keypress - } + if (Mx.widget && Mx.widget.type === "ONESHOT") { + Mx.widget = null; + plot.refresh(); + return; + } - if (Mx.widget && (Mx.widget.type === "ONESHOT")) { - Mx.widget = null; - plot.refresh(); - return; - } + var keyCode = common.getKeyCode(event); - var keyCode = common.getKeyCode(event); + // Since the mouse is in the plot area, send a keypress event + var evt = document.createEvent("Event"); + evt.initEvent("plotkeypress", true, true); + evt.originalEvent = event; + evt.keyCode = keyCode; + evt.shiftKey = event.shiftKey; + evt.ctrlKey = event.ctrlKey; + evt.altKey = event.altKey; + evt.metaKey = event.metaKey; + var executeDefault = mx.dispatchEvent(Mx, evt); + if (!executeDefault) { + return; + } - // Since the mouse is in the plot area, send a keypress event - var evt = document.createEvent('Event'); - evt.initEvent('plotkeypress', true, true); - evt.originalEvent = event; - evt.keyCode = keyCode; - evt.shiftKey = event.shiftKey; - evt.ctrlKey = event.ctrlKey; - evt.altKey = event.altKey; - evt.metaKey = event.metaKey; - var executeDefault = mx.dispatchEvent(Mx, evt); - if (!executeDefault) { - return; + // Only respond to keypresses if the mouse is + // in the plot area.... + + if (keyCode === 97) { + // 'a' + Gx.iabsc = (Gx.iabsc + 1) % 4; + // It's kinda up in the air if changing the 'specs' + // area should also change the plotting mode itself... + // on one hand, if you have multiple layers with different + // xdeta's then switching the specs area to index mode will + // give you only the index of the baselayer...on the other hand + // the use may only want to change the readout and not the x-axis + // or the plot...for now this is commented out to behave in the same + // manner as SIGPLOT. + //plot.change_settings({ + // index : Gx.iabsc === 1 + //}); + display_specs(plot); + } else if (keyCode === 108) { + // 'l' + plot.change_settings({ + legend: !Gx.legend, + }); // toggle the legend + } else if (keyCode === 103) { + // 'g' + plot.change_settings({ + grid: !Gx.grid, + }); // toggle the grid + } else if (keyCode === 98 || keyCode === 2) { + // 'b' and CTRL-'b' + if (Mx.warpbox) { + if (Mx.warpbox.mode === "box") { + Mx.warpbox.mode = "horizontal"; + } else if (Mx.warpbox.mode === "horizontal") { + Mx.warpbox.mode = "vertical"; + } else { + Mx.warpbox.mode = "box"; + } + mx.redraw_warpbox(Mx); } - - // Only respond to keypresses if the mouse is - // in the plot area.... - - if (keyCode === 97) { // 'a' - Gx.iabsc = (Gx.iabsc + 1) % 4; - // It's kinda up in the air if changing the 'specs' - // area should also change the plotting mode itself... - // on one hand, if you have multiple layers with different - // xdeta's then switching the specs area to index mode will - // give you only the index of the baselayer...on the other hand - // the use may only want to change the readout and not the x-axis - // or the plot...for now this is commented out to behave in the same - // manner as SIGPLOT. - //plot.change_settings({ - // index : Gx.iabsc === 1 - //}); - display_specs(plot); - } else if (keyCode === 108) { // 'l' - plot.change_settings({ - legend: !Gx.legend - }); // toggle the legend - } else if (keyCode === 103) { // 'g' - plot.change_settings({ - grid: !Gx.grid - }); // toggle the grid - } else if ((keyCode === 98) || (keyCode === 2)) { // 'b' and CTRL-'b' - if (Mx.warpbox) { - if (Mx.warpbox.mode === "box") { - Mx.warpbox.mode = "horizontal"; - } else if (Mx.warpbox.mode === "horizontal") { - Mx.warpbox.mode = "vertical"; - } else { - Mx.warpbox.mode = "box"; + } else if (keyCode === 99) { + // 'c' + plot.change_settings({ + xcnt: -1 * Gx.cntrls, + }); + } else if (keyCode === 114) { + // 'r' + plot.change_settings({ + show_readout: !Gx.show_readout, + }); + } else if (keyCode === 115) { + // 's' + plot.change_settings({ + specs: !Gx.specs, + }); + } else if (keyCode === 112) { + // 'p' + plot.change_settings({ + p_cuts: !Gx.p_cuts, + }); + } else if (keyCode === 120) { + // 'x' + if (Gx.x_cut_press_on) { + // leave xCut + for (var i = 0; i < Gx.lyr.length; i++) { + if (Gx.lyr[i].xCut) { + Gx.lyr[i].xCut(); + break; } - mx.redraw_warpbox(Mx); } - } else if (keyCode === 99) { // 'c' - plot.change_settings({ - xcnt: -1 * Gx.cntrls - }); - } else if (keyCode === 114) { // 'r' - plot.change_settings({ - show_readout: !Gx.show_readout - }); - } else if (keyCode === 115) { // 's' - plot.change_settings({ - specs: !Gx.specs - }); - } else if (keyCode === 112) { // 'p' - plot.change_settings({ - p_cuts: !Gx.p_cuts - }); - } else if (keyCode === 120) { // 'x' - if (Gx.x_cut_press_on) { - // leave xCut + } else if (Gx.xyKeys === "pop-up") { + if (!Gx.x_pop_now) { + sigplot_show_x(plot); + Gx.x_pop_now = true; + } else { + Gx.x_pop_now = false; + } + } else if ( + Gx.lyr[0].hcb["class"] === 1 && + Gx.xyKeys === "automatic" + ) { + if (!Gx.x_pop_now) { + sigplot_show_x(plot); + Gx.x_pop_now = true; + } else { + Gx.x_pop_now = false; + } + } else if ( + Gx.xyKeys !== "disable" && + Gx.lyr[0].hcb["class"] === 2 + ) { + // show xCut if xyKeys aren't disabled and the first layer is + // type 2000 and y-cut isn't currently enabled (we already checked + // that x_cut above) + if (!Gx.y_cut_press_on) { for (var i = 0; i < Gx.lyr.length; i++) { if (Gx.lyr[i].xCut) { - Gx.lyr[i].xCut(); + Gx.lyr[i].xCut( + pixel_to_real(plot, 0, Mx.ypos) + .y + ); break; } } - } else if (Gx.xyKeys === "pop-up") { - if (!Gx.x_pop_now) { - sigplot_show_x(plot); - Gx.x_pop_now = true; - } else { - Gx.x_pop_now = false; - } - } else if ((Gx.lyr[0].hcb["class"] === 1) && (Gx.xyKeys === "automatic")) { - if (!Gx.x_pop_now) { - sigplot_show_x(plot); - Gx.x_pop_now = true; - } else { - Gx.x_pop_now = false; - } - } else if ((Gx.xyKeys !== "disable") && (Gx.lyr[0].hcb["class"] === 2)) { - // show xCut if xyKeys aren't disabled and the first layer is - // type 2000 and y-cut isn't currently enabled (we already checked - // that x_cut above) - if (!Gx.y_cut_press_on) { - for (var i = 0; i < Gx.lyr.length; i++) { - if (Gx.lyr[i].xCut) { - Gx.lyr[i].xCut(pixel_to_real(plot, 0, Mx.ypos).y); - break; - } - } + } + } + } else if (keyCode === 121) { + // 'y' + if (Gx.y_cut_press_on) { + for (var i = 0; i < Gx.lyr.length; i++) { + if (Gx.lyr[i].yCut) { + Gx.lyr[i].yCut(); + break; } } - } else if (keyCode === 121) { // 'y' - if (Gx.y_cut_press_on) { + } else if (Gx.xyKeys === "pop-up") { + if (!Gx.y_pop_now) { + sigplot_show_y(plot); + Gx.y_pop_now = true; + } else { + Gx.y_pop_now = false; + } + } else if ( + Gx.lyr[0].hcb["class"] === 1 && + Gx.xyKeys === "automatic" + ) { + if (!Gx.y_pop_now) { + sigplot_show_y(plot); + Gx.y_pop_now = true; + } else { + Gx.y_pop_now = false; + } + } else if ( + Gx.xyKeys !== "disable" && + Gx.lyr[0].hcb["class"] === 2 + ) { + // show xCut if xyKeys aren't disabled and the first layer is + // type 2000 and y-cut isn't currently enabled (we already checked + // that y_cut above) + if (!Gx.x_cut_press_on) { for (var i = 0; i < Gx.lyr.length; i++) { if (Gx.lyr[i].yCut) { - Gx.lyr[i].yCut(); + Gx.lyr[i].yCut( + pixel_to_real(plot, Mx.xpos, 0) + .x + ); break; } } - } else if (Gx.xyKeys === "pop-up") { - if (!Gx.y_pop_now) { - sigplot_show_y(plot); - Gx.y_pop_now = true; - } else { - Gx.y_pop_now = false; - } - } else if ((Gx.lyr[0].hcb["class"] === 1) && (Gx.xyKeys === "automatic")) { - if (!Gx.y_pop_now) { - sigplot_show_y(plot); - Gx.y_pop_now = true; - } else { - Gx.y_pop_now = false; - } - } else if ((Gx.xyKeys !== "disable") && (Gx.lyr[0].hcb["class"] === 2)) { - // show xCut if xyKeys aren't disabled and the first layer is - // type 2000 and y-cut isn't currently enabled (we already checked - // that y_cut above) - if (!Gx.x_cut_press_on) { - for (var i = 0; i < Gx.lyr.length; i++) { - if (Gx.lyr[i].yCut) { - Gx.lyr[i].yCut(pixel_to_real(plot, Mx.xpos, 0).x); - break; - } - } - } } - } else if (keyCode === 122) { // 'z' - sigplot_show_z(plot); - } else if (keyCode === 116) { // 't' - sigplot_show_timecode(plot); - } else if (keyCode === 109) { // 'm' - if (!Gx.nomenu) { - var evt = document.createEvent('Event'); - evt.initEvent('showmenu', true, true); - evt.originalEvent = event; - evt.x = Mx.x; - evt.y = Mx.y; - var executeDefault = mx.dispatchEvent(Mx, evt); - if (executeDefault) { - sigplot_mainmenu(plot); - } + } + } else if (keyCode === 122) { + // 'z' + sigplot_show_z(plot); + } else if (keyCode === 116) { + // 't' + sigplot_show_timecode(plot); + } else if (keyCode === 109) { + // 'm' + if (!Gx.nomenu) { + var evt = document.createEvent("Event"); + evt.initEvent("showmenu", true, true); + evt.originalEvent = event; + evt.x = Mx.x; + evt.y = Mx.y; + var executeDefault = mx.dispatchEvent(Mx, evt); + if (executeDefault) { + sigplot_mainmenu(plot); } - } else if (keyCode === 63) { // '?' - mx.message(Mx, MAIN_HELP); - } else if (keyCode === 102) { // 'f' - mx.fullscreen(Mx); - plot.refresh(); - } else if ((keyCode === 9) && (event.ctrlKey)) { // ctrl-i - plot.change_settings({ - invert: null - }); - } else if (keyCode === 107) { // 'k' show marker - Gx.show_marker = !Gx.show_marker; - plot.redraw(); - } + } else if (keyCode === 63) { + // '?' + mx.message(Mx, MAIN_HELP); + } else if (keyCode === 102) { + // 'f' + mx.fullscreen(Mx); + plot.refresh(); + } else if (keyCode === 9 && event.ctrlKey) { + // ctrl-i + plot.change_settings({ + invert: null, + }); + } else if (keyCode === 107) { + // 'k' show marker + Gx.show_marker = !Gx.show_marker; + plot.redraw(); } - }; - }(this)); + } + }; + })(this); + + common.setKeypressHandler(this.onkeypress); + } + + return this; +}; + +// Public methods + +Plot.prototype = { + /** @lends Plot **/ - common.setKeypressHandler(this.onkeypress); + /** + * Add a plugin to the plot + * + * @param plugin + * the plugin object + * + * @param zorder + * the zorder for the plugin to render, all plugins render as + * overlays on top of the plot + */ + add_plugin: function (plugin, zorder) { + if (zorder === undefined) { + zorder = Number.MAX_VALUE; + } + if (zorder <= 0) { + throw "Invalid plugin zorder"; } - return this; - }; + var canvas = document.createElement("canvas"); + canvas.width = this._Mx.canvas.width; + canvas.height = this._Mx.canvas.height; - // Public methods + plugin.init(this, canvas); - Plot.prototype = { - /** @lends Plot **/ + this._Gx.plugins.push({ + impl: plugin, + zorder: zorder, + canvas: canvas, + }); - /** - * Add a plugin to the plot - * - * @param plugin - * the plugin object - * - * @param zorder - * the zorder for the plugin to render, all plugins render as - * overlays on top of the plot - */ - add_plugin: function(plugin, zorder) { - if (zorder === undefined) { - zorder = Number.MAX_VALUE; - } - if (zorder <= 0) { - throw "Invalid plugin zorder"; + this._Gx.plugins.sort(function (a, b) { + return a.zorder - b.zorder; + }); + + this.refresh(); + }, + + /** + * Removes a plugin from the plot + * + * @param plugin + * the plugin object + */ + remove_plugin: function (plugin) { + var i = this._Gx.plugins.length; + while (i--) { + if (this._Gx.plugins[i].impl === plugin) { + if (plugin.dispose) { + plugin.dispose(); + } + if (this._Gx.plugins[i].canvas.parentNode) { + this._Gx.plugins[i].canvas.parentNode.removeElement( + this._Gx.plugins[i].canvas + ); + } + this._Gx.plugins.splice(i, 1); } + } + this._Gx.plugins.sort(function (a, b) { + return a.zorder - b.zorder; + }); - var canvas = document.createElement('canvas'); - canvas.width = this._Mx.canvas.width; - canvas.height = this._Mx.canvas.height; + this.refresh(); + }, - plugin.init(this, canvas); + /** + * Adds a listener to plot events. + * + * @example plot.addListener(what, function(event) {}); + * + * @param what + * the name of the event to listen to. "file_deoverlayed" is + * emitted when a file is deoverlayed (the name of the deoverlayed + * file can be found in evt.filename), "file_overlayed" is emitted + * when a file is overlayed (the name of the overlayed file can + * be found in evt.filename), "hidemenu" is emitted when the + * menu should be hidden (a selection is made or a mouse click + * occurs away from the menu), "mdown" is emitted when the mouse + * down event occurs (the evt has parts evt.xpos (the mouse x-position + * relative to the canvas), evt.ypos (the mouse y-position relative + * to the canvas), evt.x (the mouse x-position relative to the data), + * evt.y (the mouse y-position relative to the data) and evt.which + * (returns which mouse button was pressed for the event)) "mmove" + * is emitted when a mouse move event occurs (the evt has parts + * evt.xpos (the mouse x-position relative to the canvas), evt.ypos + * (the mouse y-position relative to the canvas), evt.x (the mouse + * x-position relative to the data), evt.y (the mouse y-position + * relative to the data) and evt.which (returns which mouse button + * was pressed for the event)), "mtag" is emitted when a mouse "tag" + * event occurs (the evt of an mtag has different parts depending + * on what triggered it. It will always contain evt.xpos (the mouse + * x-position relative to the canvas), evt.ypos (the mouse y-position + * relative to the canvas), evt.x (the mouse x-position relative + * to the data), and evt.y (the mouse y-position relative to the data). + * If the rubberboxes are enabled, evt.h and evt.w will contain + * the width and height of the box. evt.shift will contain info + * about the shift key if it is pressed), "mmove" is emitted when + * a mouse move event has occurred, "mdown" is emitted when + * a mouse down event has occurred (the evt has parts evt.xpos + * (the mouse x-position relative to the canvas), evt.ypos (the + * mouse y-position relative to the canvas), evt.x (the mouse + * x-position relative to the data), evt.y (the mouse y-position + * relative to the data) and evt.which (returns which mouse button + * was pressed for the event)), "mup" is emitted when a mouse up + * event occurs. (the evt has parts evt.xpos (the mouse x-position + * relative to the canvas), evt.ypos (the mouse y-position relative + * to the canvas), evt.x (the mouse x-position relative to the data), + * evt.y (the mouse y-position relative to the data) and evt.which + * (returns which mouse button was pressed for the event)), + * "reread" is emitted when a reread has been performed, "sigplotexit" + * is emitted when an exit plot event occurs, and "showmenu" is + * emitted when the menu should be shown (the evt.x and evt.y + * contain the coordinates on the plot where the menu will be displayed. + * + * @param [function] + * callback the function that will be called when the event is heard + */ + addListener: function (what, callback) { + var Mx = this._Mx; + mx.addEventListener(Mx, what, callback, false); + }, - this._Gx.plugins.push({ - impl: plugin, - zorder: zorder, - canvas: canvas - }); + /** + * Removes a listener to plot events. + * + * @param what + * the event that was listned to + * @param callback + */ + removeListener: function (what, callback) { + var Mx = this._Mx; + mx.removeEventListener(Mx, what, callback, false); + }, - this._Gx.plugins.sort(function(a, b) { - return (a.zorder - b.zorder); - }); + /** + * Change one or more plot settings. For boolean types, passing null + * will toggle the setting. + * + * @example plot.change_settings({[settings]}); + * + * @param settings + * Key-value pairs whose values are the settings to change + * + * @param {Boolean} + * settings.grid change grid visibility + * + * @param {Boolean} + * settings.index change index setting + * + * @param {Boolean} + * settings.all change the plot to show all data + * + * @param {Boolean} + * settings.show_x_axis true displays the x axis + * + * @param {Boolean} + * settings.show_y_axis true displays the y axis + * + * @param {Boolean} + * settings.show_readout true displays the readout + * + * @param {Boolean} + * settings.specs turns on and off specs + * + * @param {String} + * settings.xcnt "leftmouse", "continuous", "disable", + * "enable" + * + * @param {Boolean} + * settings.legend true displays the legend + * + * @param {Boolean} + * settings.pan true will display scrollbars and enable panning + * + * @param {Boolean} + * settings.cross true displays cross hairs + * + * @param {String} + * settings.rubberbox_action controls action of rubberbox. + * "zoom" (default) = zoom to the selected area, "select" = + * select the selected area, and "null" = disabled, no action + * + * @param {String} + * settings.rubberbox_mode controls the behavior of the rubberbox. + * "zoom" = zoom to the selected area, "box" = trigger an mtag + * action on the selected area + * + * @param {String} + * settings.rightclick_rubberbox_action controls action of + * rubberbox on rightclick. "zoom" = zoom to the selected area, + * "select" = select the selected area, and "null" (the default) + * = disabled, no action + * + * @param {String} + * settings.rightclick_rubberbox_mode controls the behavior of + * the rubberbox on rightclck. "zoom" = zoom to the selected area, + * "box" = trigger an mtag action on the selected area. By default + * is null to disable right-click boxes + * + * @param {String} + * settings.wheelscroll_mode_natural true indicates natural + * mode, where scrolling the mousewheel forward will pan down + * and backwards will pan up + * + * @param {String} + * settings.cmode !!!! CHANGED + * + * @param {String} + * settings.phunits The phase units "D" = Degrees, "R" = Radians, + * "C" = Cycles + * + * @param {Boolean} + * settings.lg_colorbar true displays the large colorbar + * + * @param {Boolean} + * settings.p_cuts true displays p_cuts on a 2D plot + */ + change_settings: function (settings) { + var Gx = this._Gx; + var Mx = this._Mx; + for (var i = 0; i < Gx.lyr.length; i++) { + Gx.lyr[i].change_settings(settings); + } - this.refresh(); - }, + if (settings.xyKeys !== undefined) { + if (settings.xyKeys === null) { + Gx.xyKeys = "automatic"; + } else { + Gx.xyKeys = settings.xyKeys; + } + } - /** - * Removes a plugin from the plot - * - * @param plugin - * the plugin object - */ - remove_plugin: function(plugin) { - var i = this._Gx.plugins.length; - while (i--) { - if (this._Gx.plugins[i].impl === plugin) { - if (plugin.dispose) { - plugin.dispose(); - } - if (this._Gx.plugins[i].canvas.parentNode) { - this._Gx.plugins[i].canvas.parentNode.removeElement(this._Gx.plugins[i].canvas); - } - this._Gx.plugins.splice(i, 1); - } + if (settings.grid !== undefined) { + if (settings.grid === null) { + Gx.grid = !Gx.grid; + } else { + Gx.grid = settings.grid; } - this._Gx.plugins.sort(function(a, b) { - return (a.zorder - b.zorder); - }); + } - this.refresh(); - }, + if (settings.gridBackground !== undefined) { + Gx.gridBackground = settings.gridBackground; + } - /** - * Adds a listener to plot events. - * - * @example plot.addListener(what, function(event) {}); - * - * @param what - * the name of the event to listen to. "file_deoverlayed" is - * emitted when a file is deoverlayed (the name of the deoverlayed - * file can be found in evt.filename), "file_overlayed" is emitted - * when a file is overlayed (the name of the overlayed file can - * be found in evt.filename), "hidemenu" is emitted when the - * menu should be hidden (a selection is made or a mouse click - * occurs away from the menu), "mdown" is emitted when the mouse - * down event occurs (the evt has parts evt.xpos (the mouse x-position - * relative to the canvas), evt.ypos (the mouse y-position relative - * to the canvas), evt.x (the mouse x-position relative to the data), - * evt.y (the mouse y-position relative to the data) and evt.which - * (returns which mouse button was pressed for the event)) "mmove" - * is emitted when a mouse move event occurs (the evt has parts - * evt.xpos (the mouse x-position relative to the canvas), evt.ypos - * (the mouse y-position relative to the canvas), evt.x (the mouse - * x-position relative to the data), evt.y (the mouse y-position - * relative to the data) and evt.which (returns which mouse button - * was pressed for the event)), "mtag" is emitted when a mouse "tag" - * event occurs (the evt of an mtag has different parts depending - * on what triggered it. It will always contain evt.xpos (the mouse - * x-position relative to the canvas), evt.ypos (the mouse y-position - * relative to the canvas), evt.x (the mouse x-position relative - * to the data), and evt.y (the mouse y-position relative to the data). - * If the rubberboxes are enabled, evt.h and evt.w will contain - * the width and height of the box. evt.shift will contain info - * about the shift key if it is pressed), "mmove" is emitted when - * a mouse move event has occurred, "mdown" is emitted when - * a mouse down event has occurred (the evt has parts evt.xpos - * (the mouse x-position relative to the canvas), evt.ypos (the - * mouse y-position relative to the canvas), evt.x (the mouse - * x-position relative to the data), evt.y (the mouse y-position - * relative to the data) and evt.which (returns which mouse button - * was pressed for the event)), "mup" is emitted when a mouse up - * event occurs. (the evt has parts evt.xpos (the mouse x-position - * relative to the canvas), evt.ypos (the mouse y-position relative - * to the canvas), evt.x (the mouse x-position relative to the data), - * evt.y (the mouse y-position relative to the data) and evt.which - * (returns which mouse button was pressed for the event)), - * "reread" is emitted when a reread has been performed, "sigplotexit" - * is emitted when an exit plot event occurs, and "showmenu" is - * emitted when the menu should be shown (the evt.x and evt.y - * contain the coordinates on the plot where the menu will be displayed. - * - * @param [function] - * callback the function that will be called when the event is heard - */ - addListener: function(what, callback) { - var Mx = this._Mx; - mx.addEventListener(Mx, what, callback, false); - }, + if (settings.gridStyle !== undefined) { + Gx.gridStyle = settings.gridStyle; + } + + if (settings.wheelZoom !== undefined) { + Gx.wheelZoom = settings.wheelZoom; + } + + if (settings.wheelZoomPercent !== undefined) { + Gx.wheelZoomPercent = settings.wheelZoomPercent; + } + + if (settings.autol !== undefined) { + Gx.autol = settings.autol; + } + + if (settings.index !== undefined && settings.index !== Gx.index) { + if (settings.index === null) { + Gx.index = !Gx.index; + } else { + Gx.index = settings.index; + } + + // the original sigplot.for fails + // to do this so that the specs area + // has the correct setting. + if (Gx.index && Gx.iabsc !== 1) { + Gx.iabsc = 1; + } else if (!Gx.index && Gx.iabsc === 1) { + Gx.iabsc = 0; + } - /** - * Removes a listener to plot events. - * - * @param what - * the event that was listned to - * @param callback - */ - removeListener: function(what, callback) { - var Mx = this._Mx; - mx.removeEventListener(Mx, what, callback, false); - }, + var xmin; + var xmax; + scale_base( + this, + { + get_data: false, + }, + xmin, + xmax + ); - /** - * Change one or more plot settings. For boolean types, passing null - * will toggle the setting. - * - * @example plot.change_settings({[settings]}); - * - * @param settings - * Key-value pairs whose values are the settings to change - * - * @param {Boolean} - * settings.grid change grid visibility - * - * @param {Boolean} - * settings.index change index setting - * - * @param {Boolean} - * settings.all change the plot to show all data - * - * @param {Boolean} - * settings.show_x_axis true displays the x axis - * - * @param {Boolean} - * settings.show_y_axis true displays the y axis - * - * @param {Boolean} - * settings.show_readout true displays the readout - * - * @param {Boolean} - * settings.specs turns on and off specs - * - * @param {String} - * settings.xcnt "leftmouse", "continuous", "disable", - * "enable" - * - * @param {Boolean} - * settings.legend true displays the legend - * - * @param {Boolean} - * settings.pan true will display scrollbars and enable panning - * - * @param {Boolean} - * settings.cross true displays cross hairs - * - * @param {String} - * settings.rubberbox_action controls action of rubberbox. - * "zoom" (default) = zoom to the selected area, "select" = - * select the selected area, and "null" = disabled, no action - * - * @param {String} - * settings.rubberbox_mode controls the behavior of the rubberbox. - * "zoom" = zoom to the selected area, "box" = trigger an mtag - * action on the selected area - * - * @param {String} - * settings.rightclick_rubberbox_action controls action of - * rubberbox on rightclick. "zoom" = zoom to the selected area, - * "select" = select the selected area, and "null" (the default) - * = disabled, no action - * - * @param {String} - * settings.rightclick_rubberbox_mode controls the behavior of - * the rubberbox on rightclck. "zoom" = zoom to the selected area, - * "box" = trigger an mtag action on the selected area. By default - * is null to disable right-click boxes - * - * @param {String} - * settings.wheelscroll_mode_natural true indicates natural - * mode, where scrolling the mousewheel forward will pan down - * and backwards will pan up - * - * @param {String} - * settings.cmode !!!! CHANGED - * - * @param {String} - * settings.phunits The phase units "D" = Degrees, "R" = Radians, - * "C" = Cycles - * - * @param {Boolean} - * settings.lg_colorbar true displays the large colorbar - * - * @param {Boolean} - * settings.p_cuts true displays p_cuts on a 2D plot - */ - change_settings: function(settings) { - var Gx = this._Gx; - var Mx = this._Mx; + // like sigplot, undo all zoom levels + this.unzoom(); + } - for (var i = 0; i < Gx.lyr.length; i++) { - Gx.lyr[i].change_settings(settings); + if (settings.all !== undefined) { + if (settings.all === null) { + Gx.all = !Gx.all; + } else { + Gx.all = settings.all; } + } - if (settings.xyKeys !== undefined) { - if (settings.xyKeys === null) { - Gx.xyKeys = "automatic"; - } else { - Gx.xyKeys = settings.xyKeys; - } + if (settings.show_x_axis !== undefined) { + if (settings.show_x_axis === null) { + Gx.show_x_axis = !Gx.show_x_axis; + } else { + Gx.show_x_axis = settings.show_x_axis; } + Gx.specs = Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout; + } - if (settings.grid !== undefined) { - if (settings.grid === null) { - Gx.grid = !Gx.grid; - } else { - Gx.grid = settings.grid; - } + if (settings.show_y_axis !== undefined) { + if (settings.show_y_axis === null) { + Gx.show_y_axis = !Gx.show_y_axis; + } else { + Gx.show_y_axis = settings.show_y_axis; } + Gx.specs = Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout; + } - if (settings.gridBackground !== undefined) { - Gx.gridBackground = settings.gridBackground; + if (settings.show_readout !== undefined) { + if (settings.show_readout === null) { + Gx.show_readout = !Gx.show_readout; + } else { + Gx.show_readout = settings.show_readout; } + Gx.specs = Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout; + } - if (settings.gridStyle !== undefined) { - Gx.gridStyle = settings.gridStyle; + if (settings.specs !== undefined) { + if (settings.specs === null) { + Gx.specs = !Gx.specs; + } else { + Gx.specs = settings.specs; } + if (Gx.specs) { + Gx.show_x_axis = true; + Gx.show_y_axis = true; + Gx.show_readout = true; + } else { + Gx.show_x_axis = false; + Gx.show_y_axis = false; + Gx.show_readout = false; + } + } - if (settings.wheelZoom !== undefined) { - Gx.wheelZoom = settings.wheelZoom; + if (settings.xcnt !== undefined) { + if (settings.xcnt === "leftmouse") { + Gx.cntrls = 1; + } else if (settings.xcnt === "continuous") { + Gx.cntrls = 2; + } else if (settings.xcnt === "disable" && Gx.cntrls > 0) { + Gx.cntrls = -1 * Gx.cntrls; + } else if (settings.xcnt === "enable" && Gx.cntrls < 0) { + Gx.cntrls = -1 * Gx.cntrls; + } else { + Gx.cntrls = settings.xcnt; } + } - if (settings.wheelZoomPercent !== undefined) { - Gx.wheelZoomPercent = settings.wheelZoomPercent; + if (settings.legend !== undefined) { + if (settings.legend === null) { + Gx.legend = !Gx.legend; + } else { + Gx.legend = settings.legend; } + } - if (settings.autol !== undefined) { - Gx.autol = settings.autol; + if (settings.pan !== undefined) { + if (settings.pan === null) { + Gx.pan = !Gx.pan; + } else { + Gx.pan = settings.pan; } + } - if ((settings.index !== undefined) && (settings.index !== Gx.index)) { - if (settings.index === null) { - Gx.index = !Gx.index; - } else { - Gx.index = settings.index; + if (settings.cross !== undefined) { + if (settings.cross === null) { + // catch null or undefined here + Gx.cross = !Gx.cross; + } else { + Gx.cross = settings.cross; + } + if (!Gx.cross) { + if (Gx.cross_xpos !== undefined) { + mx.rubberline( + Mx, + Gx.cross_xpos, + Mx.t, + Gx.cross_xpos, + Mx.b + ); + } + if (Gx.cross_ypos !== undefined) { + mx.rubberline( + Mx, + Mx.l, + Gx.cross_ypos, + Mx.r, + Gx.cross_ypos + ); } - - // the original sigplot.for fails - // to do this so that the specs area - // has the correct setting. - if ((Gx.index) && (Gx.iabsc !== 1)) { - Gx.iabsc = 1; - } else if ((!Gx.index) && (Gx.iabsc === 1)) { - Gx.iabsc = 0; + Gx.cross_xpos = undefined; + Gx.cross_ypos = undefined; + } else { + Gx.cross_xpos = undefined; + Gx.cross_ypos = undefined; + if (!Mx.warpbox && this.mouseOnCanvas) { + draw_crosshairs(this); } - - var xmin; - var xmax; - scale_base(this, { - get_data: false - }, xmin, xmax); - - // like sigplot, undo all zoom levels - this.unzoom(); } + } - if (settings.all !== undefined) { - if (settings.all === null) { - Gx.all = !Gx.all; + var cmode; + var address = settings.cmode === undefined ? "" : settings.cmode; + if (typeof address === "string") { + address = address + ""; + cmode = address.toUpperCase(); + } else { + cmode = address; + } + + if (settings.cmode !== undefined) { + if ( + cmode === "MA" || + cmode === "INMA" || + cmode === "ABMA" || + cmode === "__MA" || + cmode === "MAGNITUDE" || + cmode === 1 + ) { + cmode = 1; + } + if ( + cmode === "PH" || + cmode === "INPH" || + cmode === "ABPH" || + cmode === "__PH" || + cmode === "PHASE" || + cmode === 2 + ) { + cmode = 2; + } + if ( + cmode === "RE" || + cmode === "INRE" || + cmode === "ABRE" || + cmode === "__RE" || + cmode === "REAL" || + cmode === 3 + ) { + cmode = 3; + } + if ( + cmode === "IM" || + cmode === "INIM" || + cmode === "ABIM" || + cmode === "__IM" || + cmode === "IMAGINARY" || + cmode === 4 + ) { + cmode = 4; + } + if ( + cmode === "LO" || + cmode === "D1" || + cmode === "INLO" || + cmode === "IND1" || + cmode === "ABIM" || + cmode === "ABD1" || + cmode === "__LO" || + cmode === "__D1" || + cmode === "10*LOG10" || + cmode === 6 + ) { + cmode = 6; + } + if ( + cmode === "L2" || + cmode === "D2" || + cmode === "INL2" || + cmode === "IND2" || + cmode === "ABLO" || + cmode === "ABD2" || + cmode === "__L2" || + cmode === "__D2" || + cmode === "20*LOG10" || + cmode === 7 + ) { + cmode = 7; + } + if ( + cmode === "RI" || + cmode === "IR" || + cmode === "INRI" || + cmode === "INIR" || + cmode === "ABRI" || + cmode === "ABIR" || + cmode === "__RI" || + cmode === "__IR" || + cmode === "IMAG/REAL" || + cmode === "REAL/IMAG" || + cmode === 5 + ) { + if (Gx.index) { + m.log.error( + "Imag/Real mode not permitted in INDEX mode" + ); } else { - Gx.all = settings.all; + cmode = 5; } } - if (settings.show_x_axis !== undefined) { - if (settings.show_x_axis === null) { - Gx.show_x_axis = !Gx.show_x_axis; - } else { - Gx.show_x_axis = settings.show_x_axis; - } - Gx.specs = (Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout); - } + changemode(this, cmode); + } - if (settings.show_y_axis !== undefined) { - if (settings.show_y_axis === null) { - Gx.show_y_axis = !Gx.show_y_axis; - } else { - Gx.show_y_axis = settings.show_y_axis; - } - Gx.specs = (Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout); - } + if (settings.phunits !== undefined) { + changephunits(this, settings.phunits); + } - if (settings.show_readout !== undefined) { - if (settings.show_readout === null) { - Gx.show_readout = !Gx.show_readout; - } else { - Gx.show_readout = settings.show_readout; - } - Gx.specs = (Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout); - } + if (settings.rubberbox_action !== undefined) { + Gx.default_rubberbox_action = settings.rubberbox_action; + } - if (settings.specs !== undefined) { - if (settings.specs === null) { - Gx.specs = !Gx.specs; - } else { - Gx.specs = settings.specs; - } - if (Gx.specs) { - Gx.show_x_axis = true; - Gx.show_y_axis = true; - Gx.show_readout = true; - } else { - Gx.show_x_axis = false; - Gx.show_y_axis = false; - Gx.show_readout = false; - } - } + if (settings.rubberbox_mode !== undefined) { + Gx.default_rubberbox_mode = settings.rubberbox_mode; + } - if (settings.xcnt !== undefined) { - if (settings.xcnt === "leftmouse") { - Gx.cntrls = 1; - } else if (settings.xcnt === "continuous") { - Gx.cntrls = 2; - } else if ((settings.xcnt === "disable") && (Gx.cntrls > 0)) { - Gx.cntrls = -1 * Gx.cntrls; - } else if ((settings.xcnt === "enable") && (Gx.cntrls < 0)) { - Gx.cntrls = -1 * Gx.cntrls; - } else { - Gx.cntrls = settings.xcnt; - } - } + if (settings.rightclick_rubberbox_action !== undefined) { + Gx.default_rightclick_rubberbox_action = + settings.rightclick_rubberbox_action; + } - if (settings.legend !== undefined) { - if (settings.legend === null) { - Gx.legend = !Gx.legend; - } else { - Gx.legend = settings.legend; - } - } + if (settings.rightclick_rubberbox_mode !== undefined) { + Gx.default_rightclick_rubberbox_mode = + settings.rightclick_rubberbox_mode; + } - if (settings.pan !== undefined) { - if (settings.pan === null) { - Gx.pan = !Gx.pan; - } else { - Gx.pan = settings.pan; - } + if (settings.wheelscroll_mode_natural !== undefined) { + Gx.wheelscroll_mode_natural = settings.wheelscroll_mode_natural; + } + + if (settings.colors !== undefined) { + if (!settings.colors.fg) { + settings.colors.fg = Mx.fg; + } + if (!settings.colors.bg) { + settings.colors.bg = Mx.bg; } + mx.setbgfg(Mx, settings.colors.bg, settings.colors.fg, Mx.xi); + } - if (settings.cross !== undefined) { - if (settings.cross === null) { // catch null or undefined here - Gx.cross = !Gx.cross; - } else { - Gx.cross = settings.cross; - } - if (!Gx.cross) { - if (Gx.cross_xpos !== undefined) { - mx.rubberline(Mx, Gx.cross_xpos, Mx.t, Gx.cross_xpos, - Mx.b); - } - if (Gx.cross_ypos !== undefined) { - mx.rubberline(Mx, Mx.l, Gx.cross_ypos, Mx.r, - Gx.cross_ypos); - } - Gx.cross_xpos = undefined; - Gx.cross_ypos = undefined; + if (settings.cmap !== undefined) { + if (settings.cmap === null) { + // default + if (Gx.cmode === 2) { + Gx.cmap = 2; // wheel } else { - Gx.cross_xpos = undefined; - Gx.cross_ypos = undefined; - if ((!Mx.warpbox) && (this.mouseOnCanvas)) { - draw_crosshairs(this); - } + Gx.cmap = 1; // ramp } - } - - var cmode; - var address = settings.cmode === undefined ? "" : settings.cmode; - if (typeof address === "string") { - address = address + ""; - cmode = address.toUpperCase(); } else { - cmode = address; + Gx.cmap = settings.cmap; // TODO support string lookup } - if (settings.cmode !== undefined) { - if ((cmode === "MA") || (cmode === "INMA") || (cmode === "ABMA") || - (cmode === "__MA") || (cmode === "MAGNITUDE") || (cmode === 1)) { - cmode = 1; - } - if ((cmode === "PH") || (cmode === "INPH") || (cmode === "ABPH") || - (cmode === "__PH") || (cmode === "PHASE") || (cmode === 2)) { - cmode = 2; - } - if ((cmode === "RE") || (cmode === "INRE") || (cmode === "ABRE") || - (cmode === "__RE") || (cmode === "REAL") || (cmode === 3)) { - cmode = 3; - } - if ((cmode === "IM") || (cmode === "INIM") || (cmode === "ABIM") || - (cmode === "__IM") || (cmode === "IMAGINARY") || (cmode === 4)) { - cmode = 4; - } - if ((cmode === "LO") || (cmode === "D1") || (cmode === "INLO") || (cmode === "IND1") || - (cmode === "ABIM") || (cmode === "ABD1") || (cmode === "__LO") || - (cmode === "__D1") || (cmode === "10*LOG10") || (cmode === 6)) { - cmode = 6; - } - if ((cmode === "L2") || (cmode === "D2") || (cmode === "INL2") || (cmode === "IND2") || - (cmode === "ABLO") || (cmode === "ABD2") || (cmode === "__L2") || - (cmode === "__D2") || (cmode === "20*LOG10") || (cmode === 7)) { - cmode = 7; - } - if ((cmode === "RI") || (cmode === "IR") || (cmode === "INRI") || (cmode === "INIR") || - (cmode === "ABRI") || (cmode === "ABIR") || (cmode === "__RI") || - (cmode === "__IR") || (cmode === "IMAG/REAL") || (cmode === "REAL/IMAG") || (cmode === 5)) { - if (Gx.index) { - m.log.error("Imag/Real mode not permitted in INDEX mode"); - } else { - cmode = 5; - } - } + setup_cmap(this, Gx.cmap); + } - changemode(this, cmode); + if (settings.yinv !== undefined) { + if (settings.yinv) { + Mx.origin = 4; + } else { + Mx.origin = 1; } + } - if (settings.phunits !== undefined) { - changephunits(this, settings.phunits); + if (settings.rasterSmoothing !== undefined) { + if (settings.rasterSmoothing === null) { + Gx.rasterSmoothing = !Gx.rasterSmoothing; + } else { + Gx.rasterSmoothing = settings.rasterSmoothing; } + } - if (settings.rubberbox_action !== undefined) { - Gx.default_rubberbox_action = settings.rubberbox_action; - } + if (settings.fillStyle !== undefined) { + Gx.fillStyle = settings.fillStyle; + } - if (settings.rubberbox_mode !== undefined) { - Gx.default_rubberbox_mode = settings.rubberbox_mode; + if (settings.invert !== undefined) { + if (settings.invert === null) { + mx.invertbgfg(Mx); + } else if (settings.invert === true) { + mx.setbgfg(this, "white", "black"); + } else { + mx.setbgfg(this, "black", "white"); } + } - if (settings.rightclick_rubberbox_action !== undefined) { - Gx.default_rightclick_rubberbox_action = settings.rightclick_rubberbox_action; + if (settings.nomenu !== undefined) { + if (settings.nomenu === null) { + Gx.nomenu = !Gx.nomenu; + } else { + Gx.nomenu = settings.nomenu; } + } - if (settings.rightclick_rubberbox_mode !== undefined) { - Gx.default_rightclick_rubberbox_mode = settings.rightclick_rubberbox_mode; + if (settings.ymax !== undefined) { + if (settings.ymax === null) { + Gx.autoy = Gx.autoy | 2; + Gx.panymax = undefined; + scale_base(this, {}); + Gx.ymax = Gx.panymax; + } else { + // autoy must be set correctly before calling updateViewbox + Gx.autoy = Gx.autoy & 0xd; + Gx.ymax = settings.ymax; + updateViewbox(this, Mx.stk[0].ymin, settings.ymax, "Y"); + this.redraw(); } + } - if (settings.wheelscroll_mode_natural !== undefined) { - Gx.wheelscroll_mode_natural = settings.wheelscroll_mode_natural; + if (settings.ymin !== undefined) { + if (settings.ymin === null) { + Gx.autoy = Gx.autoy | 1; + Gx.panymin = undefined; + scale_base(this, {}); + Gx.ymin = Gx.panymin; + } else { + // autoy must be set correctly before calling updateViewbox + Gx.autoy = Gx.autoy & 0xe; + Gx.ymin = settings.ymin; + updateViewbox(this, settings.ymin, Mx.stk[0].ymax, "Y"); + this.redraw(); } + } - if (settings.colors !== undefined) { - if (!settings.colors.fg) { - settings.colors.fg = Mx.fg; - } - if (!settings.colors.bg) { - settings.colors.bg = Mx.bg; - } - mx.setbgfg(Mx, settings.colors.bg, settings.colors.fg, Mx.xi); + // Check autoy setting after checking ymin/ymax + // so that explicitly setting autoy will override + // implicit settings via ymin/ymax + if (settings.autoy !== undefined) { + Gx.autoy = settings.autoy; + if ((Gx.autoy & 1) !== 0) { + Gx.ymin = undefined; } + if ((Gx.autoy & 2) !== 0) { + Gx.ymax = undefined; + } + } - if (settings.cmap !== undefined) { - if (settings.cmap === null) { - // default - if (Gx.cmode === 2) { - Gx.cmap = 2; // wheel - } else { - Gx.cmap = 1; // ramp - } - } else { - Gx.cmap = settings.cmap; // TODO support string lookup - } + if (settings.xmin !== undefined) { + updateViewbox(this, settings.xmin, Mx.stk[0].xmax, "X"); + Gx.autox = Gx.autox & 2; + this.redraw(); + } - setup_cmap(this, Gx.cmap); - } + if (settings.xmax !== undefined) { + updateViewbox(this, Mx.stk[0].xmin, settings.xmax, "X"); + Gx.autox = Gx.autox & 1; + this.redraw(); + } - if (settings.yinv !== undefined) { - if (settings.yinv) { - Mx.origin = 4; - } else { - Mx.origin = 1; - } - } + if (settings.zmin !== undefined) { + Gx.zmin = settings.zmin; + Gx.autoz = Gx.autoz & 2; + } - if (settings.rasterSmoothing !== undefined) { - if (settings.rasterSmoothing === null) { - Gx.rasterSmoothing = !Gx.rasterSmoothing; - } else { - Gx.rasterSmoothing = settings.rasterSmoothing; - } - } + if (settings.zmax !== undefined) { + Gx.zmax = settings.zmax; + Gx.autoz = Gx.autoz & 1; + } - if (settings.fillStyle !== undefined) { - Gx.fillStyle = settings.fillStyle; + if (settings.autoz !== undefined) { + Gx.autoz = settings.autoz; + if ((Gx.autoz & 1) !== 0) { + Gx.zmin = undefined; } - - if (settings.invert !== undefined) { - if (settings.invert === null) { - mx.invertbgfg(Mx); - } else if (settings.invert === true) { - mx.setbgfg(this, "white", "black"); - } else { - mx.setbgfg(this, "black", "white"); - } + if ((Gx.autoz & 2) !== 0) { + Gx.zmax = undefined; } + } - if (settings.nomenu !== undefined) { - if (settings.nomenu === null) { - Gx.nomenu = !Gx.nomenu; - } else { - Gx.nomenu = settings.nomenu; - } - } + if (settings.note !== undefined) { + Gx.note = settings.note; + } - if (settings.ymax !== undefined) { - if (settings.ymax === null) { - Gx.autoy = Gx.autoy | 2; - Gx.panymax = undefined; - scale_base(this, {}); - Gx.ymax = Gx.panymax; - } else { - // autoy must be set correctly before calling updateViewbox - Gx.autoy = Gx.autoy & 0xD; - Gx.ymax = settings.ymax; - updateViewbox(this, Mx.stk[0].ymin, settings.ymax, "Y"); - this.redraw(); - } - } + if (settings.lg_colorbar !== undefined) { + // Change the plot area and then draw the large colorbar + Gx.lg_colorbar = !Gx.lg_colorbar; + } - if (settings.ymin !== undefined) { - if (settings.ymin === null) { - Gx.autoy = Gx.autoy | 1; - Gx.panymin = undefined; - scale_base(this, {}); - Gx.ymin = Gx.panymin; - } else { - // autoy must be set correctly before calling updateViewbox - Gx.autoy = Gx.autoy & 0xE; - Gx.ymin = settings.ymin; - updateViewbox(this, settings.ymin, Mx.stk[0].ymax, "Y"); - this.redraw(); - } + if (settings.p_cuts !== undefined) { + // Change the plot area and then draw the p_cuts dipslay + if (settings.p_cuts === null) { + Gx.p_cuts = !Gx.p_cuts; + } else { + Gx.p_cuts = settings.p_cuts; } + } - // Check autoy setting after checking ymin/ymax - // so that explicitly setting autoy will override - // implicit settings via ymin/ymax - if (settings.autoy !== undefined) { - Gx.autoy = settings.autoy; - if (((Gx.autoy & 1) !== 0)) { - Gx.ymin = undefined; - } - if (((Gx.autoy & 2) !== 0)) { - Gx.ymax = undefined; - } - } + //this is a setting that is true if we are drawing an xcut + if (settings.xcut_now !== undefined) { + Gx.xcut_now = !Gx.xcut_now; + } - if (settings.xmin !== undefined) { - updateViewbox(this, settings.xmin, Mx.stk[0].xmax, "X"); - Gx.autox = (Gx.autox & 2); - this.redraw(); - } + //this is a setting that is true if we are drawing a ycut + if (settings.ycut_now !== undefined) { + Gx.ycut_now = !Gx.ycut_now; + } - if (settings.xmax !== undefined) { - updateViewbox(this, Mx.stk[0].xmin, settings.xmax, "X"); - Gx.autox = (Gx.autox & 1); - this.redraw(); - } + this.refresh(); + if (settings.pan !== undefined) { + // refactor - new code to handle + // disappearing specs + display_specs(this); + } + }, - if (settings.zmin !== undefined) { - Gx.zmin = settings.zmin; - Gx.autoz = (Gx.autoz & 2); - } + /** + * Reread all files and refresh the plot. + */ + reread: function () { + var Gx = this._Gx; + var oldLayerData = []; + for (var k = 0; k < Gx.lyr.length; k++) { + // make a copy of layer + // data before + // destroying Gx.lyr + // with the deoverlay + oldLayerData[k] = Gx.lyr[k]; + } - if (settings.zmax !== undefined) { - Gx.zmax = settings.zmax; - Gx.autoz = (Gx.autoz & 1); - } + var origHCB = Gx.HCB.slice(); + var origHCB_UUID = clone(Gx.HCB_UUID); - if (settings.autoz !== undefined) { - Gx.autoz = settings.autoz; - if (((Gx.autoz & 1) !== 0)) { - Gx.zmin = undefined; - } - if (((Gx.autoz & 2) !== 0)) { - Gx.zmax = undefined; - } - } + this.deoverlay(); + for (var i = 0; i < origHCB.length; i++) { + this.overlay_bluefile(origHCB_UUID[origHCB[i]]); + } - if (settings.note !== undefined) { - Gx.note = settings.note; - } + // propagate old layer attributes to re-read layers + for (var j = 0; j < Gx.lyr.length; j++) { + // TODO Assumes indices of old Gx.lyr and new Gx.lyr will match + // up correctly - should we instead use hcb and name to identify + Gx.lyr[j].symbol = oldLayerData[j].symbol; + Gx.lyr[j].radius = oldLayerData[j].radius; + // TODO re-copy other things like line type??? + } + this.refresh(); - if (settings.lg_colorbar !== undefined) { - // Change the plot area and then draw the large colorbar - Gx.lg_colorbar = !Gx.lg_colorbar; - } + // Notify listeners that a reread was performed + var evt = document.createEvent("Event"); + evt.initEvent("reread", true, true); + mx.dispatchEvent(this._Mx, evt); + }, - if (settings.p_cuts !== undefined) { - // Change the plot area and then draw the p_cuts dipslay - if (settings.p_cuts === null) { - Gx.p_cuts = !Gx.p_cuts; - } else { - Gx.p_cuts = settings.p_cuts; - } - } + /** + * Placeholder for cleanup logic. + */ + cleanup: function () { + // TODO not sure what we really want to do here yet + }, - //this is a setting that is true if we are drawing an xcut - if (settings.xcut_now !== undefined) { - Gx.xcut_now = !Gx.xcut_now; - } + /** + * Reload data without adjusting other aspects about a plot + * + * @param {Number} n + * the layer to push data into + * @param {Number[]} data + * data to push + * @param {Object} hdrmod + * optional changes to the file header + */ + reload: function (lyr, data, hdrmod, rsync) { + var Mx = this._Mx; + var Gx = this._Gx; - //this is a setting that is true if we are drawing a ycut - if (settings.ycut_now !== undefined) { - Gx.ycut_now = !Gx.ycut_now; - } + var n = -1; + if (has(Gx.HCB_UUID, lyr)) { + n = this.get_lyrn(lyr); + } - this.refresh(); - if (settings.pan !== undefined) { // refactor - new code to handle - // disappearing specs - display_specs(this); + if (n < 0 || n >= Gx.lyr.length) { + if (typeof lyr === "number") { + throw "reload requires use the layer uuid returned by overlay and no longer supports layer indexes"; } - }, + return; + } - /** - * Reread all files and refresh the plot. - */ - reread: function() { - var Gx = this._Gx; - var oldLayerData = []; - for (var k = 0; k < Gx.lyr.length; k++) { // make a copy of layer - // data before - // destroying Gx.lyr - // with the deoverlay - oldLayerData[k] = Gx.lyr[k]; - } + if (Gx.lyr[n].reload === undefined) { + return; + } - var origHCB = Gx.HCB.slice(); - var origHCB_UUID = _.clone(Gx.HCB_UUID); + var xbnds = Gx.lyr[n].reload(data, hdrmod); - this.deoverlay(); - for (var i = 0; i < origHCB.length; i++) { - this.overlay_bluefile(origHCB_UUID[origHCB[i]]); - } + if (Mx.level === 0) { + // Unlike push(), always call scale_base + // when reload is invoked + scale_base( + this, + { + get_data: false, + }, + xbnds.xmin, + xbnds.xmax + ); + } - // propagate old layer attributes to re-read layers - for (var j = 0; j < Gx.lyr.length; j++) { - // TODO Assumes indices of old Gx.lyr and new Gx.lyr will match - // up correctly - should we instead use hcb and name to identify - Gx.lyr[j].symbol = oldLayerData[j].symbol; - Gx.lyr[j].radius = oldLayerData[j].radius; - // TODO re-copy other things like line type??? - } + if (rsync) { + this._refresh(); + } else { this.refresh(); + } + }, - // Notify listeners that a reread was performed - var evt = document.createEvent('Event'); - evt.initEvent('reread', true, true); - mx.dispatchEvent(this._Mx, evt); - }, + rescale: function () { + var Mx = this._Mx; - /** - * Placeholder for cleanup logic. - */ - cleanup: function() { - // TODO not sure what we really want to do here yet - }, + if (Mx.level === 0) { + scale_base( + this, + { + get_data: false, + }, + undefined, + undefined + ); + } - /** - * Reload data without adjusting other aspects about a plot - * - * @param {Number} n - * the layer to push data into - * @param {Number[]} data - * data to push - * @param {Object} hdrmod - * optional changes to the file header - */ - reload: function(lyr, data, hdrmod, rsync) { - var Mx = this._Mx; - var Gx = this._Gx; - - var n = -1; - if (_.has(Gx.HCB_UUID, lyr)) { - n = this.get_lyrn(lyr); - } - - if ((n < 0) || (n >= Gx.lyr.length)) { - if (typeof lyr === "number") { - throw "reload requires use the layer uuid returned by overlay and no longer supports layer indexes"; - } - return; - } + this.refresh(); + }, - if (Gx.lyr[n].reload === undefined) { - return; - } + /** + * Change the file header + * + * @param {Number} n + * the layer to push header changes to + * @param {Object} hdrmod + * changes to the file header + */ + headermod: function (n, hdrmod) { + this.change_settings(hdrmod); + this.push(n, [], hdrmod); + }, - var xbnds = Gx.lyr[n].reload(data, hdrmod); + /** + * Push data into a layer that was created with overlay_pipe + * + * @example plot.push(n, data); + * + * @param {Number} n + * the layer to push data into + * @param {Number[]} data + * data to push + * @param {Object} hdrmod + * optional changes to the file header + * @param {boolean} [sync=false] + * optional dispatch onpipewrite syncronously + * @param {boolean} [rsync=false] + * optional dispatch refresh syncronously + */ + push: function (lyr, data, hdrmod, sync, rsync) { + var Mx = this._Mx; + var Gx = this._Gx; - if (Mx.level === 0) { - // Unlike push(), always call scale_base - // when reload is invoked - scale_base(this, { - get_data: false - }, xbnds.xmin, xbnds.xmax); - } + var n = -1; + if (has(Gx.HCB_UUID, lyr)) { + n = this.get_lyrn(lyr); + } - if (rsync) { - this._refresh(); - } else { - this.refresh(); + if (n < 0 || n >= Gx.lyr.length) { + if (typeof lyr === "number") { + throw "push requires use the layer uuid returned by overlay and no longer supports layer indexes"; } + return; + } - }, + if (Gx.lyr[n].push === undefined) { + return; + } + + if (Gx.lyr[n].display === false) { + return; + } - rescale: function() { - var Mx = this._Mx; + var hdrmod_clone = hdrmod; - if (Mx.level === 0) { - scale_base(this, { - get_data: false - }, undefined, undefined); + // quick deep copy of the header so we can + // add some necessary fields if this is + // a header-only push + if (hdrmod) { + var hdrmod_clone = JSON.parse(JSON.stringify(hdrmod)); + + // if it's a header-only push, the data should + // be an empty array + if (data.length === 0) { + hdrmod_clone.xmin = Mx.stk[0].xmin; + hdrmod_clone.xmax = Mx.stk[0].xmax; + hdrmod_clone.ymin = Mx.stk[0].ymin; + hdrmod_clone.ymax = Mx.stk[0].ymax; } + } + var rescale = Gx.lyr[n].push(data, hdrmod_clone, sync); + + if (Mx.level === 0 && rescale) { + scale_base(this, { + get_data: false, + }); + } + + if (rsync) { + this._refresh(); + } else { this.refresh(); - }, + } + }, - /** - * Change the file header - * - * @param {Number} n - * the layer to push header changes to - * @param {Object} hdrmod - * changes to the file header - */ - headermod: function(n, hdrmod) { - this.change_settings(hdrmod); - this.push(n, [], hdrmod); - }, + /** + * Create a plot layer with an array overlay + * + * @example plot.overlay_array(data, {[overrides]}, {[layerOptions]}); + * + * @param data + * data the data that you will be plotting + * + * @param [overrides] + * Key-value pairs whose values alter plot settings + * + * @param {Number} + * overrides.type 1000 = one dimensional, 2000 = two dimensional. + * this is a convention of X-midas + * + * @param {Number} + * overrides.subsize the subsize for data being read in by the plot + * + * @param [layerOptions] + * Key-value pairs whose values are the settings for the plot + * + * @param {String} + * layerOptions.name the name of the layer + * + * @param {Number} + * layerOptions.framesize the framsize of the plot + * + * @param {Varies} + * layerOptions.etc all of the parameters for the change_settings + * function except for lg_colorbar and p_cuts + * + * @returns data_layer + * + */ - /** - * Push data into a layer that was created with overlay_pipe - * - * @example plot.push(n, data); - * - * @param {Number} n - * the layer to push data into - * @param {Number[]} data - * data to push - * @param {Object} hdrmod - * optional changes to the file header - * @param {boolean} [sync=false] - * optional dispatch onpipewrite syncronously - * @param {boolean} [rsync=false] - * optional dispatch refresh syncronously - */ - push: function(lyr, data, hdrmod, sync, rsync) { - var Mx = this._Mx; - var Gx = this._Gx; - - var n = -1; - if (_.has(Gx.HCB_UUID, lyr)) { - n = this.get_lyrn(lyr); - } - - if ((n < 0) || (n >= Gx.lyr.length)) { - if (typeof lyr === "number") { - throw "push requires use the layer uuid returned by overlay and no longer supports layer indexes"; - } - return; - } + overlay_array: function (data, overrides, layerOptions) { + m.log.debug("Overlay array"); + var hcb = m.initialize(data, overrides); + return this.overlay_bluefile(hcb, layerOptions); + }, - if (Gx.lyr[n].push === undefined) { - return; - } + /** + * Create a plot layer to hold data + * + * @example plot.overlay_pipe({[overrides]},{[layerOptions]}); + * + * @param [overrides] + * Key-value pairs whose values alter plot settings + * + * @param {Number} + * overrides.type 1000 = one dimensional, 2000 = two dimensional. + * this is a convention of X-midas + * + * @param {Number} + * overrides.subsize the subsize for data being read in by the plot + * + * @param [layerOptions] + * Key-value pairs whose values are the settings for the plot + * + * @param {String} + * layerOptions.name the name of the layer + * + * @param {Number} + * layerOptions.framesize the framsize of the plot + * + * @param {Varies} + * layerOptions.etc all of the parameters for the change_settings + * function except for lg_colorbar and p_cuts + * + * @returns data_layer + * + */ - if (Gx.lyr[n].display === false) { - return; - } + overlay_pipe: function (overrides, layerOptions) { + m.log.debug("Overlay pipe"); + if (!overrides) { + overrides = {}; + } + overrides.pipe = true; + var hcb = m.initialize(null, overrides); + //console.log("pipe filename: "+hcb.file_name); + return this.overlay_bluefile(hcb, layerOptions); + }, - var hdrmod_clone = hdrmod; + /** + * Create a plot layer to hold data + * + * @example plot.overlay_websocket({wsurl, {[overrides]}, {[layerOptions]}}); + * @param {url:port_destination} + * wsurl the url and port destination for the websocket being used + * @param [overrides] + * Key-value pairs whose values alter plot settings + * + * @param {Number} + * overrides.type 1000 = one dimensional, 2000 = two dimensional. + * this is a convention of X-midas + * + * @param {Number} + * overrides.subsize the subsize for data being read in by the plot + * + * @param [layerOptions] + * Key-value pairs whose values are the settings for the plot + * + * @param {String} + * layerOptions.name the name of the layer + * + * @param {Number} + * layerOptions.framesize the framsize of the plot + * + * @param {Varies} + * layerOptions.etc all of the parameters for the change_settings + * function except for lg_colorbar and p_cuts + * + * @returns data_layer + * + */ - // quick deep copy of the header so we can - // add some necessary fields if this is - // a header-only push - if (hdrmod) { - var hdrmod_clone = JSON.parse(JSON.stringify(hdrmod)); + overlay_websocket: function (wsurl, overrides, layerOptions) { + m.log.debug("Overlay websocket: " + wsurl); + var ws = new WebSocket(wsurl, "plot-data"); + ws.binaryType = "arraybuffer"; - // if it's a header-only push, the data should - // be an empty array - if (data.length === 0) { - hdrmod_clone.xmin = Mx.stk[0].xmin; - hdrmod_clone.xmax = Mx.stk[0].xmax; - hdrmod_clone.ymin = Mx.stk[0].ymin; - hdrmod_clone.ymax = Mx.stk[0].ymax; - } - } + var plot = this; + if (!overrides) { + overrides = {}; + } + overrides.pipe = true; + var hcb = m.initialize(null, overrides); + hcb.ws = ws; - var rescale = Gx.lyr[n].push(data, hdrmod_clone, sync); + var layer_n = this.overlay_bluefile(hcb, layerOptions); - if ((Mx.level === 0) && rescale) { - scale_base(this, { - get_data: false - }); - } + ws.onopen = function (evt) {}; - if (rsync) { - this._refresh(); - } else { - this.refresh(); - } - }, + ws.onmessage = (function (theSocket) { + return function (evt) { + if (evt.data instanceof ArrayBuffer) { + var data = hcb.createArray(evt.data); + plot.push(layer_n, data); + } else if (typeof evt.data === "string") { + var Gx = plot._Gx; + var hdr = Gx.lyr[layer_n].hcb; + if (!hdr) { + m.log.warning( + "Couldn't find header for layer " + layer_n + ); + } - /** - * Create a plot layer with an array overlay - * - * @example plot.overlay_array(data, {[overrides]}, {[layerOptions]}); - * - * @param data - * data the data that you will be plotting - * - * @param [overrides] - * Key-value pairs whose values alter plot settings - * - * @param {Number} - * overrides.type 1000 = one dimensional, 2000 = two dimensional. - * this is a convention of X-midas - * - * @param {Number} - * overrides.subsize the subsize for data being read in by the plot - * - * @param [layerOptions] - * Key-value pairs whose values are the settings for the plot - * - * @param {String} - * layerOptions.name the name of the layer - * - * @param {Number} - * layerOptions.framesize the framsize of the plot - * - * @param {Varies} - * layerOptions.etc all of the parameters for the change_settings - * function except for lg_colorbar and p_cuts - * - * @returns data_layer - * - */ - - overlay_array: function(data, overrides, layerOptions) { - m.log.debug("Overlay array"); - var hcb = m.initialize(data, overrides); - return this.overlay_bluefile(hcb, layerOptions); - }, + var newHdr = JSON.parse(evt.data); + plot.push(layer_n, [], newHdr); + } + }; + })(ws); - /** - * Create a plot layer to hold data - * - * @example plot.overlay_pipe({[overrides]},{[layerOptions]}); - * - * @param [overrides] - * Key-value pairs whose values alter plot settings - * - * @param {Number} - * overrides.type 1000 = one dimensional, 2000 = two dimensional. - * this is a convention of X-midas - * - * @param {Number} - * overrides.subsize the subsize for data being read in by the plot - * - * @param [layerOptions] - * Key-value pairs whose values are the settings for the plot - * - * @param {String} - * layerOptions.name the name of the layer - * - * @param {Number} - * layerOptions.framesize the framsize of the plot - * - * @param {Varies} - * layerOptions.etc all of the parameters for the change_settings - * function except for lg_colorbar and p_cuts - * - * @returns data_layer - * - */ - - overlay_pipe: function(overrides, layerOptions) { - m.log.debug("Overlay pipe"); - if (!overrides) { - overrides = {}; - } - overrides.pipe = true; - var hcb = m.initialize(null, overrides); - //console.log("pipe filename: "+hcb.file_name); - return this.overlay_bluefile(hcb, layerOptions); - }, + return layer_n; + }, - /** - * Create a plot layer to hold data - * - * @example plot.overlay_websocket({wsurl, {[overrides]}, {[layerOptions]}}); - * @param {url:port_destination} - * wsurl the url and port destination for the websocket being used - * @param [overrides] - * Key-value pairs whose values alter plot settings - * - * @param {Number} - * overrides.type 1000 = one dimensional, 2000 = two dimensional. - * this is a convention of X-midas - * - * @param {Number} - * overrides.subsize the subsize for data being read in by the plot - * - * @param [layerOptions] - * Key-value pairs whose values are the settings for the plot - * - * @param {String} - * layerOptions.name the name of the layer - * - * @param {Number} - * layerOptions.framesize the framsize of the plot - * - * @param {Varies} - * layerOptions.etc all of the parameters for the change_settings - * function except for lg_colorbar and p_cuts - * - * @returns data_layer - * - */ - - overlay_websocket: function(wsurl, overrides, layerOptions) { - m.log.debug("Overlay websocket: " + wsurl); - var ws = new WebSocket(wsurl, "plot-data"); - ws.binaryType = "arraybuffer"; + /** + * Create a plot layer from an HREF that points to a BLUEFILE or MATFILE + * + * @example plot.overlay_href(href, function() {}, {[layeroptions]}); + * + * @param {String} + * href or |-delimited hrefs the url to the bluefile or matfile + * @param [onload] + * callback to be called when the file has been loaded + * + * @param [layerOptions] + * Key-value pairs whose values are the settings for the plot + * + * @param {String} + * layerOptions.name the name of the layer + * + * @param {Number} + * layerOptions.framesize the framesize of the plot + * + * @param {Varies} + * layerOptions.etc all of the parameters for the change_settings + * function except for lg_colorbar and p_cuts + * + * @returns data_layer + * + */ + overlay_href: function (href, onload, layerOptions, overrides) { + var self = this; + var lyr_uuids = []; + href.split("|").forEach(function (hr) { + var lyr_uuid = self.overlay_href_single( + hr.trim(), + onload, + layerOptions, + overrides + ); + lyr_uuids.push(lyr_uuid); + }); - var plot = this; - if (!overrides) { - overrides = {}; - } - overrides.pipe = true; - var hcb = m.initialize(null, overrides); - hcb.ws = ws; + if (lyr_uuids.length === 0) { + return null; + } else if (lyr_uuids.length === 1) { + return lyr_uuids[0]; + } else { + return lyr_uuids; + } + }, - var layer_n = this.overlay_bluefile(hcb, layerOptions); + /** + * Create a plot layer from an HREF that points to a BLUEFILE or MATFILE + * + * @example plot.overlay_href_single(href, function() {}, {[layeroptions]}); + * + * @param {String} + * href the url to the bluefile or matfile + * @param [onload] + * callback to be called when the file has been loaded + * + * @param [layerOptions] + * Key-value pairs whose values are the settings for the plot + * + * @param {String} + * layerOptions.name the name of the layer + * + * @param {Number} + * layerOptions.framesize the framesize of the plot + * + * @param {Varies} + * layerOptions.etc all of the parameters for the change_settings + * function except for lg_colorbar and p_cuts + * + * @returns data_layer + * + */ + overlay_href_single: function (href, onload, layerOptions, overrides) { + var lyr_uuid = this.reg_hcb(null); - ws.onopen = function(evt) {}; + m.log.debug("Overlay href: " + href + " " + lyr_uuid); + try { + this.show_spinner(); + var handleHeader = (function (plot, onload) { + return function (hcb) { + try { + if (!hcb) { + m.log.error("Failed to load data: " + href); + } else { + hcb._uuid = lyr_uuid; + common.update(hcb, overrides); - ws.onmessage = (function(theSocket) { - return function(evt) { - if (evt.data instanceof ArrayBuffer) { - var data = hcb.createArray(evt.data); - plot.push(layer_n, data); - } else if (typeof evt.data === "string") { - var Gx = plot._Gx; - var hdr = Gx.lyr[layer_n].hcb; - if (!hdr) { - m.log.warning("Couldn't find header for layer " + layer_n); + var i; + if (href.endsWith(".mat")) { + i = plot.overlay_matfile(hcb, layerOptions); + } else { + i = plot.overlay_bluefile( + hcb, + layerOptions + ); + } + if (onload) { + onload(hcb, i); + } } - - var newHdr = JSON.parse(evt.data); - plot.push(layer_n, [], newHdr); + } finally { + plot.hide_spinner(); } }; - })(ws); + })(this, onload); - return layer_n; - }, - - - /** - * Create a plot layer from an HREF that points to a BLUEFILE or MATFILE - * - * @example plot.overlay_href(href, function() {}, {[layeroptions]}); - * - * @param {String} - * href or |-delimited hrefs the url to the bluefile or matfile - * @param [onload] - * callback to be called when the file has been loaded - * - * @param [layerOptions] - * Key-value pairs whose values are the settings for the plot - * - * @param {String} - * layerOptions.name the name of the layer - * - * @param {Number} - * layerOptions.framesize the framesize of the plot - * - * @param {Varies} - * layerOptions.etc all of the parameters for the change_settings - * function except for lg_colorbar and p_cuts - * - * @returns data_layer - * - */ - overlay_href: function(href, onload, layerOptions, overrides) { - var self = this; - var lyr_uuids = []; - href.split('|').forEach(function(hr) { - var lyr_uuid = self.overlay_href_single(hr.trim(), onload, layerOptions, overrides); - lyr_uuids.push(lyr_uuid); - }); - - if (lyr_uuids.length === 0) { - return null; - } else if (lyr_uuids.length === 1) { - return lyr_uuids[0]; - } else { - return lyr_uuids; - } - }, - - /** - * Create a plot layer from an HREF that points to a BLUEFILE or MATFILE - * - * @example plot.overlay_href_single(href, function() {}, {[layeroptions]}); - * - * @param {String} - * href the url to the bluefile or matfile - * @param [onload] - * callback to be called when the file has been loaded - * - * @param [layerOptions] - * Key-value pairs whose values are the settings for the plot - * - * @param {String} - * layerOptions.name the name of the layer - * - * @param {Number} - * layerOptions.framesize the framesize of the plot - * - * @param {Varies} - * layerOptions.etc all of the parameters for the change_settings - * function except for lg_colorbar and p_cuts - * - * @returns data_layer - * - */ - overlay_href_single: function(href, onload, layerOptions, overrides) { - var lyr_uuid = this.reg_hcb(null); - - m.log.debug("Overlay href: " + href + " " + lyr_uuid); - try { - this.show_spinner(); - var handleHeader = (function(plot, onload) { - return function(hcb) { - try { - if (!hcb) { - m.log.error("Failed to load data: " + href); - } else { - hcb._uuid = lyr_uuid; - common.update(hcb, overrides); - - var i; - if (href.endsWith(".mat")) { - i = plot.overlay_matfile(hcb, layerOptions); + var handleSDS = (function (plot, onload) { + return function (hcb, layertype) { + // LOWER CASE CRAP THAT GRANT SENT US + try { + var i = null; + if (!hcb) { + m.log.error("Failed to load data: " + href); + } else { + hcb._uuid = lyr_uuid; + common.update(hcb, overrides); + if (layertype === "SDS") { + if (hcb.file_type === 1000) { + layerOptions.layerType = "1DSDS"; } else { - i = plot.overlay_bluefile(hcb, layerOptions); - } - if (onload) { - onload(hcb, i); + layerOptions.layerType = "2DSDS"; } - } - } finally { - plot.hide_spinner(); - } - }; - }(this, onload)); - - var handleSDS = (function(plot, onload) { - return function(hcb, layertype) { - // LOWER CASE CRAP THAT GRANT SENT US - try { - var i = null; - if (!hcb) { - m.log.error("Failed to load data: " + href); } else { - hcb._uuid = lyr_uuid; - common.update(hcb, overrides); - if (layertype === "SDS") { - if (hcb.file_type === 1000) { - layerOptions.layerType = "1DSDS"; - } else { - layerOptions.layerType = "2DSDS"; - } - } else { - layerOptions.layerType = layertype; - } + layerOptions.layerType = layertype; + } - i = plot.overlay_bluefile(hcb, layerOptions); - if (onload) { - onload(hcb, i); - } + i = plot.overlay_bluefile(hcb, layerOptions); + if (onload) { + onload(hcb, i); } - } finally { - plot.hide_spinner(); - } - }; - }(this, onload)); - - var reader; - var oReq; - if (href.endsWith(".mat")) { - reader = new matfile.MatFileReader(); - oReq = reader.read_http(href, handleHeader); - } else if (layerOptions && (layerOptions.layerType === "2DSDS" || layerOptions.layerType === "1DSDS" || layerOptions.layerType === "SDS")) { - // TODO it would be nice to not check layerType here but either - // peek at the URL contents OR use something in the URL - oReq = new XMLHttpRequest(); - oReq.open("GET", href, true); - oReq.responseType = ""; - oReq.onload = function(oEvent) { - var hcb = JSON.parse(oReq.responseText); - if (hcb) { - hcb.url = href; } - handleSDS(hcb, layerOptions.layerType); - - }; - oReq.onerror = function(oEvent) { - //console.log("error fetching SDS header" + oEvent) - }; - oReq.send(null); - this._Gx.HCB_RDR[lyr_uuid] = oReq; - } else { - reader = new bluefile.BlueFileReader(); - oReq = reader.read_http(href, handleHeader); - } - if (oReq) { - this._Gx.HCB_RDR[lyr_uuid] = oReq; - } - } catch (error) { - this.hide_spinner(); + } finally { + plot.hide_spinner(); + } + }; + })(this, onload); + + var reader; + var oReq; + if (href.endsWith(".mat")) { + reader = new matfile.MatFileReader(); + oReq = reader.read_http(href, handleHeader); + } else if ( + layerOptions && + (layerOptions.layerType === "2DSDS" || + layerOptions.layerType === "1DSDS" || + layerOptions.layerType === "SDS") + ) { + // TODO it would be nice to not check layerType here but either + // peek at the URL contents OR use something in the URL + oReq = new XMLHttpRequest(); + oReq.open("GET", href, true); + oReq.responseType = ""; + oReq.onload = function (oEvent) { + var hcb = JSON.parse(oReq.responseText); + if (hcb) { + hcb.url = href; + } + handleSDS(hcb, layerOptions.layerType); + }; + oReq.onerror = function (oEvent) { + //console.log("error fetching SDS header" + oEvent) + }; + oReq.send(null); + this._Gx.HCB_RDR[lyr_uuid] = oReq; + } else { + reader = new bluefile.BlueFileReader(); + oReq = reader.read_http(href, handleHeader); } + if (oReq) { + this._Gx.HCB_RDR[lyr_uuid] = oReq; + } + } catch (error) { + this.hide_spinner(); + } - return lyr_uuid; - }, + return lyr_uuid; + }, - show_spinner: function() { - if (!this._Gx.spinner) { - SPINNER_OPTS.color = this._Mx.xwfg; - this._Gx.spinner = new Spinner(SPINNER_OPTS).spin(this._Gx.parent); - } - }, + show_spinner: function () { + if (!this._Gx.spinner) { + SPINNER_OPTS.color = this._Mx.xwfg; + this._Gx.spinner = new Spinner(SPINNER_OPTS).spin( + this._Gx.parent + ); + } + }, - hide_spinner: function(force) { - var cnt_pending = 0; - _.mapObject(this._Gx.HCB_UCB, (k, v) => { - if (v === null) { - cnt_pending += 1; - } - }); + hide_spinner: function (force) { + var cnt_pending = 0; + mapObject(this._Gx.HCB_UCB, (k, v) => { + if (v === null) { + cnt_pending += 1; + } + }); - if ((cnt_pending === 0) || force) { - if (this._Gx.spinner) { - this._Gx.spinner.stop(); - } - this._Gx.spinner = undefined; + if (cnt_pending === 0 || force) { + if (this._Gx.spinner) { + this._Gx.spinner.stop(); } - }, + this._Gx.spinner = undefined; + } + }, - reg_hcb: function(hcb) { - var uuid = common.uuidv4(); - this._Gx.HCB_UUID[uuid] = hcb; + reg_hcb: function (hcb) { + var uuid = common.uuidv4(); + this._Gx.HCB_UUID[uuid] = hcb; - return uuid; - }, + return uuid; + }, - get_lyrn: function(uuid) { - return _.indexOf(this._Gx.HCB, uuid); - }, + get_lyrn: function (uuid) { + return indexOf(this._Gx.HCB, uuid); + }, - get_lyr_uuid: function(lyrN) { - return this._Gx.HCB[lyrN]; - }, + get_lyr_uuid: function (lyrN) { + return this._Gx.HCB[lyrN]; + }, - get_hcb_by_uuid: function(uuid) { - return this._Gx.HCB[uuid]; - }, + get_hcb_by_uuid: function (uuid) { + return this._Gx.HCB[uuid]; + }, - get_hcb_by_lyrn: function(lyrN) { - return this.get_hcb_by_uuid(this.get_lyr_uuid(lyrN)); - }, + get_hcb_by_lyrn: function (lyrN) { + return this.get_hcb_by_uuid(this.get_lyr_uuid(lyrN)); + }, - add_layer: function(layer) { - var Gx = this._Gx; - var Mx = this._Mx; + add_layer: function (layer) { + var Gx = this._Gx; + var Mx = this._Mx; - // Notify listeners that a file was overlayed - var evt = document.createEvent('Event'); - evt.initEvent('lyradd', true, true); - evt.name = layer.name; // the name of the layer - evt.layer = layer; - var executeDefault = mx.dispatchEvent(Mx, evt); - if (executeDefault) { - Gx.lyr.push(layer); - layer.index = Gx.lyr.length - 1; // the new index of the layer - return true; - } else { - return false; - } - }, + // Notify listeners that a file was overlayed + var evt = document.createEvent("Event"); + evt.initEvent("lyradd", true, true); + evt.name = layer.name; // the name of the layer + evt.layer = layer; + var executeDefault = mx.dispatchEvent(Mx, evt); + if (executeDefault) { + Gx.lyr.push(layer); + layer.index = Gx.lyr.length - 1; // the new index of the layer + return true; + } else { + return false; + } + }, - /** - * Get a layer of the plot - * - * @example plot.get_layer(n); - * - * @param {Number} - * n the index of the layer - * - * @returns data_layer - * - */ - - get_layer: function(lyr) { - var Gx = this._Gx; - - if (_.has(Gx.HCB_UUID, lyr)) { - lyr = this.get_lyrn(lyr); - } - if ((lyr >= 0) && (lyr < Gx.lyr.length)) { - return Gx.lyr[lyr]; - } else { - return null; - } - }, + /** + * Get a layer of the plot + * + * @example plot.get_layer(n); + * + * @param {Number} + * n the index of the layer + * + * @returns data_layer + * + */ - overlay_matfile: function(mfile, layerOptions) { - m.log.debug("Overlay matfile: " + mfile.file_name); - return this.overlay_array(mfile.dview); - }, + get_layer: function (lyr) { + var Gx = this._Gx; - /** - * Create a plot layer backed by a bluefile header - * - * @param hcb - * {BlueHeader} an opened BlueHeader file - * @returns the index of the new layer - */ - overlay_bluefile: function(hcb, layerOptions) { - m.log.debug("Overlay bluefile: " + hcb.file_name); - var Mx = this._Mx; - var Gx = this._Gx; - var size = 0; - - layerOptions = layerOptions || {}; - - var basefiles = (Gx.HCB.length === 0); - - var lyr_uuid = hcb._uuid; - if (lyr_uuid) { - // the layer was pre-registered but has already been - // deoverlayed, do nothing - if (!_.has(Gx.HCB_UUID, lyr_uuid)) { - return; - } - // Update the HCB - Gx.HCB_UUID[lyr_uuid] = hcb; - // Remove the req - delete Gx.HCB_RDR[lyr_uuid]; - } else { - lyr_uuid = this.reg_hcb(hcb); - } - this._Gx.HCB.push(lyr_uuid); + if (has(Gx.HCB_UUID, lyr)) { + lyr = this.get_lyrn(lyr); + } + if (lyr >= 0 && lyr < Gx.lyr.length) { + return Gx.lyr[lyr]; + } else { + return null; + } + }, - if (Gx.HCB.length === 1) { - basefile(this, true); - } + overlay_matfile: function (mfile, layerOptions) { + m.log.debug("Overlay matfile: " + mfile.file_name); + return this.overlay_array(mfile.dview); + }, - var layers = null; + /** + * Create a plot layer backed by a bluefile header + * + * @param hcb + * {BlueHeader} an opened BlueHeader file + * @returns the index of the new layer + */ + overlay_bluefile: function (hcb, layerOptions) { + m.log.debug("Overlay bluefile: " + hcb.file_name); + var Mx = this._Mx; + var Gx = this._Gx; + var size = 0; - if (layerOptions.layerType === undefined) { - if (hcb["class"] === 1) { - layers = Layer1D.overlay(this, hcb, layerOptions); - } else if (hcb["class"] === 2) { - layers = Layer2D.overlay(this, hcb, layerOptions); - } - } else { - if (layerOptions.layerType === "1D") { - layers = Layer1D.overlay(this, hcb, layerOptions); - } else if (layerOptions.layerType === "2D") { - layers = Layer2D.overlay(this, hcb, layerOptions); - } else if (layerOptions.layerType === "1DSDS") { - layers = Layer1DSDS.overlay(this, hcb, layerOptions); - } else if (layerOptions.layerType === "2DSDS") { - layers = Layer2DSDS.overlay(this, hcb, layerOptions); - } else { - layers = layerOptions.layerType.overlay(this, hcb, layerOptions); - } - } + layerOptions = layerOptions || {}; - if (layers === null || layers.length === 0) { - m.log.debug("failed to create layers"); + var basefiles = Gx.HCB.length === 0; + + var lyr_uuid = hcb._uuid; + if (lyr_uuid) { + // the layer was pre-registered but has already been + // deoverlayed, do nothing + if (!has(Gx.HCB_UUID, lyr_uuid)) { return; } + // Update the HCB + Gx.HCB_UUID[lyr_uuid] = hcb; + // Remove the req + delete Gx.HCB_RDR[lyr_uuid]; + } else { + lyr_uuid = this.reg_hcb(hcb); + } + this._Gx.HCB.push(lyr_uuid); - // Allow the user to store aribitary data with the layer - if (layerOptions.user_data) { - layers.forEach(function(layer) { - layer.user_data = layerOptions.user_data; - }); + if (Gx.HCB.length === 1) { + basefile(this, true); + } + + var layers = null; + + if (layerOptions.layerType === undefined) { + if (hcb["class"] === 1) { + layers = Layer1D.overlay(this, hcb, layerOptions); + } else if (hcb["class"] === 2) { + layers = Layer2D.overlay(this, hcb, layerOptions); } + } else { + if (layerOptions.layerType === "1D") { + layers = Layer1D.overlay(this, hcb, layerOptions); + } else if (layerOptions.layerType === "2D") { + layers = Layer2D.overlay(this, hcb, layerOptions); + } else if (layerOptions.layerType === "1DSDS") { + layers = Layer1DSDS.overlay(this, hcb, layerOptions); + } else if (layerOptions.layerType === "2DSDS") { + layers = Layer2DSDS.overlay(this, hcb, layerOptions); + } else { + layers = layerOptions.layerType.overlay( + this, + hcb, + layerOptions + ); + } + } - // TODO - do we want to alert like the XM plot did? - //if (!Gx.all && size > Gx.bufmax && Gx.HCB.length == 1) { - // alert("Plot truncated to buffer size. Use panning or /ALL - // switch"); - //} - // The original code has a bug here. Fixed by moving changemode - // outside of - // the !basefiles check. - // You can recreate with SIGPLOT ,,, IR - // And then loading a file. - changemode(this, Gx.cmode); - - // if this is not the first set of layers added and - // we haven't asked for the plot to expand to accomodate - // this layers new range, then simply draw the new layer. - if (!basefiles && !layerOptions.expand) { - var plot = this; - layers.forEach(function(layer) { - draw_layer(plot, layer); - }); + if (layers === null || layers.length === 0) { + m.log.debug("failed to create layers"); + return; + } + + // Allow the user to store aribitary data with the layer + if (layerOptions.user_data) { + layers.forEach(function (layer) { + layer.user_data = layerOptions.user_data; + }); + } + + // TODO - do we want to alert like the XM plot did? + //if (!Gx.all && size > Gx.bufmax && Gx.HCB.length == 1) { + // alert("Plot truncated to buffer size. Use panning or /ALL + // switch"); + //} + // The original code has a bug here. Fixed by moving changemode + // outside of + // the !basefiles check. + // You can recreate with SIGPLOT ,,, IR + // And then loading a file. + changemode(this, Gx.cmode); + + // if this is not the first set of layers added and + // we haven't asked for the plot to expand to accomodate + // this layers new range, then simply draw the new layer. + if (!basefiles && !layerOptions.expand) { + var plot = this; + layers.forEach(function (layer) { + draw_layer(plot, layer); + }); + } else { + if (size(Gx.HCB_UUID) === 0) { + // TODO dead code that cannot be reached + basefile(this, false); } else { - if (_.size(Gx.HCB_UUID) === 0) { // TODO dead code that cannot be reached - basefile(this, false); + Gx.basemode = Gx.cmode; + var xmin; + var xmax; + if ((Gx.autox & 1) === 0) { + xmin = Gx.xmin; + } + if ((Gx.autox & 2) === 0) { + xmax = Gx.xmax; + } + scale_base( + this, + { + get_data: true, + }, + xmin, + xmax + ); + Mx.level = 0; + if ((Gx.autox & 1) !== 0) { + Gx.xmin = Mx.stk[0].xmin; + } + if ((Gx.autox & 2) !== 0) { + Gx.xmax = Mx.stk[0].xmax; + } + if ((Gx.autoy & 1) !== 0) { + Gx.ymin = Mx.stk[0].ymin; + } + if ((Gx.autoy & 2) !== 0) { + Gx.ymax = Mx.stk[0].ymax; + } + Mx.resize = true; + if (Gx.lyr[0].preferred_origin) { + Mx.origin = Gx.lyr[0].preferred_origin; } else { - Gx.basemode = Gx.cmode; - var xmin; - var xmax; - if ((Gx.autox & 1) === 0) { - xmin = Gx.xmin; - } - if ((Gx.autox & 2) === 0) { - xmax = Gx.xmax; - } - scale_base(this, { - get_data: true - }, xmin, xmax); - Mx.level = 0; - if ((Gx.autox & 1) !== 0) { - Gx.xmin = Mx.stk[0].xmin; - } - if ((Gx.autox & 2) !== 0) { - Gx.xmax = Mx.stk[0].xmax; - } - if ((Gx.autoy & 1) !== 0) { - Gx.ymin = Mx.stk[0].ymin; - } - if ((Gx.autoy & 2) !== 0) { - Gx.ymax = Mx.stk[0].ymax; - } - Mx.resize = true; - if (Gx.lyr[0].preferred_origin) { - Mx.origin = Gx.lyr[0].preferred_origin; - } else { - Mx.origin = 1; - } + Mx.origin = 1; } } - form_plotnote(this); - this.refresh(); + } + form_plotnote(this); + this.refresh(); - return lyr_uuid; - }, + return lyr_uuid; + }, - /** - * Load one or more files. - * - * @param {File[]} - * a list of files to plot - */ - load_files: function(files, layerType) { - var onload = (function(plot) { - return function(hdr) { - plot.overlay_bluefile(hdr, layerType); - }; - })(this); + /** + * Load one or more files. + * + * @param {File[]} + * a list of files to plot + */ + load_files: function (files, layerType) { + var onload = (function (plot) { + return function (hdr) { + plot.overlay_bluefile(hdr, layerType); + }; + })(this); - for (var i = 0; i < files.length; i++) { - var f = files[i]; - var br = new bluefile.BlueFileReader(); - br.read(f, onload); - } - }, + for (var i = 0; i < files.length; i++) { + var f = files[i]; + var br = new bluefile.BlueFileReader(); + br.read(f, onload); + } + }, + + /** + * Reemove layers + * + * @example plot.get_layer(n); + * + * @param {Number} + * The index of the layer. If not provided, all layers will + * be removed + * + * @returns data_layer + * + */ - /** - * Reemove layers - * - * @example plot.get_layer(n); - * - * @param {Number} - * The index of the layer. If not provided, all layers will - * be removed - * - * @returns data_layer - * - */ - - deoverlay: function(index) { - var Gx = this._Gx; - var Mx = this._Mx; - - if (_.has(Gx.HCB_UUID, index)) { - this.remove_layer(index); - } else { - if (Gx.HCB.length > 0) { - if (index === undefined) { - for (var n = Gx.HCB.length - 1; n >= 0; n--) { - this.remove_layer(this.get_lyr_uuid(n)); - } - } else if (index < 0) { - var n = Gx.HCB.length + index; - if (n < 0) { - return; - } + deoverlay: function (index) { + var Gx = this._Gx; + var Mx = this._Mx; + + if (has(Gx.HCB_UUID, index)) { + this.remove_layer(index); + } else { + if (Gx.HCB.length > 0) { + if (index === undefined) { + for (var n = Gx.HCB.length - 1; n >= 0; n--) { this.remove_layer(this.get_lyr_uuid(n)); - } else if (index < Gx.HCB.length) { - this.remove_layer(this.get_lyr_uuid(index)); } + } else if (index < 0) { + var n = Gx.HCB.length + index; + if (n < 0) { + return; + } + this.remove_layer(this.get_lyr_uuid(n)); + } else if (index < Gx.HCB.length) { + this.remove_layer(this.get_lyr_uuid(index)); } } - if (_.size(Gx.HCB_UUID) === 0) { - basefile(this, false); - scale_base(this, {}); - } - }, + } + if (size(Gx.HCB_UUID) === 0) { + basefile(this, false); + scale_base(this, {}); + } + }, - /** - * Remove a layer. - * - * @param index - * the layer to remove - */ - remove_layer: function(lyr_uuid) { - var Gx = this._Gx; + /** + * Remove a layer. + * + * @param index + * the layer to remove + */ + remove_layer: function (lyr_uuid) { + var Gx = this._Gx; - var HCB = Gx.HCB_UUID[lyr_uuid]; - delete Gx.HCB_UUID[lyr_uuid]; - if (_.has(Gx.HCB_RDR, lyr_uuid)) { - Gx.HCB_RDR[lyr_uuid].abort(); - } - delete Gx.HCB_RDR[lyr_uuid]; + var HCB = Gx.HCB_UUID[lyr_uuid]; + delete Gx.HCB_UUID[lyr_uuid]; + if (has(Gx.HCB_RDR, lyr_uuid)) { + Gx.HCB_RDR[lyr_uuid].abort(); + } + delete Gx.HCB_RDR[lyr_uuid]; - var fileName = ""; - if (HCB) { - fileName = HCB.file_name; - } + var fileName = ""; + if (HCB) { + fileName = HCB.file_name; + } - var index = this.get_lyrn(lyr_uuid); + var index = this.get_lyrn(lyr_uuid); - if ((index >= 0) && (index < Gx.HCB.length)) { - // delete this UUID and shift the others down - Gx.HCB[index] = null; - for (var n = index; n < Gx.HCB.length - 1; n++) { - Gx.HCB[n] = Gx.HCB[n + 1]; - } - Gx.HCB.length -= 1; + if (index >= 0 && index < Gx.HCB.length) { + // delete this UUID and shift the others down + Gx.HCB[index] = null; + for (var n = index; n < Gx.HCB.length - 1; n++) { + Gx.HCB[n] = Gx.HCB[n + 1]; } + Gx.HCB.length -= 1; + } - // Find all layers tied to this HCB - if (HCB && index >= 0) { - for (var n = Gx.lyr.length - 1; n >= 0; n--) { - if (Gx.lyr[n].hcb === HCB) { - delete_layer(this, n); - } + // Find all layers tied to this HCB + if (HCB && index >= 0) { + for (var n = Gx.lyr.length - 1; n >= 0; n--) { + if (Gx.lyr[n].hcb === HCB) { + delete_layer(this, n); } } - form_plotnote(this); - this.refresh(); + } + form_plotnote(this); + this.refresh(); - // Notify listeners that a file has been deoverlayed - var evt = document.createEvent('Event'); - evt.initEvent('file_deoverlayed', true, true); - if (fileName !== "") { - evt.fileName = fileName; // The fileName that was - } - // de-overlayed - mx.dispatchEvent(this._Mx, evt); - }, + // Notify listeners that a file has been deoverlayed + var evt = document.createEvent("Event"); + evt.initEvent("file_deoverlayed", true, true); + if (fileName !== "") { + evt.fileName = fileName; // The fileName that was + } + // de-overlayed + mx.dispatchEvent(this._Mx, evt); + }, - /** - * Zoom onto a given pixel range. - */ - pixel_zoom: function(x1, y1, x2, y2, continuous) { - var r1 = pixel_to_real(this, x1, y1); - var r2 = pixel_to_real(this, x2, y2); + /** + * Zoom onto a given pixel range. + */ + pixel_zoom: function (x1, y1, x2, y2, continuous) { + var r1 = pixel_to_real(this, x1, y1); + var r2 = pixel_to_real(this, x2, y2); - this.zoom(r1, r2, continuous); - }, + this.zoom(r1, r2, continuous); + }, - percent_zoom: function(xperc, yperc, continuous) { - var Mx = this._Mx; - var Gx = this._Gx; + percent_zoom: function (xperc, yperc, continuous) { + var Mx = this._Mx; + var Gx = this._Gx; - var xadj = 0; - if (Math.abs(xperc) < 1) { - xadj = Math.abs(Mx.stk[Mx.level].xmax - Mx.stk[Mx.level].xmin); - xadj = (xadj * xperc) / 2; - } + var xadj = 0; + if (Math.abs(xperc) < 1) { + xadj = Math.abs(Mx.stk[Mx.level].xmax - Mx.stk[Mx.level].xmin); + xadj = (xadj * xperc) / 2; + } - var yadj = 0; - if (Math.abs(yperc) < 1) { - yadj = Math.abs(Mx.stk[Mx.level].ymax - Mx.stk[Mx.level].ymin); - yadj = (yadj * yperc) / 2; - } + var yadj = 0; + if (Math.abs(yperc) < 1) { + yadj = Math.abs(Mx.stk[Mx.level].ymax - Mx.stk[Mx.level].ymin); + yadj = (yadj * yperc) / 2; + } - var ul = { - x: Math.max(Mx.stk[Mx.level].xmin + xadj, Gx.panxmin), - y: Math.max(Mx.stk[Mx.level].ymin + yadj, Gx.panymin) - }; + var ul = { + x: Math.max(Mx.stk[Mx.level].xmin + xadj, Gx.panxmin), + y: Math.max(Mx.stk[Mx.level].ymin + yadj, Gx.panymin), + }; - var lr = { - x: Math.min(Mx.stk[Mx.level].xmax - xadj, Gx.panxmax), - y: Math.min(Mx.stk[Mx.level].ymax - yadj, Gx.panymax) - }; + var lr = { + x: Math.min(Mx.stk[Mx.level].xmax - xadj, Gx.panxmax), + y: Math.min(Mx.stk[Mx.level].ymax - yadj, Gx.panymax), + }; - this.zoom(ul, lr, continuous); - }, + this.zoom(ul, lr, continuous); + }, - /** - * Zoom onto a given region. - * - * @param ul - * the uppler left corner - * @param {Number} - * ul.x the upper left x pos in real plot value - * @param {Number} - * ul.y the upper left y pos in real plot values - * - * @param lr - * the lower right corner - * @param {Number} - * lr the lower right x pos in real plot value - * @param {Number} - * lr the lower right y pos in real plot values - * - * @param continuous - * enter continuous zoom mode. This will create a - * new if you are on level 0, but stay on the same level - * otherwise - */ - zoom: function(ul, lr, continuous) { - var Mx = this._Mx; - var Gx = this._Gx; - - if (Mx.level >= 9) { // currently only allow 10 zooms - return; - } + /** + * Zoom onto a given region. + * + * @param ul + * the uppler left corner + * @param {Number} + * ul.x the upper left x pos in real plot value + * @param {Number} + * ul.y the upper left y pos in real plot values + * + * @param lr + * the lower right corner + * @param {Number} + * lr the lower right x pos in real plot value + * @param {Number} + * lr the lower right y pos in real plot values + * + * @param continuous + * enter continuous zoom mode. This will create a + * new if you are on level 0, but stay on the same level + * otherwise + */ + zoom: function (ul, lr, continuous) { + var Mx = this._Mx; + var Gx = this._Gx; - if (ul.x === undefined) { - ul.x = Mx.stk[Mx.level].xmin; - } - if (ul.y === undefined) { - ul.y = Mx.stk[Mx.level].ymin; - } - if (lr.x === undefined) { - lr.x = Mx.stk[Mx.level].xmax; - } - if (lr.y === undefined) { - lr.y = Mx.stk[Mx.level].ymax; - } + if (Mx.level >= 9) { + // currently only allow 10 zooms + return; + } - if (lr.x < ul.x) { - var xtmp = lr.x; - lr.x = ul.x; - ul.x = xtmp; - } - if (lr.y < ul.y) { - var ytmp = lr.y; - lr.y = ul.y; - ul.y = ytmp; - } + if (ul.x === undefined) { + ul.x = Mx.stk[Mx.level].xmin; + } + if (ul.y === undefined) { + ul.y = Mx.stk[Mx.level].ymin; + } + if (lr.x === undefined) { + lr.x = Mx.stk[Mx.level].xmax; + } + if (lr.y === undefined) { + lr.y = Mx.stk[Mx.level].ymax; + } - var zstk = {}; + if (lr.x < ul.x) { + var xtmp = lr.x; + lr.x = ul.x; + ul.x = xtmp; + } + if (lr.y < ul.y) { + var ytmp = lr.y; + lr.y = ul.y; + ul.y = ytmp; + } - // xscl/yscl are reset in sigplot.refresh - zstk.xscl = Mx.stk[Mx.level].xscl; - zstk.yscl = Mx.stk[Mx.level].yscl; + var zstk = {}; - zstk.xmin = ul.x; // real world val at x1(origin=1,4) or - // x2(origin=2,4) - zstk.xmax = lr.x; // real world val at x2(origin=1,4) or - // x1(origin=2,4) - zstk.ymin = ul.y; // real world val at y2(origin=1,2) or - // y1(origin=3,4) - zstk.ymax = lr.y; // real world val at y1(origin=1,2) or - // y2(origin=3,4) - if (Gx.index) { - zstk.xmin = Math.min(zstk.xmin / Gx.xdelta); - zstk.xmax = Math.min(zstk.xmax / Gx.xdelta); - } + // xscl/yscl are reset in sigplot.refresh + zstk.xscl = Mx.stk[Mx.level].xscl; + zstk.yscl = Mx.stk[Mx.level].yscl; - if (!continuous || (!Gx.inContinuousZoom)) { - // We aren't yet in continuous zoom mode - // so create a new level - Mx.stk.push(zstk); - Mx.level = Mx.stk.length - 1; - } else { - // Once in continuous zoom mode update the current level - Mx.stk[Mx.level] = zstk; - } - Gx.inContinuousZoom = continuous; + zstk.xmin = ul.x; // real world val at x1(origin=1,4) or + // x2(origin=2,4) + zstk.xmax = lr.x; // real world val at x2(origin=1,4) or + // x1(origin=2,4) + zstk.ymin = ul.y; // real world val at y2(origin=1,2) or + // y1(origin=3,4) + zstk.ymax = lr.y; // real world val at y1(origin=1,2) or + // y2(origin=3,4) + if (Gx.index) { + zstk.xmin = Math.min(zstk.xmin / Gx.xdelta); + zstk.xmax = Math.min(zstk.xmax / Gx.xdelta); + } - this.inZoom = true; // prevent recursive zooms - var evt = document.createEvent('Event'); - evt.initEvent('zoom', true, true); - evt.level = Mx.level; - evt.inContinuousZoom = Gx.inContinuousZoom; - evt.xmin = Mx.stk[Mx.level].xmin; - evt.ymin = Mx.stk[Mx.level].ymin; - evt.xmax = Mx.stk[Mx.level].xmax; - evt.ymax = Mx.stk[Mx.level].ymax; - mx.dispatchEvent(Mx, evt); // TODO should we allow zoom to be cancelled? - this.inZoom = false; + if (!continuous || !Gx.inContinuousZoom) { + // We aren't yet in continuous zoom mode + // so create a new level + Mx.stk.push(zstk); + Mx.level = Mx.stk.length - 1; + } else { + // Once in continuous zoom mode update the current level + Mx.stk[Mx.level] = zstk; + } + Gx.inContinuousZoom = continuous; - this.refresh(); - }, + this.inZoom = true; // prevent recursive zooms + var evt = document.createEvent("Event"); + evt.initEvent("zoom", true, true); + evt.level = Mx.level; + evt.inContinuousZoom = Gx.inContinuousZoom; + evt.xmin = Mx.stk[Mx.level].xmin; + evt.ymin = Mx.stk[Mx.level].ymin; + evt.xmax = Mx.stk[Mx.level].xmax; + evt.ymax = Mx.stk[Mx.level].ymax; + mx.dispatchEvent(Mx, evt); // TODO should we allow zoom to be cancelled? + this.inZoom = false; - /** - * Unzoom one or more levels. - * - * @param [levels] - * the number of levels to unzoom, if not provided unzoom - * all. - */ - unzoom: function(levels) { - var Mx = this._Mx; - var Gx = this._Gx; + this.refresh(); + }, - if (Mx.level === 0) { - return; - } + /** + * Unzoom one or more levels. + * + * @param [levels] + * the number of levels to unzoom, if not provided unzoom + * all. + */ + unzoom: function (levels) { + var Mx = this._Mx; + var Gx = this._Gx; - if (!levels) { - levels = Mx.stk.length; - } + if (Mx.level === 0) { + return; + } - while (levels > 0) { - if (Mx.level === 0) { - break; - } - Mx.stk.pop(); - Mx.level = Mx.stk.length - 1; - levels -= 1; - } + if (!levels) { + levels = Mx.stk.length; + } - // If we are back at level 0, then - // rescale + while (levels > 0) { if (Mx.level === 0) { - this.rescale(); + break; } + Mx.stk.pop(); + Mx.level = Mx.stk.length - 1; + levels -= 1; + } - // After any unzooms you can no longer remain in - // continuous zoom - Gx.inContinuousZoom = false; + // If we are back at level 0, then + // rescale + if (Mx.level === 0) { + this.rescale(); + } - this.inZoom = true; // prevent recursive zoom - // Send the event to listeners - var evt = document.createEvent('Event'); - evt.initEvent('unzoom', true, true); - evt.level = Mx.level; - evt.xmin = Mx.stk[Mx.level].xmin; - evt.ymin = Mx.stk[Mx.level].ymin; - evt.xmax = Mx.stk[Mx.level].xmax; - evt.ymax = Mx.stk[Mx.level].ymax; - mx.dispatchEvent(Mx, evt); - this.inZoom = false; + // After any unzooms you can no longer remain in + // continuous zoom + Gx.inContinuousZoom = false; - this.refresh(); - }, + this.inZoom = true; // prevent recursive zoom + // Send the event to listeners + var evt = document.createEvent("Event"); + evt.initEvent("unzoom", true, true); + evt.level = Mx.level; + evt.xmin = Mx.stk[Mx.level].xmin; + evt.ymin = Mx.stk[Mx.level].ymin; + evt.xmax = Mx.stk[Mx.level].xmax; + evt.ymax = Mx.stk[Mx.level].ymax; + mx.dispatchEvent(Mx, evt); + this.inZoom = false; - /** - * Expand pan-bars to the full range - */ - expand_full: function(xpan, ypan) { - if (xpan) { - updateViewbox(this, this._Gx.panxmin, this._Gx.panxmax, "X"); - // syncronous refresh is necessary, because expanding the xrange - // may cause more data to be read - this._refresh(); - } + this.refresh(); + }, - if (ypan) { - updateViewbox(this, this._Gx.panymin, this._Gx.panymax, "Y"); - } + /** + * Expand pan-bars to the full range + */ + expand_full: function (xpan, ypan) { + if (xpan) { + updateViewbox(this, this._Gx.panxmin, this._Gx.panxmax, "X"); + // syncronous refresh is necessary, because expanding the xrange + // may cause more data to be read + this._refresh(); + } - // async refresh is find here - this.refresh(); - }, + if (ypan) { + updateViewbox(this, this._Gx.panymin, this._Gx.panymax, "Y"); + } - /** - * Set the current view bounds, if any bounds are not defined - * then they are kept as currently set. - * - * Will call an asyncronous refresh() after the new view box - * values have been set. - * - * @param {Object} ViewBounds - * @returns {number} ViewBounds.xmin - * the abscissa X minimum value of the view box - * @returns {number} ViewBounds.xmax - * the abscissa X maximum value of the view box - * @returns {number} ViewBounds.ymin - * the abscissa Y minimum value of the view box - * @returns {number} ViewBounds.ymax - * the abscissa Y maximum value of the view box - */ - set_view: function({ - xmin, - xmax, - ymin, - ymax - }) { - var Mx = this._Mx; - var Gx = this._Gx; - var k = Mx.level; + // async refresh is find here + this.refresh(); + }, - if (xmin !== undefined) { - Mx.stk[k].xmin = xmin; - } - if (xmax !== undefined) { - Mx.stk[k].xmax = xmax; - } - if (ymin !== undefined) { - Mx.stk[k].ymin = ymin; - } - if (ymax !== undefined) { - Mx.stk[k].ymax = ymax; - } - this.refresh(); - }, + /** + * Set the current view bounds, if any bounds are not defined + * then they are kept as currently set. + * + * Will call an asyncronous refresh() after the new view box + * values have been set. + * + * @param {Object} ViewBounds + * @returns {number} ViewBounds.xmin + * the abscissa X minimum value of the view box + * @returns {number} ViewBounds.xmax + * the abscissa X maximum value of the view box + * @returns {number} ViewBounds.ymin + * the abscissa Y minimum value of the view box + * @returns {number} ViewBounds.ymax + * the abscissa Y maximum value of the view box + */ + set_view: function ({ xmin, xmax, ymin, ymax }) { + var Mx = this._Mx; + var Gx = this._Gx; + var k = Mx.level; - /** - * Get the current view bounds - * - * @returns {Object} ViewBounds - * the view bounds - * @returns {number} ViewBounds.xmin - * the abscissa X minimum value of the view box - * @returns {number} ViewBounds.xmax - * the abscissa X maximum value of the view box - * @returns {number} ViewBounds.ymin - * the abscissa Y minimum value of the view box - * @returns {number} ViewBounds.ymax - * the abscissa Y maximum value of the view box - */ - get_view: function() { - var Mx = this._Mx; - var Gx = this._Gx; - var k = Mx.level; + if (xmin !== undefined) { + Mx.stk[k].xmin = xmin; + } + if (xmax !== undefined) { + Mx.stk[k].xmax = xmax; + } + if (ymin !== undefined) { + Mx.stk[k].ymin = ymin; + } + if (ymax !== undefined) { + Mx.stk[k].ymax = ymax; + } + this.refresh(); + }, - return { - xmin: Mx.stk[k].xmin, - xmax: Mx.stk[k].xmax, - ymin: Mx.stk[k].ymin, - ymax: Mx.stk[k].ymax - }; - }, + /** + * Get the current view bounds + * + * @returns {Object} ViewBounds + * the view bounds + * @returns {number} ViewBounds.xmin + * the abscissa X minimum value of the view box + * @returns {number} ViewBounds.xmax + * the abscissa X maximum value of the view box + * @returns {number} ViewBounds.ymin + * the abscissa Y minimum value of the view box + * @returns {number} ViewBounds.ymax + * the abscissa Y maximum value of the view box + */ + get_view: function () { + var Mx = this._Mx; + var Gx = this._Gx; + var k = Mx.level; - /** - * Register this plot to mimic zoom/unzoom of other plot - * - * @param other - * the other plot to mimic - * - * @param mask - * the set of event to respond to - * - * @param mask.zoom - * if true, respond to zoom events - * - * @param mask.xzoom - * if true, respond to zoom events for the x-axis only - * - * @param mask.yzoom - * if true, respond to zoom events for the y-axis only - * - * @param mask.unzoom - * if true, respond to unzoom events - * - * @param mask.pan - * if true, respond to pan events - * - * @param mask.xpan - * if true, respond to pan events for the x-axis only - * - * @param mask.ypan - * if true, respond to pan events for the y-axis only - */ - mimic: function(other, mask) { - var self = this; - - if (!mask) { - throw "mimic must be called with at least one event mask"; - } - - this.unmimic(other); - - if (mask.zoom) { - var f = function(event) { - if (self.inZoom) { - return; - } - self.zoom({ - x: event.xmin, - y: event.ymin - }, { - x: event.xmax, - y: event.ymax - }, - event.inContinuousZoom); - }; - other.addListener("zoom", f); - this.mimicListeners.listeners.zoom = f; - } else if (mask.xzoom) { - var f = function(event) { - if (self.inZoom) { - return; - } - self.zoom({ - x: event.xmin, - y: undefined - }, { - x: event.xmax, - y: undefined - }, - event.inContinuousZoom); - }; - other.addListener("zoom", f); - this.mimicListeners.listeners.zoom = f; - } else if (mask.yzoom) { - var f = function(event) { - if (self.inZoom) { - return; - } - self.zoom({ - x: undefined, - y: event.ymin - }, { - x: undefined, - y: event.ymax - }, - event.inContinuousZoom); - }; - other.addListener("zoom", f); - this.mimicListeners.listeners.zoom = f; - } + return { + xmin: Mx.stk[k].xmin, + xmax: Mx.stk[k].xmax, + ymin: Mx.stk[k].ymin, + ymax: Mx.stk[k].ymax, + }; + }, - if (mask.unzoom) { - var f = function(event) { - if (self.inZoom) { - return; - } - if (event.level < self._Mx.level) { - self.unzoom(self._Mx.level - event.level); - } - }; - other.addListener("unzoom", f); - this.mimicListeners.listeners.unzoom = f; - } + /** + * Register this plot to mimic zoom/unzoom of other plot + * + * @param other + * the other plot to mimic + * + * @param mask + * the set of event to respond to + * + * @param mask.zoom + * if true, respond to zoom events + * + * @param mask.xzoom + * if true, respond to zoom events for the x-axis only + * + * @param mask.yzoom + * if true, respond to zoom events for the y-axis only + * + * @param mask.unzoom + * if true, respond to unzoom events + * + * @param mask.pan + * if true, respond to pan events + * + * @param mask.xpan + * if true, respond to pan events for the x-axis only + * + * @param mask.ypan + * if true, respond to pan events for the y-axis only + */ + mimic: function (other, mask) { + var self = this; - if (mask.pan || mask.xpan) { - var f = function(event) { - if (self.inPan) { - return; - } - updateViewbox(self, event.xmin, event.xmax, "X"); - }; - other.addListener("xpan", f); - this.mimicListeners.listeners.xpan = f; - } + if (!mask) { + throw "mimic must be called with at least one event mask"; + } - if (mask.pan || mask.ypan) { - var f = function(event) { - if (self.inPan) { - return; - } - updateViewbox(self, event.ymin, event.ymax, "Y"); - }; - other.addListener("ypan", f); - this.mimicListeners.listeners.ypan = f; - } + this.unmimic(other); - this.mimicListeners.other = other; - }, + if (mask.zoom) { + var f = function (event) { + if (self.inZoom) { + return; + } + self.zoom( + { + x: event.xmin, + y: event.ymin, + }, + { + x: event.xmax, + y: event.ymax, + }, + event.inContinuousZoom + ); + }; + other.addListener("zoom", f); + this.mimicListeners.listeners.zoom = f; + } else if (mask.xzoom) { + var f = function (event) { + if (self.inZoom) { + return; + } + self.zoom( + { + x: event.xmin, + y: undefined, + }, + { + x: event.xmax, + y: undefined, + }, + event.inContinuousZoom + ); + }; + other.addListener("zoom", f); + this.mimicListeners.listeners.zoom = f; + } else if (mask.yzoom) { + var f = function (event) { + if (self.inZoom) { + return; + } + self.zoom( + { + x: undefined, + y: event.ymin, + }, + { + x: undefined, + y: event.ymax, + }, + event.inContinuousZoom + ); + }; + other.addListener("zoom", f); + this.mimicListeners.listeners.zoom = f; + } + if (mask.unzoom) { + var f = function (event) { + if (self.inZoom) { + return; + } + if (event.level < self._Mx.level) { + self.unzoom(self._Mx.level - event.level); + } + }; + other.addListener("unzoom", f); + this.mimicListeners.listeners.unzoom = f; + } - /** - * Unregister zoom/unzoom listeners added via previous call to unmimic. - */ - unmimic: function(other) { - var other = this.mimicListeners.other; - if (other) { - var that = this; - Object.keys(this.mimicListeners.listeners).forEach(function(evt) { - if (that.mimicListeners.listeners[evt]) { - other.removeListener(evt, that.mimicListeners.listeners[evt]); - } - }); - } - this.mimicListeners = { - other: null, - listeners: { - zoom: null, - unzoom: null, - xpan: null, - ypan: null + if (mask.pan || mask.xpan) { + var f = function (event) { + if (self.inPan) { + return; } + updateViewbox(self, event.xmin, event.xmax, "X"); }; - }, + other.addListener("xpan", f); + this.mimicListeners.listeners.xpan = f; + } - /** - * Like refresh, but doesn't rerender data - * - * @example plot.redraw(); - */ - redraw: function() { - var Gx = this._Gx; - var Mx = this._Mx; - var ctx = Mx.canvas.getContext("2d"); - if (!Gx.plotData.valid) { - this.refresh(); - } else { - ctx.drawImage(Gx.plotData, - Mx.l - 1, - Mx.t - 1, (Mx.r - Mx.l) + 2, (Mx.b - Mx.t) + 2, - Mx.l - 1, - Mx.t - 1, (Mx.r - Mx.l) + 2, (Mx.b - Mx.t) + 2 - ); + if (mask.pan || mask.ypan) { + var f = function (event) { + if (self.inPan) { + return; + } + updateViewbox(self, event.ymin, event.ymax, "Y"); + }; + other.addListener("ypan", f); + this.mimicListeners.listeners.ypan = f; + } - draw_plugins(this); + this.mimicListeners.other = other; + }, - Gx.cross_xpos = undefined; - Gx.cross_ypos = undefined; - if ((!Mx.warpbox) && (this.mouseOnCanvas)) { - draw_crosshairs(this); + /** + * Unregister zoom/unzoom listeners added via previous call to unmimic. + */ + unmimic: function (other) { + var other = this.mimicListeners.other; + if (other) { + var that = this; + Object.keys(this.mimicListeners.listeners).forEach(function ( + evt + ) { + if (that.mimicListeners.listeners[evt]) { + other.removeListener( + evt, + that.mimicListeners.listeners[evt] + ); } + }); + } + this.mimicListeners = { + other: null, + listeners: { + zoom: null, + unzoom: null, + xpan: null, + ypan: null, + }, + }; + }, - if (Gx.always_show_marker || Gx.show_marker) { - draw_marker(this); - } - } - }, + /** + * Like refresh, but doesn't rerender data + * + * @example plot.redraw(); + */ + redraw: function () { + var Gx = this._Gx; + var Mx = this._Mx; + var ctx = Mx.canvas.getContext("2d"); + if (!Gx.plotData.valid) { + this.refresh(); + } else { + ctx.drawImage( + Gx.plotData, + Mx.l - 1, + Mx.t - 1, + Mx.r - Mx.l + 2, + Mx.b - Mx.t + 2, + Mx.l - 1, + Mx.t - 1, + Mx.r - Mx.l + 2, + Mx.b - Mx.t + 2 + ); - /** - * Refresh the entire plot - * - * @example plot.refresh(); - */ - refresh: function() { - if (!this._Gx.initialized || this._Gx.refresh_after_ctr > 0) { - return; - } - var self = this; - mx.render(this._Mx, function() { - self._refresh(); - }); - }, + draw_plugins(this); - /** - * Refresh the entire plot after a function has been called. - * - * The plot will be guaranteed to have refresh called after - * the provided function is executed; while the function is - * executed all plot refreshes will be disabled. - * - * In most cases, you should not need to use this function because - * SigPlot will do the right thing and refresh when necessary. The - * primary reason for using this is to temporarily disable refreshes - * while many actions are occuring, but guarantee that the refresh - * occurs after all those actions have been applied. - * - * While calls to refresh() are disabled until after the callback has - * completed, any calls to _refresh() will continue to be processed. - * - * @param {refreshAfterCallback} cb - * The function to execute - * @callback refreshAfterCallback - * @param {Plot} the plot - * - * @example plot.refresh_after((plot) => {plot.push(n, data)}); - */ - refresh_after: function(cb) { - this._Gx.refresh_after_ctr += 1; - try { - cb(this); - } finally { - this._Gx.refresh_after_ctr = - Math.max(this._Gx.refresh_after_ctr - 1, 0); - if (this._Gx.refresh_after_ctr === 0) { - this.refresh(); - } + Gx.cross_xpos = undefined; + Gx.cross_ypos = undefined; + if (!Mx.warpbox && this.mouseOnCanvas) { + draw_crosshairs(this); } - }, - /** - * Enable listeners for events on plot - */ - - enable_listeners: function() { - var Mx = this._Mx; - mx.addEventListener(Mx, "mousedown", this.onmousedown, false); - mx.addEventListener(Mx, "mousemove", this.throttledOnMouseMove, false); - window.addEventListener("mouseup", Mx.onmouseup, false); - window.addEventListener("keydown", Mx.onkeydown, false); - window.addEventListener("keyup", Mx.onkeyup, false); - window.addEventListener("resize", this.onresize, false); - document.addEventListener("mouseup", this.docMouseUp, false); - mx.addEventListener(Mx, "mouseup", this.mouseup, false); - window.addEventListener("mousedown", this.dragMouseDownHandler, false); - window.addEventListener("mousemove", this.throttledDragOnMouseMove, false); - window.addEventListener("mouseup", this.dragMouseUpHandler, false); - window.addEventListener("wheel", this.wheelHandler, false); - window.addEventListener("mousewheel", this.wheelHandler, false); - window.addEventListener("DOMMouseScroll", this.wheelHandler, false); - window.addEventListener("keypress", this.onkeypress, false); - }, + if (Gx.always_show_marker || Gx.show_marker) { + draw_marker(this); + } + } + }, - /** - * Enable listeners for events on plot - */ - - disable_listeners: function() { - var Mx = this._Mx; - - mx.removeEventListener(Mx, "mousedown", this.onmousedown, false); - mx.removeEventListener(Mx, "mousemove", this.throttledOnMouseMove, - false); - mx.removeEventListener(Mx, "mouseup", this.mouseup, false); - window.removeEventListener("mouseup", Mx.onmouseup, false); - window.removeEventListener("keydown", Mx.onkeydown, false); - window.removeEventListener("keyup", Mx.onkeyup, false); - window.removeEventListener("resize", this.onresize, false); - document.removeEventListener("mouseup", this.docMouseUp, false); - window.removeEventListener("mousedown", this.dragMouseDownHandler, - false); - window.removeEventListener("mousemove", this.throttledDragOnMouseMove, - false); - window.removeEventListener("mouseup", this.dragMouseUpHandler, false); - window.removeEventListener("wheel", this.wheelHandler, false); - window.removeEventListener("mousewheel", this.wheelHandler, false); - window.removeEventListener("DOMMouseScroll", this.wheelHandler, false); - window.removeEventListener("keypress", this.onkeypress, false); - }, + /** + * Refresh the entire plot + * + * @example plot.refresh(); + */ + refresh: function () { + if (!this._Gx.initialized || this._Gx.refresh_after_ctr > 0) { + return; + } + var self = this; + mx.render(this._Mx, function () { + self._refresh(); + }); + }, - checkresize: function() { - if (mx.checkresize(this._Mx)) { + /** + * Refresh the entire plot after a function has been called. + * + * The plot will be guaranteed to have refresh called after + * the provided function is executed; while the function is + * executed all plot refreshes will be disabled. + * + * In most cases, you should not need to use this function because + * SigPlot will do the right thing and refresh when necessary. The + * primary reason for using this is to temporarily disable refreshes + * while many actions are occuring, but guarantee that the refresh + * occurs after all those actions have been applied. + * + * While calls to refresh() are disabled until after the callback has + * completed, any calls to _refresh() will continue to be processed. + * + * @param {refreshAfterCallback} cb + * The function to execute + * @callback refreshAfterCallback + * @param {Plot} the plot + * + * @example plot.refresh_after((plot) => {plot.push(n, data)}); + */ + refresh_after: function (cb) { + this._Gx.refresh_after_ctr += 1; + try { + cb(this); + } finally { + this._Gx.refresh_after_ctr = Math.max( + this._Gx.refresh_after_ctr - 1, + 0 + ); + if (this._Gx.refresh_after_ctr === 0) { this.refresh(); } - }, - addColorMaps: function(colormaps) { - colormaps.forEach(function(cmap) { - if (cmap.hasOwnProperty("name")) { - m.Mc.colormap.push(cmap); - } + } + }, - }); + /** + * Enable listeners for events on plot + */ - }, + enable_listeners: function () { + var Mx = this._Mx; + mx.addEventListener(Mx, "mousedown", this.onmousedown, false); + mx.addEventListener( + Mx, + "mousemove", + this.throttledOnMouseMove, + false + ); + window.addEventListener("mouseup", Mx.onmouseup, false); + window.addEventListener("keydown", Mx.onkeydown, false); + window.addEventListener("keyup", Mx.onkeyup, false); + window.addEventListener("resize", this.onresize, false); + document.addEventListener("mouseup", this.docMouseUp, false); + mx.addEventListener(Mx, "mouseup", this.mouseup, false); + window.addEventListener( + "mousedown", + this.dragMouseDownHandler, + false + ); + window.addEventListener( + "mousemove", + this.throttledDragOnMouseMove, + false + ); + window.addEventListener("mouseup", this.dragMouseUpHandler, false); + window.addEventListener("wheel", this.wheelHandler, false); + window.addEventListener("mousewheel", this.wheelHandler, false); + window.addEventListener("DOMMouseScroll", this.wheelHandler, false); + window.addEventListener("keypress", this.onkeypress, false); + }, - _refresh: function() { - var Mx = this._Mx; - var Gx = this._Gx; - var ctx = Mx.canvas.getContext("2d"); - var plugin_index = 0; + /** + * Enable listeners for events on plot + */ - if (Gx.hold) { - return; - } - var font_width = Mx.font_width; - if (Mx.font_scaled) { - font_width = Math.min(Mx.font_width, Mx.width / 64); + disable_listeners: function () { + var Mx = this._Mx; + + mx.removeEventListener(Mx, "mousedown", this.onmousedown, false); + mx.removeEventListener( + Mx, + "mousemove", + this.throttledOnMouseMove, + false + ); + mx.removeEventListener(Mx, "mouseup", this.mouseup, false); + window.removeEventListener("mouseup", Mx.onmouseup, false); + window.removeEventListener("keydown", Mx.onkeydown, false); + window.removeEventListener("keyup", Mx.onkeyup, false); + window.removeEventListener("resize", this.onresize, false); + document.removeEventListener("mouseup", this.docMouseUp, false); + window.removeEventListener( + "mousedown", + this.dragMouseDownHandler, + false + ); + window.removeEventListener( + "mousemove", + this.throttledDragOnMouseMove, + false + ); + window.removeEventListener( + "mouseup", + this.dragMouseUpHandler, + false + ); + window.removeEventListener("wheel", this.wheelHandler, false); + window.removeEventListener("mousewheel", this.wheelHandler, false); + window.removeEventListener( + "DOMMouseScroll", + this.wheelHandler, + false + ); + window.removeEventListener("keypress", this.onkeypress, false); + }, + + checkresize: function () { + if (mx.checkresize(this._Mx)) { + this.refresh(); + } + }, + addColorMaps: function (colormaps) { + colormaps.forEach(function (cmap) { + if (cmap.hasOwnProperty("name")) { + m.Mc.colormap.push(cmap); } - mx.set_font(Mx, font_width); - Gx.pthk = Mx.text_w * 1.5; + }); + }, - if (Gx.specs) { - var ytimecode = false; - if (Gx.ylab === 4) { //time-based tics - ytimecode = true; - } - // Set left and right edges - if (Gx.show_y_axis === true) { - Mx.l = Mx.text_w * 6; - if (ytimecode) { - // If we are in ytimecode, determine if we need the extra - // space to hold the entire YYYY:MM:DD - var need_full_ymd = ((Math.abs(Mx.stk[0].ymin) >= 31536000) || - (Math.abs(Mx.stk[0].ymax) >= 31536000)); - if (need_full_ymd) { - Mx.l = Mx.text_w * 11; - } + _refresh: function () { + var Mx = this._Mx; + var Gx = this._Gx; + var ctx = Mx.canvas.getContext("2d"); + var plugin_index = 0; + + if (Gx.hold) { + return; + } + var font_width = Mx.font_width; + if (Mx.font_scaled) { + font_width = Math.min(Mx.font_width, Mx.width / 64); + } + mx.set_font(Mx, font_width); + Gx.pthk = Mx.text_w * 1.5; + + if (Gx.specs) { + var ytimecode = false; + if (Gx.ylab === 4) { + //time-based tics + ytimecode = true; + } + // Set left and right edges + if (Gx.show_y_axis === true) { + Mx.l = Mx.text_w * 6; + if (ytimecode) { + // If we are in ytimecode, determine if we need the extra + // space to hold the entire YYYY:MM:DD + var need_full_ymd = + Math.abs(Mx.stk[0].ymin) >= 31536000 || + Math.abs(Mx.stk[0].ymax) >= 31536000; + if (need_full_ymd) { + Mx.l = Mx.text_w * 11; } - } else { - Mx.l = 1; } - if (Gx.pan === true) { - Mx.r = Mx.width - (Gx.pthk + 2 * Mx.text_w); + } else { + Mx.l = 1; + } + if (Gx.pan === true) { + Mx.r = Mx.width - (Gx.pthk + 2 * Mx.text_w); + } else { + Mx.r = Mx.width - 5; + } + + // Set top and bottom + if (Gx.show_readout) { + Mx.t = Mx.text_h * 2; + if (Gx.show_x_axis) { + Mx.b = Mx.height - Mx.text_h * 4; } else { - Mx.r = Mx.width - 5; + Mx.b = Mx.height - Mx.text_h * 3; } - - // Set top and bottom - if (Gx.show_readout) { - Mx.t = Mx.text_h * 2; + } else if (Gx.x_scrollbar_location === "bottom") { + Mx.t = Mx.text_h * 2; + if (Gx.pan) { if (Gx.show_x_axis) { - Mx.b = Mx.height - Mx.text_h * 4; - } else { Mx.b = Mx.height - Mx.text_h * 3; - } - } else if (Gx.x_scrollbar_location === "bottom") { - Mx.t = Mx.text_h * 2; - if (Gx.pan) { - if (Gx.show_x_axis) { - Mx.b = Mx.height - Mx.text_h * 3; - } else { - Mx.b = Mx.height - Mx.text_h * 2; - } } else { - if (Gx.show_x_axis) { - Mx.b = Mx.height - Mx.text_h * 2; - } else { - Mx.b = Mx.height - 5; - } + Mx.b = Mx.height - Mx.text_h * 2; } } else { - if (Gx.pan) { - Mx.t = Gx.pthk + 2 * Mx.text_w; - } else { - Mx.t = 1; - } if (Gx.show_x_axis) { - Mx.b = Mx.height - (Mx.text_h * 3) / 2; + Mx.b = Mx.height - Mx.text_h * 2; } else { - Mx.b = Mx.height - 2; + Mx.b = Mx.height - 5; } } + } else { + if (Gx.pan) { + Mx.t = Gx.pthk + 2 * Mx.text_w; + } else { + Mx.t = 1; + } + if (Gx.show_x_axis) { + Mx.b = Mx.height - (Mx.text_h * 3) / 2; + } else { + Mx.b = Mx.height - 2; + } + } - // set left and right edges for X scrollbar - if (Gx.show_readout) { - // If there is a readout, show it in the bottom-right - // next to the readout - Gx.pl = Mx.text_w * 50; + // set left and right edges for X scrollbar + if (Gx.show_readout) { + // If there is a readout, show it in the bottom-right + // next to the readout + Gx.pl = Mx.text_w * 50; + } else { + // Otherwise, by default it conforms to legacy + // behaviour and renders at the top next to the label + if (Gx.x_scrollbar_location === "bottom") { + Gx.pl = Mx.l; } else { - // Otherwise, by default it conforms to legacy - // behaviour and renders at the top next to the label - if (Gx.x_scrollbar_location === "bottom") { - Gx.pl = Mx.l; - } else { - Gx.pl = Mx.text_w * 35; - } + Gx.pl = Mx.text_w * 35; } - Gx.pr = Math.max(Gx.pl + Mx.text_w * 9, Mx.r); + } + Gx.pr = Math.max(Gx.pl + Mx.text_w * 9, Mx.r); - // set top scrollbar edge for X scrollbar - if (Gx.show_readout) { + // set top scrollbar edge for X scrollbar + if (Gx.show_readout) { + if (Gx.show_x_axis) { + Gx.pt = + Mx.b + + Mx.text_h + + (Mx.height - Mx.b - Mx.text_h - Gx.pthk) / 2; + } else { + Gx.pt = Mx.b + (Mx.height - Mx.b - Gx.pthk) / 2; + } + } else { + // Otherwise, by default it conforms to legacy + // behaviour and renders at the top + if (Gx.x_scrollbar_location === "bottom") { if (Gx.show_x_axis) { - Gx.pt = Mx.b + Mx.text_h + (Mx.height - Mx.b - Mx.text_h - Gx.pthk) / 2; + Gx.pt = + Mx.b + + Mx.text_h + + (Mx.height - Mx.b - Mx.text_h - Gx.pthk) / 2; } else { Gx.pt = Mx.b + (Mx.height - Mx.b - Gx.pthk) / 2; } } else { - // Otherwise, by default it conforms to legacy - // behaviour and renders at the top - if (Gx.x_scrollbar_location === "bottom") { - if (Gx.show_x_axis) { - Gx.pt = Mx.b + Mx.text_h + (Mx.height - Mx.b - Mx.text_h - Gx.pthk) / 2; - } else { - Gx.pt = Mx.b + (Mx.height - Mx.b - Gx.pthk) / 2; - } - } else { - Gx.pt = (Mx.t - Gx.pthk) / 2; - } + Gx.pt = (Mx.t - Gx.pthk) / 2; } - Gx.lbtn = Mx.text_h + Mx.text_w + 2; + } + Gx.lbtn = Mx.text_h + Mx.text_w + 2; + } else { + if (Gx.pan) { + Mx.t = Gx.pthk + 2 * Mx.text_w; + Mx.r = Mx.width - (Gx.pthk + Mx.text_w); } else { - if (Gx.pan) { - Mx.t = Gx.pthk + 2 * Mx.text_w; - Mx.r = Mx.width - (Gx.pthk + Mx.text_w); - } else { - Mx.t = 1; - Mx.r = Mx.width - 2; - } - Mx.b = Mx.height - 2; - Mx.l = 1; - Gx.pl = Mx.l; - Gx.pr = Mx.r; - Gx.pt = (Mx.t - Gx.pthk) / 2; - Gx.lbtn = 0; + Mx.t = 1; + Mx.r = Mx.width - 2; } + Mx.b = Mx.height - 2; + Mx.l = 1; + Gx.pl = Mx.l; + Gx.pr = Mx.r; + Gx.pt = (Mx.t - Gx.pthk) / 2; + Gx.lbtn = 0; + } - // pan select ranges - Gx.pyl = Mx.r + (Mx.width - Mx.r - Gx.pthk) / 2 + 1; + // pan select ranges + Gx.pyl = Mx.r + (Mx.width - Mx.r - Gx.pthk) / 2 + 1; - if (Gx.lg_colorbar && (Gx.lyr[0].hcb["class"] === 2)) { - // Move the plot over to make room - var prev_Mx_r = Mx.r; - Mx.r = prev_Mx_r - 100; + if (Gx.lg_colorbar && Gx.lyr[0].hcb["class"] === 2) { + // Move the plot over to make room + var prev_Mx_r = Mx.r; + Mx.r = prev_Mx_r - 100; + } - } + if ( + Gx.p_cuts && + Gx.lyr.length === 1 && + Gx.lyr[0].hcb["class"] === 2 + ) { + //turn cross hairs on + Gx.cross = true; - if (Gx.p_cuts && (Gx.lyr.length === 1) && (Gx.lyr[0].hcb["class"] === 2)) { - //turn cross hairs on - Gx.cross = true; + //Move the plot over to make room + var prev_Mx_r = Mx.r; + Mx.r = prev_Mx_r - 100; - //Move the plot over to make room - var prev_Mx_r = Mx.r; - Mx.r = prev_Mx_r - 100; + //Move the plot up to make room + var prev_Mx_b = Mx.b; + Mx.b = prev_Mx_b - 100; + } - //Move the plot up to make room - var prev_Mx_b = Mx.b; - Mx.b = prev_Mx_b - 100; - } + if (Gx.xcut_now) { + Mx.canvas.width = Gx.x_box_w - 1; + Mx.canvas.height = Gx.x_box_h; + Mx.r = Gx.x_box_w - 1; + Mx.l = 0; + Mx.b = Gx.x_box_h; + Mx.t = 0; + } - if (Gx.xcut_now) { - Mx.canvas.width = Gx.x_box_w - 1; - Mx.canvas.height = Gx.x_box_h; - Mx.r = Gx.x_box_w - 1; - Mx.l = 0; - Mx.b = Gx.x_box_h; - Mx.t = 0; - } + if (Gx.ycut_now) { + Mx.canvas.width = Gx.y_box_h - 1; + Mx.canvas.height = Gx.y_box_w; + Mx.r = Gx.y_box_h - 1; + Mx.l = 0; + Mx.b = Gx.y_box_w; + Mx.t = 0; + } - if (Gx.ycut_now) { - Mx.canvas.width = Gx.y_box_h - 1; - Mx.canvas.height = Gx.y_box_w; - Mx.r = Gx.y_box_h - 1; - Mx.l = 0; - Mx.b = Gx.y_box_w; - Mx.t = 0; - } + if (Gx.panymin === undefined || Gx.panymax === undefined) { + scale_base(this, {}); + } - if ((Gx.panymin === undefined) || (Gx.panymax === undefined)) { - scale_base(this, {}); + // set virtual window size/pos/scaling for current level + var k = Mx.level; + Mx.stk[k].x1 = Mx.l; + Mx.stk[k].y1 = Mx.t; + Mx.stk[k].x2 = Mx.r; + Mx.stk[k].y2 = Mx.b; + Mx.stk[k].xscl = (Mx.stk[k].xmax - Mx.stk[k].xmin) / (Mx.r - Mx.l); + Mx.stk[k].yscl = (Mx.stk[k].ymax - Mx.stk[k].ymin) / (Mx.b - Mx.t); + + // In case things have rescaled + var re = pixel_to_real(this, Mx.xpos, Mx.ypos); + Gx.retx = re.x; + Gx.rety = re.y; + + // modify stack for section plotting + //if (Gx.sections) { + // TODO + //} + + if (Gx.panning === 0 || Gx.panning !== 0) { + // TODO Gx.panning !== + // 0?? Does this work? + Gx.plotData.valid = false; + mx.clear_window(Mx); + } //else if (!Gx.specs) { + // TODO + //} else if (Gx.panning === 1) { + // TODO + //} else { + // TODO + //} + + var xlab = Gx.xlab; + var ylab = Gx.ylab; + + if (xlab === undefined) { + xlab = 30; + } + if (Gx.index) { + xlab = 0; + } + + if (ylab === undefined) { + var cx = Gx.lyr.length > 0 && Gx.lyr[0].cx; + if (Gx.cmode === 1) { + ylab = 28; + } else if (Gx.cmode === 2) { + ylab = Gx.plab; + } else if (Gx.cmode === 3 && cx) { + ylab = 21; + } else if (Gx.cmode === 4) { + ylab = 22; + } else if (Gx.cmode === 5) { + ylab = 22; + xlab = 21; + } else if (Gx.cmode === 6) { + ylab = 26; + } else if (Gx.cmode === 7) { + ylab = 27; + } else { + ylab = 0; } + } - // set virtual window size/pos/scaling for current level - var k = Mx.level; - Mx.stk[k].x1 = Mx.l; - Mx.stk[k].y1 = Mx.t; - Mx.stk[k].x2 = Mx.r; - Mx.stk[k].y2 = Mx.b; - Mx.stk[k].xscl = (Mx.stk[k].xmax - Mx.stk[k].xmin) / (Mx.r - Mx.l); - Mx.stk[k].yscl = (Mx.stk[k].ymax - Mx.stk[k].ymin) / (Mx.b - Mx.t); - - // In case things have rescaled - var re = pixel_to_real(this, Mx.xpos, Mx.ypos); - Gx.retx = re.x; - Gx.rety = re.y; - - // modify stack for section plotting - //if (Gx.sections) { - // TODO - //} - - if (Gx.panning === 0 || Gx.panning !== 0) { // TODO Gx.panning !== - // 0?? Does this work? - Gx.plotData.valid = false; - mx.clear_window(Mx); - } //else if (!Gx.specs) { - // TODO - //} else if (Gx.panning === 1) { - // TODO - //} else { - // TODO + if (Gx.specs) { + if (Gx.sections === 0) { + var drawaxis_flags = { + grid: Gx.grid, + }; + if (Gx.panning === 2) { + drawaxis_flags.noxtlab = true; + } // TODO Does this work?? + if (!Gx.show_x_axis) { + drawaxis_flags.noxtics = true; + drawaxis_flags.noxtlab = true; + drawaxis_flags.noxplab = true; + } + if (!Gx.show_y_axis) { + drawaxis_flags.noytics = true; + drawaxis_flags.noytlab = true; + drawaxis_flags.noyplab = true; + } + if (Gx.specs && !Gx.show_readout && !Gx.pan) { + drawaxis_flags.noyplab = true; + drawaxis_flags.noxplab = true; + } + if (Gx.gridBackground) { + drawaxis_flags.fillStyle = Gx.gridBackground; + } + if (Gx.gridStyle) { + drawaxis_flags.gridStyle = Gx.gridStyle; + } + if (Gx.xmult) { + drawaxis_flags.xmult = Gx.xmult; + } + if (Gx.ymult) { + drawaxis_flags.ymult = Gx.ymult; + } + if (xlab === 4) { + //time-based tics + drawaxis_flags.xtimecode = true; + } + if (ylab === 4) { + //time-based tics + drawaxis_flags.ytimecode = true; + } + if (Gx.xlabel !== undefined) { + drawaxis_flags.xlabel = Gx.xlabel; + } + if (Gx.ylabel !== undefined) { + drawaxis_flags.ylabel = Gx.ylabel; + } + mx.drawaxis( + Gx, + Mx, + Gx.xdiv, + Gx.ydiv, + xlab, + ylab, + drawaxis_flags + ); + } //else { + // Not implemented yet //} - var xlab = Gx.xlab; - var ylab = Gx.ylab; - - if (xlab === undefined) { - xlab = 30; - } - if (Gx.index) { - xlab = 0; - } - - if (ylab === undefined) { - var cx = ((Gx.lyr.length > 0) && Gx.lyr[0].cx); - if (Gx.cmode === 1) { - ylab = 28; - } else if (Gx.cmode === 2) { - ylab = Gx.plab; - } else if ((Gx.cmode === 3) && (cx)) { - ylab = 21; - } else if (Gx.cmode === 4) { - ylab = 22; - } else if (Gx.cmode === 5) { - ylab = 22; - xlab = 21; - } else if (Gx.cmode === 6) { - ylab = 26; - } else if (Gx.cmode === 7) { - ylab = 27; - } else { - ylab = 0; - } - } + var i = Gx.lbtn - 2; - if (Gx.specs) { - if (Gx.sections === 0) { - var drawaxis_flags = { - grid: Gx.grid - }; - if (Gx.panning === 2) { - drawaxis_flags.noxtlab = true; - } // TODO Does this work?? - if (!Gx.show_x_axis) { - drawaxis_flags.noxtics = true; - drawaxis_flags.noxtlab = true; - drawaxis_flags.noxplab = true; - } - if (!Gx.show_y_axis) { - drawaxis_flags.noytics = true; - drawaxis_flags.noytlab = true; - drawaxis_flags.noyplab = true; - } - if (Gx.specs && !Gx.show_readout && !Gx.pan) { - drawaxis_flags.noyplab = true; - drawaxis_flags.noxplab = true; - } - if (Gx.gridBackground) { - drawaxis_flags.fillStyle = Gx.gridBackground; - } - if (Gx.gridStyle) { - drawaxis_flags.gridStyle = Gx.gridStyle; - } - if (Gx.xmult) { - drawaxis_flags.xmult = Gx.xmult; - } - if (Gx.ymult) { - drawaxis_flags.ymult = Gx.ymult; - } - if (xlab === 4) { //time-based tics - drawaxis_flags.xtimecode = true; - } - if (ylab === 4) { //time-based tics - drawaxis_flags.ytimecode = true; - } - if (Gx.xlabel !== undefined) { - drawaxis_flags.xlabel = Gx.xlabel; - } - if (Gx.ylabel !== undefined) { - drawaxis_flags.ylabel = Gx.ylabel; - } - mx.drawaxis(Gx, Mx, Gx.xdiv, Gx.ydiv, xlab, ylab, drawaxis_flags); - } //else { - // Not implemented yet - //} - - var i = Gx.lbtn - 2; - - if (Gx.show_readout) { - if (!Gx.no_legend_button) { - if (Gx.legend) { - Gx.legendBtnLocation = { - x: Mx.width - Gx.lbtn, - y: 2, - width: i, - height: i - }; - mx.shadowbox(Mx, Mx.width - Gx.lbtn, 2, i, i, 1, -2, - 'L'); - } else { - Gx.legendBtnLocation = { - x: Mx.width - Gx.lbtn, - y: 2, - width: i, - height: i - }; - mx.shadowbox(Mx, Mx.width - Gx.lbtn, 2, i, i, 1, - 2, 'L'); - } + if (Gx.show_readout) { + if (!Gx.no_legend_button) { + if (Gx.legend) { + Gx.legendBtnLocation = { + x: Mx.width - Gx.lbtn, + y: 2, + width: i, + height: i, + }; + mx.shadowbox( + Mx, + Mx.width - Gx.lbtn, + 2, + i, + i, + 1, + -2, + "L" + ); + } else { + Gx.legendBtnLocation = { + x: Mx.width - Gx.lbtn, + y: 2, + width: i, + height: i, + }; + mx.shadowbox( + Mx, + Mx.width - Gx.lbtn, + 2, + i, + i, + 1, + 2, + "L" + ); } - display_specs(this); - } else { - Gx.legendBtnLocation = null; } - } else if (Gx.grid && Gx.sections >= 0) { - var drawaxis_flags = { - grid: true, - noaxisbox: true, - noxtics: true, - noxtlab: true, - noxplab: true, - noytics: true, - noytlab: true, - noyplab: true - }; - mx.drawaxis(Gx, Mx, Gx.xdiv, Gx.ydiv, xlab, ylab, - drawaxis_flags); - } - - draw_layers(this); - - draw_accessories(this, 4); - - + display_specs(this); + } else { + Gx.legendBtnLocation = null; + } + } else if (Gx.grid && Gx.sections >= 0) { + var drawaxis_flags = { + grid: true, + noaxisbox: true, + noxtics: true, + noxtlab: true, + noxplab: true, + noytics: true, + noytlab: true, + noyplab: true, + }; + mx.drawaxis( + Gx, + Mx, + Gx.xdiv, + Gx.ydiv, + xlab, + ylab, + drawaxis_flags + ); + } - draw_plugins(this); + draw_layers(this); + draw_accessories(this, 4); - Gx.cross_xpos = undefined; - Gx.cross_ypos = undefined; - if ((!Mx.warpbox) && (this.mouseOnCanvas)) { - draw_crosshairs(this); - if (!Gx.y_cut_press_on && !Gx.x_cut_press_on && (Gx.lyr.length === 1) && (Gx.lyr[0].hcb["class"] === 2)) { - draw_p_cuts(this); - } - } + draw_plugins(this); - if (Gx.always_show_marker || Gx.show_marker) { - draw_marker(this); + Gx.cross_xpos = undefined; + Gx.cross_ypos = undefined; + if (!Mx.warpbox && this.mouseOnCanvas) { + draw_crosshairs(this); + if ( + !Gx.y_cut_press_on && + !Gx.x_cut_press_on && + Gx.lyr.length === 1 && + Gx.lyr[0].hcb["class"] === 2 + ) { + draw_p_cuts(this); } } - }; - - // ///////////////////////////////////////////////////////////////////////// - // Private methods and objects - // ///////////////////////////////////////////////////////////////////////// - - /** - * Map integer cmode to string equivalent. - * - * @memberOf sigplot - * @private - */ - var cxm = ["Ma", "Ph", "Re", "Im", "IR", "Lo", "L2"]; - - /** - * Map integer abscissa mode to string equivalent. - * - * @memberOf sigplot - * @private - */ - var cam = ["(absc)", "(indx)", "(1/ab)", "(dydx)"]; + if (Gx.always_show_marker || Gx.show_marker) { + draw_marker(this); + } + }, +}; +// ///////////////////////////////////////////////////////////////////////// +// Private methods and objects +// ///////////////////////////////////////////////////////////////////////// +/** + * Map integer cmode to string equivalent. + * + * @memberOf sigplot + * @private + */ +var cxm = ["Ma", "Ph", "Re", "Im", "IR", "Lo", "L2"]; - /** - * This object holds the data associated with layers in the plot. - * - * @constructor - * @memberOf sigplot - * @private - */ - function SIGPLOTLAYER() { - - this.xbuf = undefined; // raw (ArrayBuffer) of ABSC data - this.ybuf = undefined; // raw (ArrayBuffer) of ORD data - - this.offset = 0.0; - this.xstart = 0.0; - this.xdelta = 0.0; - this.imin = 0; - this.xmin = 0.0; - this.xmax = 0.0; - this.name = ""; - this.cx = false; - this.hcb = undefined; // index in Gx.HCB - // xbufn = xbuf.byteLength - // ybufn = ybuf.byteLength - this.size = 0; - - this.display = true; - this.color = 0; - this.line = 3; // 0=none, 1-vertical, 2-horizontal, 3-connecting - this.thick = 1; // negative for dashed - this.symbol = 0; - this.radius = 3; - - this.skip = 0; // number of elements between ord values - this.xsub = 0; - this.ysub = 0; - this.xdata = false; // true if X data is data from file - - this.options = {}; - } +/** + * Map integer abscissa mode to string equivalent. + * + * @memberOf sigplot + * @private + */ +var cam = ["(absc)", "(indx)", "(1/ab)", "(dydx)"]; - /** - * The graphics structure object used to hold state about the plot. - * - * @constructor - * @memberOf sigplot - * @private - */ - function GX() { - this.initialized = false; - this.xptr = undefined; // xpoints as anything "array-like"... - this.yptr = undefined; // ypoints as anything "array-like"... - - this.retx = 0.0; // absc coord. at mouse location - this.rety = 0.0; - this.xmrk = 0.0; // absc coord of mark - this.ymrk = 0.0; - this.aretx = 0.0; // absc coord. at mouse location - this.arety = 0.0; - - this.xstart = 0.0; - this.xdelta = 0.0; - - this.panxmin = 0.0; - this.panxmax = 0.0; - this.panymin = 0.0; - this.panymax = 0.0; - this.xmin = 0.0; - this.xmax = 0.0; - this.xmult = undefined; - this.ymin = 0.0; - this.ymax = 0.0; - this.ymult = undefined; - this.zmin = undefined; - this.zmax = undefined; - this.zoff = 0; - this.dbmin = 0.0; - this.pxscl = 0.0; - this.pyscl = 0.0; - this.pmt = 0.0; - - this.note = ""; - // this.mouse unnecssary because we don't have res table - this.format = ""; - - this.pl = 0; - this.pr = 0; - this.pt = 0; - this.pb = 0; - this.px1 = 0; // specifies plotting field - this.px2 = 0; - this.py1 = 0; - this.py2 = 0; - - this.pyl = 0; - this.pthk = 0; // thickness of pan drag box - - this.modlayer = 0; - this.modsource = 0; - this.modified = false; - this.modmode = 0; - - this.xdiv = 0; - this.ydiv = 0; - - this.all = false; - this.expand = false; - this.cross = false; - this.grid = true; - this.gridBackground = undefined; - this.index = false; - this.pan = true; - this.specs = true; - this.legend = true; - this.xdata = false; - - this.show_x_axis = true; - this.show_y_axis = true; - this.show_readout = true; - this.hide_note = false; - this.autohide_readout = false; - this.autohide_panbars = false; - this.panning = undefined; - this.panmode = 0; // TODO Is this a good default value? Where is this - // changed? - this.hold = false; - - this.sections = 0; // number of plot sections, -1 for layers - this.iysec = 0; - this.nsec = 0; // actual number of sections - this.isec = 0; // current sections - - this.xlab = undefined; - this.xlabel = undefined; - this.ylab = undefined; - this.ylabel = undefined; - - // 0 - use HTML5 canvas smoothing - // 1 - average - // 2 - min - // 3 - max - // 4 - first - // 5 - max abs - this.xcompression = 0; - - this.default_rubberbox_action = "zoom"; - this.default_rubberbox_mode = "box"; - - this.wheelscroll_mode_natural = true; - this.scroll_time_interval = 10; - - this.repeatPanning = undefined; - this.stillPanning = undefined; // TODO maybe merge this variable with - // Gx.panning in future? - - this.autol = -1; - - this.lineSmoothing = false; // not implemented - this.rasterSmoothing = false; - - this.wheelZoom = false; - this.wheelZoomPercent = 0.2; - this.inContinuousZoom = false; - - this.lyr = []; - this.HCB = []; - this.HCB_UUID = {}; - this.HCB_RDR = {}; - this.plugins = []; - - this.plotData = document.createElement("canvas"); - this.plotData.valid = false; - - // Large colorbar info, like button locations - this.lg_colorbar = false; - - // Colorbar button top or bottom positions - this.cbb_top_x1 = 0; - this.cbb_top_y1 = 0; - this.cbb_bot_x1 = 0; - this.cbb_bot_y1 = 0; - this.cbb_width = 0; - this.cbb_height = 0; - - //P_cuts info - this.p_cuts = false; - this.x_box_x = 0; - this.x_box_y = 0; - this.x_box_h = 0; - this.x_box_w = 0; - this.y_box_x = 0; - this.y_box_y = 0; - this.y_box_h = 0; - this.y_box_w = 0; - this.p_cuts_xpos = undefined; - this.p_cuts_ypos = undefined; - this.x_cut_data = []; - this.y_cut_data = []; - //the plot to hold the x-cut on bottom - this.xcut = undefined; - //layer xcut that will be displayed on pop-up - this.xcut_layer = undefined; - this.x_cut_press_on = false; - //variable that is true if the bottom xcut is being drawn - this.xcut_now = false; - //the plot to hold the y-cut - this.ycut = undefined; - //layer ycut that will be displayed on pop-up - this.ycut_layer = undefined; - this.y_cut_press_on = false; - //variable that is true if the ycut is being drawn - this.ycut_now = false; - this.ylabel_stash = undefined; - this.cut_stash = undefined; - //div to hold x-cut - this.element1 = undefined; - //div to hold y cut - this.element2 = undefined; - - //x and y sticky key configuration ("automatic" displays point on - //1D and cut on 2D, "disable" doesn't display anything, "pop-up" - //displays point on both, and "cuts" displays only cuts on 2D) - this.xyKeys = "automatic"; - //true if the x value is being displayed on plot - this.x_pop_now = false; - //true if the y value is being displayed on plot - this.y_pop_now = false; - - //the drawmode and autol before the x or y cut was showing - this.old_drawmode = undefined; - this.old_autol = undefined; - - // refresh-reference-counter - this.refresh_after_ctr = 0; - } +/** + * This object holds the data associated with layers in the plot. + * + * @constructor + * @memberOf sigplot + * @private + */ +function SIGPLOTLAYER() { + this.xbuf = undefined; // raw (ArrayBuffer) of ABSC data + this.ybuf = undefined; // raw (ArrayBuffer) of ORD data + + this.offset = 0.0; + this.xstart = 0.0; + this.xdelta = 0.0; + this.imin = 0; + this.xmin = 0.0; + this.xmax = 0.0; + this.name = ""; + this.cx = false; + this.hcb = undefined; // index in Gx.HCB + // xbufn = xbuf.byteLength + // ybufn = ybuf.byteLength + this.size = 0; + + this.display = true; + this.color = 0; + this.line = 3; // 0=none, 1-vertical, 2-horizontal, 3-connecting + this.thick = 1; // negative for dashed + this.symbol = 0; + this.radius = 3; + + this.skip = 0; // number of elements between ord values + this.xsub = 0; + this.ysub = 0; + this.xdata = false; // true if X data is data from file + + this.options = {}; +} - /** - * @memberOf sigplot - * @private - */ - function setup_cmap(plot, cmap) { - var Gx = plot._Gx; - var Mx = plot._Mx; +/** + * The graphics structure object used to hold state about the plot. + * + * @constructor + * @memberOf sigplot + * @private + */ +function GX() { + this.initialized = false; + this.xptr = undefined; // xpoints as anything "array-like"... + this.yptr = undefined; // ypoints as anything "array-like"... + + this.retx = 0.0; // absc coord. at mouse location + this.rety = 0.0; + this.xmrk = 0.0; // absc coord of mark + this.ymrk = 0.0; + this.aretx = 0.0; // absc coord. at mouse location + this.arety = 0.0; + + this.xstart = 0.0; + this.xdelta = 0.0; + + this.panxmin = 0.0; + this.panxmax = 0.0; + this.panymin = 0.0; + this.panymax = 0.0; + this.xmin = 0.0; + this.xmax = 0.0; + this.xmult = undefined; + this.ymin = 0.0; + this.ymax = 0.0; + this.ymult = undefined; + this.zmin = undefined; + this.zmax = undefined; + this.zoff = 0; + this.dbmin = 0.0; + this.pxscl = 0.0; + this.pyscl = 0.0; + this.pmt = 0.0; + + this.note = ""; + // this.mouse unnecssary because we don't have res table + this.format = ""; + + this.pl = 0; + this.pr = 0; + this.pt = 0; + this.pb = 0; + this.px1 = 0; // specifies plotting field + this.px2 = 0; + this.py1 = 0; + this.py2 = 0; + + this.pyl = 0; + this.pthk = 0; // thickness of pan drag box + + this.modlayer = 0; + this.modsource = 0; + this.modified = false; + this.modmode = 0; + + this.xdiv = 0; + this.ydiv = 0; + + this.all = false; + this.expand = false; + this.cross = false; + this.grid = true; + this.gridBackground = undefined; + this.index = false; + this.pan = true; + this.specs = true; + this.legend = true; + this.xdata = false; + + this.show_x_axis = true; + this.show_y_axis = true; + this.show_readout = true; + this.hide_note = false; + this.autohide_readout = false; + this.autohide_panbars = false; + this.panning = undefined; + this.panmode = 0; // TODO Is this a good default value? Where is this + // changed? + this.hold = false; + + this.sections = 0; // number of plot sections, -1 for layers + this.iysec = 0; + this.nsec = 0; // actual number of sections + this.isec = 0; // current sections + + this.xlab = undefined; + this.xlabel = undefined; + this.ylab = undefined; + this.ylabel = undefined; + + // 0 - use HTML5 canvas smoothing + // 1 - average + // 2 - min + // 3 - max + // 4 - first + // 5 - max abs + this.xcompression = 0; + + this.default_rubberbox_action = "zoom"; + this.default_rubberbox_mode = "box"; + + this.wheelscroll_mode_natural = true; + this.scroll_time_interval = 10; + + this.repeatPanning = undefined; + this.stillPanning = undefined; // TODO maybe merge this variable with + // Gx.panning in future? + + this.autol = -1; + + this.lineSmoothing = false; // not implemented + this.rasterSmoothing = false; + + this.wheelZoom = false; + this.wheelZoomPercent = 0.2; + this.inContinuousZoom = false; + + this.lyr = []; + this.HCB = []; + this.HCB_UUID = {}; + this.HCB_RDR = {}; + this.plugins = []; + + this.plotData = document.createElement("canvas"); + this.plotData.valid = false; + + // Large colorbar info, like button locations + this.lg_colorbar = false; + + // Colorbar button top or bottom positions + this.cbb_top_x1 = 0; + this.cbb_top_y1 = 0; + this.cbb_bot_x1 = 0; + this.cbb_bot_y1 = 0; + this.cbb_width = 0; + this.cbb_height = 0; + + //P_cuts info + this.p_cuts = false; + this.x_box_x = 0; + this.x_box_y = 0; + this.x_box_h = 0; + this.x_box_w = 0; + this.y_box_x = 0; + this.y_box_y = 0; + this.y_box_h = 0; + this.y_box_w = 0; + this.p_cuts_xpos = undefined; + this.p_cuts_ypos = undefined; + this.x_cut_data = []; + this.y_cut_data = []; + //the plot to hold the x-cut on bottom + this.xcut = undefined; + //layer xcut that will be displayed on pop-up + this.xcut_layer = undefined; + this.x_cut_press_on = false; + //variable that is true if the bottom xcut is being drawn + this.xcut_now = false; + //the plot to hold the y-cut + this.ycut = undefined; + //layer ycut that will be displayed on pop-up + this.ycut_layer = undefined; + this.y_cut_press_on = false; + //variable that is true if the ycut is being drawn + this.ycut_now = false; + this.ylabel_stash = undefined; + this.cut_stash = undefined; + //div to hold x-cut + this.element1 = undefined; + //div to hold y cut + this.element2 = undefined; + + //x and y sticky key configuration ("automatic" displays point on + //1D and cut on 2D, "disable" doesn't display anything, "pop-up" + //displays point on both, and "cuts" displays only cuts on 2D) + this.xyKeys = "automatic"; + //true if the x value is being displayed on plot + this.x_pop_now = false; + //true if the y value is being displayed on plot + this.y_pop_now = false; + + //the drawmode and autol before the x or y cut was showing + this.old_drawmode = undefined; + this.old_autol = undefined; + + // refresh-reference-counter + this.refresh_after_ctr = 0; +} - // If a color map array was provided make a custom map - if (Array.isArray(cmap)) { - var custom_cmap = { - name: "Custom", - colors: cmap - }; - if (m.Mc.colormap[m.Mc.colormap.length - 1].name === "Custom") { - m.Mc.colormap[m.Mc.colormap.length - 1].colors = cmap; - } else { - m.Mc.colormap.push(custom_cmap); - } - Gx.cmap = m.Mc.colormap.length - 1; - } else if (typeof cmap === "string") { - Gx.cmap = -1; - for (var xc = 0; xc < m.Mc.colormap.length; xc++) { - if (m.Mc.colormap[xc].name === cmap) { - Gx.cmap = xc; - break; - } - } +/** + * @memberOf sigplot + * @private + */ +function setup_cmap(plot, cmap) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + // If a color map array was provided make a custom map + if (Array.isArray(cmap)) { + var custom_cmap = { + name: "Custom", + colors: cmap, + }; + if (m.Mc.colormap[m.Mc.colormap.length - 1].name === "Custom") { + m.Mc.colormap[m.Mc.colormap.length - 1].colors = cmap; } else { - Gx.cmap = cmap; - } - - if (Gx.ncolors < 0) { - Gx.ncolors = -1 * Gx.ncolors; - Gx.cmap = Math.max(1, Gx.cmap); + m.Mc.colormap.push(custom_cmap); } - if ((Gx.cmap < 0) || (Gx.cmap > m.Mc.colormap.length)) { - if (Gx.cmode === 2) { - Gx.cmap = 2; // wheel - } else { - Gx.cmap = 1; // ramp + Gx.cmap = m.Mc.colormap.length - 1; + } else if (typeof cmap === "string") { + Gx.cmap = -1; + for (var xc = 0; xc < m.Mc.colormap.length; xc++) { + if (m.Mc.colormap[xc].name === cmap) { + Gx.cmap = xc; + break; } } - - mx.colormap(Mx, m.Mc.colormap[Gx.cmap].colors, Gx.ncolors); + } else { + Gx.cmap = cmap; } - /** - * @memberOf sigplot - * @private - */ - function sigplot_show_x(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; - - var ls = Gx.aretx.toString(); - if (Gx.iabsc === 1) { - mx.message(Mx, "INDEX = " + ls); - } else if (Gx.iabsc === 2) { - mx.message(Mx, "1/X = " + ls); + if (Gx.ncolors < 0) { + Gx.ncolors = -1 * Gx.ncolors; + Gx.cmap = Math.max(1, Gx.cmap); + } + if (Gx.cmap < 0 || Gx.cmap > m.Mc.colormap.length) { + if (Gx.cmode === 2) { + Gx.cmap = 2; // wheel } else { - //if (Gx.xlab === 4) { - // TODO - //} - mx.message(Mx, "X = " + ls); + Gx.cmap = 1; // ramp } } - /** - * @memberOf sigplot - * @private - */ - function sigplot_show_timecode(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; - - if (Gx.lyr.length > 0) { - //var hcb = Gx.HCB[Gx.lyr[0].hcb]; - var hcb = Gx.lyr[0].hcb; // mmm-TODO-needs investigation - if (hcb) { - if ((hcb["class"] === 1) && ((hcb.xunits === 1) || (hcb.xunits === 4))) { - mx.message(Mx, "Time = " + m.sec2tod(hcb.timecode + Gx.retx), true); - } else if ((hcb["class"] === 2) && ((hcb.yunits === 1) || (hcb.yunits === 4))) { - mx.message(Mx, "Time = " + m.sec2tod(hcb.timecode + Gx.rety), true); - } else { - mx.message(Mx, "Time = UNK"); - } - } - } + mx.colormap(Mx, m.Mc.colormap[Gx.cmap].colors, Gx.ncolors); +} +/** + * @memberOf sigplot + * @private + */ +function sigplot_show_x(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + var ls = Gx.aretx.toString(); + if (Gx.iabsc === 1) { + mx.message(Mx, "INDEX = " + ls); + } else if (Gx.iabsc === 2) { + mx.message(Mx, "1/X = " + ls); + } else { + //if (Gx.xlab === 4) { + // TODO + //} + mx.message(Mx, "X = " + ls); } +} - /** - * @memberOf sigplot - * @private - */ - function sigplot_show_y(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; - - var ls = Gx.arety.toString(); - if (Gx.iabsc === 2) { - mx.message(Mx, "1/Y = " + ls); - } else { - //if (Gx.xlab === 4) { - // TODO - //} - mx.message(Mx, "Y = " + ls); +/** + * @memberOf sigplot + * @private + */ +function sigplot_show_timecode(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + if (Gx.lyr.length > 0) { + //var hcb = Gx.HCB[Gx.lyr[0].hcb]; + var hcb = Gx.lyr[0].hcb; // mmm-TODO-needs investigation + if (hcb) { + if ( + hcb["class"] === 1 && + (hcb.xunits === 1 || hcb.xunits === 4) + ) { + mx.message( + Mx, + "Time = " + m.sec2tod(hcb.timecode + Gx.retx), + true + ); + } else if ( + hcb["class"] === 2 && + (hcb.yunits === 1 || hcb.yunits === 4) + ) { + mx.message( + Mx, + "Time = " + m.sec2tod(hcb.timecode + Gx.rety), + true + ); + } else { + mx.message(Mx, "Time = UNK"); + } } } +} - /** - * @memberOf sigplot - * @private - */ - function sigplot_show_z(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; +/** + * @memberOf sigplot + * @private + */ +function sigplot_show_y(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + var ls = Gx.arety.toString(); + if (Gx.iabsc === 2) { + mx.message(Mx, "1/Y = " + ls); + } else { + //if (Gx.xlab === 4) { + // TODO + //} + mx.message(Mx, "Y = " + ls); + } +} - if (Gx.zmin && Gx.zmax) { // at least one layer has a z dimension - var msg = ""; - if (Gx.lyr.length === 1) { - var msg = "Z = " + Gx.lyr[0].get_z(Gx.retx, Gx.rety).toString(); - } else { - var msg = "TODO"; // TODO we need to think of what we want to display here - } - mx.message(Mx, msg); +/** + * @memberOf sigplot + * @private + */ +function sigplot_show_z(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + if (Gx.zmin && Gx.zmax) { + // at least one layer has a z dimension + var msg = ""; + if (Gx.lyr.length === 1) { + var msg = "Z = " + Gx.lyr[0].get_z(Gx.retx, Gx.rety).toString(); + } else { + var msg = "TODO"; // TODO we need to think of what we want to display here } + mx.message(Mx, msg); } +} - /** - * Constructs a menu for updating the pan scale of the plot. - * - * @param plot - * The plot to work with. - * @param command - * The scroll direction to use. Either "XPAN" or "YPAN" are - * acceptable. - * @private - */ - function sigplot_scrollScaleMenu(plot, command) { - var Mx = plot._Mx; +/** + * Constructs a menu for updating the pan scale of the plot. + * + * @param plot + * The plot to work with. + * @param command + * The scroll direction to use. Either "XPAN" or "YPAN" are + * acceptable. + * @private + */ +function sigplot_scrollScaleMenu(plot, command) { + var Mx = plot._Mx; - mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); + mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); - mx.menu(Mx, { - title: "SCROLLBAR", - refresh: function() { - plot.refresh(); - }, - finalize: function() { - mx.addEventListener(Mx, "mousedown", - plot.onmousedown, false); - plot.refresh(); - }, - items: [{ + mx.menu(Mx, { + title: "SCROLLBAR", + refresh: function () { + plot.refresh(); + }, + finalize: function () { + mx.addEventListener(Mx, "mousedown", plot.onmousedown, false); + plot.refresh(); + }, + items: [ + { text: "Expand Range", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_EXPAND, command); - } - }, { + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_EXPAND, + command + ); + }, + }, + { text: "Shrink Range", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_SHRINK, command); - } - }, { + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_SHRINK, + command + ); + }, + }, + { text: "Expand Full", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_FULL, command); - } - }] - }); - } - - /** - * @memberOf sigplot - * @private - */ - function sigplot_mainmenu(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; - - // show mainmenu - // - - mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); + handler: function () { + middleClickScrollMenuAction(plot, mx.SB_FULL, command); + }, + }, + ], + }); +} - // Sub-menus - var CONTROLS_MENU = { - text: "Cntrls...", - menu: { - title: "CONTROLS OPTIONS", - items: [{ +/** + * @memberOf sigplot + * @private + */ +function sigplot_mainmenu(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + // show mainmenu + // + + mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); + + // Sub-menus + var CONTROLS_MENU = { + text: "Cntrls...", + menu: { + title: "CONTROLS OPTIONS", + items: [ + { text: "Continuous (Disabled)", checked: Gx.cntrls === -2, - handler: function() { + handler: function () { plot.change_settings({ - xcnt: -2 + xcnt: -2, }); - } - }, { + }, + }, + { text: "LM Click (Disabled)", checked: Gx.cntrls === -1, - handler: function() { + handler: function () { plot.change_settings({ - xcnt: -1 + xcnt: -1, }); - } - }, { + }, + }, + { text: "Off", checked: Gx.cntrls === 0, - handler: function() { + handler: function () { plot.change_settings({ - xcnt: 0 + xcnt: 0, }); - } - }, { + }, + }, + { text: "LM Click", checked: Gx.cntrls === 1, - handler: function() { + handler: function () { plot.change_settings({ - xcnt: 1 + xcnt: 1, }); - } - }, { + }, + }, + { text: "Continuous", checked: Gx.cntrls === 2, - handler: function() { + handler: function () { plot.change_settings({ - xcnt: 2 + xcnt: 2, }); - } - }] - } - }; + }, + }, + ], + }, + }; - var CXMODE_MENU = { - text: "CX Mode...", - menu: { - title: "COMPLEX MODE", - items: [{ + var CXMODE_MENU = { + text: "CX Mode...", + menu: { + title: "COMPLEX MODE", + items: [ + { text: "Magnitude", checked: Gx.cmode === 1, - handler: function() { + handler: function () { plot.change_settings({ - cmode: 1 + cmode: 1, }); - } - }, { + }, + }, + { text: "Phase", checked: Gx.cmode === 2, - handler: function() { + handler: function () { plot.change_settings({ - cmode: 2 + cmode: 2, }); - } - }, { + }, + }, + { text: "Real", checked: Gx.cmode === 3, - handler: function() { + handler: function () { plot.change_settings({ - cmode: 3 + cmode: 3, }); - } - }, { + }, + }, + { text: "Imaginary", checked: Gx.cmode === 4, - handler: function() { + handler: function () { plot.change_settings({ - cmode: 4 + cmode: 4, }); - } - }, { + }, + }, + { text: "IR: Imag/Real", checked: Gx.cmode === 5, - handler: function() { + handler: function () { plot.change_settings({ - cmode: 5 + cmode: 5, }); - } - }, { + }, + }, + { text: "10*Log10", checked: Gx.cmode === 6, - handler: function() { + handler: function () { plot.change_settings({ - cmode: 6 + cmode: 6, }); - } - }, { + }, + }, + { text: "20*Log10", checked: Gx.cmode === 7, - handler: function() { + handler: function () { plot.change_settings({ - cmode: 7 + cmode: 7, }); - } - }] - } - }; + }, + }, + ], + }, + }; - var SCALING_MENU = { - text: "Scaling...", - menu: { - title: "SCALING", - items: [{ + var SCALING_MENU = { + text: "Scaling...", + menu: { + title: "SCALING", + items: [ + { text: "Y Axis", - style: "separator" - }, { + style: "separator", + }, + { text: "Parameters...", - checked: (Gx.autoy === 0), - handler: function() { + checked: Gx.autoy === 0, + handler: function () { Gx.autoy = 0; - var nextPrompt = function() { + var nextPrompt = function () { setupPrompt( plot, "Y Axis Max:", mx.floatValidator, - function(finalValue) { - if (parseFloat(finalValue) !== Mx.stk[Mx.level].ymax) { + function (finalValue) { + if ( + parseFloat(finalValue) !== + Mx.stk[Mx.level].ymax + ) { // Only update if different // value if (finalValue === "") { @@ -4485,70 +4882,91 @@ plot, Mx.stk[Mx.level].ymin, parseFloat(finalValue), - "Y"); + "Y" + ); } else { plot.refresh(); } - }, Mx.stk[Mx.level].ymax, - undefined, undefined, undefined); + }, + Mx.stk[Mx.level].ymax, + undefined, + undefined, + undefined + ); }; setupPrompt( plot, "Y Axis Min:", mx.floatValidator, - function(finalValue) { - if (parseFloat(finalValue) !== Mx.stk[Mx.level].ymin) { + function (finalValue) { + if ( + parseFloat(finalValue) !== + Mx.stk[Mx.level].ymin + ) { // Only update if different // value if (finalValue === "") { finalValue = 0; } - updateViewbox(plot, + updateViewbox( + plot, parseFloat(finalValue), Mx.stk[Mx.level].ymax, - "Y"); + "Y" + ); } else { plot.refresh(); } - - }, Mx.stk[Mx.level].ymin, undefined, - undefined, nextPrompt); - } - }, { + }, + Mx.stk[Mx.level].ymin, + undefined, + undefined, + nextPrompt + ); + }, + }, + { text: "Min Auto", - checked: (Gx.autoy === 1), - handler: function() { + checked: Gx.autoy === 1, + handler: function () { Gx.autoy = 1; - } - }, { + }, + }, + { text: "Max Auto", - checked: (Gx.autoy === 2), - handler: function() { + checked: Gx.autoy === 2, + handler: function () { Gx.autoy = 2; - } - }, { + }, + }, + { text: "Full Auto", - checked: (Gx.autoy === 3), - handler: function() { + checked: Gx.autoy === 3, + handler: function () { Gx.autoy = 3; - } - }, { + }, + }, + { text: "X Axis", - style: "separator" - }, { + style: "separator", + }, + { text: "Parameters...", - checked: (Gx.autox === 0), - handler: function() { + checked: Gx.autox === 0, + handler: function () { Gx.autox = 0; - var nextPrompt = function() { + var nextPrompt = function () { setupPrompt( plot, "X Axis Max:", mx.floatValidator, - function(finalValue) { - if (parseFloat(finalValue) !== Mx.stk[Mx.level].xmax) { + function (finalValue) { + if ( + parseFloat(finalValue) !== + Mx.stk[Mx.level].xmax + ) { // Only update if different // value if (finalValue === "") { @@ -4558,69 +4976,89 @@ plot, Mx.stk[Mx.level].xmin, parseFloat(finalValue), - "X"); + "X" + ); } else { plot.refresh(); } - }, Mx.stk[Mx.level].xmax, - undefined, undefined, undefined); + }, + Mx.stk[Mx.level].xmax, + undefined, + undefined, + undefined + ); }; setupPrompt( plot, "X Axis Min:", mx.floatValidator, - function(finalValue) { - if (parseFloat(finalValue) !== Mx.stk[Mx.level].xmin) { + function (finalValue) { + if ( + parseFloat(finalValue) !== + Mx.stk[Mx.level].xmin + ) { // Only update if different // value if (finalValue === "") { finalValue = 0; } - updateViewbox(plot, + updateViewbox( + plot, parseFloat(finalValue), Mx.stk[Mx.level].xmax, - "X"); + "X" + ); } else { plot.refresh(); } - }, Mx.stk[Mx.level].xmin, undefined, - undefined, nextPrompt); - } - }, { + }, + Mx.stk[Mx.level].xmin, + undefined, + undefined, + nextPrompt + ); + }, + }, + { text: "Min Auto", - checked: (Gx.autox === 1), - handler: function() { + checked: Gx.autox === 1, + handler: function () { Gx.autox = 1; - } - }, { + }, + }, + { text: "Max Auto", - checked: (Gx.autox === 2), - handler: function() { + checked: Gx.autox === 2, + handler: function () { Gx.autox = 2; - } - }, { + }, + }, + { text: "Full Auto", - checked: (Gx.autox === 3), - handler: function() { + checked: Gx.autox === 3, + handler: function () { Gx.autox = 3; - } - }, { + }, + }, + { text: "Z Axis", - style: "separator" - }, { + style: "separator", + }, + { text: "Parameters...", - checked: (Gx.autoz === 0), - handler: function() { + checked: Gx.autoz === 0, + handler: function () { Gx.autoz = 0; - var nextPrompt = function() { + var nextPrompt = function () { setupPrompt( plot, "Z Axis Max:", mx.floatValidator, - function(finalValue) { - var floatFinalValue = parseFloat(finalValue); + function (finalValue) { + var floatFinalValue = + parseFloat(finalValue); if (floatFinalValue !== Gx.zmax) { // Only update if different // value @@ -4628,341 +5066,417 @@ floatFinalValue = 0; } plot.change_settings({ - zmax: floatFinalValue + zmax: floatFinalValue, }); } - }, Gx.zmax, - undefined, undefined, undefined); + }, + Gx.zmax, + undefined, + undefined, + undefined + ); }; setupPrompt( plot, "Z Axis Min:", mx.floatValidator, - function(finalValue) { - var floatFinalValue = parseFloat(finalValue); + function (finalValue) { + var floatFinalValue = + parseFloat(finalValue); if (floatFinalValue !== Gx.zmin) { if (finalValue === "") { floatFinalValue = 0; } plot.change_settings({ - zmin: floatFinalValue + zmin: floatFinalValue, }); } - }, Gx.zmin, undefined, - undefined, nextPrompt); - } - }, { + }, + Gx.zmin, + undefined, + undefined, + nextPrompt + ); + }, + }, + { text: "Min Auto", - checked: (Gx.autoz === 1), - handler: function() { + checked: Gx.autoz === 1, + handler: function () { plot.change_settings({ - autoz: 1 + autoz: 1, }); - } - }, { + }, + }, + { text: "Max Auto", - checked: (Gx.autoz === 2), - handler: function() { + checked: Gx.autoz === 2, + handler: function () { plot.change_settings({ - autoz: 2 + autoz: 2, }); - } - }, { + }, + }, + { text: "Full Auto", - checked: (Gx.autoz === 3), - handler: function() { + checked: Gx.autoz === 3, + handler: function () { plot.change_settings({ - autoz: 3 + autoz: 3, }); - } - }] - } - }; + }, + }, + ], + }, + }; - var GRID_MENU = { - text: "Grid", - handler: function() { - plot.change_settings({ - grid: !Gx.grid - }); - } - }; + var GRID_MENU = { + text: "Grid", + handler: function () { + plot.change_settings({ + grid: !Gx.grid, + }); + }, + }; - var SETTINGS_MENU = { - text: "Settings...", - menu: { - title: "SETTINGS", - items: [{ + var SETTINGS_MENU = { + text: "Settings...", + menu: { + title: "SETTINGS", + items: [ + { text: "ALL Mode", checked: Gx.all, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - all: !Gx.all + all: !Gx.all, }); - } - }, { + }, + }, + { text: "Controls...", menu: { title: "CONTROLS OPTIONS", - items: [{ - text: "Continuous (Disabled)", - checked: Gx.cntrls === -2, - handler: function() { - plot.change_settings({ - xcnt: -2 - }); - } - }, { - text: "LM Click (Disabled)", - checked: Gx.cntrls === -1, - handler: function() { - plot.change_settings({ - xcnt: -1 - }); - } - }, { - text: "Off", - checked: Gx.cntrls === 0, - handler: function() { - plot.change_settings({ - xcnt: 0 - }); - } - }, { - text: "LM Click", - checked: Gx.cntrls === 1, - handler: function() { - plot.change_settings({ - xcnt: 1 - }); - } - }, { - text: "Continuous", - checked: Gx.cntrls === 2, - handler: function() { - plot.change_settings({ - xcnt: 2 - }); - } - }] - } - }, { + items: [ + { + text: "Continuous (Disabled)", + checked: Gx.cntrls === -2, + handler: function () { + plot.change_settings({ + xcnt: -2, + }); + }, + }, + { + text: "LM Click (Disabled)", + checked: Gx.cntrls === -1, + handler: function () { + plot.change_settings({ + xcnt: -1, + }); + }, + }, + { + text: "Off", + checked: Gx.cntrls === 0, + handler: function () { + plot.change_settings({ + xcnt: 0, + }); + }, + }, + { + text: "LM Click", + checked: Gx.cntrls === 1, + handler: function () { + plot.change_settings({ + xcnt: 1, + }); + }, + }, + { + text: "Continuous", + checked: Gx.cntrls === 2, + handler: function () { + plot.change_settings({ + xcnt: 2, + }); + }, + }, + ], + }, + }, + { text: "Mouse...", menu: { title: "MOUSE OPTIONS", - items: [{ - text: "LM Drag (Zoom)", - checked: Gx.default_rubberbox_action === "zoom", - handler: function() { - Gx.default_rubberbox_action = "zoom"; - } - }, { - text: "LM Drag (Select)", - checked: Gx.default_rubberbox_action === "select", - handler: function() { - Gx.default_rubberbox_action = "select"; - } - }, { - text: "LM Drag (Disabled)", - checked: Gx.default_rubberbox_action === null, - handler: function() { - Gx.default_rubberbox_action = null; - } - }, { - text: "RM Drag (Zoom)", - checked: Gx.default_rightclick_rubberbox_action === "zoom", - handler: function() { - Gx.default_rightclick_rubberbox_action = "zoom"; - } - }, { - text: "RM Drag (Select)", - checked: Gx.default_rightclick_rubberbox_action === "select", - handler: function() { - Gx.default_rightclick_rubberbox_action = "select"; - } - }, { - text: "RM Drag (Disabled)", - checked: Gx.default_rightclick_rubberbox_action === null, - handler: function() { - Gx.default_rightclick_rubberbox_action = null; - } - }, { - text: "Mode...", - menu: { - title: "MOUSE Mode", - items: [{ - text: "Box", - checked: Gx.default_rubberbox_mode === "box", - handler: function() { - Gx.default_rubberbox_mode = "box"; - } - - }, { - text: "Horizontal", - checked: Gx.default_rubberbox_mode === "horizontal", - handler: function() { - Gx.default_rubberbox_mode = "horizontal"; - } - }, { - text: "Vertical", - checked: Gx.default_rubberbox_mode === "vertical", - handler: function() { - Gx.default_rubberbox_mode = "vertical"; - } - }] - } - }, { - text: "CROSShairs...", - menu: { - title: "Crosshairs Mode", - items: [{ - text: "Off", - checked: !Gx.cross, - handler: function() { - Gx.cross = false; - } - - }, { - text: "On", - checked: Gx.cross === true, - handler: function() { - Gx.cross = true; - } - }, { - text: "Horizontal", - checked: Gx.cross === "horizontal", - handler: function() { - Gx.cross = "horizontal"; - } - }, { - text: "Vertical", - checked: Gx.cross === "vertical", - handler: function() { - Gx.cross = "vertical"; - } - }] - } - }, { - text: "Mousewheel Natural Mode", - checked: Gx.wheelscroll_mode_natural, - style: "checkbox", - handler: function() { - plot - .change_settings({ - wheelscroll_mode_natural: !Gx.wheelscroll_mode_natural + items: [ + { + text: "LM Drag (Zoom)", + checked: + Gx.default_rubberbox_action === "zoom", + handler: function () { + Gx.default_rubberbox_action = "zoom"; + }, + }, + { + text: "LM Drag (Select)", + checked: + Gx.default_rubberbox_action === + "select", + handler: function () { + Gx.default_rubberbox_action = "select"; + }, + }, + { + text: "LM Drag (Disabled)", + checked: + Gx.default_rubberbox_action === null, + handler: function () { + Gx.default_rubberbox_action = null; + }, + }, + { + text: "RM Drag (Zoom)", + checked: + Gx.default_rightclick_rubberbox_action === + "zoom", + handler: function () { + Gx.default_rightclick_rubberbox_action = + "zoom"; + }, + }, + { + text: "RM Drag (Select)", + checked: + Gx.default_rightclick_rubberbox_action === + "select", + handler: function () { + Gx.default_rightclick_rubberbox_action = + "select"; + }, + }, + { + text: "RM Drag (Disabled)", + checked: + Gx.default_rightclick_rubberbox_action === + null, + handler: function () { + Gx.default_rightclick_rubberbox_action = + null; + }, + }, + { + text: "Mode...", + menu: { + title: "MOUSE Mode", + items: [ + { + text: "Box", + checked: + Gx.default_rubberbox_mode === + "box", + handler: function () { + Gx.default_rubberbox_mode = + "box"; + }, + }, + { + text: "Horizontal", + checked: + Gx.default_rubberbox_mode === + "horizontal", + handler: function () { + Gx.default_rubberbox_mode = + "horizontal"; + }, + }, + { + text: "Vertical", + checked: + Gx.default_rubberbox_mode === + "vertical", + handler: function () { + Gx.default_rubberbox_mode = + "vertical"; + }, + }, + ], + }, + }, + { + text: "CROSShairs...", + menu: { + title: "Crosshairs Mode", + items: [ + { + text: "Off", + checked: !Gx.cross, + handler: function () { + Gx.cross = false; + }, + }, + { + text: "On", + checked: Gx.cross === true, + handler: function () { + Gx.cross = true; + }, + }, + { + text: "Horizontal", + checked: + Gx.cross === "horizontal", + handler: function () { + Gx.cross = "horizontal"; + }, + }, + { + text: "Vertical", + checked: + Gx.cross === "vertical", + handler: function () { + Gx.cross = "vertical"; + }, + }, + ], + }, + }, + { + text: "Mousewheel Natural Mode", + checked: Gx.wheelscroll_mode_natural, + style: "checkbox", + handler: function () { + plot.change_settings({ + wheelscroll_mode_natural: + !Gx.wheelscroll_mode_natural, }); - } - }] - } - }, { + }, + }, + ], + }, + }, + { text: "CROSShairs", checked: Gx.cross, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - cross: !Gx.cross + cross: !Gx.cross, }); - } - }, { + }, + }, + { text: "GRID", checked: Gx.grid, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - grid: !Gx.grid + grid: !Gx.grid, }); - } - }, { + }, + }, + { text: "INDEX Mode", checked: Gx.index, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - index: !Gx.index + index: !Gx.index, }); - } - }, { + }, + }, + { text: "LEGEND", checked: Gx.legend, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - legend: !Gx.legend + legend: !Gx.legend, }); - } - }, { + }, + }, + { text: "PAN Scrollbars", checked: Gx.pan, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - pan: !Gx.pan + pan: !Gx.pan, }); - } - }, { + }, + }, + { text: "PHase UNITS...", menu: { title: "PHASE UNITS", - items: [{ - text: "Radians", - checked: Gx.plab === 23, - handler: function() { - plot.change_settings({ - phunits: 'R' - }); - } - - }, { - text: "Degrees", - checked: Gx.plab === 24, - handler: function() { - plot.change_settings({ - phunits: 'D' - }); - } - }, { - text: "Cycles", - checked: Gx.plab === 25, - handler: function() { - plot.change_settings({ - phunits: 'C' - }); - } - }] - } - }, { + items: [ + { + text: "Radians", + checked: Gx.plab === 23, + handler: function () { + plot.change_settings({ + phunits: "R", + }); + }, + }, + { + text: "Degrees", + checked: Gx.plab === 24, + handler: function () { + plot.change_settings({ + phunits: "D", + }); + }, + }, + { + text: "Cycles", + checked: Gx.plab === 25, + handler: function () { + plot.change_settings({ + phunits: "C", + }); + }, + }, + ], + }, + }, + { text: "SPECS", checked: Gx.specs, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - specs: !Gx.specs + specs: !Gx.specs, }); - } - }, { + }, + }, + { text: "P-Cuts", checked: Gx.p_cuts, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - p_cuts: !Gx.p_cuts + p_cuts: !Gx.p_cuts, }); - } - }, { + }, + }, + { text: "Large Colorbar", checked: Gx.lg_colorbar, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - lg_colorbar: !Gx.lg_colorbar + lg_colorbar: !Gx.lg_colorbar, }); - } - }, { + }, + }, + { text: "XDIVisions...", - handler: function() { - var validator = function(value) { + handler: function () { + var validator = function (value) { var isValid = mx.intValidator(value); var maxXDIV = m.trunc(Mx.width / 2); // TODO // Make value an option on the plot? @@ -4972,7 +5486,10 @@ if (isValid.valid && value > maxXDIV) { return { valid: false, - reason: "Exceeds maximum number of divisions (" + maxXDIV + ")." + reason: + "Exceeds maximum number of divisions (" + + maxXDIV + + ").", }; } else { return isValid; @@ -4983,8 +5500,9 @@ plot, "X Divisions:", validator, - function(finalValue) { - if (parseFloat(finalValue) !== Gx.xdiv) { // Only + function (finalValue) { + if (parseFloat(finalValue) !== Gx.xdiv) { + // Only // update if different value if (finalValue === "") { finalValue = 1; @@ -4992,14 +5510,18 @@ Gx.xdiv = parseFloat(finalValue); } plot.refresh(); - - }, Gx.xdiv, undefined, undefined, - undefined); - } - }, { + }, + Gx.xdiv, + undefined, + undefined, + undefined + ); + }, + }, + { text: "XLABel...", - handler: function() { - var validator = function(value) { + handler: function () { + var validator = function (value) { console.log("The value is " + value); var isValid = mx.intValidator(value); return isValid; @@ -5009,8 +5531,9 @@ plot, "X Units:", validator, - function(finalValue) { - if (parseFloat(finalValue) !== Gx.xlab) { // Only + function (finalValue) { + if (parseFloat(finalValue) !== Gx.xlab) { + // Only // update if different value if (finalValue < 0) { finalValue = 0; @@ -5018,14 +5541,18 @@ Gx.xlab = parseFloat(finalValue); } plot.refresh(); - - }, Gx.xlab, undefined, undefined, - undefined); - } - }, { + }, + Gx.xlab, + undefined, + undefined, + undefined + ); + }, + }, + { text: "YDIVisions...", - handler: function() { - var validator = function(value) { + handler: function () { + var validator = function (value) { var isValid = mx.intValidator(value); var maxYDIV = m.trunc(Mx.height / 2); // TODO // Make value an option on the plot? @@ -5035,7 +5562,10 @@ if (isValid.valid && value > maxYDIV) { return { valid: false, - reason: "Exceeds maximum number of divisions (" + maxYDIV + ")." + reason: + "Exceeds maximum number of divisions (" + + maxYDIV + + ").", }; } else { return isValid; @@ -5046,7 +5576,7 @@ plot, "Y Divisions:", validator, - function(finalValue) { + function (finalValue) { if (parseFloat(finalValue) !== Gx.ydiv) { // Only update if different // value @@ -5056,23 +5586,28 @@ Gx.ydiv = parseFloat(finalValue); } plot.refresh(); - - }, Gx.ydiv, undefined, undefined, - undefined); - } - }, { + }, + Gx.ydiv, + undefined, + undefined, + undefined + ); + }, + }, + { text: "YINVersion", - checked: (Mx.origin === 4), + checked: Mx.origin === 4, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - yinv: (Mx.origin !== 4) + yinv: Mx.origin !== 4, }); - } - }, { + }, + }, + { text: "YLABel...", - handler: function() { - var validator = function(value) { + handler: function () { + var validator = function (value) { var isValid = mx.intValidator(value); return isValid; }; @@ -5081,8 +5616,9 @@ plot, "Y Units:", validator, - function(finalValue) { - if (parseFloat(finalValue) !== Gx.ylab) { // Only + function (finalValue) { + if (parseFloat(finalValue) !== Gx.ylab) { + // Only // update if different value if (finalValue < 0) { finalValue = 0; @@ -5090,78 +5626,87 @@ Gx.ylab = parseFloat(finalValue); } plot.refresh(); - - }, Gx.ylab, undefined, undefined, - undefined); - } - }, { + }, + Gx.ylab, + undefined, + undefined, + undefined + ); + }, + }, + { text: "X-axis", checked: Gx.show_x_axis, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - show_x_axis: !Gx.show_x_axis + show_x_axis: !Gx.show_x_axis, }); - } - }, { + }, + }, + { text: "Y-axis", checked: Gx.show_y_axis, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - show_y_axis: !Gx.show_y_axis + show_y_axis: !Gx.show_y_axis, }); - } - }, { + }, + }, + { text: "Readout", checked: Gx.show_readout, style: "checkbox", - handler: function() { + handler: function () { plot.change_settings({ - show_readout: !Gx.show_readout + show_readout: !Gx.show_readout, }); - } - }, { + }, + }, + { text: "Invert Colors", checked: Mx.xi, style: "checkbox", - handler: function() { + handler: function () { mx.invertbgfg(Mx); - } - }] - } - }; + }, + }, + ], + }, + }; - var COLORMAP_MENU = { - text: "Colormap...", - menu: { - title: "COLORMAP", - items: [] - } - }; + var COLORMAP_MENU = { + text: "Colormap...", + menu: { + title: "COLORMAP", + items: [], + }, + }; - var colormap_handler = function(item) { - plot.change_settings({ - cmap: this.cmap - }); - }; + var colormap_handler = function (item) { + plot.change_settings({ + cmap: this.cmap, + }); + }; - for (var xc = 0; xc < m.Mc.colormap.length; xc++) { - var menuitem = { - text: m.Mc.colormap[xc].name, - cmap: xc, - checked: (Gx.cmap === xc), - handler: colormap_handler - }; - COLORMAP_MENU.menu.items.push(menuitem); - } + for (var xc = 0; xc < m.Mc.colormap.length; xc++) { + var menuitem = { + text: m.Mc.colormap[xc].name, + cmap: xc, + checked: Gx.cmap === xc, + handler: colormap_handler, + }; + COLORMAP_MENU.menu.items.push(menuitem); + } - var traceoptionsmenu = function(index) { - return { - title: "TRACE OPTIONS", - items: [{ + var traceoptionsmenu = function (index) { + return { + title: "TRACE OPTIONS", + items: [ + { text: "Dashed...", - handler: function() { + handler: function () { // Figure out the current thickness var thk = 1; if (index !== undefined) { @@ -5173,7 +5718,9 @@ thk = Math.abs(plot._Gx.lyr[0].thick); for (var i = 0; i < Gx.lyr.length; i++) { - if (thk !== Math.abs(plot._Gx.lyr[i].thick)) { + if ( + thk !== Math.abs(plot._Gx.lyr[i].thick) + ) { thk = 1; break; } @@ -5183,156 +5730,271 @@ plot, "Line thickness:", mx.intValidator, - function(finalValue) { + function (finalValue) { if (index !== undefined) { plot._Gx.lyr[index].line = 3; - plot._Gx.lyr[index].thick = -1 * finalValue; + plot._Gx.lyr[index].thick = + -1 * finalValue; plot._Gx.lyr[index].symbol = 0; } else { - for (var ii = 0; ii < Gx.lyr.length; ii++) { + for ( + var ii = 0; + ii < Gx.lyr.length; + ii++ + ) { plot._Gx.lyr[ii].line = 3; - plot._Gx.lyr[ii].thick = -1 * finalValue; + plot._Gx.lyr[ii].thick = + -1 * finalValue; plot._Gx.lyr[ii].symbol = 0; } } - }, thk); - } - }, { + }, + thk + ); + }, + }, + { text: "Colors...", menu: { title: "COLORS", - items: [{ - text: "Retain Current" - }, { - text: "Red", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "red" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "red"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "red"; + items: [ + { + text: "Retain Current", + }, + { + text: "Red", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "red" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = "red"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = "red"; + } } - } - } - }, { - text: "Pink", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "pink" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "pink"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "pink"; + }, + }, + { + text: "Pink", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "pink" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = "pink"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = "pink"; + } } - } - } - }, { - text: "Hot Pink", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "#ff009e" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "#ff009e"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "#ff009e"; + }, + }, + { + text: "Hot Pink", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "#ff009e" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = + "#ff009e"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = + "#ff009e"; + } } - } - } - }, { - text: "Orange", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "orange" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "orange"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "orange"; + }, + }, + { + text: "Orange", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "orange" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = + "orange"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = + "orange"; + } } - } - } - }, { - text: "Yellow", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "yellow" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "yellow"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "yellow"; + }, + }, + { + text: "Yellow", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "yellow" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = + "yellow"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = + "yellow"; + } } - } - } - }, { - text: "Lime Green", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "#80f741" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "#80f741"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "#80f741"; + }, + }, + { + text: "Lime Green", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "#80f741" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = + "#80f741"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = + "#80f741"; + } } - } - } - }, { - text: "Green", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "green" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "green"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "green"; + }, + }, + { + text: "Green", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "green" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = "green"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = "green"; + } } - } - } - }, { - text: "Blue", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "blue" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "blue"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "blue"; + }, + }, + { + text: "Blue", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "blue" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = "blue"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = "blue"; + } } - } - } - }, { - text: "Purple", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "purple" : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].color = "purple"; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].color = "purple"; + }, + }, + { + text: "Purple", + checked: + index !== undefined + ? plot._Gx.lyr[index].color === + "purple" + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].color = + "purple"; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].color = + "purple"; + } } - } - } - }, { - text: "Custom Hexcode", - handler: function() { - setupPrompt( - plot, - "Color code (requires #):", - mx.hexValidator, - function(finalValue) { - if (index !== undefined) { - plot._Gx.lyr[index].color = finalValue; - } else { - for (var ii = 0; ii < Gx.lyr.length; index++) { - plot._Gx.lyr[ii].color = finalValue; + }, + }, + { + text: "Custom Hexcode", + handler: function () { + setupPrompt( + plot, + "Color code (requires #):", + mx.hexValidator, + function (finalValue) { + if (index !== undefined) { + plot._Gx.lyr[index].color = + finalValue; + } else { + for ( + var ii = 0; + ii < Gx.lyr.length; + index++ + ) { + plot._Gx.lyr[ii].color = + finalValue; + } } - } - }, undefined, undefined, undefined, undefined); - } - }] - } - }, { + }, + undefined, + undefined, + undefined, + undefined + ); + }, + }, + ], + }, + }, + { text: "Dots...", - handler: function() { + handler: function () { // Figure out the current thickness var radius = 3; if (index !== undefined) { @@ -5343,7 +6005,10 @@ } var i; for (i = 0; i < Gx.lyr.length; i++) { - if (radius !== Math.abs(plot._Gx.lyr[i].radius)) { + if ( + radius !== + Math.abs(plot._Gx.lyr[i].radius) + ) { radius = 3; break; } @@ -5353,7 +6018,7 @@ plot, "Radius/Shape:", mx.intValidator, - function(finalValue) { + function (finalValue) { var sym; var rad; if (finalValue < 0) { @@ -5378,11 +6043,14 @@ plot._Gx.lyr[i].symbol = sym; } } - }, radius); - } - }, { + }, + radius + ); + }, + }, + { text: "Radius...", - handler: function() { + handler: function () { // Figure out the current thickness var radius = 3; if (index !== undefined) { @@ -5392,7 +6060,10 @@ return; } for (var i = 0; i < Gx.lyr.length; i++) { - if (radius !== Math.abs(plot._Gx.lyr[i].radius)) { + if ( + radius !== + Math.abs(plot._Gx.lyr[i].radius) + ) { radius = 3; break; } @@ -5402,7 +6073,7 @@ plot, "Radius:", mx.intValidator, - function(finalValue) { + function (finalValue) { var sym; var rad; if (finalValue < 0) { @@ -5417,16 +6088,23 @@ plot._Gx.lyr[index].line = 0; plot._Gx.lyr[index].radius = rad; } else { - for (var i = 0; i < Gx.lyr.length; i++) { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { plot._Gx.lyr[i].line = 0; plot._Gx.lyr[i].radius = rad; } } - }, radius); - } - }, { + }, + radius + ); + }, + }, + { text: "Solid...", - handler: function() { + handler: function () { // Figure out the current thickness var thk = 1; if (index !== undefined) { @@ -5439,7 +6117,9 @@ thk = Math.abs(plot._Gx.lyr[0].thick); var i; for (i = 0; i < Gx.lyr.length; i++) { - if (thk !== Math.abs(plot._Gx.lyr[i].thick)) { + if ( + thk !== Math.abs(plot._Gx.lyr[i].thick) + ) { thk = 1; break; } @@ -5449,7 +6129,7 @@ plot, "Line thickness:", mx.intValidator, - function(finalValue) { + function (finalValue) { if (index !== undefined) { plot._Gx.lyr[index].line = 3; plot._Gx.lyr[index].thick = finalValue; @@ -5462,200 +6142,311 @@ plot._Gx.lyr[i].symbol = 0; } } - }, thk); - } - }, { + }, + thk + ); + }, + }, + { text: "Toggle", - style: (index !== undefined) ? "checkbox" : undefined, - checked: (index !== undefined) ? plot._Gx.lyr[index].display : undefined, - handler: function() { + style: index !== undefined ? "checkbox" : undefined, + checked: + index !== undefined + ? plot._Gx.lyr[index].display + : undefined, + handler: function () { if (index !== undefined) { - plot._Gx.lyr[index].display = !plot._Gx.lyr[index].display; + plot._Gx.lyr[index].display = + !plot._Gx.lyr[index].display; } else { for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].display = !plot._Gx.lyr[i].display; + plot._Gx.lyr[i].display = + !plot._Gx.lyr[i].display; } } - } - }, { + }, + }, + { text: "Symbols...", menu: { title: "SYMBOLS", - items: [{ - text: "Retain Current" - }, { - text: "None", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 0 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 0; - plot._Gx.lyr[index].symbol = 0; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 0; - plot._Gx.lyr[i].symbol = 0; + items: [ + { + text: "Retain Current", + }, + { + text: "None", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 0 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 0; + plot._Gx.lyr[index].symbol = 0; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 0; + plot._Gx.lyr[i].symbol = 0; + } } - } - } - }, { - text: "Pixels", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 1 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 1; - plot._Gx.lyr[index].symbol = 1; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 1; - plot._Gx.lyr[i].symbol = 1; + }, + }, + { + text: "Pixels", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 1 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 1; + plot._Gx.lyr[index].symbol = 1; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 1; + plot._Gx.lyr[i].symbol = 1; + } } - } - } - }, { - text: "Circles", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 2 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 4; - plot._Gx.lyr[index].symbol = 2; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 4; - plot._Gx.lyr[i].symbol = 2; + }, + }, + { + text: "Circles", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 2 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 4; + plot._Gx.lyr[index].symbol = 2; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 4; + plot._Gx.lyr[i].symbol = 2; + } } - } - } - }, { - text: "Squares", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 3 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 4; - plot._Gx.lyr[index].symbol = 3; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 4; - plot._Gx.lyr[i].symbol = 3; + }, + }, + { + text: "Squares", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 3 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 4; + plot._Gx.lyr[index].symbol = 3; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 4; + plot._Gx.lyr[i].symbol = 3; + } } - } - } - }, { - text: "Plusses", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 4 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 4; - plot._Gx.lyr[index].symbol = 4; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 4; - plot._Gx.lyr[i].symbol = 4; + }, + }, + { + text: "Plusses", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 4 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 4; + plot._Gx.lyr[index].symbol = 4; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 4; + plot._Gx.lyr[i].symbol = 4; + } } - } - } - }, { - text: "X's", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 5 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 4; - plot._Gx.lyr[index].symbol = 5; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 4; - plot._Gx.lyr[i].symbol = 5; + }, + }, + { + text: "X's", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 5 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 4; + plot._Gx.lyr[index].symbol = 5; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 4; + plot._Gx.lyr[i].symbol = 5; + } } - } - } - }, { - text: "Triangles", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 6 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 6; - plot._Gx.lyr[index].symbol = 6; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 6; - plot._Gx.lyr[i].symbol = 6; + }, + }, + { + text: "Triangles", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 6 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 6; + plot._Gx.lyr[index].symbol = 6; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 6; + plot._Gx.lyr[i].symbol = 6; + } } - } - } - }, { - text: "Downward Triangles", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 7 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].radius = 6; - plot._Gx.lyr[index].symbol = 7; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].radius = 6; - plot._Gx.lyr[i].symbol = 7; + }, + }, + { + text: "Downward Triangles", + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 7 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].radius = 6; + plot._Gx.lyr[index].symbol = 7; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].radius = 6; + plot._Gx.lyr[i].symbol = 7; + } } - } - } - }] - } - }, { + }, + }, + ], + }, + }, + { text: "Line Type...", menu: { title: "LINE TYPE", - items: [{ - text: "Retain Current" - }, { - text: "None", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 0 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].line = 0; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].line = 0; + items: [ + { + text: "Retain Current", + }, + { + text: "None", + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 0 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].line = 0; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].line = 0; + } } - } - } - }, { - text: "Verticals", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 1 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].line = 1; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].line = 1; + }, + }, + { + text: "Verticals", + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 1 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].line = 1; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].line = 1; + } } - } - } - }, { - text: "Horizontals", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 2 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].line = 2; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].line = 2; + }, + }, + { + text: "Horizontals", + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 2 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].line = 2; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].line = 2; + } } - } - } - }, { - text: "Connecting", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 3 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].line = 3; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].line = 3; + }, + }, + { + text: "Connecting", + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 3 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].line = 3; + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].line = 3; + } } - } - } - }] - } - }, { + }, + }, + ], + }, + }, + { text: "Thickness...", - handler: function() { + handler: function () { var thickness = 1; if (index !== undefined) { thickness = plot._Gx.lyr[index].thick; @@ -5664,7 +6455,7 @@ plot, "Thickness", mx.intValidator, - function(finalValue) { + function (finalValue) { if (finalValue === "") { finalValue = 1; } @@ -5673,16 +6464,25 @@ if (index !== undefined) { plot._Gx.lyr[index].thick = finalValue; } else { - for (var i = 0; i < Gx.lyr.length; i++) { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { plot._Gx.lyr[i].thick = finalValue; } } - }, thickness, undefined, - undefined, undefined); - } - }, { + }, + thickness, + undefined, + undefined, + undefined + ); + }, + }, + { text: "Opacity...", - handler: function() { + handler: function () { var opacity = 1.0; if (index !== undefined) { opacity = plot._Gx.lyr[index].opacity; @@ -5691,7 +6491,7 @@ plot, "Opacity:", mx.floatValidator, - function(finalValue) { + function (finalValue) { if (finalValue === "") { finalValue = 1.0; } @@ -5699,423 +6499,576 @@ finalValue = Math.min(1, finalValue); if (index !== undefined) { - plot._Gx.lyr[index].opacity = finalValue; + plot._Gx.lyr[index].opacity = + finalValue; } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].opacity = finalValue; + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[i].opacity = + finalValue; } } - }, opacity, undefined, - undefined, undefined); - } - }, { + }, + opacity, + undefined, + undefined, + undefined + ); + }, + }, + { text: "XCompression...", menu: { title: "XCOMPRESSION", - items: [{ - text: "Retain Current" - }, { - text: "Smoothing", - checked: (index !== undefined) ? plot._Gx.lyr[index].xcompression === 0 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].change_settings({ - xcmp: 0 - }); - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[index].change_settings({ - xcmp: 0 - }); + items: [ + { + text: "Retain Current", + }, + { + text: "Smoothing", + checked: + index !== undefined + ? plot._Gx.lyr[index] + .xcompression === 0 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].change_settings( + { + xcmp: 0, + } + ); + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[ + index + ].change_settings({ + xcmp: 0, + }); + } } - } - } - }, { - text: "Average", - checked: (index !== undefined) ? plot._Gx.lyr[index].xcompression === 1 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].change_settings({ - xcmp: 1 - }); - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[index].change_settings({ - xcmp: 1 - }); + }, + }, + { + text: "Average", + checked: + index !== undefined + ? plot._Gx.lyr[index] + .xcompression === 1 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].change_settings( + { + xcmp: 1, + } + ); + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[ + index + ].change_settings({ + xcmp: 1, + }); + } } - } - } - }, { - text: "Minimum", - checked: (index !== undefined) ? plot._Gx.lyr[index].xcompression === 2 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].change_settings({ - xcmp: 2 - }); - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[index].change_settings({ - xcmp: 2 - }); + }, + }, + { + text: "Minimum", + checked: + index !== undefined + ? plot._Gx.lyr[index] + .xcompression === 2 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].change_settings( + { + xcmp: 2, + } + ); + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[ + index + ].change_settings({ + xcmp: 2, + }); + } } - } - } - }, { - text: "Maximum", - checked: (index !== undefined) ? plot._Gx.lyr[index].xcompression === 3 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].change_settings({ - xcmp: 3 - }); - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[index].change_settings({ - xcmp: 3 - }); + }, + }, + { + text: "Maximum", + checked: + index !== undefined + ? plot._Gx.lyr[index] + .xcompression === 3 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].change_settings( + { + xcmp: 3, + } + ); + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[ + index + ].change_settings({ + xcmp: 3, + }); + } } - } - } - }, { - text: "First", - checked: (index !== undefined) ? plot._Gx.lyr[index].xcompression === 4 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].change_settings({ - xcmp: 4 - }); - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[index].change_settings({ - xcmp: 4 - }); + }, + }, + { + text: "First", + checked: + index !== undefined + ? plot._Gx.lyr[index] + .xcompression === 4 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].change_settings( + { + xcmp: 4, + } + ); + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[ + index + ].change_settings({ + xcmp: 4, + }); + } } - } - } - }, { - text: "Max (Abs)", - checked: (index !== undefined) ? plot._Gx.lyr[index].xcompression === 5 : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].change_settings({ - xcmp: 5 - }); - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[index].change_settings({ - xcmp: 5 - }); + }, + }, + { + text: "Max (Abs)", + checked: + index !== undefined + ? plot._Gx.lyr[index] + .xcompression === 5 + : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].change_settings( + { + xcmp: 5, + } + ); + } else { + for ( + var i = 0; + i < Gx.lyr.length; + i++ + ) { + plot._Gx.lyr[ + index + ].change_settings({ + xcmp: 5, + }); + } } - } - } - }] - } - }] - }; + }, + }, + ], + }, + }, + ], }; + }; - var VIEW_MENU = { - text: "View...", - menu: { - title: "VIEW", - items: [{ + var VIEW_MENU = { + text: "View...", + menu: { + title: "VIEW", + items: [ + { text: "Reset", - handler: function() { + handler: function () { plot.unzoom(); - } - }, { + }, + }, + { text: "Y Axis", - style: "separator" - }, { + style: "separator", + }, + { text: "Expand Range", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_EXPAND, "YPAN"); - } - }, { + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_EXPAND, + "YPAN" + ); + }, + }, + { text: "Shrink Range", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_SHRINK, "YPAN"); - } - }, { + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_SHRINK, + "YPAN" + ); + }, + }, + { text: "Expand Full", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_FULL, "YPAN"); - } - }, { + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_FULL, + "YPAN" + ); + }, + }, + { text: "X Axis", - style: "separator" - }, { + style: "separator", + }, + { text: "Expand Range", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_EXPAND, "XPAN"); - } - }, { + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_EXPAND, + "XPAN" + ); + }, + }, + { text: "Shrink Range", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_SHRINK, "XPAN"); - } - }, { + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_SHRINK, + "XPAN" + ); + }, + }, + { text: "Expand Full", - handler: function() { - middleClickScrollMenuAction(plot, - mx.SB_FULL, "XPAN"); - } - }] - } - }; + handler: function () { + middleClickScrollMenuAction( + plot, + mx.SB_FULL, + "XPAN" + ); + }, + }, + ], + }, + }; - var TRACES_MENU = { - text: "Traces...", - menu: function() { - var Gx = plot._Gx; - var tracemenu = { - title: "TRACE", - items: [] - }; - // Add the ALL option + var TRACES_MENU = { + text: "Traces...", + menu: function () { + var Gx = plot._Gx; + var tracemenu = { + title: "TRACE", + items: [], + }; + // Add the ALL option + tracemenu.items.push({ + text: "All", + menu: traceoptionsmenu(), + }); + // Add all the active layers + for (var i = 0; i < Gx.lyr.length; i++) { tracemenu.items.push({ - text: "All", - menu: traceoptionsmenu() + text: Gx.lyr[i].name, + menu: traceoptionsmenu(i), }); - // Add all the active layers - for (var i = 0; i < Gx.lyr.length; i++) { - tracemenu.items.push({ - text: Gx.lyr[i].name, - menu: traceoptionsmenu(i) - }); - } - return tracemenu; } - }; + return tracemenu; + }, + }; + + var FILES_MENU = { + text: "Files...", + menu: { + title: "FILES OPTIONS", + items: [ + // Overlay File... is disabled + // because it's actually very + // difficult to bring up a + // a file upload browse dialog + /* + * { text: "Overlay File...", handler: function() { + * plot.change_settings( {phunits: 'R'} ); } }, + */ + { + text: "Deoverlay File...", + menu: function () { + var Gx = plot._Gx; + var deoverlaymenu = { + title: "DEOVERLAY", + items: [], + }; + deoverlaymenu.items.push({ + text: "Deoverlay All", + handler: function () { + plot.deoverlay(); + }, + }); + /* jshint -W083 */ + /* TODO figure out how to not create functions within a loop */ + for (var i = 0; i < Gx.lyr.length; i++) { + var handler = (function (index) { + return function () { + plot.deoverlay(index); + }; + })(i); - var FILES_MENU = { - text: "Files...", - menu: { - title: "FILES OPTIONS", - items: [ - // Overlay File... is disabled - // because it's actually very - // difficult to bring up a - // a file upload browse dialog - /* - * { text: "Overlay File...", handler: function() { - * plot.change_settings( {phunits: 'R'} ); } }, - */ - { - text: "Deoverlay File...", - menu: function() { - var Gx = plot._Gx; - var deoverlaymenu = { - title: "DEOVERLAY", - items: [] - }; deoverlaymenu.items.push({ - text: "Deoverlay All", - handler: function() { - plot.deoverlay(); - } + text: Gx.lyr[i].name, + handler: handler, }); - /* jshint -W083 */ - /* TODO figure out how to not create functions within a loop */ - for (var i = 0; i < Gx.lyr.length; i++) { - var handler = (function(index) { - return function() { - plot.deoverlay(index); - }; - }(i)); - - deoverlaymenu.items.push({ - text: Gx.lyr[i].name, - handler: handler - }); - } - /* jshint +W083 */ - return deoverlaymenu; } - } - ] - } - }; + /* jshint +W083 */ + return deoverlaymenu; + }, + }, + ], + }, + }; - var PLUGINS_MENU = { - text: "Plugins...", - menu: { - title: "PLUGINS", - items: (function() { // Immediately - // Invoked - // Function - var result = []; - for (var i = 0; i < Gx.plugins.length; i++) { - var plugin = Gx.plugins[i]; - if (plugin.impl.menu) { - if (typeof plugin.impl.menu === 'function') { - result.push(plugin.impl.menu()); - } else { - result.push(plugin.impl.menu); - } + var PLUGINS_MENU = { + text: "Plugins...", + menu: { + title: "PLUGINS", + items: (function () { + // Immediately + // Invoked + // Function + var result = []; + for (var i = 0; i < Gx.plugins.length; i++) { + var plugin = Gx.plugins[i]; + if (plugin.impl.menu) { + if (typeof plugin.impl.menu === "function") { + result.push(plugin.impl.menu()); + } else { + result.push(plugin.impl.menu); } } - return result; - }()) - } - }; + } + return result; + })(), + }, + }; - var SAVE_MENU = { - text: "Save as...", - menu: { - title: "SAVE AS", - items: [{ + var SAVE_MENU = { + text: "Save as...", + menu: { + title: "SAVE AS", + items: [ + { text: "PNG", - handler: function() { - var img = plot._Mx.active_canvas.toDataURL("image/png"); + handler: function () { + var img = + plot._Mx.active_canvas.toDataURL("image/png"); var link = document.createElement("a"); link.href = img; - link.download = "SigPlot." + (new Date()).getTime() + ".png"; + link.download = + "SigPlot." + new Date().getTime() + ".png"; link.display = "none"; document.body.appendChild(link); link.click(); document.body.removeChild(link); - } - }, { + }, + }, + { text: "JPG", - handler: function() { - var img = plot._Mx.active_canvas.toDataURL("image/jpg"); + handler: function () { + var img = + plot._Mx.active_canvas.toDataURL("image/jpg"); var link = document.createElement("a"); link.href = img; - link.download = "SigPlot." + (new Date()).getTime() + ".jpg"; + link.download = + "SigPlot." + new Date().getTime() + ".jpg"; link.display = "none"; document.body.appendChild(link); link.click(); document.body.removeChild(link); - } - }, { + }, + }, + { text: "SVG", - handler: function() { - var img = plot._Mx.active_canvas.toDataURL("image/svg"); + handler: function () { + var img = + plot._Mx.active_canvas.toDataURL("image/svg"); var link = document.createElement("a"); link.href = img; - link.download = "SigPlot." + (new Date()).getTime() + ".svg"; + link.download = + "SigPlot." + new Date().getTime() + ".svg"; link.display = "none"; document.body.appendChild(link); link.click(); document.body.removeChild(link); - } - }] - } - }; - - var REFRESH_ITEM = { - text: "Refresh" - // no handler, just let the finalizer deal with it - }; - - var KEYPRESSINFO_ITEM = { - text: "Keypress Info", - handler: function() { - mx.message(Mx, KEYPRESS_HELP); - } - }; + }, + }, + ], + }, + }; - var EXIT_ITEM = { - text: "Exit", - handler: function() { - var evt = document.createEvent('Event'); - evt.initEvent('sigplotexit', true, true); - mx.dispatchEvent(Mx, evt); - } - }; + var REFRESH_ITEM = { + text: "Refresh", + // no handler, just let the finalizer deal with it + }; - // Main Menu - var MAINMENU = { - title: "SIG-PLOT", - finalize: function() { - if (!Mx.prompt) { - // A prompt may have been - // created by a menu handler - // - let it deal with - // eventListener re-setting - mx.addEventListener(Mx, "mousedown", plot.onmousedown, - false); - } - plot.refresh(); - }, - items: [REFRESH_ITEM, CONTROLS_MENU, CXMODE_MENU, SCALING_MENU, VIEW_MENU, - GRID_MENU, SETTINGS_MENU, COLORMAP_MENU, TRACES_MENU, FILES_MENU, - PLUGINS_MENU, KEYPRESSINFO_ITEM, SAVE_MENU, EXIT_ITEM - ] - }; + var KEYPRESSINFO_ITEM = { + text: "Keypress Info", + handler: function () { + mx.message(Mx, KEYPRESS_HELP); + }, + }; - mx.menu(Mx, MAINMENU); - } + var EXIT_ITEM = { + text: "Exit", + handler: function () { + var evt = document.createEvent("Event"); + evt.initEvent("sigplotexit", true, true); + mx.dispatchEvent(Mx, evt); + }, + }; - /** - * @memberOf sigplot - * @private - */ - function sigplot_legend_menu(plot, index) { - var Gx = plot._Gx; - var Mx = plot._Mx; + // Main Menu + var MAINMENU = { + title: "SIG-PLOT", + finalize: function () { + if (!Mx.prompt) { + // A prompt may have been + // created by a menu handler + // - let it deal with + // eventListener re-setting + mx.addEventListener( + Mx, + "mousedown", + plot.onmousedown, + false + ); + } + plot.refresh(); + }, + items: [ + REFRESH_ITEM, + CONTROLS_MENU, + CXMODE_MENU, + SCALING_MENU, + VIEW_MENU, + GRID_MENU, + SETTINGS_MENU, + COLORMAP_MENU, + TRACES_MENU, + FILES_MENU, + PLUGINS_MENU, + KEYPRESSINFO_ITEM, + SAVE_MENU, + EXIT_ITEM, + ], + }; - mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); + mx.menu(Mx, MAINMENU); +} - var DASHED = { - text: "Dashed...", - handler: function() { - // Figure out the current thickness - var thk = 1; - if (index !== undefined) { - thk = Math.abs(plot._Gx.lyr[index].thick); - } else { - if (Gx.lyr.length === 0) { - return; - } +/** + * @memberOf sigplot + * @private + */ +function sigplot_legend_menu(plot, index) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); + + var DASHED = { + text: "Dashed...", + handler: function () { + // Figure out the current thickness + var thk = 1; + if (index !== undefined) { + thk = Math.abs(plot._Gx.lyr[index].thick); + } else { + if (Gx.lyr.length === 0) { + return; + } - thk = Math.abs(plot._Gx.lyr[0].thick); - for (var i = 0; i < Gx.lyr.length; i++) { - if (thk !== Math.abs(plot._Gx.lyr[i].thick)) { - thk = 1; - break; - } + thk = Math.abs(plot._Gx.lyr[0].thick); + for (var i = 0; i < Gx.lyr.length; i++) { + if (thk !== Math.abs(plot._Gx.lyr[i].thick)) { + thk = 1; + break; } } - setupPrompt( - plot, - "Line thickness:", - mx.intValidator, - function(finalValue) { - if (index !== undefined) { - plot._Gx.lyr[index].line = 3; - plot._Gx.lyr[index].thick = -1 * finalValue; - plot._Gx.lyr[index].symbol = 0; - } else { - for (var ii = 0; ii < Gx.lyr.length; ii++) { - plot._Gx.lyr[ii].line = 3; - plot._Gx.lyr[ii].thick = -1 * finalValue; - plot._Gx.lyr[ii].symbol = 0; - } - } - }, thk); } + setupPrompt( + plot, + "Line thickness:", + mx.intValidator, + function (finalValue) { + if (index !== undefined) { + plot._Gx.lyr[index].line = 3; + plot._Gx.lyr[index].thick = -1 * finalValue; + plot._Gx.lyr[index].symbol = 0; + } else { + for (var ii = 0; ii < Gx.lyr.length; ii++) { + plot._Gx.lyr[ii].line = 3; + plot._Gx.lyr[ii].thick = -1 * finalValue; + plot._Gx.lyr[ii].symbol = 0; + } + } + }, + thk + ); + }, + }; - }; - - var COLORS = { - text: "Colors...", - menu: { - title: "COLORS", - items: [{ - text: "Retain Current" - }, { + var COLORS = { + text: "Colors...", + menu: { + title: "COLORS", + items: [ + { + text: "Retain Current", + }, + { text: "Red", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "red" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "red" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "red"; } else { @@ -6123,11 +7076,15 @@ plot._Gx.lyr[i].color = "red"; } } - } - }, { + }, + }, + { text: "Pink", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "pink" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "pink" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "pink"; } else { @@ -6135,11 +7092,15 @@ plot._Gx.lyr[i].color = "pink"; } } - } - }, { + }, + }, + { text: "Hot Pink", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "#ff009e" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "#ff009e" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "#ff009e"; } else { @@ -6147,11 +7108,15 @@ plot._Gx.lyr[i].color = "#ff009e"; } } - } - }, { + }, + }, + { text: "Orange", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "orange" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "orange" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "orange"; } else { @@ -6159,11 +7124,15 @@ plot._Gx.lyr[i].color = "orange"; } } - } - }, { + }, + }, + { text: "Yellow", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "yellow" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "yellow" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "yellow"; } else { @@ -6171,11 +7140,15 @@ plot._Gx.lyr[i].color = "yellow"; } } - } - }, { + }, + }, + { text: "Lime Green", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "#80f741" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "#80f741" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "#80f741"; } else { @@ -6183,11 +7156,15 @@ plot._Gx.lyr[i].color = "#80f741"; } } - } - }, { + }, + }, + { text: "Green", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "green" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "green" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "green"; } else { @@ -6195,11 +7172,15 @@ plot._Gx.lyr[i].color = "green"; } } - } - }, { + }, + }, + { text: "Blue", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "blue" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "blue" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "blue"; } else { @@ -6207,11 +7188,15 @@ plot._Gx.lyr[i].color = "blue"; } } - } - }, { + }, + }, + { text: "Purple", - checked: (index !== undefined) ? plot._Gx.lyr[index].color === "purple" : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].color === "purple" + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].color = "purple"; } else { @@ -6219,95 +7204,114 @@ plot._Gx.lyr[i].color = "purple"; } } - } - }, { + }, + }, + { text: "Custom Hexcode", - handler: function() { + handler: function () { setupPrompt( plot, "Color code (requires #):", mx.hexValidator, - function(finalValue) { + function (finalValue) { if (index !== undefined) { plot._Gx.lyr[index].color = finalValue; } else { - for (var ii = 0; ii < Gx.lyr.length; ii++) { + for ( + var ii = 0; + ii < Gx.lyr.length; + ii++ + ) { plot._Gx.lyr[ii].color = finalValue; } } - }, undefined, undefined, undefined, undefined); - } - }] - } - }; - - var SOLID = { - text: "Solid...", - handler: function() { - // Figure out the current thickness - var thk = 1; - if (index !== undefined) { - thk = Math.abs(plot._Gx.lyr[index].thick); - } else { - if (Gx.lyr.length === 0) { - return; - } + }, + undefined, + undefined, + undefined, + undefined + ); + }, + }, + ], + }, + }; - thk = Math.abs(plot._Gx.lyr[0].thick); - var i; - for (i = 0; i < Gx.lyr.length; i++) { - if (thk !== Math.abs(plot._Gx.lyr[i].thick)) { - thk = 1; - break; - } + var SOLID = { + text: "Solid...", + handler: function () { + // Figure out the current thickness + var thk = 1; + if (index !== undefined) { + thk = Math.abs(plot._Gx.lyr[index].thick); + } else { + if (Gx.lyr.length === 0) { + return; + } + + thk = Math.abs(plot._Gx.lyr[0].thick); + var i; + for (i = 0; i < Gx.lyr.length; i++) { + if (thk !== Math.abs(plot._Gx.lyr[i].thick)) { + thk = 1; + break; } } - setupPrompt( - plot, - "Line thickness:", - mx.intValidator, - function(finalValue) { - if (index !== undefined) { - plot._Gx.lyr[index].line = 3; - plot._Gx.lyr[index].thick = finalValue; - plot._Gx.lyr[index].symbol = 0; - } else { - var i; - for (i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].line = 3; - plot._Gx.lyr[i].thick = finalValue; - plot._Gx.lyr[i].symbol = 0; - } - } - }, thk); } - }; - - var TOGGLE = { - text: "Toggle", - style: (index !== undefined) ? "checkbox" : undefined, - checked: (index !== undefined) ? plot._Gx.lyr[index].display : undefined, - handler: function() { - if (index !== undefined) { - plot._Gx.lyr[index].display = !plot._Gx.lyr[index].display; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].display = !plot._Gx.lyr[i].display; + setupPrompt( + plot, + "Line thickness:", + mx.intValidator, + function (finalValue) { + if (index !== undefined) { + plot._Gx.lyr[index].line = 3; + plot._Gx.lyr[index].thick = finalValue; + plot._Gx.lyr[index].symbol = 0; + } else { + var i; + for (i = 0; i < Gx.lyr.length; i++) { + plot._Gx.lyr[i].line = 3; + plot._Gx.lyr[i].thick = finalValue; + plot._Gx.lyr[i].symbol = 0; + } } + }, + thk + ); + }, + }; + + var TOGGLE = { + text: "Toggle", + style: index !== undefined ? "checkbox" : undefined, + checked: + index !== undefined ? plot._Gx.lyr[index].display : undefined, + handler: function () { + if (index !== undefined) { + plot._Gx.lyr[index].display = !plot._Gx.lyr[index].display; + } else { + for (var i = 0; i < Gx.lyr.length; i++) { + plot._Gx.lyr[i].display = !plot._Gx.lyr[i].display; } } - }; + }, + }; - var SYMBOLS = { - text: "Symbols...", - menu: { - title: "SYMBOLS", - items: [{ - text: "Retain Current" - }, { + var SYMBOLS = { + text: "Symbols...", + menu: { + title: "SYMBOLS", + items: [ + { + text: "Retain Current", + }, + { text: "None", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 0 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 0 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 0; plot._Gx.lyr[index].symbol = 0; @@ -6317,11 +7321,15 @@ plot._Gx.lyr[i].symbol = 0; } } - } - }, { + }, + }, + { text: "Pixels", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 1 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 1 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 1; plot._Gx.lyr[index].symbol = 1; @@ -6331,11 +7339,15 @@ plot._Gx.lyr[i].symbol = 1; } } - } - }, { + }, + }, + { text: "Circles", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 2 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 2 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 4; plot._Gx.lyr[index].symbol = 2; @@ -6345,11 +7357,15 @@ plot._Gx.lyr[i].symbol = 2; } } - } - }, { + }, + }, + { text: "Squares", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 3 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 3 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 4; plot._Gx.lyr[index].symbol = 3; @@ -6359,11 +7375,15 @@ plot._Gx.lyr[i].symbol = 3; } } - } - }, { + }, + }, + { text: "Plusses", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 4 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 4 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 4; plot._Gx.lyr[index].symbol = 4; @@ -6373,11 +7393,15 @@ plot._Gx.lyr[i].symbol = 4; } } - } - }, { + }, + }, + { text: "X's", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 5 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 5 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 4; plot._Gx.lyr[index].symbol = 5; @@ -6387,11 +7411,15 @@ plot._Gx.lyr[i].symbol = 5; } } - } - }, { + }, + }, + { text: "Triangles", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 6 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 6 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 6; plot._Gx.lyr[index].symbol = 6; @@ -6401,11 +7429,15 @@ plot._Gx.lyr[i].symbol = 6; } } - } - }, { + }, + }, + { text: "Downward Triangles", - checked: (index !== undefined) ? plot._Gx.lyr[index].symbol === 7 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].symbol === 7 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].radius = 6; plot._Gx.lyr[index].symbol = 7; @@ -6415,21 +7447,27 @@ plot._Gx.lyr[i].symbol = 7; } } - } - }] - } - }; + }, + }, + ], + }, + }; - var LINE_TYPE = { - text: "Line Type...", - menu: { - title: "LINE TYPE", - items: [{ - text: "Retain Current" - }, { + var LINE_TYPE = { + text: "Line Type...", + menu: { + title: "LINE TYPE", + items: [ + { + text: "Retain Current", + }, + { text: "None", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 0 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 0 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].line = 0; } else { @@ -6437,11 +7475,15 @@ plot._Gx.lyr[i].line = 0; } } - } - }, { + }, + }, + { text: "Verticals", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 1 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 1 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].line = 1; } else { @@ -6449,11 +7491,15 @@ plot._Gx.lyr[i].line = 1; } } - } - }, { + }, + }, + { text: "Horizontals", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 2 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 2 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].line = 2; } else { @@ -6461,11 +7507,15 @@ plot._Gx.lyr[i].line = 2; } } - } - }, { + }, + }, + { text: "Connecting", - checked: (index !== undefined) ? plot._Gx.lyr[index].line === 3 : undefined, - handler: function() { + checked: + index !== undefined + ? plot._Gx.lyr[index].line === 3 + : undefined, + handler: function () { if (index !== undefined) { plot._Gx.lyr[index].line = 3; } else { @@ -6473,2579 +7523,2960 @@ plot._Gx.lyr[i].line = 3; } } - } - }] - } - }; - - var THICKNESS = { - text: "Thickness...", - handler: function() { - var thickness = 1; - if (index !== undefined) { - thickness = plot._Gx.lyr[index].thick; - } - setupPrompt( - plot, - "Thickness", - mx.intValidator, - function(finalValue) { - if (finalValue === "") { - finalValue = 1; - } - finalValue = Math.max(0, finalValue); - - if (index !== undefined) { - plot._Gx.lyr[index].thick = finalValue; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].thick = finalValue; - } - } - }, thickness, undefined, - undefined, undefined); - } - }; + }, + }, + ], + }, + }; - var OPACITY = { - text: "Opacity...", - handler: function() { - var opacity = 1.0; - if (index !== undefined) { - opacity = plot._Gx.lyr[index].opacity; - } - setupPrompt( - plot, - "Opacity:", - mx.floatValidator, - function(finalValue) { - if (finalValue === "") { - finalValue = 1.0; + var THICKNESS = { + text: "Thickness...", + handler: function () { + var thickness = 1; + if (index !== undefined) { + thickness = plot._Gx.lyr[index].thick; + } + setupPrompt( + plot, + "Thickness", + mx.intValidator, + function (finalValue) { + if (finalValue === "") { + finalValue = 1; + } + finalValue = Math.max(0, finalValue); + + if (index !== undefined) { + plot._Gx.lyr[index].thick = finalValue; + } else { + for (var i = 0; i < Gx.lyr.length; i++) { + plot._Gx.lyr[i].thick = finalValue; } - finalValue = Math.max(0, finalValue); - finalValue = Math.min(1, finalValue); + } + }, + thickness, + undefined, + undefined, + undefined + ); + }, + }; - if (index !== undefined) { - plot._Gx.lyr[index].opacity = finalValue; - } else { - for (var i = 0; i < Gx.lyr.length; i++) { - plot._Gx.lyr[i].opacity = finalValue; - } + var OPACITY = { + text: "Opacity...", + handler: function () { + var opacity = 1.0; + if (index !== undefined) { + opacity = plot._Gx.lyr[index].opacity; + } + setupPrompt( + plot, + "Opacity:", + mx.floatValidator, + function (finalValue) { + if (finalValue === "") { + finalValue = 1.0; + } + finalValue = Math.max(0, finalValue); + finalValue = Math.min(1, finalValue); + + if (index !== undefined) { + plot._Gx.lyr[index].opacity = finalValue; + } else { + for (var i = 0; i < Gx.lyr.length; i++) { + plot._Gx.lyr[i].opacity = finalValue; } - }, opacity, undefined, - undefined, undefined); - } - }; - - var LEGEND_TRACE = { - title: Gx.lyr[index].name, - finalize: function() { - if (!Mx.prompt) { - // A prompt may have been - // created by a menu handler - // - let it deal with - // eventListener re-setting - mx.addEventListener(Mx, "mousedown", plot.onmousedown, - false); - } - plot.refresh(); - }, - items: [DASHED, COLORS, SOLID, TOGGLE, SYMBOLS, LINE_TYPE, THICKNESS, OPACITY] - }; - - mx.menu(Mx, LEGEND_TRACE); - } - - - /** - * @memberOf sigplot - * @private - */ - function rubberbox_cb(plot, triggerEvent) { - return function(event, xo, yo, xl, yl, action, mode) { - var Gx = plot._Gx; - var Mx = plot._Mx; - - var x = Math.min(xo, xl); - var y = Math.min(yo, yl); - var w = Math.abs(xl - xo); - var h = Math.abs(yl - yo); - - var takeAction = false; - if (event.which === triggerEvent) { - // On some browsers, a click will actually be sent as - // mousedown/mousemove/mouseup so - // don't make insanely small zooms...instead treat them as a - // click - if (mode === "horizontal") { - takeAction = (w > 2); - } else if (mode === "vertical") { - takeAction = (h > 2); - } else { - takeAction = ((w > 2) && (h > 2)); - } - } - - if (!takeAction) { - // The mouse didn't shift enough to be considered - // as a rubberbox action so treat it as mouseup - plot.mouseup(event); - } else { - // action === null is disabled, but undefined is default - if ((action === undefined) || (action === "zoom")) { - plot.pixel_zoom(xo, yo, xl, yl); - plot.refresh(); - } else if (action === "select") { - var evt = document.createEvent('Event'); - evt.initEvent('mtag', true, true); - evt.originalEvent = event; - var re = pixel_to_real(plot, x, y); - var rwh = pixel_to_real(plot, x + w, y + h); - evt.x = re.x; - evt.y = re.y; - evt.xpos = x; - evt.ypos = y; - evt.w = Math.abs(rwh.x - re.x); - evt.h = Math.abs(rwh.y - re.y); - evt.wpxl = w; - evt.hpxl = h; - evt.shift = event.shiftKey; - mx.dispatchEvent(Mx, evt); - } - } - }; - } - - /** - * @memberOf sigplot - * @private - */ - function plot_init(plot, o) { - var Mx = plot._Mx; - var Gx = plot._Gx; - - if (!o.xlab) { - o.xlab = 0; - } - if (!o.ylab) { - o.ylab = 0; - } - if (o.useDomMenu) { - Mx.useDomMenu = true; - } - - //Convert xunits and yunits to numbers if they are strings - o.xlab = m.unit_lookup(o.xlab); - o.ylab = m.unit_lookup(o.ylab); - - // Equivalent to reading cmd line args - Gx.xmin = o.xmin === undefined ? 0.0 : o.xmin; - Gx.xmax = o.xmax === undefined ? 0.0 : o.xmax; - var havexmin = (o.xmin !== undefined); - var havexmax = (o.xmax !== undefined); - var address; - if (typeof o.cmode === "number") { - switch (o.cmode) { - case 1: - address = "MA"; - break; - case 2: - address = "PH"; - break; - case 3: - address = "RE"; - break; - case 4: - address = "IM"; - break; - case 5: - address = "IR"; - break; - case 6: - address = "LO"; - break; - case 7: - address = "L2"; - break; - default: - throw new RangeError("Invalid cmode value"); - } - } else { - address = o.cmode === undefined ? "" : o.cmode.toUpperCase(); - } - var line = o.line === undefined ? 3 : o.line; - Gx.ylab = o.ylab; - Gx.ylabel = o.ylabel; - Gx.ymin = o.ymin === undefined ? 0.0 : o.ymin; - Gx.ymax = o.ymax === undefined ? 0.0 : o.ymax; - var haveymin = (o.ymin !== undefined); - var haveymax = (o.ymax !== undefined); - Gx.zmin = o.zmin; - Gx.zmax = o.zmax; - var havezmin = (o.zmin !== undefined); - var havezmax = (o.zmax !== undefined); - - if (o.colors !== undefined) { - mx.setbgfg(Mx, o.colors.bg, o.colors.fg, Mx.xi); - } - - if (o.xi) { - mx.invertbgfg(Mx); - } - - Gx.forcelab = o.forcelab === undefined ? true : o.forcelab; - - Gx.all = o.all === undefined ? false : o.all; - // By default, SIGPLOT auto-scales only on the first buffer size. - // "expand" is a feature added for websigplot that when - // combined with "all" will expand the y-range automaticall - // to accomodate all of the samples - Gx.expand = o.expand === undefined ? false : o.expand; - - // TODO Gx.mimic = M$GET_SWITCH ('MIMIC') - Gx.xlab = o.xlab; - Gx.xlabel = o.xlabel; - Gx.segment = o.segment === undefined ? false : o.segment; - Gx.plab = 24; - - var phunits = (o.phunits === undefined) ? 'D' : o.phunits; - if (phunits[0] === 'R') { - Gx.plab = 23; - } else if (phunits[0] === 'C') { - Gx.plab = 25; - } - Gx.xdiv = o.xdiv === undefined ? 5 : o.xdiv; - Gx.ydiv = o.ydiv === undefined ? 5 : o.ydiv; - - Gx.xcompression = o.xcmp || 0; - Gx.rasterDownscale = o.downscale || 0; - Gx.rasterSmoothing = o.smoothing || false; - - Mx.origin = 1; - if (o.yinv) { - Mx.origin = 4; - } - Gx.pmt = o.pmt === undefined ? 1.0 : o.pmt; - Gx.bufmax = o.bufmax === undefined ? 32768 : o.bufmax; - Gx.sections = o.nsec === undefined ? 0 : o.nsec; - Gx.anno_type = o.anno_type === undefined ? 0 : o.anno_type; - - Gx.xfmt = o.xfmt === undefined ? "" : o.xfmt; - Gx.yfmt = o.yfmt === undefined ? "" : o.yfmt; - - // TODO Gx.xf.msgid = M$GET_SWITCH ('MSGID') - // Gx.xf.msgmask = max (0, M$GET_SWITCH ('MASK')) - - Gx.index = o.index === undefined ? false : o.index; - var imode = (Gx.index || (address.slice(0, 2) === "IN")); - if (imode) { - if (havexmin && (Gx.xmin === 1.0)) { - havexmin = false; - } - if (havexmax && (Gx.xmin === 1.0)) { - havexmax = false; - } - } - - Gx.xdata = false; - Gx.note = o.note || ""; - Gx.hold = 0; - Gx.always_show_marker = o.always_show_marker || false; - - m.vstype('D'); - - if (!o.inputs) { - basefile(plot, false); - } else { - // TODO load files - } - - var cmode = address; - - if ((Gx.lyr.length > 0) && (Gx.lyr[0].cx)) { - Gx.cmode = 1; - } else { - Gx.cmode = 3; - } - - if ((cmode === "MA") || (cmode === "INMA") || (cmode === "ABMA") || - (cmode === "__MA") || (cmode === "MAGNITUDE")) { - Gx.cmode = 1; - } - if ((cmode === "PH") || (cmode === "INPH") || (cmode === "ABPH") || - (cmode === "__PH") || (cmode === "PHASE")) { - Gx.cmode = 2; - } - if ((cmode === "RE") || (cmode === "INRE") || (cmode === "ABRE") || - (cmode === "__RE") || (cmode === "REAL")) { - Gx.cmode = 3; - } - if ((cmode === "IM") || (cmode === "INIM") || (cmode === "ABIM") || - (cmode === "__IM") || (cmode === "IMAGINARY")) { - Gx.cmode = 4; - } - if ((cmode === "LO") || (cmode === "D1") || (cmode === "INLO") || (cmode === "IND1") || - (cmode === "ABIM") || (cmode === "ABD1") || (cmode === "__LO") || - (cmode === "__D1") || (cmode === "10*LOG10")) { - Gx.cmode = 6; - } - if ((cmode === "L2") || (cmode === "D2") || (cmode === "INL2") || (cmode === "IND2") || - (cmode === "ABLO") || (cmode === "ABD2") || (cmode === "__L2") || - (cmode === "__D2") || (cmode === "20*LOG10")) { - Gx.cmode = 7; - } - if ((cmode === "RI") || (cmode === "IR") || (cmode === "INRI") || (cmode === "INIR") || - (cmode === "ABRI") || (cmode === "ABIR") || (cmode === "__RI") || - (cmode === "__IR") || (cmode === "IMAG/REAL") || (cmode === "REAL/IMAG")) { - if (Gx.index) { - m.log.error("Imag/Real mode not permitted in INDEX mode"); - } else { - Gx.cmode = 5; - } - } - - Gx.basemode = Gx.cmode; - - plot.change_settings({ - cmode: Gx.cmode - }); - - // if ( (Gx.forcelab) .and. (Gx.xlab .le. 0) .and. - // & (Gx.ylab .le. 0) ) then - // call M$WARNING - // & ('/xlab or /ylab is missing with /forcelab usage') - // Gx.forcelab = .false. - // endif - - Gx.dbmin = 1.0e-20; - if (Gx.cmode >= 6) { - var dbscale = 10.0; - if (Gx.cmode === 7) { - dbscale = 20.0; - } - if ((cmode[0] === "L") || (cmode[0] === "1") || (cmode[0] === "2")) { - if ((Gx.lyr.length > 0) && (Gx.lyr[0].cx)) { - Gx.ymin = Math.max(Gx.ymin, 1e-10); - Gx.ymax = Math.max(Gx.ymax, 1e-10); - } else { - Gx.ymin = Math.max(Gx.ymin, 1e-20); - Gx.ymax = Math.max(Gx.ymax, 1e-20); - } - Gx.ymin = m.log10(Gx.ymin) * dbscale; - Gx.ymax = m.log10(Gx.ymax) * dbscale; - } else if ((Gx.lyr.length > 0) && (Gx.lyr[0].cx)) { - Gx.ymin = Math.max(-18.0 * dbscale, Gx.ymin); - Gx.ymax = Math.max(-18.0 * dbscale, Gx.ymax); - Gx.dbmin = 1e-37; - } else if (Math.min(Gx.ymin, Gx.ymax) < -20.0 * dbscale) { - Gx.ymin = Math.max(-37.0 * dbscale, Gx.ymin); - Gx.ymax = Math.max(-37.0 * dbscale, Gx.ymax); - Gx.dbmin = Math.pow(10, Math.min(Gx.ymin, Gx.ymax) / dbscale); - } - } - - Mx.level = 0; - if (imode && !Gx.index) { - if (havexmin) { - Gx.xmin = Gx.xstart + Gx.xdelta * (Gx.xmin - 1.0); - } - if (havexmin) { - Gx.xmax = Gx.xstart + Gx.xdelta * (Gx.xmax - 1.0); - } - } - Gx.xmult = o.xmult; - Gx.ymult = o.xmult; - - //Convert string inputs of autox to numbers - switch (o.autox) { - case "none": - o.autox = -1; - break; - case "min": - o.autox = 1; - break; - case "max": - o.autox = 2; - break; - case "full": - o.autox = 3; - break; - } - - Gx.autox = o.autox === undefined ? -1 : o.autox; - if (Gx.autox < 0) { - Gx.autox = 0; - if (!havexmin) { - Gx.autox += 1; - } - if (!havexmax) { - Gx.autox += 2; - } - } - - //Convert string inputs of autoy to numbers - - switch (o.autoy) { - case "none": - o.autoy = -1; - break; - case "min": - o.autoy = 1; - break; - case "max": - o.autoy = 2; - break; - case "full": - o.autoy = 3; - break; - } - - Gx.autoy = o.autoy === undefined ? -1 : o.autoy; - if (Gx.autoy < 0) { - Gx.autoy = 0; - if (!haveymin) { - Gx.autoy += 1; - } - if (!haveymax) { - Gx.autoy += 2; - } - } - - //Convert string inputs of autoz to numbers - - switch (o.autoz) { - case "none": - o.autoz = -1; - break; - case "min": - o.autoz = 1; - break; - case "max": - o.autoz = 2; - break; - case "full": - o.autoz = 3; - break; - } - - Gx.autoz = o.autoz === undefined ? -1 : o.autoz; - if (Gx.autoz < 0) { - Gx.autoz = 0; - if (!havezmin) { - Gx.autoz += 1; - } - if (!havezmax) { - Gx.autoz += 2; - } - } - Gx.autol = o.autol === undefined ? -1 : o.autol; - - if (!havexmin) { - Gx.xmin = undefined; - } - if (!havexmax) { - Gx.xmax = undefined; - } - - scale_base(plot, { - get_data: true - }, Gx.xmin, Gx.xmax, Gx.xlab, Gx.ylab); - - if (!havexmin) { - Gx.xmin = Mx.stk[0].xmin; - } - if (!havexmax) { - Gx.xmax = Mx.stk[0].xmax; - } - if (!haveymin) { - Gx.ymin = Mx.stk[0].ymin; - } - if (!haveymax) { - Gx.ymax = Mx.stk[0].ymax; - } - - if (Gx.xmin > Gx.xmax) { - Mx.stk[0].xmin = Gx.xmax; - Gx.xmax = Gx.xmin; - Gx.xmin = Mx.stk[0].xmin; - } - if (Gx.ymin > Gx.ymax) { - Mx.stk[0].ymin = Gx.ymax; - Gx.ymax = Gx.ymin; - Gx.ymin = Mx.stk[0].ymin; - } - Mx.stk[0].xmin = Gx.xmin; - Mx.stk[0].xmax = Gx.xmax; - Mx.stk[0].ymin = Gx.ymin; - Mx.stk[0].ymax = Gx.ymax; - - Gx.panxmin = Math.min(Gx.panxmin, Gx.xmin); - Gx.panxmax = Math.max(Gx.panxmax, Gx.xmax); - Gx.panymin = Math.min(Gx.panymin, Gx.ymin); - Gx.panymax = Math.max(Gx.panymax, Gx.ymax); - - Gx.panxpad = o.panxpad; - Gx.panypad = o.panypad; - - var xran = (Gx.panxmax - Gx.panxmin); - var yran = (Gx.panymax - Gx.panymin); - - Gx.panxmin -= m.pad(xran, Gx.panxpad); - Gx.panxmax += m.pad(xran, Gx.panxpad); - Gx.panymin -= m.pad(yran, Gx.panypad); - Gx.panymax += m.pad(yran, Gx.panypad); - - Gx.xmin = Mx.stk[0].xmin; - Gx.ymin = Mx.stk[0].ymin; - - if (o.font_family) { - Mx.font_family = o.font_family; - } - if (o.font_width) { - Mx.font_width = o.font_width; - } - if (o.font_scaled) { - Mx.font_scaled = true; - } - - var font_width = Mx.font_width; - if (Mx.font_scaled) { - font_width = Math.min(Mx.font_width, Mx.width / 64); - } - mx.set_font(Mx, font_width); - - Gx.ncolors = o.ncolors === undefined ? 500 : o.ncolors; - Gx.cmap = null; - if (o.cmap !== undefined) { - Gx.cmap = o.cmap; - } else { - Gx.cmap = o.xc === undefined ? -1 : o.xc; - } - - setup_cmap(plot, Gx.cmap); - - // TODO setup annotate, boxes and points facilities - - // TODO initialize layer structure line types - - if (o.xcnt === "leftmouse") { - Gx.cntrls = 1; - } else if (o.xcnt === "continuous") { - Gx.cntrls = 2; - } else { - Gx.cntrls = o.xcnt === undefined ? 1 : o.xcnt; - } - - Gx.default_rubberbox_mode = o.rubberbox_mode === undefined ? "box" : o.rubberbox_mode; - Gx.default_rubberbox_action = o.rubberbox_action === undefined ? "zoom" : o.rubberbox_action; - Gx.default_rightclick_rubberbox_mode = o.rightclick_rubberbox_mode === undefined ? "box" : o.rightclick_rubberbox_mode; - Gx.default_rightclick_rubberbox_action = o.rightclick_rubberbox_action === undefined ? null : o.rightclick_rubberbox_action; - - Gx.cross = o.cross === undefined ? false : o.cross; - Gx.grid = o.nogrid === undefined ? true : !o.nogrid; - Gx.fillStyle = o.fillStyle; - Gx.gridBackground = o.gridBackground; - Gx.gridStyle = o.gridStyle; - Gx.wheelZoom = o.wheelZoom; - Gx.wheelZoomPercent = o.wheelZoomPercent; - Gx.legend = o.legend === undefined ? false : o.legend; - Gx.no_legend_button = o.no_legend_button === undefined ? false : o.no_legend_button; - Gx.legendBtnLocation = null; - Gx.pan = o.nopan === undefined ? true : !o.nopan; - Gx.nomenu = o.nomenu === undefined ? false : o.nomenu; - - // TODO Gx.lmap.ip = 0 - Gx.modmode = 0; - Gx.modlayer = -1; // 0-based indexing instead of 1 - Gx.modsource = 0; - Gx.modified = (o.mod && Gx.lyr.length > 0); - // TODO Gx.marks(5) = 5 - Gx.nmark = 0; - Gx.iabsc = 0; - if (Gx.index) { - Gx.iabsc = 1; - } - // TODO if (o.specs > 0) Gx.iabsc = M$SEARCH('IRS',c(1:1)) - Gx.specs = !o.nospecs; - - Gx.scroll_time_interval = o.scroll_time_interval === undefined ? Gx.scroll_time_interval : o.scroll_time_interval; - - Gx.autohide_readout = o.autohide_readout; - Gx.autohide_panbars = o.autohide_panbars; - Gx.x_scrollbar_location = o.x_scrollbar_location; - if (Gx.specs) { - Gx.show_x_axis = !o.noxaxis; - Gx.show_y_axis = !o.noyaxis; - Gx.show_readout = !o.noreadout; - if (Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout) { - Gx.specs = true; - } else { - Gx.specs = false; - } - } else { - Gx.show_x_axis = false; - Gx.show_y_axis = false; - Gx.show_readout = false; - } - Gx.hide_note = o.hide_note || false; - - Gx.xmrk = 0.0; - Gx.ymrk = 0.0; - - if (!o.nodragdrop) { - mx.addEventListener(Mx, "dragover", function(evt) { - evt.preventDefault(); - }, false); - - mx.addEventListener(Mx, "drop", (function(plot) { - return function(evt) { - var files = evt.dataTransfer.files; - if (files.length > 0) { - evt.preventDefault(); - plot.load_files(files); - } - }; - }(plot)), false); - } + } + }, + opacity, + undefined, + undefined, + undefined + ); + }, + }; - Gx.initialized = true; - } + var LEGEND_TRACE = { + title: Gx.lyr[index].name, + finalize: function () { + if (!Mx.prompt) { + // A prompt may have been + // created by a menu handler + // - let it deal with + // eventListener re-setting + mx.addEventListener( + Mx, + "mousedown", + plot.onmousedown, + false + ); + } + plot.refresh(); + }, + items: [ + DASHED, + COLORS, + SOLID, + TOGGLE, + SYMBOLS, + LINE_TYPE, + THICKNESS, + OPACITY, + ], + }; - /** - * @memberOf sigplot - * @private - */ - function basefile(plot, open) { + mx.menu(Mx, LEGEND_TRACE); +} + +/** + * @memberOf sigplot + * @private + */ +function rubberbox_cb(plot, triggerEvent) { + return function (event, xo, yo, xl, yl, action, mode) { var Gx = plot._Gx; var Mx = plot._Mx; - // != BASEFILE(false) - - // unlike SIGPLOT, where if Gx.index == 1 - // then xstart = 1.0 and xdelta = 1.0...technically - // Gx.retx is supposed to be the real X coordinate - // and Gx.aretx is supposed to be the X coordinate in the - // current abscissa mode - var hcb = plot.get_hcb_by_lyrn(0); - if (open) { - if (hcb) { - Gx.xstart = hcb.xstart; - Gx.xdelta = hcb.xdelta; + + var x = Math.min(xo, xl); + var y = Math.min(yo, yl); + var w = Math.abs(xl - xo); + var h = Math.abs(yl - yo); + + var takeAction = false; + if (event.which === triggerEvent) { + // On some browsers, a click will actually be sent as + // mousedown/mousemove/mouseup so + // don't make insanely small zooms...instead treat them as a + // click + if (mode === "horizontal") { + takeAction = w > 2; + } else if (mode === "vertical") { + takeAction = h > 2; } else { - Gx.xstart = 0.0; - Gx.xdelta = 1.0; - } - Mx.origin = 1; - if (Gx.autoz & 1) { - Gx.zmin = undefined; - } - if (Gx.autoz & 2) { - Gx.zmax = undefined; + takeAction = w > 2 && h > 2; } + } + + if (!takeAction) { + // The mouse didn't shift enough to be considered + // as a rubberbox action so treat it as mouseup + plot.mouseup(event); } else { - Gx.xstart = 0.0; - Gx.xdelta = 1.0; - Gx.autol = -1; - Mx.origin = 1; - if (Gx.autoz & 1) { - Gx.zmin = undefined; - } - if (Gx.autoz & 2) { - Gx.zmax = undefined; + // action === null is disabled, but undefined is default + if (action === undefined || action === "zoom") { + plot.pixel_zoom(xo, yo, xl, yl); + plot.refresh(); + } else if (action === "select") { + var evt = document.createEvent("Event"); + evt.initEvent("mtag", true, true); + evt.originalEvent = event; + var re = pixel_to_real(plot, x, y); + var rwh = pixel_to_real(plot, x + w, y + h); + evt.x = re.x; + evt.y = re.y; + evt.xpos = x; + evt.ypos = y; + evt.w = Math.abs(rwh.x - re.x); + evt.h = Math.abs(rwh.y - re.y); + evt.wpxl = w; + evt.hpxl = h; + evt.shift = event.shiftKey; + mx.dispatchEvent(Mx, evt); } } + }; +} - // if (!open) { - // Gx.lay[0].cx = false; - // } +/** + * @memberOf sigplot + * @private + */ +function plot_init(plot, o) { + var Mx = plot._Mx; + var Gx = plot._Gx; + + if (!o.xlab) { + o.xlab = 0; + } + if (!o.ylab) { + o.ylab = 0; + } + if (o.useDomMenu) { + Mx.useDomMenu = true; } - /** - * @memberOf sigplot - * @private - */ - function draw_accessories(plot, mode) { - var Mx = plot._Mx; - var Gx = plot._Gx; - if (mode > 0) { - if ((mode >= 4) && (Gx.show_readout) && (!Gx.hide_note)) { - var ln = Gx.note.length; - mx.text(Mx, Mx.width - Gx.lbtn - (ln + 1) * Mx.text_w, - Mx.text_h, Gx.note); - } - if (mode >= 4) { - draw_panbars(plot); - } - if ((mode >= 1) && (Gx.legend)) { - draw_legend(plot); - } + //Convert xunits and yunits to numbers if they are strings + o.xlab = m.unit_lookup(o.xlab); + o.ylab = m.unit_lookup(o.ylab); + + // Equivalent to reading cmd line args + Gx.xmin = o.xmin === undefined ? 0.0 : o.xmin; + Gx.xmax = o.xmax === undefined ? 0.0 : o.xmax; + var havexmin = o.xmin !== undefined; + var havexmax = o.xmax !== undefined; + var address; + if (typeof o.cmode === "number") { + switch (o.cmode) { + case 1: + address = "MA"; + break; + case 2: + address = "PH"; + break; + case 3: + address = "RE"; + break; + case 4: + address = "IM"; + break; + case 5: + address = "IR"; + break; + case 6: + address = "LO"; + break; + case 7: + address = "L2"; + break; + default: + throw new RangeError("Invalid cmode value"); } + } else { + address = o.cmode === undefined ? "" : o.cmode.toUpperCase(); + } + var line = o.line === undefined ? 3 : o.line; + Gx.ylab = o.ylab; + Gx.ylabel = o.ylabel; + Gx.ymin = o.ymin === undefined ? 0.0 : o.ymin; + Gx.ymax = o.ymax === undefined ? 0.0 : o.ymax; + var haveymin = o.ymin !== undefined; + var haveymax = o.ymax !== undefined; + Gx.zmin = o.zmin; + Gx.zmax = o.zmax; + var havezmin = o.zmin !== undefined; + var havezmax = o.zmax !== undefined; + + if (o.colors !== undefined) { + mx.setbgfg(Mx, o.colors.bg, o.colors.fg, Mx.xi); } - /** - * @memberOf sigplot - * @private - */ - function draw_plugins(plot) { - var Gx = plot._Gx; - var ctx = plot._Mx.canvas.getContext("2d"); - var canvas; + if (o.xi) { + mx.invertbgfg(Mx); + } - var plugin_index = 0; - while (plugin_index < Gx.plugins.length) { - var plugin = Gx.plugins[plugin_index].impl; - if (plugin.refresh) { - canvas = Gx.plugins[plugin_index].canvas; + Gx.forcelab = o.forcelab === undefined ? true : o.forcelab; + + Gx.all = o.all === undefined ? false : o.all; + // By default, SIGPLOT auto-scales only on the first buffer size. + // "expand" is a feature added for websigplot that when + // combined with "all" will expand the y-range automaticall + // to accomodate all of the samples + Gx.expand = o.expand === undefined ? false : o.expand; + + // TODO Gx.mimic = M$GET_SWITCH ('MIMIC') + Gx.xlab = o.xlab; + Gx.xlabel = o.xlabel; + Gx.segment = o.segment === undefined ? false : o.segment; + Gx.plab = 24; + + var phunits = o.phunits === undefined ? "D" : o.phunits; + if (phunits[0] === "R") { + Gx.plab = 23; + } else if (phunits[0] === "C") { + Gx.plab = 25; + } + Gx.xdiv = o.xdiv === undefined ? 5 : o.xdiv; + Gx.ydiv = o.ydiv === undefined ? 5 : o.ydiv; - // Ensure the plugin canvas has the same size as the plot - if (canvas.width !== plot._Mx.canvas.width) { - canvas.width = plot._Mx.canvas.width; - } - if (canvas.height !== plot._Mx.canvas.height) { - canvas.height = plot._Mx.canvas.height; - } + Gx.xcompression = o.xcmp || 0; + Gx.rasterDownscale = o.downscale || 0; + Gx.rasterSmoothing = o.smoothing || false; - // If the plugin canvas is visible, draw it - if (canvas.height !== 0 && canvas.width !== 0) { - if (canvas.width !== plot._Mx.canvas.width) { - canvas.width = plot._Mx.canvas.width; - } - if (canvas.height !== plot._Mx.canvas.height) { - canvas.height = plot._Mx.canvas.height; - } - canvas.getContext("2d").clearRect(0, 0, canvas.width, canvas.height); - Gx.plugins[plugin_index].impl.refresh(canvas); - ctx.drawImage(canvas, 0, 0); - } - } - plugin_index = plugin_index + 1; - } + Mx.origin = 1; + if (o.yinv) { + Mx.origin = 4; } + Gx.pmt = o.pmt === undefined ? 1.0 : o.pmt; + Gx.bufmax = o.bufmax === undefined ? 32768 : o.bufmax; + Gx.sections = o.nsec === undefined ? 0 : o.nsec; + Gx.anno_type = o.anno_type === undefined ? 0 : o.anno_type; - function get_legend_pos(plot) { - var Mx = plot._Mx; - var Gx = plot._Gx; + Gx.xfmt = o.xfmt === undefined ? "" : o.xfmt; + Gx.yfmt = o.yfmt === undefined ? "" : o.yfmt; + + // TODO Gx.xf.msgid = M$GET_SWITCH ('MSGID') + // Gx.xf.msgmask = max (0, M$GET_SWITCH ('MASK')) - var tw = Mx.text_w; - var xs = tw * 23; - var ys = (Gx.lyr.length + 1) * Mx.text_h; - var xc = Mx.r - xs; - var yc = Mx.t; + Gx.index = o.index === undefined ? false : o.index; + var imode = Gx.index || address.slice(0, 2) === "IN"; + if (imode) { + if (havexmin && Gx.xmin === 1.0) { + havexmin = false; + } + if (havexmax && Gx.xmin === 1.0) { + havexmax = false; + } + } + + Gx.xdata = false; + Gx.note = o.note || ""; + Gx.hold = 0; + Gx.always_show_marker = o.always_show_marker || false; - var legendPos = { - x: xc + 2, - y: yc + 2, - width: xs - 5, - height: ys - 5 - }; // default legend size + m.vstype("D"); - return legendPos; + if (!o.inputs) { + basefile(plot, false); + } else { + // TODO load files } - /** - * @memberOf sigplot - * @private - */ - function draw_legend(plot) { - var Mx = plot._Mx; - var Gx = plot._Gx; - //Gx.always_show_marker = true; - var ctx = Mx.canvas.getContext("2d"); + var cmode = address; - var i = 0; - var n = 0; // integer*4 - var ix = 0; // integer*4 - var iy = 0; // integer*4 - var ln = 0; // integer*4 - var tw = 0; // integer*4 - var xc = 0; // integer*4 - var yc = 0; // integer*4 - var xs = 0; // integer*4 - var ys = 0; // integer*4 - var thk = 0; // integer*4 - var ic = 0; // integer*4 - - tw = Mx.text_w; - xs = tw * 23; - ys = (Gx.lyr.length + 1) * Mx.text_h; - xc = Mx.r - xs; - yc = Mx.t; - - var legendPos = get_legend_pos(plot); - - // Determine legend position and label offset based on label sizes - var defLabelWidth = 98; // a magic number - default width of pixels - var maxLabelWidth = 0; - var labelOffset = 0; - for (n = 0; n < Gx.lyr.length; n++) { // figure out maximum label - // length - var labelLength = ctx.measureText(Gx.lyr[n].name).width; - if (labelLength > maxLabelWidth) { - maxLabelWidth = labelLength; - } - } - if (maxLabelWidth > defLabelWidth) { - labelOffset = (maxLabelWidth - defLabelWidth); - legendPos.width += labelOffset; - legendPos.x -= labelOffset; - } - - ctx.strokeStyle = Mx.fg; // Mx.xwfg swapped in for FGColor - ctx.fillStyle = Mx.bg; - ctx.fillRect(legendPos.x, legendPos.y, legendPos.width, - legendPos.height); // Creating a filled box instead of using - // clear_area - ctx.strokeRect(legendPos.x, legendPos.y, legendPos.width, - legendPos.height); - - for (n = 0; n < Gx.lyr.length; n++) { - ix = Math.floor(xc + 4 * tw); - iy = Math.floor(yc + n * Mx.text_h + Mx.text_h); // additional text_h to - // account for 0-based - // indexing - if (n === Gx.modlayer) { - mx.text(Mx, xc + tw - labelOffset, iy + Math.floor(Mx.text_w / 2), '**'); // Added text_w/2 - // offset - } - if (Gx.lyr[n].display) { - // TODO refactor this code so that each layer type is responsible - // for drawing it's own legend icon, providing flexibliity down the road - // for other layer types - if (Gx.lyr[n] instanceof Layer1D) { - ic = Gx.lyr[n].color; - if (Gx.lyr[n].line > 0) { - thk = m.sign(Math.min(tw, Math.abs(Gx.lyr[n].thick)), - Gx.lyr[n].thick); - // added magic -3 offset to y coordinates to center lines - // with text - if (thk < 0 || thk === mx.L_dashed) { - mx.draw_line(Mx, ic, ix - labelOffset, iy - 3, (ix + tw * 2) - labelOffset, iy - 3, Math.abs(thk), { - mode: "dashed", - on: 4, - off: 4 - }); - } else { - mx.draw_line(Mx, ic, ix - labelOffset, iy - 3, (ix + tw * 2) - labelOffset, iy - 3, Math.abs(thk)); - } - } - if (Gx.lyr[n].symbol > 0) { - // New logic here with 0.6*tw to help with legend symbol - // sizing - if (Gx.lyr[n].radius < 0) { - thk = -m.trunc(0.6 * tw); - } else { - thk = Math.min(Gx.lyr[n].radius, m.trunc(0.6 * tw)); - } + if (Gx.lyr.length > 0 && Gx.lyr[0].cx) { + Gx.cmode = 1; + } else { + Gx.cmode = 3; + } - mx.draw_symbol(Mx, ic, ix + tw - labelOffset, iy - 3, - Gx.lyr[n].symbol, thk); - } - } else if (Gx.lyr[n] instanceof Layer2D) { - //draw colorbar for 2D layers. The bar needs to leave space for the modlayer - // icon which occupies the first text-width - mx.legend_colorbar(Mx, xc + (2 * tw) - labelOffset, iy - (Mx.text_h / 2), - (tw * 4), (Mx.text_h / 2)); - } - } - ix = ix + tw * 3; - iy = iy + Mx.text_h * 0.3; - mx.text(Mx, ix - labelOffset, iy, Gx.lyr[n].name); + if ( + cmode === "MA" || + cmode === "INMA" || + cmode === "ABMA" || + cmode === "__MA" || + cmode === "MAGNITUDE" + ) { + Gx.cmode = 1; + } + if ( + cmode === "PH" || + cmode === "INPH" || + cmode === "ABPH" || + cmode === "__PH" || + cmode === "PHASE" + ) { + Gx.cmode = 2; + } + if ( + cmode === "RE" || + cmode === "INRE" || + cmode === "ABRE" || + cmode === "__RE" || + cmode === "REAL" + ) { + Gx.cmode = 3; + } + if ( + cmode === "IM" || + cmode === "INIM" || + cmode === "ABIM" || + cmode === "__IM" || + cmode === "IMAGINARY" + ) { + Gx.cmode = 4; + } + if ( + cmode === "LO" || + cmode === "D1" || + cmode === "INLO" || + cmode === "IND1" || + cmode === "ABIM" || + cmode === "ABD1" || + cmode === "__LO" || + cmode === "__D1" || + cmode === "10*LOG10" + ) { + Gx.cmode = 6; + } + if ( + cmode === "L2" || + cmode === "D2" || + cmode === "INL2" || + cmode === "IND2" || + cmode === "ABLO" || + cmode === "ABD2" || + cmode === "__L2" || + cmode === "__D2" || + cmode === "20*LOG10" + ) { + Gx.cmode = 7; + } + if ( + cmode === "RI" || + cmode === "IR" || + cmode === "INRI" || + cmode === "INIR" || + cmode === "ABRI" || + cmode === "ABIR" || + cmode === "__RI" || + cmode === "__IR" || + cmode === "IMAG/REAL" || + cmode === "REAL/IMAG" + ) { + if (Gx.index) { + m.log.error("Imag/Real mode not permitted in INDEX mode"); + } else { + Gx.cmode = 5; } + } + Gx.basemode = Gx.cmode; + + plot.change_settings({ + cmode: Gx.cmode, + }); + + // if ( (Gx.forcelab) .and. (Gx.xlab .le. 0) .and. + // & (Gx.ylab .le. 0) ) then + // call M$WARNING + // & ('/xlab or /ylab is missing with /forcelab usage') + // Gx.forcelab = .false. + // endif + + Gx.dbmin = 1.0e-20; + if (Gx.cmode >= 6) { + var dbscale = 10.0; + if (Gx.cmode === 7) { + dbscale = 20.0; + } + if (cmode[0] === "L" || cmode[0] === "1" || cmode[0] === "2") { + if (Gx.lyr.length > 0 && Gx.lyr[0].cx) { + Gx.ymin = Math.max(Gx.ymin, 1e-10); + Gx.ymax = Math.max(Gx.ymax, 1e-10); + } else { + Gx.ymin = Math.max(Gx.ymin, 1e-20); + Gx.ymax = Math.max(Gx.ymax, 1e-20); + } + Gx.ymin = m.log10(Gx.ymin) * dbscale; + Gx.ymax = m.log10(Gx.ymax) * dbscale; + } else if (Gx.lyr.length > 0 && Gx.lyr[0].cx) { + Gx.ymin = Math.max(-18.0 * dbscale, Gx.ymin); + Gx.ymax = Math.max(-18.0 * dbscale, Gx.ymax); + Gx.dbmin = 1e-37; + } else if (Math.min(Gx.ymin, Gx.ymax) < -20.0 * dbscale) { + Gx.ymin = Math.max(-37.0 * dbscale, Gx.ymin); + Gx.ymax = Math.max(-37.0 * dbscale, Gx.ymax); + Gx.dbmin = Math.pow(10, Math.min(Gx.ymin, Gx.ymax) / dbscale); + } } - /** - * @memberOf sigplot - * @private - */ - function form_plotnote(plot) { - var Gx = plot._Gx; - if (Gx.note) { - return; + Mx.level = 0; + if (imode && !Gx.index) { + if (havexmin) { + Gx.xmin = Gx.xstart + Gx.xdelta * (Gx.xmin - 1.0); } + if (havexmin) { + Gx.xmax = Gx.xstart + Gx.xdelta * (Gx.xmax - 1.0); + } + } + Gx.xmult = o.xmult; + Gx.ymult = o.xmult; + + //Convert string inputs of autox to numbers + switch (o.autox) { + case "none": + o.autox = -1; + break; + case "min": + o.autox = 1; + break; + case "max": + o.autox = 2; + break; + case "full": + o.autox = 3; + break; + } - var hcb0 = plot.get_hcb_by_lyrn(0); - if (_.size(Gx.HCB_UUID) === 0) { - Gx.note = ""; - } else if (hcb0 && hcb0.plotnote === undefined) { - // if layer 0 doesn't have a plot note, build one - var files = []; - for (var n = 0; n < Gx.HCB.length; n++) { - var hcb = plot.get_hcb_by_lyrn(n); - if (hcb.file_name) { - files.push(hcb.file_name); - } - } - Gx.note = files.join("|").toUpperCase(); + Gx.autox = o.autox === undefined ? -1 : o.autox; + if (Gx.autox < 0) { + Gx.autox = 0; + if (!havexmin) { + Gx.autox += 1; + } + if (!havexmax) { + Gx.autox += 2; } } - function draw_pcut_x(plot) { - var Mx = plot._Mx; - var Gx = plot._Gx; + //Convert string inputs of autoy to numbers + + switch (o.autoy) { + case "none": + o.autoy = -1; + break; + case "min": + o.autoy = 1; + break; + case "max": + o.autoy = 2; + break; + case "full": + o.autoy = 3; + break; + } - if ((Gx.zmin === undefined) || (Gx.zmax === undefined)) { - return; + Gx.autoy = o.autoy === undefined ? -1 : o.autoy; + if (Gx.autoy < 0) { + Gx.autoy = 0; + if (!haveymin) { + Gx.autoy += 1; } + if (!haveymax) { + Gx.autoy += 2; + } + } - //fill variables to draw x-cut box along bottom - // one-pixel lines need to be draw on half-pixel boundaries - var plot_width = Mx.r - Mx.l; - Gx.x_box_x = Math.floor(Mx.l - 2) + 0.5; - Gx.x_box_y = Math.floor(Mx.b + 25) + 0.5; - Gx.x_box_w = Math.floor(plot_width + 4); - Gx.x_box_h = Math.floor((5 * Mx.text_h) + 20); - - mx.draw_box(Mx, Mx.fg, Gx.x_box_x, Gx.x_box_y, Gx.x_box_w, Gx.x_box_h, 1, Mx.bg); + //Convert string inputs of autoz to numbers + + switch (o.autoz) { + case "none": + o.autoz = -1; + break; + case "min": + o.autoz = 1; + break; + case "max": + o.autoz = 2; + break; + case "full": + o.autoz = 3; + break; + } - var ctx = Mx.active_canvas.getContext("2d"); - ctx.beginPath(); - ctx.lineWidth = 1; - ctx.strokeStyle = Mx.fg; + Gx.autoz = o.autoz === undefined ? -1 : o.autoz; + if (Gx.autoz < 0) { + Gx.autoz = 0; + if (!havezmin) { + Gx.autoz += 1; + } + if (!havezmax) { + Gx.autoz += 2; + } + } + Gx.autol = o.autol === undefined ? -1 : o.autol; - var x = null; - var y = null; - for (var ii = 0; ii < plot._Gx.x_cut_data.length; ii++) { - var z = plot._Gx.x_cut_data[ii]; // the real z-value - // constrain to bounds - z = Math.min(Math.max(z, Gx.zmin), Gx.zmax); - var zrt = plot._Gx.x_box_h / (Gx.zmax - Gx.zmin); // the z-value to pixel ratio - var zpx = Math.round((z - Gx.zmin) * zrt); + if (!havexmin) { + Gx.xmin = undefined; + } + if (!havexmax) { + Gx.xmax = undefined; + } - var xrt = plot._Gx.x_box_w / plot._Gx.x_cut_data.length; - var xpx = Math.round(ii * xrt); + scale_base( + plot, + { + get_data: true, + }, + Gx.xmin, + Gx.xmax, + Gx.xlab, + Gx.ylab + ); - var xnew = plot._Gx.x_box_x + xpx; - var ynew = (plot._Gx.x_box_y + plot._Gx.x_box_h - zpx); + if (!havexmin) { + Gx.xmin = Mx.stk[0].xmin; + } + if (!havexmax) { + Gx.xmax = Mx.stk[0].xmax; + } + if (!haveymin) { + Gx.ymin = Mx.stk[0].ymin; + } + if (!haveymax) { + Gx.ymax = Mx.stk[0].ymax; + } - if (ii === 0) { - ctx.moveTo(xnew, ynew); - } else if ((xnew !== x) || (ynew !== y)) { - // only draw the line if we are moving to a new point - ctx.lineTo(xnew, ynew); - x = xnew; - y = ynew; - } - } - ctx.stroke(); + if (Gx.xmin > Gx.xmax) { + Mx.stk[0].xmin = Gx.xmax; + Gx.xmax = Gx.xmin; + Gx.xmin = Mx.stk[0].xmin; + } + if (Gx.ymin > Gx.ymax) { + Mx.stk[0].ymin = Gx.ymax; + Gx.ymax = Gx.ymin; + Gx.ymin = Mx.stk[0].ymin; } + Mx.stk[0].xmin = Gx.xmin; + Mx.stk[0].xmax = Gx.xmax; + Mx.stk[0].ymin = Gx.ymin; + Mx.stk[0].ymax = Gx.ymax; - function draw_pcut_y(plot) { - var Mx = plot._Mx; - var Gx = plot._Gx; + Gx.panxmin = Math.min(Gx.panxmin, Gx.xmin); + Gx.panxmax = Math.max(Gx.panxmax, Gx.xmax); + Gx.panymin = Math.min(Gx.panymin, Gx.ymin); + Gx.panymax = Math.max(Gx.panymax, Gx.ymax); - if ((Gx.zmin === undefined) || (Gx.zmax === undefined)) { - return; - } + Gx.panxpad = o.panxpad; + Gx.panypad = o.panypad; - var plot_height = Mx.b - Mx.t; + var xran = Gx.panxmax - Gx.panxmin; + var yran = Gx.panymax - Gx.panymin; - //fill variables to draw y-cut box along right sidea - // one-pixel lines need to be draw on half-pixel boundaries - Gx.y_box_x = Math.floor(Mx.r + 25) + 0.5; - Gx.y_box_y = Math.floor(Mx.t - 2) + 0.5; - Gx.y_box_w = Math.floor((5 * Mx.text_w) + 20); - Gx.y_box_h = Math.floor(plot_height + 2); + Gx.panxmin -= m.pad(xran, Gx.panxpad); + Gx.panxmax += m.pad(xran, Gx.panxpad); + Gx.panymin -= m.pad(yran, Gx.panypad); + Gx.panymax += m.pad(yran, Gx.panypad); - if (Gx.lg_colorbar) { //move over box if large colorbar displayed - Gx.y_box_x += 100; - } + Gx.xmin = Mx.stk[0].xmin; + Gx.ymin = Mx.stk[0].ymin; - //draw y-cut box - mx.draw_box(Mx, Mx.fg, Gx.y_box_x, Gx.y_box_y, Gx.y_box_w, Gx.y_box_h, 1, Mx.bg); + if (o.font_family) { + Mx.font_family = o.font_family; + } + if (o.font_width) { + Mx.font_width = o.font_width; + } + if (o.font_scaled) { + Mx.font_scaled = true; + } - var ctx = Mx.active_canvas.getContext("2d"); - ctx.beginPath(); - ctx.lineWidth = 1; - ctx.strokeStyle = Mx.fg; + var font_width = Mx.font_width; + if (Mx.font_scaled) { + font_width = Math.min(Mx.font_width, Mx.width / 64); + } + mx.set_font(Mx, font_width); + + Gx.ncolors = o.ncolors === undefined ? 500 : o.ncolors; + Gx.cmap = null; + if (o.cmap !== undefined) { + Gx.cmap = o.cmap; + } else { + Gx.cmap = o.xc === undefined ? -1 : o.xc; + } - var x = null; - var y = null; - for (var ii = 0; ii < plot._Gx.y_cut_data.length; ii++) { - var z = plot._Gx.y_cut_data[ii]; // the real z-value - // constrain to bounds - z = Math.min(Math.max(z, Gx.zmin), Gx.zmax); - var zrt = plot._Gx.y_box_w / (Gx.zmax - Gx.zmin); // the z-value to pixel ratio - var zpx = Math.round((z - Gx.zmin) * zrt); + setup_cmap(plot, Gx.cmap); - var yrt = plot._Gx.y_box_h / plot._Gx.y_cut_data.length; - var ypx = Math.round(ii * yrt); + // TODO setup annotate, boxes and points facilities - var xnew = (plot._Gx.y_box_x + zpx); - var ynew = plot._Gx.y_box_y + ypx; + // TODO initialize layer structure line types - if (ii === 0) { - ctx.moveTo(xnew, ynew); - } else if ((xnew !== x) || (ynew !== y)) { - // only draw the line if we are moving to a new point - ctx.lineTo(xnew, ynew); - x = xnew; - y = ynew; - } - } - ctx.stroke(); + if (o.xcnt === "leftmouse") { + Gx.cntrls = 1; + } else if (o.xcnt === "continuous") { + Gx.cntrls = 2; + } else { + Gx.cntrls = o.xcnt === undefined ? 1 : o.xcnt; } - function draw_layers(plot) { - let Gx = plot._Gx; - let Mx = plot._Mx; - - var layers = Gx.lyr; - for (var n = 0; n < layers.length; n++) { - //if (Gx.sections !== 0) { - // TODO - //} - draw_layer(plot, layers[n]); + Gx.default_rubberbox_mode = + o.rubberbox_mode === undefined ? "box" : o.rubberbox_mode; + Gx.default_rubberbox_action = + o.rubberbox_action === undefined ? "zoom" : o.rubberbox_action; + Gx.default_rightclick_rubberbox_mode = + o.rightclick_rubberbox_mode === undefined + ? "box" + : o.rightclick_rubberbox_mode; + Gx.default_rightclick_rubberbox_action = + o.rightclick_rubberbox_action === undefined + ? null + : o.rightclick_rubberbox_action; + + Gx.cross = o.cross === undefined ? false : o.cross; + Gx.grid = o.nogrid === undefined ? true : !o.nogrid; + Gx.fillStyle = o.fillStyle; + Gx.gridBackground = o.gridBackground; + Gx.gridStyle = o.gridStyle; + Gx.wheelZoom = o.wheelZoom; + Gx.wheelZoomPercent = o.wheelZoomPercent; + Gx.legend = o.legend === undefined ? false : o.legend; + Gx.no_legend_button = + o.no_legend_button === undefined ? false : o.no_legend_button; + Gx.legendBtnLocation = null; + Gx.pan = o.nopan === undefined ? true : !o.nopan; + Gx.nomenu = o.nomenu === undefined ? false : o.nomenu; + + // TODO Gx.lmap.ip = 0 + Gx.modmode = 0; + Gx.modlayer = -1; // 0-based indexing instead of 1 + Gx.modsource = 0; + Gx.modified = o.mod && Gx.lyr.length > 0; + // TODO Gx.marks(5) = 5 + Gx.nmark = 0; + Gx.iabsc = 0; + if (Gx.index) { + Gx.iabsc = 1; + } + // TODO if (o.specs > 0) Gx.iabsc = M$SEARCH('IRS',c(1:1)) + Gx.specs = !o.nospecs; + + Gx.scroll_time_interval = + o.scroll_time_interval === undefined + ? Gx.scroll_time_interval + : o.scroll_time_interval; + + Gx.autohide_readout = o.autohide_readout; + Gx.autohide_panbars = o.autohide_panbars; + Gx.x_scrollbar_location = o.x_scrollbar_location; + if (Gx.specs) { + Gx.show_x_axis = !o.noxaxis; + Gx.show_y_axis = !o.noyaxis; + Gx.show_readout = !o.noreadout; + if (Gx.show_x_axis || Gx.show_y_axis || Gx.show_readout) { + Gx.specs = true; + } else { + Gx.specs = false; } + } else { + Gx.show_x_axis = false; + Gx.show_y_axis = false; + Gx.show_readout = false; + } + Gx.hide_note = o.hide_note || false; - // if we are allowing auto-scaling on y - if ((Gx.autol > 1) && (Gx.panymin !== undefined) && (Gx.panymax !== undefined)) { - var fac = 1.0 / (Math.max(Gx.autol, 1)); - - Gx.panymin = Gx.panymin * fac + Mx.stk[0].ymin * (1.0 - fac); - Gx.panymax = Gx.panymax * fac + Mx.stk[0].ymax * (1.0 - fac); + Gx.xmrk = 0.0; + Gx.ymrk = 0.0; - if (((Gx.autoy & 1) !== 0)) { - Mx.stk[0].ymin = Gx.panymin; - } - if (((Gx.autoy & 2) !== 0)) { - Mx.stk[0].ymax = Gx.panymax; - } - } + if (!o.nodragdrop) { + mx.addEventListener( + Mx, + "dragover", + function (evt) { + evt.preventDefault(); + }, + false + ); + + mx.addEventListener( + Mx, + "drop", + (function (plot) { + return function (evt) { + var files = evt.dataTransfer.files; + if (files.length > 0) { + evt.preventDefault(); + plot.load_files(files); + } + }; + })(plot), + false + ); } - /** - * Draws the specified layer. - * - * This is expected to be called after clearing the plot. - * - * @param {sigplot.Plot} - * the plot object - * @param {Number} - * the layer to draw - * @private - * @memberOf sigplot - */ - function draw_layer(plot, layer) { - var Mx = plot._Mx; - var Gx = plot._Gx; + Gx.initialized = true; +} - if ((!layer.display) || (Gx.hold !== 0)) { - return; +/** + * @memberOf sigplot + * @private + */ +function basefile(plot, open) { + var Gx = plot._Gx; + var Mx = plot._Mx; + // != BASEFILE(false) + + // unlike SIGPLOT, where if Gx.index == 1 + // then xstart = 1.0 and xdelta = 1.0...technically + // Gx.retx is supposed to be the real X coordinate + // and Gx.aretx is supposed to be the X coordinate in the + // current abscissa mode + var hcb = plot.get_hcb_by_lyrn(0); + if (open) { + if (hcb) { + Gx.xstart = hcb.xstart; + Gx.xdelta = hcb.xdelta; + } else { + Gx.xstart = 0.0; + Gx.xdelta = 1.0; } - - let lyr_bnds = layer.draw(); - if (lyr_bnds && Gx.autol !== 0) { - set_panbounds(plot, lyr_bnds); + Mx.origin = 1; + if (Gx.autoz & 1) { + Gx.zmin = undefined; } - - // TODO consider if this is a source of performance - // issues on streaming plots - var evt = document.createEvent('Event'); - evt.initEvent('lyrdraw', true, true); - evt.index = layer.index; - evt.name = layer.name; // the name of the layer - evt.layer = layer; - mx.dispatchEvent(Mx, evt); - } - - /** - * @memberOf sigplot - * @private - */ - function delete_layer(plot, n) { - var Gx = plot._Gx; - var Mx = plot._Mx; - //if (n < Gx.modlayer) Gx.modlayer = Gx.modlayer - 1; - //if (n < Gx.modsource) Gx.modsource = Gx.modsource - 1; - - // Notify listeners that a layer is about to be deleted - var evt = document.createEvent('Event'); - evt.initEvent('lyrdel', true, true); - evt.index = n; - evt.name = Gx.lyr[n].name; // the name of the layer - evt.layer = Gx.lyr[n]; - var executeDefault = mx.dispatchEvent(Mx, evt); - if (!executeDefault) { - return; // Delete was prevented + if (Gx.autoz & 2) { + Gx.zmax = undefined; } - - Gx.lyr[n].ybufn = 0; - Gx.lyr[n].ybuf = null; - if (n < Gx.lyr.length - 1) { - var lyr = Gx.lyr[n]; - for (var i = n; i < Gx.lyr.length - 1; i++) { - Gx.lyr[i] = Gx.lyr[i + 1]; - } + } else { + Gx.xstart = 0.0; + Gx.xdelta = 1.0; + Gx.autol = -1; + Mx.origin = 1; + if (Gx.autoz & 1) { + Gx.zmin = undefined; } - Gx.lyr.length -= 1; - - if (_.size(Gx.HCB_UUID) > 0) { - Gx.panxmin = 1.0; - Gx.panxmax = -1.0; - Gx.panymin = 1.0; - Gx.panymax = -1.0; + if (Gx.autoz & 2) { + Gx.zmax = undefined; } } - /** - * @memberOf sigplot - * @private - */ - - function draw_p_cuts(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; - if (Gx.lyr[0].hcb["class"] !== 2) { - return; - } - var plot_height = Mx.b - Mx.t; - var plot_width = Mx.r - Mx.l; - var height = Gx.lyr[0].yframe; - var width = Gx.lyr[0].xframe; - - if (Gx.p_cuts) { - if (!Gx.lyr[0].hcb.pipe) { - if (((Mx.xpos >= Mx.l) && (Mx.xpos <= Mx.r) && (Gx.p_cuts_xpos !== Mx.xpos))) { - var line = 0; - var i = 0; - - //fill data for y_cut for this mouse xpos - Gx.y_cut_data = []; - line = Math.floor((width * (Mx.xpos - Mx.l)) / plot_width); - for (i = line; i < (width * height); i += width) { - Gx.y_cut_data.push(Gx.lyr[0].zbuf[i]); - } - draw_pcut_y(plot); - Gx.p_cuts_xpos = Mx.xpos; - } - if (((Mx.ypos >= Mx.t) && (Mx.ypos <= Mx.b) && (Gx.p_cuts_ypos !== Mx.ypos))) { - var row = 0; - var start = 0; - var finish = 0; - var i = 0; - - //fill data for x_cut for this mouse ypos - row = Math.floor((height * (Mx.ypos - Mx.t)) / plot_height); - start = row * width; - finish = start + width; - Gx.x_cut_data = Gx.lyr[0].zbuf.slice(start, finish); - draw_pcut_x(plot); - - Gx.p_cuts_ypos = Mx.ypos; - } - } else { - if ((Mx.xpos >= Mx.l) && (Mx.xpos <= Mx.r)) { - var line = 0; - var i = 0; - height = Gx.lyr[0].lps; - //fill data for y_cut for this mouse xpos - Gx.y_cut_data = []; - line = Math.floor((width * (Mx.xpos - Mx.l)) / plot_width); - for (i = line; i < (width * height); i += width) { - Gx.y_cut_data.push(Gx.lyr[0].zbuf[i]); - } - draw_pcut_y(plot); - } + // if (!open) { + // Gx.lay[0].cx = false; + // } +} - if ((Mx.ypos >= Mx.t) && (Mx.ypos <= Mx.b)) { - var row = 0; - var start = 0; - var finish = 0; - //fill data for x_cut for this mouse ypos - Gx.x_cut_data = []; - row = Math.floor((height * (Mx.ypos - Mx.t)) / plot_height); - start = row * width; - finish = start + width; - Gx.x_cut_data = Gx.lyr[0].zbuf.slice(start, finish); - draw_pcut_x(plot); - } - } +/** + * @memberOf sigplot + * @private + */ +function draw_accessories(plot, mode) { + var Mx = plot._Mx; + var Gx = plot._Gx; + if (mode > 0) { + if (mode >= 4 && Gx.show_readout && !Gx.hide_note) { + var ln = Gx.note.length; + mx.text( + Mx, + Mx.width - Gx.lbtn - (ln + 1) * Mx.text_w, + Mx.text_h, + Gx.note + ); + } + if (mode >= 4) { + draw_panbars(plot); + } + if (mode >= 1 && Gx.legend) { + draw_legend(plot); } } +} - /** - * @memberOf sigplot - * @private - */ - function draw_crosshairs(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; +/** + * @memberOf sigplot + * @private + */ +function draw_plugins(plot) { + var Gx = plot._Gx; + var ctx = plot._Mx.canvas.getContext("2d"); + var canvas; - if (Gx.cross) { - if ((Gx.cross === "vertical") || (Gx.cross === true)) { - if ((Mx.xpos >= Mx.l) && (Mx.xpos <= Mx.r) && (Gx.cross_xpos !== Mx.xpos)) { - if (Gx.cross_xpos !== undefined) { - mx.rubberline(Mx, Gx.cross_xpos, Mx.t, Gx.cross_xpos, Mx.b); - } - mx.rubberline(Mx, Mx.xpos, Mx.t, Mx.xpos, Mx.b); - Gx.cross_xpos = Mx.xpos; - } - } - if ((Gx.cross === "horizontal") || (Gx.cross === true)) { - if ((Mx.ypos >= Mx.t) && (Mx.ypos <= Mx.b) && (Gx.cross_ypos !== Mx.ypos)) { - if (Gx.cross_ypos !== undefined) { - mx.rubberline(Mx, Mx.l, Gx.cross_ypos, Mx.r, Gx.cross_ypos); - } + var plugin_index = 0; + while (plugin_index < Gx.plugins.length) { + var plugin = Gx.plugins[plugin_index].impl; + if (plugin.refresh) { + canvas = Gx.plugins[plugin_index].canvas; - mx.rubberline(Mx, Mx.l, Mx.ypos, Mx.r, Mx.ypos); - Gx.cross_ypos = Mx.ypos; - } + // Ensure the plugin canvas has the same size as the plot + if (canvas.width !== plot._Mx.canvas.width) { + canvas.width = plot._Mx.canvas.width; + } + if (canvas.height !== plot._Mx.canvas.height) { + canvas.height = plot._Mx.canvas.height; } - } - } - - /** - * @memberOf sigplot - * @private - */ - function draw_marker(plot) { - var Gx = plot._Gx; - var Mx = plot._Mx; - if (Gx.xmrk !== null && Gx.ymrk !== null) { - var pix = mx.real_to_pixel(Mx, Gx.xmrk, Gx.ymrk); - if ((Gx.lyr.length > 0) && (Gx.lyr[0].hcb["class"] === 1)) { - if (pix.clipped) { - return; + // If the plugin canvas is visible, draw it + if (canvas.height !== 0 && canvas.width !== 0) { + if (canvas.width !== plot._Mx.canvas.width) { + canvas.width = plot._Mx.canvas.width; } - } else if ((Gx.lyr.length > 0) && (Gx.lyr[0].hcb["class"] === 2)) { - if (pix.clipped_x || !pix.clipped_y) { - return; + if (canvas.height !== plot._Mx.canvas.height) { + canvas.height = plot._Mx.canvas.height; } + canvas + .getContext("2d") + .clearRect(0, 0, canvas.width, canvas.height); + Gx.plugins[plugin_index].impl.refresh(canvas); + ctx.drawImage(canvas, 0, 0); } - var ctx = Mx.active_canvas.getContext("2d"); - ctx.beginPath(); - ctx.strokeStyle = Mx.xwfg; - ctx.fillStyle = Mx.xwfg; - ctx.arc(pix.x, pix.y, 2, 0, 360); - ctx.stroke(); // just draw the arc's outline - - // TODO add x/y coord - ctx.textBaseline = "alphabetic"; - ctx.textAlign = "left"; - ctx.fillStyle = Mx.fg; - ctx.font = Mx.font.font; - - var text = "x:" + mx.format_g(Gx.xmrk, 6, 3, true); - ctx.fillText(text, pix.x + 5, pix.y - 5); - text = "y:" + mx.format_g(Gx.ymrk, 6, 3, true); - ctx.fillText(text, pix.x + 5, pix.y - 5 + Mx.text_h); } + plugin_index = plugin_index + 1; } +} - /** - * @memberOf sigplot - * @private - */ - function changephunits(plot, newphunits) { - var Gx = plot._Gx; - var Mx = plot._Mx; - var newplab = Gx.plab; - if (newphunits === 'R') { - newplab = 23; - } else if (newphunits === 'D') { - newplab = 24; - } - if (newphunits === 'C') { - newplab = 25; - } - if (newplab !== Gx.plab) { - var phscale = [Math.PI, 180.0, 0.5]; - var dscl = phscale[newplab - 23] / phscale[Gx.plab - 23]; - Gx.plab = newplab; - if (Gx.cmode === 2) { - for (var i = 0; i <= Mx.level; i++) { - Mx.stk[i].ymin = Mx.stk[i].ymin * dscl; - Mx.stk[i].ymax = Mx.stk[i].ymax * dscl; - Mx.stk[i].yscl = Mx.stk[i].yscl * dscl; - } +function get_legend_pos(plot) { + var Mx = plot._Mx; + var Gx = plot._Gx; - Gx.panymin = Gx.panymin * dscl; - Gx.panymax = Gx.panymax * dscl; - plot.refresh(); - } + var tw = Mx.text_w; + var xs = tw * 23; + var ys = (Gx.lyr.length + 1) * Mx.text_h; + var xc = Mx.r - xs; + var yc = Mx.t; + + var legendPos = { + x: xc + 2, + y: yc + 2, + width: xs - 5, + height: ys - 5, + }; // default legend size + + return legendPos; +} + +/** + * @memberOf sigplot + * @private + */ +function draw_legend(plot) { + var Mx = plot._Mx; + var Gx = plot._Gx; + //Gx.always_show_marker = true; + var ctx = Mx.canvas.getContext("2d"); + + var i = 0; + var n = 0; // integer*4 + var ix = 0; // integer*4 + var iy = 0; // integer*4 + var ln = 0; // integer*4 + var tw = 0; // integer*4 + var xc = 0; // integer*4 + var yc = 0; // integer*4 + var xs = 0; // integer*4 + var ys = 0; // integer*4 + var thk = 0; // integer*4 + var ic = 0; // integer*4 + + tw = Mx.text_w; + xs = tw * 23; + ys = (Gx.lyr.length + 1) * Mx.text_h; + xc = Mx.r - xs; + yc = Mx.t; + + var legendPos = get_legend_pos(plot); + + // Determine legend position and label offset based on label sizes + var defLabelWidth = 98; // a magic number - default width of pixels + var maxLabelWidth = 0; + var labelOffset = 0; + for (n = 0; n < Gx.lyr.length; n++) { + // figure out maximum label + // length + var labelLength = ctx.measureText(Gx.lyr[n].name).width; + if (labelLength > maxLabelWidth) { + maxLabelWidth = labelLength; } } + if (maxLabelWidth > defLabelWidth) { + labelOffset = maxLabelWidth - defLabelWidth; + legendPos.width += labelOffset; + legendPos.x -= labelOffset; + } - /** - * @memberOf sigplot - * @private - */ - function changemode(plot, newmode) { - var Mx = plot._Mx; - var Gx = plot._Gx; - - Gx.xdata = false; - for (var n = 0; n < Gx.lyr.length; n++) { - if (newmode === 5) { - Gx.lyr[n].xdata = true; - } else { - Gx.lyr[n].xdata = false; // TODO (Gx.lyr(n).xsub > 0) - } - if (Gx.lyr[n].xdata) { - Gx.xdata = true; + ctx.strokeStyle = Mx.fg; // Mx.xwfg swapped in for FGColor + ctx.fillStyle = Mx.bg; + ctx.fillRect( + legendPos.x, + legendPos.y, + legendPos.width, + legendPos.height + ); // Creating a filled box instead of using + // clear_area + ctx.strokeRect( + legendPos.x, + legendPos.y, + legendPos.width, + legendPos.height + ); + + for (n = 0; n < Gx.lyr.length; n++) { + ix = Math.floor(xc + 4 * tw); + iy = Math.floor(yc + n * Mx.text_h + Mx.text_h); // additional text_h to + // account for 0-based + // indexing + if (n === Gx.modlayer) { + mx.text( + Mx, + xc + tw - labelOffset, + iy + Math.floor(Mx.text_w / 2), + "**" + ); // Added text_w/2 + // offset + } + if (Gx.lyr[n].display) { + // TODO refactor this code so that each layer type is responsible + // for drawing it's own legend icon, providing flexibliity down the road + // for other layer types + if (Gx.lyr[n] instanceof Layer1D) { + ic = Gx.lyr[n].color; + if (Gx.lyr[n].line > 0) { + thk = m.sign( + Math.min(tw, Math.abs(Gx.lyr[n].thick)), + Gx.lyr[n].thick + ); + // added magic -3 offset to y coordinates to center lines + // with text + if (thk < 0 || thk === mx.L_dashed) { + mx.draw_line( + Mx, + ic, + ix - labelOffset, + iy - 3, + ix + tw * 2 - labelOffset, + iy - 3, + Math.abs(thk), + { + mode: "dashed", + on: 4, + off: 4, + } + ); + } else { + mx.draw_line( + Mx, + ic, + ix - labelOffset, + iy - 3, + ix + tw * 2 - labelOffset, + iy - 3, + Math.abs(thk) + ); + } + } + if (Gx.lyr[n].symbol > 0) { + // New logic here with 0.6*tw to help with legend symbol + // sizing + if (Gx.lyr[n].radius < 0) { + thk = -m.trunc(0.6 * tw); + } else { + thk = Math.min(Gx.lyr[n].radius, m.trunc(0.6 * tw)); + } + + mx.draw_symbol( + Mx, + ic, + ix + tw - labelOffset, + iy - 3, + Gx.lyr[n].symbol, + thk + ); + } + } else if (Gx.lyr[n] instanceof Layer2D) { + //draw colorbar for 2D layers. The bar needs to leave space for the modlayer + // icon which occupies the first text-width + mx.legend_colorbar( + Mx, + xc + 2 * tw - labelOffset, + iy - Mx.text_h / 2, + tw * 4, + Mx.text_h / 2 + ); } } + ix = ix + tw * 3; + iy = iy + Mx.text_h * 0.3; + mx.text(Mx, ix - labelOffset, iy, Gx.lyr[n].name); + } +} - if (newmode === Gx.cmode) { - return; - } else if (newmode === 5 && Gx.index) { - m.log.error("Imag/Real mode not permitted in INDEX mode"); - } else if (Gx.lyr.length <= 0) { - Gx.cmode = newmode; - // The call to display specs isn't found in sigplot.for; - // which causes a small bug where the plot mode is - // changed but the mode label in the specs area - // isn't updated. - display_specs(plot); - } else if (newmode > 0) { - var oldmode = Gx.cmode; - Gx.cmode = newmode; - - var autox = Gx.autox; - var autoy = Gx.autoy; - Gx.autox = 3; - Gx.autoy = 3; - - if ((newmode === 5) || (oldmode === 5)) { - Gx.panxmin = 1.0; - Gx.panxmax = -1.0; - Gx.panymin = 1.0; - Gx.panymax = -1.0; - Mx.level = 0; +/** + * @memberOf sigplot + * @private + */ +function form_plotnote(plot) { + var Gx = plot._Gx; + if (Gx.note) { + return; + } - if (newmode === Gx.basemode) { - Mx.stk[0].xmin = Gx.xmin; - Mx.stk[0].xmax = Gx.xmax; - Mx.stk[0].ymin = Gx.ymin; - Mx.stk[0].ymax = Gx.ymax; - } else if ((newmode === 5) || (Gx.basemode === 5)) { - scale_base(plot, { - get_data: true - }); - } else { - Mx.stk[0].xmin = Gx.xmin; - Mx.stk[0].xmax = Gx.xmax; - scale_base(plot, { - get_data: true - }, Gx.xmin, Gx.xmax); - } - } else { - if ((_.size(Gx.HCB_UUID) === 0) && (newmode === Gx.basemode)) { - Gx.panymin = 1.0; - Gx.panymax = -1.0; - Mx.stk[0].ymin = Gx.ymin; - Mx.stk[0].ymax = Gx.ymax; - } else { - scale_base(plot, {}, Mx.stk[Mx.level].xmin, - Mx.stk[Mx.level].xmax); - } - for (var n = 1; n <= Mx.level; n++) { - Mx.stk[n].ymin = Mx.stk[0].ymin; - Mx.stk[n].ymax = Mx.stk[0].ymax; - } + var hcb0 = plot.get_hcb_by_lyrn(0); + if (size(Gx.HCB_UUID) === 0) { + Gx.note = ""; + } else if (hcb0 && hcb0.plotnote === undefined) { + // if layer 0 doesn't have a plot note, build one + var files = []; + for (var n = 0; n < Gx.HCB.length; n++) { + var hcb = plot.get_hcb_by_lyrn(n); + if (hcb.file_name) { + files.push(hcb.file_name); } - Gx.autox = autox; - Gx.autoy = autoy; - plot.refresh(); } + Gx.note = files.join("|").toUpperCase(); } +} - /** - * @memberOf sigplot - * @private - */ - function draw_panbars(plot) { - var k; // integer*4 - //var i1; // integer*4 - //var itext; // integer*4 +function draw_pcut_x(plot) { + var Mx = plot._Mx; + var Gx = plot._Gx; - var Mx = plot._Mx; - var Gx = plot._Gx; + if (Gx.zmin === undefined || Gx.zmax === undefined) { + return; + } - if ((!Gx.pan) || (Mx.widget)) { - return; + //fill variables to draw x-cut box along bottom + // one-pixel lines need to be draw on half-pixel boundaries + var plot_width = Mx.r - Mx.l; + Gx.x_box_x = Math.floor(Mx.l - 2) + 0.5; + Gx.x_box_y = Math.floor(Mx.b + 25) + 0.5; + Gx.x_box_w = Math.floor(plot_width + 4); + Gx.x_box_h = Math.floor(5 * Mx.text_h + 20); + + mx.draw_box( + Mx, + Mx.fg, + Gx.x_box_x, + Gx.x_box_y, + Gx.x_box_w, + Gx.x_box_h, + 1, + Mx.bg + ); + + var ctx = Mx.active_canvas.getContext("2d"); + ctx.beginPath(); + ctx.lineWidth = 1; + ctx.strokeStyle = Mx.fg; + + var x = null; + var y = null; + for (var ii = 0; ii < plot._Gx.x_cut_data.length; ii++) { + var z = plot._Gx.x_cut_data[ii]; // the real z-value + // constrain to bounds + z = Math.min(Math.max(z, Gx.zmin), Gx.zmax); + var zrt = plot._Gx.x_box_h / (Gx.zmax - Gx.zmin); // the z-value to pixel ratio + var zpx = Math.round((z - Gx.zmin) * zrt); + + var xrt = plot._Gx.x_box_w / plot._Gx.x_cut_data.length; + var xpx = Math.round(ii * xrt); + + var xnew = plot._Gx.x_box_x + xpx; + var ynew = plot._Gx.x_box_y + plot._Gx.x_box_h - zpx; + + if (ii === 0) { + ctx.moveTo(xnew, ynew); + } else if (xnew !== x || ynew !== y) { + // only draw the line if we are moving to a new point + ctx.lineTo(xnew, ynew); + x = xnew; + y = ynew; } + } + ctx.stroke(); +} - k = Mx.level; // Y scrollbar +function draw_pcut_y(plot) { + var Mx = plot._Mx; + var Gx = plot._Gx; - var out = { - ps: Mx.stk[k].ymin, - pe: Mx.stk[k].ymax - }; - var need_y_scrollbar = ((out.ps !== Gx.panymin) || (out.pe !== Gx.panymax)); - need_y_scrollbar = need_y_scrollbar && (Mx.level > 0); + if (Gx.zmin === undefined || Gx.zmax === undefined) { + return; + } - if (Gx.autohide_panbars && (!need_y_scrollbar || !plot.mouseOnCanvas) && !Gx.panning) { - var ctx = Mx.canvas.getContext("2d"); - ctx.fillStyle = Mx.bg; - ctx.fillRect(Gx.pyl, Mx.t, Gx.pyl + Gx.pthk, Mx.b - Mx.t); - } else { - var i1 = mx.scrollbar(Mx, 0, Gx.pyl, Gx.pyl + Gx.pthk, Mx.t, Mx.b, out, - Gx.panymin, Gx.panymax, undefined, Mx.scrollbar_y); - Mx.stk[k].ymin = out.ps; - Mx.stk[k].ymax = out.pe; - } + var plot_height = Mx.b - Mx.t; - if (Gx.pl < Mx.width) { // X scrollbar - out = { - ps: Mx.stk[k].xmin, - pe: Mx.stk[k].xmax - }; - var need_x_scrollbar = ((out.ps !== Gx.panxmin) || (out.pe !== Gx.panxmax)); - need_x_scrollbar = need_x_scrollbar && (!Gx.all || (Mx.level > 0)); + //fill variables to draw y-cut box along right sidea + // one-pixel lines need to be draw on half-pixel boundaries + Gx.y_box_x = Math.floor(Mx.r + 25) + 0.5; + Gx.y_box_y = Math.floor(Mx.t - 2) + 0.5; + Gx.y_box_w = Math.floor(5 * Mx.text_w + 20); + Gx.y_box_h = Math.floor(plot_height + 2); - if (Gx.autohide_panbars && (!need_x_scrollbar || !plot.mouseOnCanvas) && !Gx.panning) { - var ctx = Mx.canvas.getContext("2d"); - ctx.fillStyle = Mx.bg; - ctx.fillRect(Gx.pl, Gx.pt - 1, Gx.pr - Gx.pl, Gx.pthk + 4); - } else { - var i1 = mx.scrollbar(Mx, 0, Gx.pl, Gx.pr, Gx.pt, Gx.pt + Gx.pthk, out, - Gx.panxmin, Gx.panxmax, undefined, Mx.scrollbar_x); - Mx.stk[k].xmin = out.ps; - Mx.stk[k].xmax = out.pe; - } + if (Gx.lg_colorbar) { + //move over box if large colorbar displayed + Gx.y_box_x += 100; + } + + //draw y-cut box + mx.draw_box( + Mx, + Mx.fg, + Gx.y_box_x, + Gx.y_box_y, + Gx.y_box_w, + Gx.y_box_h, + 1, + Mx.bg + ); + + var ctx = Mx.active_canvas.getContext("2d"); + ctx.beginPath(); + ctx.lineWidth = 1; + ctx.strokeStyle = Mx.fg; + + var x = null; + var y = null; + for (var ii = 0; ii < plot._Gx.y_cut_data.length; ii++) { + var z = plot._Gx.y_cut_data[ii]; // the real z-value + // constrain to bounds + z = Math.min(Math.max(z, Gx.zmin), Gx.zmax); + var zrt = plot._Gx.y_box_w / (Gx.zmax - Gx.zmin); // the z-value to pixel ratio + var zpx = Math.round((z - Gx.zmin) * zrt); + + var yrt = plot._Gx.y_box_h / plot._Gx.y_cut_data.length; + var ypx = Math.round(ii * yrt); + + var xnew = plot._Gx.y_box_x + zpx; + var ynew = plot._Gx.y_box_y + ypx; + + if (ii === 0) { + ctx.moveTo(xnew, ynew); + } else if (xnew !== x || ynew !== y) { + // only draw the line if we are moving to a new point + ctx.lineTo(xnew, ynew); + x = xnew; + y = ynew; } } + ctx.stroke(); +} + +function draw_layers(plot) { + let Gx = plot._Gx; + let Mx = plot._Mx; + + var layers = Gx.lyr; + for (var n = 0; n < layers.length; n++) { + //if (Gx.sections !== 0) { + // TODO + //} + draw_layer(plot, layers[n]); + } - /** - * @memberOf sigplot - * @private - */ - function pan(plot, action, flag, mouseEvent) { - var Mx = plot._Mx; - var Gx = plot._Gx; + // if we are allowing auto-scaling on y + if ( + Gx.autol > 1 && + Gx.panymin !== undefined && + Gx.panymax !== undefined + ) { + var fac = 1.0 / Math.max(Gx.autol, 1); - var i; // an integer*4 - var k; // an integer*4 - // var ih // an integer*4 - // var iw; // an integer*4 - // var imin; // an integer*4 - // var imax; // an integer*4 - var j; // an integer*4 - var xmin; // a real*8 - var xmax; // a real*8 - var xran; // a real*8 - // var xtemp; // a real*8 - var ymin; // a real*8 - var ymax; // a real*8 - var yran; // a real*8 - // var ytemp; // a real*8 - var warn; // a logical*4 - - var scrollbarState; - - var sbx = new mx.SCROLLBAR(); // a SCROLLBAR - var sby = new mx.SCROLLBAR(); // a SCROLLBAR - - var SIGPLOT_PAN = false; - k = Mx.level; - if (Gx.panmode > 0) { - sbx.flag = 11; - sby.flag = 11; - } else { - sbx.flag = -12; - sby.flag = -12; + Gx.panymin = Gx.panymin * fac + Mx.stk[0].ymin * (1.0 - fac); + Gx.panymax = Gx.panymax * fac + Mx.stk[0].ymax * (1.0 - fac); + + if ((Gx.autoy & 1) !== 0) { + Mx.stk[0].ymin = Gx.panymin; } - if (flag === 0) { - sbx.action = 0; - sby.action = 0; + if ((Gx.autoy & 2) !== 0) { + Mx.stk[0].ymax = Gx.panymax; } + } +} - warn = true; - if (action.substring(0, 1) === 'Y') { - ymin = Mx.stk[k].ymin; - ymax = Mx.stk[k].ymax; - yran = ymax - ymin; - if (action === 'YPAN') { - scrollbarState = Mx.scrollbar_y; - - var out = { - ps: ymin, - pe: ymax - }; - i = mx - .scrollbar(Mx, sby, Gx.pyl, Gx.pyl + Gx.pthk, Mx.t, - Mx.b, out, Gx.panymin, Gx.panymax, mouseEvent, - scrollbarState); - ymin = out.ps; - ymax = out.pe; - // TODO: Warn only if Scrollbar arrow is pressed and no - // movement. - if (sby.action !== 0) { - j = mx.scroll(Mx, sby, mx.XW_UPDATE, undefined, - scrollbarState); - } - warn = false; - } else if (action === 'YCENTER') { - // Orig code : ymin = ymin - yran * (Mx.ypos - (Mx.t + Mx.b) / - // 2) / (Mx.b - Mx.t) // TODO Worry about any int division here? - ymin = ymin - yran * (Mx.ypos - (Mx.t + Mx.b) / 2) / (Mx.b - Mx.t); - ymax = ymin + yran; - warn = false; - } - - if (ymin !== Mx.stk[k].ymin || ymax !== Mx.stk[k].ymax) { - Mx.stk[k].ymin = ymin; - Mx.stk[k].ymax = ymax; - if (Gx.cmode === Gx.basemode && Mx.level === 1) { - Gx.ymin = Math.min(Gx.ymin, ymin); - Gx.ymax = Math.max(Gx.ymax, ymax); - } +/** + * Draws the specified layer. + * + * This is expected to be called after clearing the plot. + * + * @param {sigplot.Plot} + * the plot object + * @param {Number} + * the layer to draw + * @private + * @memberOf sigplot + */ +function draw_layer(plot, layer) { + var Mx = plot._Mx; + var Gx = plot._Gx; - plot.inPan = true; // prevent recursive pans - var evt = document.createEvent('Event'); - evt.initEvent('ypan', true, true); - evt.level = Mx.level; - evt.xmin = Mx.stk[Mx.level].xmin; - evt.ymin = Mx.stk[Mx.level].ymin; - evt.xmax = Mx.stk[Mx.level].xmax; - evt.ymax = Mx.stk[Mx.level].ymax; - mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? - plot.inPan = false; + if (!layer.display || Gx.hold !== 0) { + return; + } - plot.refresh(); - // MSGDO(MSK_PANY, Mx.level); // just sets plotinfo.xmin and - // xmax into the MQD for the menu - SIGPLOT_PAN = true; - } - // TODO Later - Implement a messagebox status method - // else if (warn) { - // mx.message('All panned out', -1.0); - // } - } else { - xmin = Mx.stk[k].xmin; - xmax = Mx.stk[k].xmax; - xran = xmax - xmin; - if (action === 'XPAN') { - scrollbarState = Mx.scrollbar_x; - - var out = { - ps: xmin, - pe: xmax - }; - i = mx - .scrollbar(Mx, sbx, Gx.pl, Gx.pr, Gx.pt, Gx.pt + Gx.pthk, out, Gx.panxmin, Gx.panxmax, - mouseEvent, scrollbarState); - xmin = out.ps; - xmax = out.pe; - // TODO: Warn only if Scrollbox arrow is pressed and no - // movement. - if (sbx.action !== 0) { - j = mx.scroll(Mx, sbx, mx.XW_UPDATE, undefined, - scrollbarState); - } - warn = false; - } else if (action === 'XCENTER') { - // Original code : xmin = xmin + xran * (Mx.xpos - (Mx.l + Gx.r) - // / 2) / (Mx.r - Mx.l) // TODO Worry about any int division - // here? - xmin = xmin + xran * (Mx.xpos - (Mx.l + Mx.r) / 2) / (Mx.r - Mx.l); - if (xmin !== Mx.stk[k].xmin) { - xmax = xmin + xran; - } - warn = false; - } + let lyr_bnds = layer.draw(); + if (lyr_bnds && Gx.autol !== 0) { + set_panbounds(plot, lyr_bnds); + } - if (Mx.stk[k].xmin !== xmin || Mx.stk[k].xmax !== xmax) { - Mx.stk[k].xmin = xmin; - Mx.stk[k].xmax = xmax; - if (!Gx.xdata && Mx.level === 1) { - Gx.xmin = Mx.stk[1].xmin; - Gx.xmax = Mx.stk[1].xmax; - } + // TODO consider if this is a source of performance + // issues on streaming plots + var evt = document.createEvent("Event"); + evt.initEvent("lyrdraw", true, true); + evt.index = layer.index; + evt.name = layer.name; // the name of the layer + evt.layer = layer; + mx.dispatchEvent(Mx, evt); +} - plot.inPan = true; // prevent recursive pans - var evt = document.createEvent('Event'); - evt.initEvent('xpan', true, true); - evt.level = Mx.level; - evt.xmin = Mx.stk[Mx.level].xmin; - evt.ymin = Mx.stk[Mx.level].ymin; - evt.xmax = Mx.stk[Mx.level].xmax; - evt.ymax = Mx.stk[Mx.level].ymax; - mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? - plot.inPan = false; +/** + * @memberOf sigplot + * @private + */ +function delete_layer(plot, n) { + var Gx = plot._Gx; + var Mx = plot._Mx; + //if (n < Gx.modlayer) Gx.modlayer = Gx.modlayer - 1; + //if (n < Gx.modsource) Gx.modsource = Gx.modsource - 1; + + // Notify listeners that a layer is about to be deleted + var evt = document.createEvent("Event"); + evt.initEvent("lyrdel", true, true); + evt.index = n; + evt.name = Gx.lyr[n].name; // the name of the layer + evt.layer = Gx.lyr[n]; + var executeDefault = mx.dispatchEvent(Mx, evt); + if (!executeDefault) { + return; // Delete was prevented + } - plot.refresh(); - // MSGDO (MSK_PANX, Mx.level); // just sets plotinfo.xmin and - // xmax into the MQD for the menu - SIGPLOT_PAN = true; - } - // TODO Later - Implement a messagebox status method - // else if (warn) { - // mx.message('All panned out', -1.0); - // } + Gx.lyr[n].ybufn = 0; + Gx.lyr[n].ybuf = null; + if (n < Gx.lyr.length - 1) { + var lyr = Gx.lyr[n]; + for (var i = n; i < Gx.lyr.length - 1; i++) { + Gx.lyr[i] = Gx.lyr[i + 1]; } + } + Gx.lyr.length -= 1; - return SIGPLOT_PAN; + if (size(Gx.HCB_UUID) > 0) { + Gx.panxmin = 1.0; + Gx.panxmax = -1.0; + Gx.panymin = 1.0; + Gx.panymax = -1.0; } +} +/** + * @memberOf sigplot + * @private + */ - /** - * Direct method to handle the dragging of a scrollbar. - * - * @param plot - * The plot to work with. - * @param scrollAction - * The scroll action being performed. Either "YPAN" or "XPAN" are - * accepted. - * @param event - * The mouse move event. - * @private - * @memberOf sigplot - */ - function drag_scrollbar(plot, scrollAction, event) { - var Mx = plot._Mx; - var Gx = plot._Gx; - var min; - var max; - - // ----- Retrieve appropriate SCROLLBAR ----- - var scrollbar; - if (scrollAction === "XPAN") { - scrollbar = plot._Mx.scrollbar_x; - } else if (scrollAction === "YPAN") { - scrollbar = plot._Mx.scrollbar_y; +function draw_p_cuts(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + if (Gx.lyr[0].hcb["class"] !== 2) { + return; + } + + var plot_height = Mx.b - Mx.t; + var plot_width = Mx.r - Mx.l; + var height = Gx.lyr[0].yframe; + var width = Gx.lyr[0].xframe; + + if (Gx.p_cuts) { + if (!Gx.lyr[0].hcb.pipe) { + if ( + Mx.xpos >= Mx.l && + Mx.xpos <= Mx.r && + Gx.p_cuts_xpos !== Mx.xpos + ) { + var line = 0; + var i = 0; + + //fill data for y_cut for this mouse xpos + Gx.y_cut_data = []; + line = Math.floor((width * (Mx.xpos - Mx.l)) / plot_width); + for (i = line; i < width * height; i += width) { + Gx.y_cut_data.push(Gx.lyr[0].zbuf[i]); + } + draw_pcut_y(plot); + Gx.p_cuts_xpos = Mx.xpos; + } + if ( + Mx.ypos >= Mx.t && + Mx.ypos <= Mx.b && + Gx.p_cuts_ypos !== Mx.ypos + ) { + var row = 0; + var start = 0; + var finish = 0; + var i = 0; + + //fill data for x_cut for this mouse ypos + row = Math.floor((height * (Mx.ypos - Mx.t)) / plot_height); + start = row * width; + finish = start + width; + Gx.x_cut_data = Gx.lyr[0].zbuf.slice(start, finish); + draw_pcut_x(plot); + + Gx.p_cuts_ypos = Mx.ypos; + } } else { - throw "Unable to drag scrollbar - scrollAction is not 'XPAN' or 'YPAN'!!"; + if (Mx.xpos >= Mx.l && Mx.xpos <= Mx.r) { + var line = 0; + var i = 0; + height = Gx.lyr[0].lps; + //fill data for y_cut for this mouse xpos + Gx.y_cut_data = []; + line = Math.floor((width * (Mx.xpos - Mx.l)) / plot_width); + for (i = line; i < width * height; i += width) { + Gx.y_cut_data.push(Gx.lyr[0].zbuf[i]); + } + draw_pcut_y(plot); + } + + if (Mx.ypos >= Mx.t && Mx.ypos <= Mx.b) { + var row = 0; + var start = 0; + var finish = 0; + //fill data for x_cut for this mouse ypos + Gx.x_cut_data = []; + row = Math.floor((height * (Mx.ypos - Mx.t)) / plot_height); + start = row * width; + finish = start + width; + Gx.x_cut_data = Gx.lyr[0].zbuf.slice(start, finish); + draw_pcut_x(plot); + } } + } +} - // ----- OLD SIGPLOT.PAN Logic ----- - scrollbar.flag = -12; // TODO Necessary? - var k = Mx.level; - if (scrollAction === "XPAN") { - min = Mx.stk[k].xmin; - max = Mx.stk[k].xmax; - } else if (scrollAction === "YPAN") { - min = Mx.stk[k].ymin; - max = Mx.stk[k].ymax; - } else { - min = undefined; - max = undefined; +/** + * @memberOf sigplot + * @private + */ +function draw_crosshairs(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + if (Gx.cross) { + if (Gx.cross === "vertical" || Gx.cross === true) { + if ( + Mx.xpos >= Mx.l && + Mx.xpos <= Mx.r && + Gx.cross_xpos !== Mx.xpos + ) { + if (Gx.cross_xpos !== undefined) { + mx.rubberline( + Mx, + Gx.cross_xpos, + Mx.t, + Gx.cross_xpos, + Mx.b + ); + } + mx.rubberline(Mx, Mx.xpos, Mx.t, Mx.xpos, Mx.b); + Gx.cross_xpos = Mx.xpos; + } + } + if (Gx.cross === "horizontal" || Gx.cross === true) { + if ( + Mx.ypos >= Mx.t && + Mx.ypos <= Mx.b && + Gx.cross_ypos !== Mx.ypos + ) { + if (Gx.cross_ypos !== undefined) { + mx.rubberline( + Mx, + Mx.l, + Gx.cross_ypos, + Mx.r, + Gx.cross_ypos + ); + } + + mx.rubberline(Mx, Mx.l, Mx.ypos, Mx.r, Mx.ypos); + Gx.cross_ypos = Mx.ypos; + } } + } +} - // ----- MX.SCROLLBAR Logic ----- - var rangeOut = { - "min": min, - "max": max - }; - drag_updateRange(Mx, Gx, scrollbar, scrollAction, rangeOut, event); - min = rangeOut.min; - max = rangeOut.max; - - // ----- UPDATE SCROLLBAR ----- - scrollbar.smin = min; - scrollbar.srange = max - min; - mx.redrawScrollbar(scrollbar, Mx, undefined); - - // ----- Update the viewbox ----- - updateViewbox(plot, scrollbar.smin, scrollbar.smin + scrollbar.srange, - scrollAction.slice(0, 1)); - - plot.inPan = true; // prevent recursive pans - var evt = document.createEvent('Event'); - if (scrollAction === "XPAN") { - evt.initEvent('xpan', true, true); - } else if (scrollAction === "YPAN") { - evt.initEvent('ypan', true, true); +/** + * @memberOf sigplot + * @private + */ +function draw_marker(plot) { + var Gx = plot._Gx; + var Mx = plot._Mx; + + if (Gx.xmrk !== null && Gx.ymrk !== null) { + var pix = mx.real_to_pixel(Mx, Gx.xmrk, Gx.ymrk); + if (Gx.lyr.length > 0 && Gx.lyr[0].hcb["class"] === 1) { + if (pix.clipped) { + return; + } + } else if (Gx.lyr.length > 0 && Gx.lyr[0].hcb["class"] === 2) { + if (pix.clipped_x || !pix.clipped_y) { + return; + } } - evt.level = Mx.level; - evt.xmin = Mx.stk[Mx.level].xmin; - evt.ymin = Mx.stk[Mx.level].ymin; - evt.xmax = Mx.stk[Mx.level].xmax; - evt.ymax = Mx.stk[Mx.level].ymax; - mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? - plot.inPan = false; + var ctx = Mx.active_canvas.getContext("2d"); + ctx.beginPath(); + ctx.strokeStyle = Mx.xwfg; + ctx.fillStyle = Mx.xwfg; + ctx.arc(pix.x, pix.y, 2, 0, 360); + ctx.stroke(); // just draw the arc's outline + + // TODO add x/y coord + ctx.textBaseline = "alphabetic"; + ctx.textAlign = "left"; + ctx.fillStyle = Mx.fg; + ctx.font = Mx.font.font; + + var text = "x:" + mx.format_g(Gx.xmrk, 6, 3, true); + ctx.fillText(text, pix.x + 5, pix.y - 5); + text = "y:" + mx.format_g(Gx.ymrk, 6, 3, true); + ctx.fillText(text, pix.x + 5, pix.y - 5 + Mx.text_h); + } +} - scrollbar.action = 0; // TODO New step - reset action of the scrollbar - // after drag is done... - plot.refresh(); +/** + * @memberOf sigplot + * @private + */ +function changephunits(plot, newphunits) { + var Gx = plot._Gx; + var Mx = plot._Mx; + var newplab = Gx.plab; + if (newphunits === "R") { + newplab = 23; + } else if (newphunits === "D") { + newplab = 24; + } + if (newphunits === "C") { + newplab = 25; + } + if (newplab !== Gx.plab) { + var phscale = [Math.PI, 180.0, 0.5]; + var dscl = phscale[newplab - 23] / phscale[Gx.plab - 23]; + Gx.plab = newplab; + if (Gx.cmode === 2) { + for (var i = 0; i <= Mx.level; i++) { + Mx.stk[i].ymin = Mx.stk[i].ymin * dscl; + Mx.stk[i].ymax = Mx.stk[i].ymax * dscl; + Mx.stk[i].yscl = Mx.stk[i].yscl * dscl; + } + + Gx.panymin = Gx.panymin * dscl; + Gx.panymax = Gx.panymax * dscl; + plot.refresh(); + } } +} - /** - * Method to update plot range based on a drag event. Takes the mouse offset - * introduced by the drag and adds a scale factor. - * - * @param Gx - * The GX Context to work with. - * @param scrollbar - * The Scrollbar to use. - * @param scrollAction - * The scroll action being performed. Either "YPAN" or "XPAN" are - * accepted. - * @param range - * The plot' min and max range values to update. - * @param event - * The mouse move event. - * - * @private - * @memberOf sigplot - */ - function drag_updateRange(Mx, Gx, scrollbar, scrollAction, range, event) { - scrollbar.action = mx.SB_DRAG; - - if (scrollAction === "YPAN") { - var scaleFactor = Mx.scrollbar_y.trange / Mx.scrollbar_y.h; - if (scrollbar.origin === 4) { // inverted y - scaleFactor *= -1; - } - var mouseOffset = event.screenY - Gx.panning.ypos; - var realOffset = mouseOffset * scaleFactor; - - if ((Gx.panning.ymin - realOffset) < Gx.panymin) { // At the left - // edge - range.max = Gx.panymin + (range.max - range.min); - range.min = Gx.panymin; - } else if ((Gx.panning.ymax - realOffset) > Gx.panymax) { // At - // the - // right - // edge - range.min = Gx.panymax - (range.max - range.min); - range.max = Gx.panymax; +/** + * @memberOf sigplot + * @private + */ +function changemode(plot, newmode) { + var Mx = plot._Mx; + var Gx = plot._Gx; + + Gx.xdata = false; + for (var n = 0; n < Gx.lyr.length; n++) { + if (newmode === 5) { + Gx.lyr[n].xdata = true; + } else { + Gx.lyr[n].xdata = false; // TODO (Gx.lyr(n).xsub > 0) + } + if (Gx.lyr[n].xdata) { + Gx.xdata = true; + } + } + + if (newmode === Gx.cmode) { + return; + } else if (newmode === 5 && Gx.index) { + m.log.error("Imag/Real mode not permitted in INDEX mode"); + } else if (Gx.lyr.length <= 0) { + Gx.cmode = newmode; + // The call to display specs isn't found in sigplot.for; + // which causes a small bug where the plot mode is + // changed but the mode label in the specs area + // isn't updated. + display_specs(plot); + } else if (newmode > 0) { + var oldmode = Gx.cmode; + Gx.cmode = newmode; + + var autox = Gx.autox; + var autoy = Gx.autoy; + Gx.autox = 3; + Gx.autoy = 3; + + if (newmode === 5 || oldmode === 5) { + Gx.panxmin = 1.0; + Gx.panxmax = -1.0; + Gx.panymin = 1.0; + Gx.panymax = -1.0; + Mx.level = 0; + + if (newmode === Gx.basemode) { + Mx.stk[0].xmin = Gx.xmin; + Mx.stk[0].xmax = Gx.xmax; + Mx.stk[0].ymin = Gx.ymin; + Mx.stk[0].ymax = Gx.ymax; + } else if (newmode === 5 || Gx.basemode === 5) { + scale_base(plot, { + get_data: true, + }); } else { - range.min = Gx.panning.ymin - realOffset; - range.max = Gx.panning.ymax - realOffset; - } - } else if (scrollAction === "XPAN") { - var scaleFactor = Mx.scrollbar_x.trange / Mx.scrollbar_x.w; - if (scrollbar.origin === 3) { // inverted x - scaleFactor *= -1; - } - var mouseOffset = event.screenX - Gx.panning.xpos; - var realOffset = mouseOffset * scaleFactor; - - if ((Gx.panning.xmin + realOffset) < Gx.panxmin) { // At the left - // edge - range.max = Gx.panxmin + (range.max - range.min); - range.min = Gx.panxmin; - } else if ((Gx.panning.xmax + realOffset) > Gx.panxmax) { // At - // the - // right - // edge - range.min = Gx.panxmax - (range.max - range.min); - range.max = Gx.panxmax; + Mx.stk[0].xmin = Gx.xmin; + Mx.stk[0].xmax = Gx.xmax; + scale_base( + plot, + { + get_data: true, + }, + Gx.xmin, + Gx.xmax + ); + } + } else { + if (size(Gx.HCB_UUID) === 0 && newmode === Gx.basemode) { + Gx.panymin = 1.0; + Gx.panymax = -1.0; + Mx.stk[0].ymin = Gx.ymin; + Mx.stk[0].ymax = Gx.ymax; } else { - range.min = Gx.panning.xmin + realOffset; - range.max = Gx.panning.xmax + realOffset; + scale_base( + plot, + {}, + Mx.stk[Mx.level].xmin, + Mx.stk[Mx.level].xmax + ); + } + for (var n = 1; n <= Mx.level; n++) { + Mx.stk[n].ymin = Mx.stk[0].ymin; + Mx.stk[n].ymax = Mx.stk[0].ymax; } } + Gx.autox = autox; + Gx.autoy = autoy; + plot.refresh(); } +} - /** - * @memberOf sigplot - * @private - */ - function setupPrompt(plot, promptText, isValid, onSuccess, inputValue, - xpos, ypos, callback) { - var Mx = plot._Mx; +/** + * @memberOf sigplot + * @private + */ +function draw_panbars(plot) { + var k; // integer*4 + //var i1; // integer*4 + //var itext; // integer*4 - if (Mx.prompt) { - throw "Prompt already exists! Can only have one prompt at a time!"; - } + var Mx = plot._Mx; + var Gx = plot._Gx; + + if (!Gx.pan || Mx.widget) { + return; + } - // Disable Mx keypress/mouse listeners - mx.disableListeners(Mx); + k = Mx.level; // Y scrollbar + + var out = { + ps: Mx.stk[k].ymin, + pe: Mx.stk[k].ymax, + }; + var need_y_scrollbar = out.ps !== Gx.panymin || out.pe !== Gx.panymax; + need_y_scrollbar = need_y_scrollbar && Mx.level > 0; + + if ( + Gx.autohide_panbars && + (!need_y_scrollbar || !plot.mouseOnCanvas) && + !Gx.panning + ) { + var ctx = Mx.canvas.getContext("2d"); + ctx.fillStyle = Mx.bg; + ctx.fillRect(Gx.pyl, Mx.t, Gx.pyl + Gx.pthk, Mx.b - Mx.t); + } else { + var i1 = mx.scrollbar( + Mx, + 0, + Gx.pyl, + Gx.pyl + Gx.pthk, + Mx.t, + Mx.b, + out, + Gx.panymin, + Gx.panymax, + undefined, + Mx.scrollbar_y + ); + Mx.stk[k].ymin = out.ps; + Mx.stk[k].ymax = out.pe; + } - // Disable Plot keypress/mouse listeners - plot.disable_listeners(); + if (Gx.pl < Mx.width) { + // X scrollbar + out = { + ps: Mx.stk[k].xmin, + pe: Mx.stk[k].xmax, + }; + var need_x_scrollbar = + out.ps !== Gx.panxmin || out.pe !== Gx.panxmax; + need_x_scrollbar = need_x_scrollbar && (!Gx.all || Mx.level > 0); + + if ( + Gx.autohide_panbars && + (!need_x_scrollbar || !plot.mouseOnCanvas) && + !Gx.panning + ) { + var ctx = Mx.canvas.getContext("2d"); + ctx.fillStyle = Mx.bg; + ctx.fillRect(Gx.pl, Gx.pt - 1, Gx.pr - Gx.pl, Gx.pthk + 4); + } else { + var i1 = mx.scrollbar( + Mx, + 0, + Gx.pl, + Gx.pr, + Gx.pt, + Gx.pt + Gx.pthk, + out, + Gx.panxmin, + Gx.panxmax, + undefined, + Mx.scrollbar_x + ); + Mx.stk[k].xmin = out.ps; + Mx.stk[k].xmax = out.pe; + } + } +} - // Add on to the onSuccess method with plot specifics - var realOnSuccess = function(plot, onSuccess) { - return function(value) { - onSuccess(value); +/** + * @memberOf sigplot + * @private + */ +function pan(plot, action, flag, mouseEvent) { + var Mx = plot._Mx; + var Gx = plot._Gx; + + var i; // an integer*4 + var k; // an integer*4 + // var ih // an integer*4 + // var iw; // an integer*4 + // var imin; // an integer*4 + // var imax; // an integer*4 + var j; // an integer*4 + var xmin; // a real*8 + var xmax; // a real*8 + var xran; // a real*8 + // var xtemp; // a real*8 + var ymin; // a real*8 + var ymax; // a real*8 + var yran; // a real*8 + // var ytemp; // a real*8 + var warn; // a logical*4 + + var scrollbarState; + + var sbx = new mx.SCROLLBAR(); // a SCROLLBAR + var sby = new mx.SCROLLBAR(); // a SCROLLBAR + + var SIGPLOT_PAN = false; + k = Mx.level; + if (Gx.panmode > 0) { + sbx.flag = 11; + sby.flag = 11; + } else { + sbx.flag = -12; + sby.flag = -12; + } + if (flag === 0) { + sbx.action = 0; + sby.action = 0; + } - // Re-enable Mx keypress/mouse listeners - mx.enableListeners(Mx); + warn = true; + if (action.substring(0, 1) === "Y") { + ymin = Mx.stk[k].ymin; + ymax = Mx.stk[k].ymax; + yran = ymax - ymin; + if (action === "YPAN") { + scrollbarState = Mx.scrollbar_y; + + var out = { + ps: ymin, + pe: ymax, + }; + i = mx.scrollbar( + Mx, + sby, + Gx.pyl, + Gx.pyl + Gx.pthk, + Mx.t, + Mx.b, + out, + Gx.panymin, + Gx.panymax, + mouseEvent, + scrollbarState + ); + ymin = out.ps; + ymax = out.pe; + // TODO: Warn only if Scrollbar arrow is pressed and no + // movement. + if (sby.action !== 0) { + j = mx.scroll( + Mx, + sby, + mx.XW_UPDATE, + undefined, + scrollbarState + ); + } + warn = false; + } else if (action === "YCENTER") { + // Orig code : ymin = ymin - yran * (Mx.ypos - (Mx.t + Mx.b) / + // 2) / (Mx.b - Mx.t) // TODO Worry about any int division here? + ymin = + ymin - + (yran * (Mx.ypos - (Mx.t + Mx.b) / 2)) / (Mx.b - Mx.t); + ymax = ymin + yran; + warn = false; + } - // Re-enable Plot keypress/mouse listeners - plot.enable_listeners(); + if (ymin !== Mx.stk[k].ymin || ymax !== Mx.stk[k].ymax) { + Mx.stk[k].ymin = ymin; + Mx.stk[k].ymax = ymax; + if (Gx.cmode === Gx.basemode && Mx.level === 1) { + Gx.ymin = Math.min(Gx.ymin, ymin); + Gx.ymax = Math.max(Gx.ymax, ymax); + } - plot.refresh(); + plot.inPan = true; // prevent recursive pans + var evt = document.createEvent("Event"); + evt.initEvent("ypan", true, true); + evt.level = Mx.level; + evt.xmin = Mx.stk[Mx.level].xmin; + evt.ymin = Mx.stk[Mx.level].ymin; + evt.xmax = Mx.stk[Mx.level].xmax; + evt.ymax = Mx.stk[Mx.level].ymax; + mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? + plot.inPan = false; - if (callback !== undefined) { - callback(); - } + plot.refresh(); + // MSGDO(MSK_PANY, Mx.level); // just sets plotinfo.xmin and + // xmax into the MQD for the menu + SIGPLOT_PAN = true; + } + // TODO Later - Implement a messagebox status method + // else if (warn) { + // mx.message('All panned out', -1.0); + // } + } else { + xmin = Mx.stk[k].xmin; + xmax = Mx.stk[k].xmax; + xran = xmax - xmin; + if (action === "XPAN") { + scrollbarState = Mx.scrollbar_x; + + var out = { + ps: xmin, + pe: xmax, }; - }; + i = mx.scrollbar( + Mx, + sbx, + Gx.pl, + Gx.pr, + Gx.pt, + Gx.pt + Gx.pthk, + out, + Gx.panxmin, + Gx.panxmax, + mouseEvent, + scrollbarState + ); + xmin = out.ps; + xmax = out.pe; + // TODO: Warn only if Scrollbox arrow is pressed and no + // movement. + if (sbx.action !== 0) { + j = mx.scroll( + Mx, + sbx, + mx.XW_UPDATE, + undefined, + scrollbarState + ); + } + warn = false; + } else if (action === "XCENTER") { + // Original code : xmin = xmin + xran * (Mx.xpos - (Mx.l + Gx.r) + // / 2) / (Mx.r - Mx.l) // TODO Worry about any int division + // here? + xmin = + xmin + + (xran * (Mx.xpos - (Mx.l + Mx.r) / 2)) / (Mx.r - Mx.l); + if (xmin !== Mx.stk[k].xmin) { + xmax = xmin + xran; + } + warn = false; + } + + if (Mx.stk[k].xmin !== xmin || Mx.stk[k].xmax !== xmax) { + Mx.stk[k].xmin = xmin; + Mx.stk[k].xmax = xmax; + if (!Gx.xdata && Mx.level === 1) { + Gx.xmin = Mx.stk[1].xmin; + Gx.xmax = Mx.stk[1].xmax; + } + + plot.inPan = true; // prevent recursive pans + var evt = document.createEvent("Event"); + evt.initEvent("xpan", true, true); + evt.level = Mx.level; + evt.xmin = Mx.stk[Mx.level].xmin; + evt.ymin = Mx.stk[Mx.level].ymin; + evt.xmax = Mx.stk[Mx.level].xmax; + evt.ymax = Mx.stk[Mx.level].ymax; + mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? + plot.inPan = false; - var refresh = function() { // TODO Refactor this setup method to be - // more like mx.menu/main menu widget? plot.refresh(); - }; + // MSGDO (MSK_PANX, Mx.level); // just sets plotinfo.xmin and + // xmax into the MQD for the menu + SIGPLOT_PAN = true; + } + // TODO Later - Implement a messagebox status method + // else if (warn) { + // mx.message('All panned out', -1.0); + // } + } - // Create the prompt - var errorMessageTimeout = 5000; + return SIGPLOT_PAN; +} - try { - mx.prompt(Mx, promptText, isValid, realOnSuccess(plot, onSuccess), - refresh, inputValue, xpos, ypos, errorMessageTimeout); - } catch (err) { - console.log("ERROR: Failed to set up prompt due to: " + err); +/** + * Direct method to handle the dragging of a scrollbar. + * + * @param plot + * The plot to work with. + * @param scrollAction + * The scroll action being performed. Either "YPAN" or "XPAN" are + * accepted. + * @param event + * The mouse move event. + * @private + * @memberOf sigplot + */ +function drag_scrollbar(plot, scrollAction, event) { + var Mx = plot._Mx; + var Gx = plot._Gx; + var min; + var max; + + // ----- Retrieve appropriate SCROLLBAR ----- + var scrollbar; + if (scrollAction === "XPAN") { + scrollbar = plot._Mx.scrollbar_x; + } else if (scrollAction === "YPAN") { + scrollbar = plot._Mx.scrollbar_y; + } else { + throw "Unable to drag scrollbar - scrollAction is not 'XPAN' or 'YPAN'!!"; + } + + // ----- OLD SIGPLOT.PAN Logic ----- + scrollbar.flag = -12; // TODO Necessary? + var k = Mx.level; + if (scrollAction === "XPAN") { + min = Mx.stk[k].xmin; + max = Mx.stk[k].xmax; + } else if (scrollAction === "YPAN") { + min = Mx.stk[k].ymin; + max = Mx.stk[k].ymax; + } else { + min = undefined; + max = undefined; + } + + // ----- MX.SCROLLBAR Logic ----- + var rangeOut = { + min: min, + max: max, + }; + drag_updateRange(Mx, Gx, scrollbar, scrollAction, rangeOut, event); + min = rangeOut.min; + max = rangeOut.max; + + // ----- UPDATE SCROLLBAR ----- + scrollbar.smin = min; + scrollbar.srange = max - min; + mx.redrawScrollbar(scrollbar, Mx, undefined); + + // ----- Update the viewbox ----- + updateViewbox( + plot, + scrollbar.smin, + scrollbar.smin + scrollbar.srange, + scrollAction.slice(0, 1) + ); + + plot.inPan = true; // prevent recursive pans + var evt = document.createEvent("Event"); + if (scrollAction === "XPAN") { + evt.initEvent("xpan", true, true); + } else if (scrollAction === "YPAN") { + evt.initEvent("ypan", true, true); + } + evt.level = Mx.level; + evt.xmin = Mx.stk[Mx.level].xmin; + evt.ymin = Mx.stk[Mx.level].ymin; + evt.xmax = Mx.stk[Mx.level].xmax; + evt.ymax = Mx.stk[Mx.level].ymax; + mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? + plot.inPan = false; + + scrollbar.action = 0; // TODO New step - reset action of the scrollbar + // after drag is done... + plot.refresh(); +} + +/** + * Method to update plot range based on a drag event. Takes the mouse offset + * introduced by the drag and adds a scale factor. + * + * @param Gx + * The GX Context to work with. + * @param scrollbar + * The Scrollbar to use. + * @param scrollAction + * The scroll action being performed. Either "YPAN" or "XPAN" are + * accepted. + * @param range + * The plot' min and max range values to update. + * @param event + * The mouse move event. + * + * @private + * @memberOf sigplot + */ +function drag_updateRange(Mx, Gx, scrollbar, scrollAction, range, event) { + scrollbar.action = mx.SB_DRAG; + + if (scrollAction === "YPAN") { + var scaleFactor = Mx.scrollbar_y.trange / Mx.scrollbar_y.h; + if (scrollbar.origin === 4) { + // inverted y + scaleFactor *= -1; + } + var mouseOffset = event.screenY - Gx.panning.ypos; + var realOffset = mouseOffset * scaleFactor; + + if (Gx.panning.ymin - realOffset < Gx.panymin) { + // At the left + // edge + range.max = Gx.panymin + (range.max - range.min); + range.min = Gx.panymin; + } else if (Gx.panning.ymax - realOffset > Gx.panymax) { + // At + // the + // right + // edge + range.min = Gx.panymax - (range.max - range.min); + range.max = Gx.panymax; + } else { + range.min = Gx.panning.ymin - realOffset; + range.max = Gx.panning.ymax - realOffset; + } + } else if (scrollAction === "XPAN") { + var scaleFactor = Mx.scrollbar_x.trange / Mx.scrollbar_x.w; + if (scrollbar.origin === 3) { + // inverted x + scaleFactor *= -1; + } + var mouseOffset = event.screenX - Gx.panning.xpos; + var realOffset = mouseOffset * scaleFactor; + + if (Gx.panning.xmin + realOffset < Gx.panxmin) { + // At the left + // edge + range.max = Gx.panxmin + (range.max - range.min); + range.min = Gx.panxmin; + } else if (Gx.panning.xmax + realOffset > Gx.panxmax) { + // At + // the + // right + // edge + range.min = Gx.panxmax - (range.max - range.min); + range.max = Gx.panxmax; + } else { + range.min = Gx.panning.xmin + realOffset; + range.max = Gx.panning.xmax + realOffset; } } +} - /** - * @memberOf sigplot - * @private - */ - function enable_listeners(plot) { - var Mx = plot._Mx; - mx.addEventListener(Mx, "mousedown", plot.onmousedown, false); - mx.addEventListener(Mx, "mousemove", plot.throttledOnMouseMove, false); - document.addEventListener("mouseup", plot.docMouseUp, false); - mx.addEventListener(Mx, "mouseup", plot.mouseup, false); - window.addEventListener("mousedown", plot.dragMouseDownHandler, false); - window.addEventListener("mousemove", plot.throttledDragOnMouseMove, false); - window.addEventListener("mouseup", plot.dragMouseUpHandler, false); - window.addEventListener("wheel", plot.wheelHandler, false); - window.addEventListener("mousewheel", plot.wheelHandler, false); - window.addEventListener("DOMMouseScroll", plot.wheelHandler, false); - window.addEventListener("keypress", plot.onkeypress, false); +/** + * @memberOf sigplot + * @private + */ +function setupPrompt( + plot, + promptText, + isValid, + onSuccess, + inputValue, + xpos, + ypos, + callback +) { + var Mx = plot._Mx; + + if (Mx.prompt) { + throw "Prompt already exists! Can only have one prompt at a time!"; } - /** - * @memberOf sigplot - * @private - */ - function disable_listeners(plot) { - var Mx = plot._Mx; + // Disable Mx keypress/mouse listeners + mx.disableListeners(Mx); + + // Disable Plot keypress/mouse listeners + plot.disable_listeners(); + + // Add on to the onSuccess method with plot specifics + var realOnSuccess = function (plot, onSuccess) { + return function (value) { + onSuccess(value); + + // Re-enable Mx keypress/mouse listeners + mx.enableListeners(Mx); + + // Re-enable Plot keypress/mouse listeners + plot.enable_listeners(); - mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); - mx.removeEventListener(Mx, "mousemove", plot.throttledOnMouseMove, - false); - document.removeEventListener("mouseup", plot.docMouseUp, false); - mx.removeEventListener(Mx, "mouseup", plot.mouseup, false); - window.removeEventListener("mousedown", plot.dragMouseDownHandler, - false); - window.removeEventListener("mousemove", plot.throttledDragOnMouseMove, - false); - window.removeEventListener("mouseup", plot.dragMouseUpHandler, false); - window.removeEventListener("wheel", plot.wheelHandler, false); - window.removeEventListener("mousewheel", plot.wheelHandler, false); - window.removeEventListener("DOMMouseScroll", plot.wheelHandler, false); - window.removeEventListener("keypress", plot.onkeypress, false); - } + plot.refresh(); - /** - * @memberOf sigplot - * @private - */ - function display_specs(plot) { - var Mx = plot._Mx; - var Gx = plot._Gx; + if (callback !== undefined) { + callback(); + } + }; + }; - var ctx = Mx.canvas.getContext("2d"); + var refresh = function () { + // TODO Refactor this setup method to be + // more like mx.menu/main menu widget? + plot.refresh(); + }; - // section logic - if (Gx.sections !== 0) { - // TODO - } else { - Gx.isec = 0; - } + // Create the prompt + var errorMessageTimeout = 5000; + + try { + mx.prompt( + Mx, + promptText, + isValid, + realOnSuccess(plot, onSuccess), + refresh, + inputValue, + xpos, + ypos, + errorMessageTimeout + ); + } catch (err) { + console.log("ERROR: Failed to set up prompt due to: " + err); + } +} - // transform into realworld coordinates - // is already done by the mousemove listener - // adjust for abscissa mode - if (Mx.warpbox) { - var re = pixel_to_real(plot, Mx.warpbox.xo, Mx.warpbox.yo); - var rwh = pixel_to_real(plot, Mx.warpbox.xl, Mx.warpbox.yl); +/** + * @memberOf sigplot + * @private + */ +function enable_listeners(plot) { + var Mx = plot._Mx; + mx.addEventListener(Mx, "mousedown", plot.onmousedown, false); + mx.addEventListener(Mx, "mousemove", plot.throttledOnMouseMove, false); + document.addEventListener("mouseup", plot.docMouseUp, false); + mx.addEventListener(Mx, "mouseup", plot.mouseup, false); + window.addEventListener("mousedown", plot.dragMouseDownHandler, false); + window.addEventListener( + "mousemove", + plot.throttledDragOnMouseMove, + false + ); + window.addEventListener("mouseup", plot.dragMouseUpHandler, false); + window.addEventListener("wheel", plot.wheelHandler, false); + window.addEventListener("mousewheel", plot.wheelHandler, false); + window.addEventListener("DOMMouseScroll", plot.wheelHandler, false); + window.addEventListener("keypress", plot.onkeypress, false); +} - Gx.aretx = re.x; - Gx.arety = re.y; - Gx.dretx = rwh.x - re.x; - Gx.drety = rwh.y - re.y; - } else { - Gx.aretx = Gx.retx; - Gx.arety = Gx.rety; - Gx.dretx = Gx.retx - Gx.xmrk; - Gx.drety = Gx.rety - Gx.ymrk; - } +/** + * @memberOf sigplot + * @private + */ +function disable_listeners(plot) { + var Mx = plot._Mx; + + mx.removeEventListener(Mx, "mousedown", plot.onmousedown, false); + mx.removeEventListener( + Mx, + "mousemove", + plot.throttledOnMouseMove, + false + ); + document.removeEventListener("mouseup", plot.docMouseUp, false); + mx.removeEventListener(Mx, "mouseup", plot.mouseup, false); + window.removeEventListener( + "mousedown", + plot.dragMouseDownHandler, + false + ); + window.removeEventListener( + "mousemove", + plot.throttledDragOnMouseMove, + false + ); + window.removeEventListener("mouseup", plot.dragMouseUpHandler, false); + window.removeEventListener("wheel", plot.wheelHandler, false); + window.removeEventListener("mousewheel", plot.wheelHandler, false); + window.removeEventListener("DOMMouseScroll", plot.wheelHandler, false); + window.removeEventListener("keypress", plot.onkeypress, false); +} - if ((Gx.cmode === 5) && (Gx.iabsc === 1)) { - Gx.iabsc = 2; - } // R/I mode - if (Gx.iabsc === 1) { // index - Gx.aretx = Math.round((Gx.aretx - Gx.xstart) / Gx.xdelta); - if (!Gx.index) { - Gx.aretx += 1; - } - Gx.dretx = Math.round(Gx.dretx / Gx.xdelta); - } else if (Gx.iabsc === 2) { // 1/absc - if (Gx.aretx !== 0.0) { - Gx.aretx = 1.0 / Gx.aretx; - } - if (Gx.arety !== 0.0) { - Gx.arety = 1.0 / Gx.arety; - } - if (Gx.dretx !== 0.0) { - Gx.dretx = 1.0 / Gx.dretx; - } - if (Gx.drety !== 0.0) { - Gx.drety = 1.0 / Gx.drety; - } - } +/** + * @memberOf sigplot + * @private + */ +function display_specs(plot) { + var Mx = plot._Mx; + var Gx = plot._Gx; - if ((!Gx.show_readout) || (Mx.widget)) { - return; - } + var ctx = Mx.canvas.getContext("2d"); - // Clear the specs area - // First clear the y-row - ctx.fillStyle = Mx.bg; - var iy = Math.floor(Mx.height - 2.5 * Mx.text_h); - ctx.fillRect(Mx.text_w, iy - 1, 49 * Mx.text_w, iy + 1.5 * Mx.text_h); + // section logic + if (Gx.sections !== 0) { + // TODO + } else { + Gx.isec = 0; + } - // Then clear the x-row - iy = Math.floor(Mx.height - 0.5 * Mx.text_h); - var k = Math.max(Gx.pr + Mx.text_w, Mx.width - Mx.text_w * 2); - ctx.fillStyle = Mx.bg; - ctx.fillRect(k, iy - Mx.text_h, Mx.text_w, Mx.text_h); + // transform into realworld coordinates + // is already done by the mousemove listener + // adjust for abscissa mode + if (Mx.warpbox) { + var re = pixel_to_real(plot, Mx.warpbox.xo, Mx.warpbox.yo); + var rwh = pixel_to_real(plot, Mx.warpbox.xl, Mx.warpbox.yl); + + Gx.aretx = re.x; + Gx.arety = re.y; + Gx.dretx = rwh.x - re.x; + Gx.drety = rwh.y - re.y; + } else { + Gx.aretx = Gx.retx; + Gx.arety = Gx.rety; + Gx.dretx = Gx.retx - Gx.xmrk; + Gx.drety = Gx.rety - Gx.ymrk; + } - if (Gx.autohide_readout && !plot.mouseOnCanvas && !Gx.panning) { - return; + if (Gx.cmode === 5 && Gx.iabsc === 1) { + Gx.iabsc = 2; + } // R/I mode + if (Gx.iabsc === 1) { + // index + Gx.aretx = Math.round((Gx.aretx - Gx.xstart) / Gx.xdelta); + if (!Gx.index) { + Gx.aretx += 1; } - - var xval, yval, xdelta, ydelta; - // TODO handle xfmt/yfmt using m.d2a_form equivalent - if ((Gx.iabsc === 0) && (Gx.ylab === 4)) { - yval = (m.sec2tspec(Gx.arety) + " ").substring(0, 16); - ydelta = (m.sec2tspec(Gx.drety, "delta") + " ").substring(0, 16); - } else { - yval = mx.format_g(Gx.arety, 16, 9, true); - ydelta = mx.format_g(Gx.drety, 16, 9); + Gx.dretx = Math.round(Gx.dretx / Gx.xdelta); + } else if (Gx.iabsc === 2) { + // 1/absc + if (Gx.aretx !== 0.0) { + Gx.aretx = 1.0 / Gx.aretx; } - if ((Gx.iabsc === 0) && (Gx.xlab === 4)) { - xval = (m.sec2tspec(Gx.aretx) + " ").substring(0, 16); - xdelta = (m.sec2tspec(Gx.dretx, "delta") + " ").substring(0, 16); - } else { - xval = mx.format_g(Gx.aretx, 16, 9, true); - xdelta = mx.format_g(Gx.dretx, 16, 9); + if (Gx.arety !== 0.0) { + Gx.arety = 1.0 / Gx.arety; } - - var chara = "y: " + yval + " dy: " + ydelta + " L=" + Mx.level + " " + cxm[Gx.cmode - 1]; - var charb = "x: " + xval + " dx: " + xdelta + " " + cam[Gx.iabsc]; - if (Gx.iabsc === 3) { - if (Gx.dretx === 0.0) { - chara = chara.substr(0, 20) + "sl: Inf " + chara.substr(40, chara.length); - } else { - chara = chara.substr(0, 20) + "sl: " + mx.format_g(Gx.drety / Gx.dretx, 16, 9) + chara.substr(40, chara.length); - } + if (Gx.dretx !== 0.0) { + Gx.dretx = 1.0 / Gx.dretx; } - - iy = Math.floor(Mx.height - 1.5 * Mx.text_h); - mx.text(Mx, Mx.text_w, iy, chara); - iy = Math.floor(Mx.height - 0.5 * Mx.text_h); - mx.text(Mx, Mx.text_w, iy, charb); - - if (mx.LEGACY_RENDER) { - // display controls indicator - if (k < Mx.width) { - if (Gx.cntrls > 0) { - mx.text(Mx, k, iy, 'C'); - } else { - mx.text(Mx, k, iy, ' '); - } - } + if (Gx.drety !== 0.0) { + Gx.drety = 1.0 / Gx.drety; } + } - // If one of the layers is 2D we can draw a color-bar. - // Note that if two Layer2D are drawn it is possible to - // use a different color bar for each. - var needsColorBar = Gx.lyr.some(function(lyr) { - return (lyr instanceof Layer2D); - }); + if (!Gx.show_readout || Mx.widget) { + return; + } - if (needsColorBar) { - // draw color bar - large - var x = 0; - var y = 0; - var w = 0; - var h = 0; - if (Gx.lg_colorbar) { - var plot_height = Mx.b - Mx.t; + // Clear the specs area + // First clear the y-row + ctx.fillStyle = Mx.bg; + var iy = Math.floor(Mx.height - 2.5 * Mx.text_h); + ctx.fillRect(Mx.text_w, iy - 1, 49 * Mx.text_w, iy + 1.5 * Mx.text_h); - x = Mx.r + 35; - y = Mx.t + (1 / 8) * plot_height; - w = 5 * Mx.text_w; - h = (3 / 4) * plot_height; + // Then clear the x-row + iy = Math.floor(Mx.height - 0.5 * Mx.text_h); + var k = Math.max(Gx.pr + Mx.text_w, Mx.width - Mx.text_w * 2); + ctx.fillStyle = Mx.bg; + ctx.fillRect(k, iy - Mx.text_h, Mx.text_w, Mx.text_h); - // If I have a large color bar, I probably also want to add buttons - var ctx = Mx.active_canvas.getContext("2d"); - ctx.strokeStyle = "rgba(124, 123, 121, 0.8)"; - ctx.fillStyle = " rgba(124, 123, 121, 0.8)"; + if (Gx.autohide_readout && !plot.mouseOnCanvas && !Gx.panning) { + return; + } - // For more precise referencing - var colorbar_x = x; - var colorbar_y = y; - var colorbar_width = w; - var colorbar_height = h; - var button_width = colorbar_width - 2; - var button_height = button_width / 2; - var button_x = colorbar_x + ((colorbar_width - button_width) / 2); - var button_y = colorbar_y - 10; + var xval, yval, xdelta, ydelta; + // TODO handle xfmt/yfmt using m.d2a_form equivalent + if (Gx.iabsc === 0 && Gx.ylab === 4) { + yval = (m.sec2tspec(Gx.arety) + " ").substring( + 0, + 16 + ); + ydelta = ( + m.sec2tspec(Gx.drety, "delta") + " " + ).substring(0, 16); + } else { + yval = mx.format_g(Gx.arety, 16, 9, true); + ydelta = mx.format_g(Gx.drety, 16, 9); + } + if (Gx.iabsc === 0 && Gx.xlab === 4) { + xval = (m.sec2tspec(Gx.aretx) + " ").substring( + 0, + 16 + ); + xdelta = ( + m.sec2tspec(Gx.dretx, "delta") + " " + ).substring(0, 16); + } else { + xval = mx.format_g(Gx.aretx, 16, 9, true); + xdelta = mx.format_g(Gx.dretx, 16, 9); + } - // Draw the top button - ctx.beginPath(); - ctx.moveTo(button_x, button_y); - ctx.lineTo(button_x + button_width, button_y); - ctx.lineTo(button_x + (1 / 2) * button_width, button_y - button_height); - ctx.lineTo(button_x, button_y); - ctx.stroke(); - ctx.fill(); + var chara = + "y: " + + yval + + " dy: " + + ydelta + + " L=" + + Mx.level + + " " + + cxm[Gx.cmode - 1]; + var charb = "x: " + xval + " dx: " + xdelta + " " + cam[Gx.iabsc]; + if (Gx.iabsc === 3) { + if (Gx.dretx === 0.0) { + chara = + chara.substr(0, 20) + + "sl: Inf " + + chara.substr(40, chara.length); + } else { + chara = + chara.substr(0, 20) + + "sl: " + + mx.format_g(Gx.drety / Gx.dretx, 16, 9) + + chara.substr(40, chara.length); + } + } - // Draw the bottom button - var button_y_2 = button_y + colorbar_height + 20; + iy = Math.floor(Mx.height - 1.5 * Mx.text_h); + mx.text(Mx, Mx.text_w, iy, chara); + iy = Math.floor(Mx.height - 0.5 * Mx.text_h); + mx.text(Mx, Mx.text_w, iy, charb); - ctx.beginPath(); - ctx.moveTo(button_x, button_y_2); - ctx.lineTo(button_x + button_width, button_y_2); - ctx.lineTo(button_x + (1 / 2) * button_width, button_y_2 + button_height); - ctx.lineTo(button_x, button_y_2); - ctx.stroke(); - ctx.fill(); + if (mx.LEGACY_RENDER) { + // display controls indicator + if (k < Mx.width) { + if (Gx.cntrls > 0) { + mx.text(Mx, k, iy, "C"); + } else { + mx.text(Mx, k, iy, " "); + } + } + } - // Store this info so we can access it later + // If one of the layers is 2D we can draw a color-bar. + // Note that if two Layer2D are drawn it is possible to + // use a different color bar for each. + var needsColorBar = Gx.lyr.some(function (lyr) { + return lyr instanceof Layer2D; + }); - Gx.cbb_top_x1 = button_x; - Gx.cbb_top_y1 = button_y; - Gx.cbb_bot_x1 = button_x; - Gx.cbb_bot_y1 = button_y_2; - Gx.cbb_width = button_width; - Gx.cbb_height = button_height; + if (needsColorBar) { + // draw color bar - large + var x = 0; + var y = 0; + var w = 0; + var h = 0; + if (Gx.lg_colorbar) { + var plot_height = Mx.b - Mx.t; - } else { // draw a small colorbar - x = (49 * Mx.text_w) - 3; - y = Mx.height - Mx.text_h * 2.5; - w = Mx.text_w; - h = Mx.text_h * 2; - } + x = Mx.r + 35; + y = Mx.t + (1 / 8) * plot_height; + w = 5 * Mx.text_w; + h = (3 / 4) * plot_height; + // If I have a large color bar, I probably also want to add buttons + var ctx = Mx.active_canvas.getContext("2d"); + ctx.strokeStyle = "rgba(124, 123, 121, 0.8)"; + ctx.fillStyle = " rgba(124, 123, 121, 0.8)"; + + // For more precise referencing + var colorbar_x = x; + var colorbar_y = y; + var colorbar_width = w; + var colorbar_height = h; + var button_width = colorbar_width - 2; + var button_height = button_width / 2; + var button_x = colorbar_x + (colorbar_width - button_width) / 2; + var button_y = colorbar_y - 10; + + // Draw the top button + ctx.beginPath(); + ctx.moveTo(button_x, button_y); + ctx.lineTo(button_x + button_width, button_y); + ctx.lineTo( + button_x + (1 / 2) * button_width, + button_y - button_height + ); + ctx.lineTo(button_x, button_y); + ctx.stroke(); + ctx.fill(); + + // Draw the bottom button + var button_y_2 = button_y + colorbar_height + 20; - mx.colorbar(Mx, x, y, w, h); + ctx.beginPath(); + ctx.moveTo(button_x, button_y_2); + ctx.lineTo(button_x + button_width, button_y_2); + ctx.lineTo( + button_x + (1 / 2) * button_width, + button_y_2 + button_height + ); + ctx.lineTo(button_x, button_y_2); + ctx.stroke(); + ctx.fill(); + + // Store this info so we can access it later + + Gx.cbb_top_x1 = button_x; + Gx.cbb_top_y1 = button_y; + Gx.cbb_bot_x1 = button_x; + Gx.cbb_bot_y1 = button_y_2; + Gx.cbb_width = button_width; + Gx.cbb_height = button_height; + } else { + // draw a small colorbar + x = 49 * Mx.text_w - 3; + y = Mx.height - Mx.text_h * 2.5; + w = Mx.text_w; + h = Mx.text_h * 2; } - //draw boxes for the p_cuts - if (Gx.p_cuts && (Gx.lyr.length === 1) && (Gx.lyr[0].hcb["class"] === 2)) { - draw_pcut_y(plot); - draw_pcut_x(plot); - } + mx.colorbar(Mx, x, y, w, h); + } + //draw boxes for the p_cuts + if (Gx.p_cuts && Gx.lyr.length === 1 && Gx.lyr[0].hcb["class"] === 2) { + draw_pcut_y(plot); + draw_pcut_x(plot); } +} - /** - * Determine the effective bounds of the plottable area, which is defined - * via the pan-boundaries (panxmin/panxmax/panymin/panymax). Then check - * the stack (i.e. the viewable area) and update accordingly. - * - * @memberOf sigplot - * @private - * - * @param plot - * the plot to scale - * @param mode - * various mode options (deprecated) - * @param xxmin - * the xmin to begin scaling at - * @param xxmax - * the xmax to end scaling at - * @param xlab - * force a specific x-label - * @param ylab - * force a specific y-label - */ - function scale_base(plot, mode, xxmin, xxmax, xlab, ylab) { - const Mx = plot._Mx; - const Gx = plot._Gx; - - // Reset pan boundaries - Gx.panxmin = undefined; - Gx.panxmax = undefined; - Gx.panymin = undefined; - Gx.panymax = undefined; - - // Determine if we have been requested to only scale a subset of the xrange - // TODO - this is kinda holdover from 1D only mode and should be reconsidered - // given that SigPlot can do both 1D and 2D - let xmin = xxmin; - let xmax = xxmax; - const noxmin = (xmin === undefined); - const noxmax = (xmax === undefined); - - if (Gx.lyr.length === 0) { - // If there are no layers we simply show -1 to 1 on each axis - Gx.panxmin = -1.0; - Gx.panxmax = 1.0; - Gx.panymin = -1.0; - Gx.panymax = 1.0; - } else { - // If there is at least on layer +/** + * Determine the effective bounds of the plottable area, which is defined + * via the pan-boundaries (panxmin/panxmax/panymin/panymax). Then check + * the stack (i.e. the viewable area) and update accordingly. + * + * @memberOf sigplot + * @private + * + * @param plot + * the plot to scale + * @param mode + * various mode options (deprecated) + * @param xxmin + * the xmin to begin scaling at + * @param xxmax + * the xmax to end scaling at + * @param xlab + * force a specific x-label + * @param ylab + * force a specific y-label + */ +function scale_base(plot, mode, xxmin, xxmax, xlab, ylab) { + const Mx = plot._Mx; + const Gx = plot._Gx; + + // Reset pan boundaries + Gx.panxmin = undefined; + Gx.panxmax = undefined; + Gx.panymin = undefined; + Gx.panymax = undefined; + + // Determine if we have been requested to only scale a subset of the xrange + // TODO - this is kinda holdover from 1D only mode and should be reconsidered + // given that SigPlot can do both 1D and 2D + let xmin = xxmin; + let xmax = xxmax; + const noxmin = xmin === undefined; + const noxmax = xmax === undefined; + + if (Gx.lyr.length === 0) { + // If there are no layers we simply show -1 to 1 on each axis + Gx.panxmin = -1.0; + Gx.panxmax = 1.0; + Gx.panymin = -1.0; + Gx.panymax = 1.0; + } else { + // If there is at least on layer + + // If specific xlabel/ylabel wasn't provided use the first layer + if (xlab === undefined) { + Gx.xlab = Gx.lyr[0].xlab; + } + if (ylab === undefined) { + Gx.ylab = Gx.lyr[0].ylab; + } + + // Iterate over each layer + for (var n = 0; n < Gx.lyr.length; n++) { + // If a layer isn't displayed it's not considered as part of rescaling + if (Gx.lyr[n].display === false) { + continue; + } + // If xmin wasn't provided as an argument, grab the layers + if (noxmin) { + xmin = Gx.lyr[n].xmin; + } else { + xmin = xxmin; + } + // If xmax wasn't provided as an argument, grab the layers + if (noxmax) { + xmax = Gx.lyr[n].xmax; + } else { + xmax = xxmax; + } - // If specific xlabel/ylabel wasn't provided use the first layer - if (xlab === undefined) { - Gx.xlab = Gx.lyr[0].xlab; + // If the labels between layers aren't consistent, use None instead + if (Gx.xlab !== Gx.lyr[n].xlab) { + Gx.xlab = 0; // If the layers aren't consistent use None } - if (ylab === undefined) { - Gx.ylab = Gx.lyr[0].ylab; + if (Gx.ylab !== Gx.lyr[n].ylab) { + Gx.ylab = 0; // If the layers aren't consistent use None } - // Iterate over each layer + // Ask the layer for it's bounds + let lyr_bnds = Gx.lyr[n].get_pan_bounds(); + // And update the boundaries accordingly + set_panbounds(plot, lyr_bnds); + } // end per-layer iteration + } + + var xran = Gx.panxmax - Gx.panxmin; + if (xran < 0.0) { + Gx.panxmax = Gx.panxmin; + Gx.panxmin = Gx.panxmax + xran; + xran = -xran; + } + if (xran <= 1.0e-20) { + Gx.panxmin = Gx.panxmin - 1.0; + Gx.panxmax = Gx.panxmax + 1.0; + } + xran = Gx.panxmax - Gx.panxmin; + + Gx.panxmin -= m.pad(xran, Gx.panxpad); + Gx.panxmax += m.pad(xran, Gx.panxpad); + + if ((Gx.autox & 1) !== 0 && noxmin) { + Mx.stk[0].xmin = Gx.panxmin; + } + // If autox is set to allow auto-xmax _and_ xmax was not provided by scale_base + if ((Gx.autox & 2) !== 0 && noxmax) { + // the top-level stack xmax becomes the panxmax + Mx.stk[0].xmax = Gx.panxmax; + // unless 'All' mode is set or 'xdata' mode is used + // we emulate XPLOT by only showing the first 32768 points + if (!(Gx.all || Gx.xdata)) { for (var n = 0; n < Gx.lyr.length; n++) { - // If a layer isn't displayed it's not considered as part of rescaling if (Gx.lyr[n].display === false) { continue; } - // If xmin wasn't provided as an argument, grab the layers - if (noxmin) { - xmin = Gx.lyr[n].xmin; - } else { - xmin = xxmin; - } - // If xmax wasn't provided as an argument, grab the layers - if (noxmax) { - xmax = Gx.lyr[n].xmax; - } else { - xmax = xxmax; - } - - // If the labels between layers aren't consistent, use None instead - if (Gx.xlab !== Gx.lyr[n].xlab) { - Gx.xlab = 0; // If the layers aren't consistent use None - } - if (Gx.ylab !== Gx.lyr[n].ylab) { - Gx.ylab = 0; // If the layers aren't consistent use None - } - - // Ask the layer for it's bounds - let lyr_bnds = Gx.lyr[n].get_pan_bounds(); - // And update the boundaries accordingly - set_panbounds(plot, lyr_bnds); - } // end per-layer iteration - } - - var xran = Gx.panxmax - Gx.panxmin; - if (xran < 0.0) { - Gx.panxmax = Gx.panxmin; - Gx.panxmin = Gx.panxmax + xran; - xran = -xran; - } - if (xran <= 1.0e-20) { - Gx.panxmin = Gx.panxmin - 1.0; - Gx.panxmax = Gx.panxmax + 1.0; - } - xran = Gx.panxmax - Gx.panxmin; - - Gx.panxmin -= m.pad(xran, Gx.panxpad); - Gx.panxmax += m.pad(xran, Gx.panxpad); - - if (((Gx.autox & 1) !== 0) && noxmin) { - Mx.stk[0].xmin = Gx.panxmin; - } - // If autox is set to allow auto-xmax _and_ xmax was not provided by scale_base - if (((Gx.autox & 2) !== 0) && noxmax) { - // the top-level stack xmax becomes the panxmax - Mx.stk[0].xmax = Gx.panxmax; - // unless 'All' mode is set or 'xdata' mode is used - // we emulate XPLOT by only showing the first 32768 points - if (!(Gx.all || Gx.xdata)) { - for (var n = 0; n < Gx.lyr.length; n++) { - if (Gx.lyr[n].display === false) { - continue; - } - xmax = Math.min(Gx.lyr[n].xmax, Mx.stk[0].xmax); - var dpts = Math.abs((xmax - Gx.lyr[n].xmin) / Gx.lyr[n].xdelta) - Gx.bufmax + 1.0; - if (dpts > 0) { - Mx.stk[0].xmax = xmax - dpts * Math.abs(Gx.lyr[n].xdelta); - } + xmax = Math.min(Gx.lyr[n].xmax, Mx.stk[0].xmax); + var dpts = + Math.abs((xmax - Gx.lyr[n].xmin) / Gx.lyr[n].xdelta) - + Gx.bufmax + + 1.0; + if (dpts > 0) { + Mx.stk[0].xmax = + xmax - dpts * Math.abs(Gx.lyr[n].xdelta); } } } + } - if (((Gx.autoy & 1) !== 0)) { - Mx.stk[0].ymin = Gx.panymin; - for (var i = 0; i < Mx.stk.length; i++) { - if (Mx.stk[i].ymin === undefined) { - Mx.stk[i].ymin = Gx.panymin; - } + if ((Gx.autoy & 1) !== 0) { + Mx.stk[0].ymin = Gx.panymin; + for (var i = 0; i < Mx.stk.length; i++) { + if (Mx.stk[i].ymin === undefined) { + Mx.stk[i].ymin = Gx.panymin; } } - if (((Gx.autoy & 2) !== 0)) { - Mx.stk[0].ymax = Gx.panymax; - for (var j = 0; j < Mx.stk.length; j++) { - if (Mx.stk[j].ymax === undefined) { - Mx.stk[j].ymax = Gx.panymax; - } + } + if ((Gx.autoy & 2) !== 0) { + Mx.stk[0].ymax = Gx.panymax; + for (var j = 0; j < Mx.stk.length; j++) { + if (Mx.stk[j].ymax === undefined) { + Mx.stk[j].ymax = Gx.panymax; } } + } - if ((Gx.panymin !== undefined) && (Gx.panymax !== undefined)) { - var yran = (Gx.panymax - Gx.panymin); - Gx.panymin -= m.pad(yran, Gx.panypad); - Gx.panymax += m.pad(yran, Gx.panypad); - } - + if (Gx.panymin !== undefined && Gx.panymax !== undefined) { + var yran = Gx.panymax - Gx.panymin; + Gx.panymin -= m.pad(yran, Gx.panypad); + Gx.panymax += m.pad(yran, Gx.panypad); } +} - /** - * @memberOf sigplot - * @private - */ - function set_panbounds(plot, { - xmin, - xmax, - ymin, - ymax - }) { - var Gx = plot._Gx; - var Mx = plot._Mx; +/** + * @memberOf sigplot + * @private + */ +function set_panbounds(plot, { xmin, xmax, ymin, ymax }) { + var Gx = plot._Gx; + var Mx = plot._Mx; - if (xmin !== undefined) { - if (Gx.panxmin === undefined) { - Gx.panxmin = xmin; - } else { - Gx.panxmin = Math.min(Gx.panxmin, xmin); - } - } - if (xmax !== undefined) { - if (Gx.panxmax === undefined) { - Gx.panxmax = xmax; - } else { - Gx.panxmax = Math.max(Gx.panxmax, xmax); - } - } - if (ymin !== undefined) { - if (Gx.panymin === undefined) { - Gx.panymin = ymin; - } else { - Gx.panymin = Math.min(Gx.panymin, ymin); - } + if (xmin !== undefined) { + if (Gx.panxmin === undefined) { + Gx.panxmin = xmin; + } else { + Gx.panxmin = Math.min(Gx.panxmin, xmin); } - if (ymax !== undefined) { - if (Gx.panymax === undefined) { - Gx.panymax = ymax; - } else { - Gx.panymax = Math.max(Gx.panymax, ymax); - } + } + if (xmax !== undefined) { + if (Gx.panxmax === undefined) { + Gx.panxmax = xmax; + } else { + Gx.panxmax = Math.max(Gx.panxmax, xmax); } } - - /** - * @memberOf sigplot - * @private - */ - function pixel_to_real(plot, xpos, ypos) { - var Gx = plot._Gx; - var Mx = plot._Mx; - - var ret = mx.pixel_to_real(Mx, xpos, ypos); - if (Gx.index) { - ret.x = ret.x * Gx.xdelta; + if (ymin !== undefined) { + if (Gx.panymin === undefined) { + Gx.panymin = ymin; + } else { + Gx.panymin = Math.min(Gx.panymin, ymin); } - - return ret; } - - /** - * @memberOf sigplot - * @private - */ - function coordsInRectangle(x, y, rect_x, rect_y, rect_width, rect_height) { - return (x >= rect_x && x <= rect_x + rect_width && y >= rect_y && y <= rect_y + rect_height); + if (ymax !== undefined) { + if (Gx.panymax === undefined) { + Gx.panymax = ymax; + } else { + Gx.panymax = Math.max(Gx.panymax, ymax); + } } +} - /** - * @memberOf sigplot - * @private - */ - function coordsInTriangle(x, y, tri_x1, tri_y1, tri_x2, tri_y2, tri_x3, tri_y3) { - // Uses barycentric coordinates - // https://en.wikipedia.org/wiki/Barycentric_coordinate_system ( and http://blackpawn.com/texts/pointinpoly/) - - // Compute vectors - var v0 = [tri_x3 - tri_x1, tri_y3 - tri_y1]; - var v1 = [tri_x2 - tri_x1, tri_y2 - tri_y1]; - var v2 = [x - tri_x1, y - tri_y1]; - - // Compute dot products - var dot00 = (v0[0] * v0[0]) + (v0[1] * v0[1]); - var dot01 = (v0[0] * v1[0]) + (v0[1] * v1[1]); - var dot02 = (v0[0] * v2[0]) + (v0[1] * v2[1]); - var dot11 = (v1[0] * v1[0]) + (v1[1] * v1[1]); - var dot12 = (v1[0] * v2[0]) + (v1[1] * v2[1]); - - var inv_denom = 1 / (dot00 * dot11 - dot01 * dot01); - - var u = (dot11 * dot02 - dot01 * dot12) * inv_denom; - var v = (dot00 * dot12 - dot01 * dot02) * inv_denom; - - /* - console.log("u ", u); - console.log("v ", v); - */ - - return (u >= 0 && v >= 0 && u + v < 1); +/** + * @memberOf sigplot + * @private + */ +function pixel_to_real(plot, xpos, ypos) { + var Gx = plot._Gx; + var Mx = plot._Mx; + var ret = mx.pixel_to_real(Mx, xpos, ypos); + if (Gx.index) { + ret.x = ret.x * Gx.xdelta; } - /** - * @memberOf sigplot - * @private - */ - function inPanRegion(plot, coord) { - var inPanRegion = false; - var Gx = plot._Gx; - var Mx = plot._Mx; - - var x = 0; - var y = 0; - if (coord === undefined) { - x = Mx.xpos; - y = Mx.ypos; + return ret; +} - if (!plot.mouseOnCanvas) { - return false; - } - } else { - x = coord.x; - y = coord.y; - } +/** + * @memberOf sigplot + * @private + */ +function coordsInRectangle(x, y, rect_x, rect_y, rect_width, rect_height) { + return ( + x >= rect_x && + x <= rect_x + rect_width && + y >= rect_y && + y <= rect_y + rect_height + ); +} - var command = ' '; +/** + * @memberOf sigplot + * @private + */ +function coordsInTriangle( + x, + y, + tri_x1, + tri_y1, + tri_x2, + tri_y2, + tri_x3, + tri_y3 +) { + // Uses barycentric coordinates + // https://en.wikipedia.org/wiki/Barycentric_coordinate_system ( and http://blackpawn.com/texts/pointinpoly/) + + // Compute vectors + var v0 = [tri_x3 - tri_x1, tri_y3 - tri_y1]; + var v1 = [tri_x2 - tri_x1, tri_y2 - tri_y1]; + var v2 = [x - tri_x1, y - tri_y1]; + + // Compute dot products + var dot00 = v0[0] * v0[0] + v0[1] * v0[1]; + var dot01 = v0[0] * v1[0] + v0[1] * v1[1]; + var dot02 = v0[0] * v2[0] + v0[1] * v2[1]; + var dot11 = v1[0] * v1[0] + v1[1] * v1[1]; + var dot12 = v1[0] * v2[0] + v1[1] * v2[1]; + + var inv_denom = 1 / (dot00 * dot11 - dot01 * dot01); + + var u = (dot11 * dot02 - dot01 * dot12) * inv_denom; + var v = (dot00 * dot12 - dot01 * dot02) * inv_denom; + + /* + console.log("u ", u); + console.log("v ", v); + */ + + return u >= 0 && v >= 0 && u + v < 1; +} - if (!Gx.pan) { +/** + * @memberOf sigplot + * @private + */ +function inPanRegion(plot, coord) { + var inPanRegion = false; + var Gx = plot._Gx; + var Mx = plot._Mx; + + var x = 0; + var y = 0; + if (coord === undefined) { + x = Mx.xpos; + y = Mx.ypos; + + if (!plot.mouseOnCanvas) { return false; } + } else { + x = coord.x; + y = coord.y; + } - var outside_right_border = (x > Mx.r); - var above_top_border = (y <= Gx.pt + Gx.pthk + 2); - var below_bottom_border = (y > Gx.pt - 2); - var between_top_and_bottom = (y >= Mx.t && y <= Mx.b); - var between_left_and_right = (x >= Gx.pl && x <= Gx.pr); - var has_bottom_scrollbar = (Gx.show_readout || (Gx.x_scrollbar_location === "bottom")); - - if (outside_right_border && between_top_and_bottom) { // YPAN - command = 'YPAN'; // Y scrollbar - // TODO do we want to - // reset the xposition? + var command = " "; - if (Gx.lg_colorbar && (Gx.lyr[0].hcb["class"] === 2)) { - // Need to do an additional check since there is area outside Mx.r that is NOT the pan region - var right_of_colorbar = (x > Mx.r + 100); // Mx.r = Mx.r - 100 is how we moved it initally - if (right_of_colorbar) { - inPanRegion = true; - } else { - inPanRegion = false; - } + if (!Gx.pan) { + return false; + } - } else { - Mx.xpos = Gx.pyl + m.trunc(Gx.pthk / 2); + var outside_right_border = x > Mx.r; + var above_top_border = y <= Gx.pt + Gx.pthk + 2; + var below_bottom_border = y > Gx.pt - 2; + var between_top_and_bottom = y >= Mx.t && y <= Mx.b; + var between_left_and_right = x >= Gx.pl && x <= Gx.pr; + var has_bottom_scrollbar = + Gx.show_readout || Gx.x_scrollbar_location === "bottom"; + + if (outside_right_border && between_top_and_bottom) { + // YPAN + command = "YPAN"; // Y scrollbar + // TODO do we want to + // reset the xposition? + + if (Gx.lg_colorbar && Gx.lyr[0].hcb["class"] === 2) { + // Need to do an additional check since there is area outside Mx.r that is NOT the pan region + var right_of_colorbar = x > Mx.r + 100; // Mx.r = Mx.r - 100 is how we moved it initally + if (right_of_colorbar) { inPanRegion = true; + } else { + inPanRegion = false; } - //possibly do another check for p_cuts as well; - } else if (has_bottom_scrollbar && between_left_and_right && below_bottom_border) { - command = 'XPAN'; // X scrollbar - Mx.ypos = Gx.pt + m.trunc(Gx.pthk / 2); // TODO Do we want to reset - // the yposition? - inPanRegion = true; - } else if (!has_bottom_scrollbar && between_left_and_right && above_top_border) { - command = 'XPAN'; // X scrollbar - Mx.ypos = Gx.pt + m.trunc(Gx.pthk / 2); // TODO Do we want to reset - // the yposition? + } else { + Mx.xpos = Gx.pyl + m.trunc(Gx.pthk / 2); inPanRegion = true; } - - return { - inPanRegion: inPanRegion, - command: command - }; + //possibly do another check for p_cuts as well; + } else if ( + has_bottom_scrollbar && + between_left_and_right && + below_bottom_border + ) { + command = "XPAN"; // X scrollbar + Mx.ypos = Gx.pt + m.trunc(Gx.pthk / 2); // TODO Do we want to reset + // the yposition? + inPanRegion = true; + } else if ( + !has_bottom_scrollbar && + between_left_and_right && + above_top_border + ) { + command = "XPAN"; // X scrollbar + Mx.ypos = Gx.pt + m.trunc(Gx.pthk / 2); // TODO Do we want to reset + // the yposition? + inPanRegion = true; } + return { + inPanRegion: inPanRegion, + command: command, + }; +} - /** - * @memberOf sigplot - * @private - */ - function inPanCenterRegion(plot) { - var inCenterRegion = false; - var Mx = plot._Mx; - var x = Mx.xpos; - var y = Mx.ypos; - var th = Mx.text_h; - var tw = Mx.text_w; - var command = ' '; - - if (x < Mx.l - tw && y <= Mx.b && y >= Mx.t) { // YCENTER - // Mx.canvas.getContext("2d").strokeStyle = "blue"; - // Mx.canvas.getContext("2d").strokeRect(0, Mx.t, Mx.l - tw, Mx.b - - // Mx.t); - command = 'YCENTER'; - inCenterRegion = true; - } else if (y > Mx.b + m.trunc(0.5 * tw) && y <= Mx.b + m.trunc(m.trunc(3 * th) / 2) && x >= Mx.l && x <= Mx.r) { // XCENTER - // Mx.canvas.getContext("2d").strokeStyle = "red"; - // Mx.canvas.getContext("2d").strokeRect(Mx.l, Mx.b + m.trunc(.5 * - // tw), - // Mx.r - Mx.l, (Mx.b + m.trunc(m.trunc(3 * th) / 2)) - (Mx.b + - // m.trunc(.5 * tw))); - command = 'XCENTER'; - inCenterRegion = true; - } - - return { - inCenterRegion: inCenterRegion, - command: command - }; +/** + * @memberOf sigplot + * @private + */ +function inPanCenterRegion(plot) { + var inCenterRegion = false; + var Mx = plot._Mx; + var x = Mx.xpos; + var y = Mx.ypos; + var th = Mx.text_h; + var tw = Mx.text_w; + var command = " "; + + if (x < Mx.l - tw && y <= Mx.b && y >= Mx.t) { + // YCENTER + // Mx.canvas.getContext("2d").strokeStyle = "blue"; + // Mx.canvas.getContext("2d").strokeRect(0, Mx.t, Mx.l - tw, Mx.b - + // Mx.t); + command = "YCENTER"; + inCenterRegion = true; + } else if ( + y > Mx.b + m.trunc(0.5 * tw) && + y <= Mx.b + m.trunc(m.trunc(3 * th) / 2) && + x >= Mx.l && + x <= Mx.r + ) { + // XCENTER + // Mx.canvas.getContext("2d").strokeStyle = "red"; + // Mx.canvas.getContext("2d").strokeRect(Mx.l, Mx.b + m.trunc(.5 * + // tw), + // Mx.r - Mx.l, (Mx.b + m.trunc(m.trunc(3 * th) / 2)) - (Mx.b + + // m.trunc(.5 * tw))); + command = "XCENTER"; + inCenterRegion = true; } - /** - * Returns true if position is within the given scrollbar's area. Depends on - * mx.scroll_real2pix method. - * - * @param position - * An object containing 'x' and 'y' pixel values that represent a - * position. - * @param scrollbar - * The scrollbar object itself. - * - * @private - * @memberOf sigplot - */ - function onScrollbar(position, scrollbar) { - var s1; - var sw; - - /* - * Compute s, the offset in pixels from the 'origin' of the scrollbar's - * on-screen region. - */ - var s; - if (scrollbar.origin & 1) { - s = position.x - scrollbar.x; - if (scrollbar.origin & 2) { - s = scrollbar.w - s; - } - } else { - s = position.y - scrollbar.y; - if (scrollbar.origin <= 2) { - s = scrollbar.h - s; - } - } - - // Update s1 and sw values - var scrollReal2PixOut = mx.scroll_real2pix(scrollbar); - s1 = scrollReal2PixOut.s1; - sw = scrollReal2PixOut.sw; + return { + inCenterRegion: inCenterRegion, + command: command, + }; +} - // Determine if mouse is on scrollbar - if (s >= s1 && s <= s1 + sw) { - return true; - } else { - return false; - } - } +/** + * Returns true if position is within the given scrollbar's area. Depends on + * mx.scroll_real2pix method. + * + * @param position + * An object containing 'x' and 'y' pixel values that represent a + * position. + * @param scrollbar + * The scrollbar object itself. + * + * @private + * @memberOf sigplot + */ +function onScrollbar(position, scrollbar) { + var s1; + var sw; - /** - * Performs the middle-click scroll-menu action specified on the plot. - * - * @param plot - * The plot to work with. - * @param action - * The scrollbar action to perform. - * @param direction - * The scroll direction to update. Acceptable directions are - * either "XPAN" or "YPAN". - * @memberOf sigplot - * @private + /* + * Compute s, the offset in pixels from the 'origin' of the scrollbar's + * on-screen region. */ - function middleClickScrollMenuAction(plot, action, direction) { - var Mx = plot._Mx; - - // Determine the appropriate scrollbar to work with - var scrollbar; - if (direction === "XPAN") { - scrollbar = Mx.scrollbar_x; - } else if (direction === "YPAN") { - scrollbar = Mx.scrollbar_y; + var s; + if (scrollbar.origin & 1) { + s = position.x - scrollbar.x; + if (scrollbar.origin & 2) { + s = scrollbar.w - s; } + } else { + s = position.y - scrollbar.y; + if (scrollbar.origin <= 2) { + s = scrollbar.h - s; + } + } - // Set scrollbar action - scrollbar.action = action; - scrollbar.step = 0.1 * scrollbar.srange; - scrollbar.page = 9 * scrollbar.step; - scrollbar.scale = 2.0; - - // Update min and range to the appropriate values based on action - mx.scroll(Mx, scrollbar, mx.XW_COMMAND, undefined, scrollbar); + // Update s1 and sw values + var scrollReal2PixOut = mx.scroll_real2pix(scrollbar); + s1 = scrollReal2PixOut.s1; + sw = scrollReal2PixOut.sw; - // Update the viewbox based on new min and max values - updateViewbox(plot, scrollbar.smin, scrollbar.smin + scrollbar.srange, - direction.slice(0, 1)); + // Determine if mouse is on scrollbar + if (s >= s1 && s <= s1 + sw) { + return true; + } else { + return false; + } +} - plot.inPan = true; // prevent recursive pans - var evt = document.createEvent('Event'); - if (direction === "XPAN") { - evt.initEvent('xpan', true, true); - } else if (direction === "YPAN") { - evt.initEvent('ypan', true, true); - } - evt.level = Mx.level; - evt.xmin = Mx.stk[Mx.level].xmin; - evt.ymin = Mx.stk[Mx.level].ymin; - evt.xmax = Mx.stk[Mx.level].xmax; - evt.ymax = Mx.stk[Mx.level].ymax; - mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? - plot.inPan = false; +/** + * Performs the middle-click scroll-menu action specified on the plot. + * + * @param plot + * The plot to work with. + * @param action + * The scrollbar action to perform. + * @param direction + * The scroll direction to update. Acceptable directions are + * either "XPAN" or "YPAN". + * @memberOf sigplot + * @private + */ +function middleClickScrollMenuAction(plot, action, direction) { + var Mx = plot._Mx; + + // Determine the appropriate scrollbar to work with + var scrollbar; + if (direction === "XPAN") { + scrollbar = Mx.scrollbar_x; + } else if (direction === "YPAN") { + scrollbar = Mx.scrollbar_y; + } + // Set scrollbar action + scrollbar.action = action; + scrollbar.step = 0.1 * scrollbar.srange; + scrollbar.page = 9 * scrollbar.step; + scrollbar.scale = 2.0; + + // Update min and range to the appropriate values based on action + mx.scroll(Mx, scrollbar, mx.XW_COMMAND, undefined, scrollbar); + + // Update the viewbox based on new min and max values + updateViewbox( + plot, + scrollbar.smin, + scrollbar.smin + scrollbar.srange, + direction.slice(0, 1) + ); + + plot.inPan = true; // prevent recursive pans + var evt = document.createEvent("Event"); + if (direction === "XPAN") { + evt.initEvent("xpan", true, true); + } else if (direction === "YPAN") { + evt.initEvent("ypan", true, true); } + evt.level = Mx.level; + evt.xmin = Mx.stk[Mx.level].xmin; + evt.ymin = Mx.stk[Mx.level].ymin; + evt.xmax = Mx.stk[Mx.level].xmax; + evt.ymax = Mx.stk[Mx.level].ymax; + mx.dispatchEvent(Mx, evt); // TODO should we allow pan to be cancelled? + plot.inPan = false; +} - /** - * Updates a plot's viewbox along a given axis to the provided min and max - * values. - * - * @param plot - * The plot to work with. - * @param newMin - * The new minimum axis value to use - * @param newMax - * The new maximum axis value to use - * @param axis - * The axis to update. Acceptable axis values are "X" or "Y". - * @memberOf sigplot - * @private - */ - function updateViewbox(plot, newMin, newMax, axis) { - var Mx = plot._Mx; - var Gx = plot._Gx; +/** + * Updates a plot's viewbox along a given axis to the provided min and max + * values. + * + * @param plot + * The plot to work with. + * @param newMin + * The new minimum axis value to use + * @param newMax + * The new maximum axis value to use + * @param axis + * The axis to update. Acceptable axis values are "X" or "Y". + * @memberOf sigplot + * @private + */ +function updateViewbox(plot, newMin, newMax, axis) { + var Mx = plot._Mx; + var Gx = plot._Gx; - var k = Mx.level; + var k = Mx.level; - if (axis === "X") { - var xmin = newMin; - var xmax = newMax; + if (axis === "X") { + var xmin = newMin; + var xmax = newMax; - if (Mx.stk[k].xmin !== xmin || Mx.stk[k].xmax !== xmax) { - Mx.stk[k].xmin = xmin; - Mx.stk[k].xmax = xmax; - if (!Gx.xdata && Mx.level === 1) { - Gx.xmin = Mx.stk[1].xmin; - Gx.xmax = Mx.stk[1].xmax; - } - plot.refresh(); + if (Mx.stk[k].xmin !== xmin || Mx.stk[k].xmax !== xmax) { + Mx.stk[k].xmin = xmin; + Mx.stk[k].xmax = xmax; + if (!Gx.xdata && Mx.level === 1) { + Gx.xmin = Mx.stk[1].xmin; + Gx.xmax = Mx.stk[1].xmax; } - } else if (axis === "Y") { - var ymin = newMin; - var ymax = newMax; + plot.refresh(); + } + } else if (axis === "Y") { + var ymin = newMin; + var ymax = newMax; - if (ymin !== Mx.stk[k].ymin || ymax !== Mx.stk[k].ymax) { - Mx.stk[k].ymin = ymin; - Mx.stk[k].ymax = ymax; - if (Gx.cmode === Gx.basemode && Mx.level === 1) { - Gx.ymin = Math.min(Gx.ymin, ymin); - Gx.ymax = Math.max(Gx.ymax, ymax); - } - plot.refresh(); + if (ymin !== Mx.stk[k].ymin || ymax !== Mx.stk[k].ymax) { + Mx.stk[k].ymin = ymin; + Mx.stk[k].ymax = ymax; + if (Gx.cmode === Gx.basemode && Mx.level === 1) { + Gx.ymin = Math.min(Gx.ymin, ymin); + Gx.ymax = Math.max(Gx.ymax, ymax); } + plot.refresh(); } } - - sigplot.Plot = Plot; - module.exports = sigplot; - -}()); +} + +const sigplot = { + Plot, + m, + mx, + Layer1D, + Layer2D, + Layer1DSDS, + Layer2DSDS, + version, +}; + +window.sigplot = { ...sigplot, bluefile, matfile }; + +module.exports = sigplot; \ No newline at end of file diff --git a/js/sigplot.layer1d.js b/js/sigplot.layer1d.js index 557f557..23694de 100644 --- a/js/sigplot.layer1d.js +++ b/js/sigplot.layer1d.js @@ -26,8 +26,7 @@ /* global module */ /* global require */ -(function() { - +(function () { var m = require("./m"); var mx = require("./mx"); @@ -36,7 +35,7 @@ * @param plot */ - var Layer1D = function(plot) { + var Layer1D = function (plot) { this.plot = plot; this.xbuf = undefined; // raw (ArrayBuffer) of ABSC data @@ -81,7 +80,6 @@ }; Layer1D.prototype = { - /** * Initializes the layer to display the provided data. * @@ -93,7 +91,7 @@ * @memberOf Layer1D * @private */ - init: function(hcb, options) { + init: function (hcb, options) { var Gx = this.plot._Gx; this.hcb = hcb; @@ -132,7 +130,7 @@ if (hcb["class"] <= 2) { this.xsub = -1; this.ysub = 1; - this.cx = (hcb.format[0] === 'C'); + this.cx = hcb.format[0] === "C"; } else { // TODO } @@ -166,17 +164,22 @@ this.position = 0; this.tle = options.tl; - this.ybufn = this.size * Math.max(this.skip * m.PointArray.BYTES_PER_ELEMENT, m.PointArray.BYTES_PER_ELEMENT); + this.ybufn = + this.size * + Math.max( + this.skip * m.PointArray.BYTES_PER_ELEMENT, + m.PointArray.BYTES_PER_ELEMENT + ); this.ybuf = new ArrayBuffer(this.ybufn); var self = this; - m.addPipeWriteListener(this.hcb, function() { + m.addPipeWriteListener(this.hcb, function () { self._onpipewrite(); }); } }, - _onpipewrite: function() { + _onpipewrite: function () { var ybuf = new m.PointArray(this.ybuf); var tle = this.tle; // in scalars @@ -189,7 +192,6 @@ // Calculate transfer length in scalars var tl = tle * this.hcb.spa; while (m.pavail(this.hcb) >= tl) { - if (this.drawmode === "lefttoright") { this.position = 0; ybuf.set(ybuf.subarray(0, this.size - tl), tl); @@ -202,10 +204,11 @@ throw "Invalid draw mode"; } - // transfer length is adjusted to the remaining size + // transfer length is adjusted to the remaining size // before wrapping var ngot = m.grabx( - this.hcb, ybuf, + this.hcb, + ybuf, Math.min(tle, this.size - this.position) * this.hcb.spa, this.position * this.hcb.spa ); @@ -223,7 +226,7 @@ } }, - get_data: function(xmin, xmax) { + get_data: function (xmin, xmax) { var Gx = this.plot._Gx; var HCB = this.hcb; @@ -245,7 +248,6 @@ imin = Math.floor((xmin - HCB.xstart) / HCB.xdelta) - 1; imax = Math.floor((xmax - HCB.xstart) / HCB.xdelta + 0.5); } else { - imin = Math.floor((xmax - HCB.xstart) / HCB.xdelta) - 1; imax = Math.floor((xmin - HCB.xstart) / HCB.xdelta + 0.5); } @@ -257,33 +259,42 @@ imin = imax - npts + 1; } - if ((imin >= this.imin) && (imin + npts <= this.imin + this.size) && (this.ybuf !== undefined)) { + if ( + imin >= this.imin && + imin + npts <= this.imin + this.size && + this.ybuf !== undefined + ) { // data already in buffers } else if (this.modified) { // modified data not yet saved off - } else if (HCB["class"] <= 2) { // load new data var start = this.offset + imin; var skip = this.skip; - this.ybufn = npts * Math.max(skip * m.PointArray.BYTES_PER_ELEMENT, - m.PointArray.BYTES_PER_ELEMENT); - if ((this.ybuf === undefined) || (this.ybuf.byteLength < this.ybufn)) { + this.ybufn = + npts * + Math.max( + skip * m.PointArray.BYTES_PER_ELEMENT, + m.PointArray.BYTES_PER_ELEMENT + ); + if ( + this.ybuf === undefined || + this.ybuf.byteLength < this.ybufn + ) { this.ybuf = new ArrayBuffer(this.ybufn); } var ybuf = new m.PointArray(this.ybuf); var ngot = m.grab(HCB, ybuf, start, npts); this.imin = imin; - this.xstart = HCB.xstart + (imin) * this.xdelta; + this.xstart = HCB.xstart + imin * this.xdelta; this.size = ngot; } else { // type 3000, 4000, 5000 // TODO yeah right } - }, - change_settings: function(settings) { + change_settings: function (settings) { if (settings.index !== undefined) { if (settings.index) { this.xstart = 1.0; @@ -291,9 +302,10 @@ this.xmin = 1.0; this.xmax = this.size; } else { - this.xstart = this.hcb.xstart + (this.imin) * this.xdelta; + this.xstart = this.hcb.xstart + this.imin * this.xdelta; this.xdelta = this.hcb.xdelta; - var d = this.hcb.xstart + this.hcb.xdelta * (this.size - 1.0); + var d = + this.hcb.xstart + this.hcb.xdelta * (this.size - 1.0); this.xmin = Math.min(this.hcb.xstart, d); this.xmax = Math.max(this.hcb.xstart, d); } @@ -303,27 +315,37 @@ this.drawmode = settings.drawmode; // Reset the buffer this.position = 0; - this.ybufn = this.size * Math.max(this.skip * m.PointArray.BYTES_PER_ELEMENT, m.PointArray.BYTES_PER_ELEMENT); + this.ybufn = + this.size * + Math.max( + this.skip * m.PointArray.BYTES_PER_ELEMENT, + m.PointArray.BYTES_PER_ELEMENT + ); this.ybuf = new ArrayBuffer(this.ybufn); } if (settings.framesize !== undefined) { this.size = settings.framesize; - this.xstart = this.hcb.xstart + (this.imin) * this.xdelta; + this.xstart = this.hcb.xstart + this.imin * this.xdelta; this.xdelta = this.hcb.xdelta; var d = this.hcb.xstart + this.hcb.xdelta * (this.size - 1.0); this.xmin = Math.min(this.hcb.xstart, d); this.xmax = Math.max(this.hcb.xstart, d); - this.ybufn = this.size * Math.max(this.skip * m.PointArray.BYTES_PER_ELEMENT, m.PointArray.BYTES_PER_ELEMENT); + this.ybufn = + this.size * + Math.max( + this.skip * m.PointArray.BYTES_PER_ELEMENT, + m.PointArray.BYTES_PER_ELEMENT + ); this.ybuf = new ArrayBuffer(this.ybufn); } }, - reload: function(data, hdrmod) { + reload: function (data, hdrmod) { if (this.hcb.pipe) { throw "reload cannot be used with pipe, use push instead"; } - var axis_change = (this.hcb.dview.length !== data.length) || hdrmod; + var axis_change = this.hcb.dview.length !== data.length || hdrmod; if (hdrmod) { for (var k in hdrmod) { this.hcb[k] = hdrmod[k]; @@ -345,7 +367,8 @@ if (this.hcb["class"] === 2) { m.force1000(this.hcb); } - var d = this.hcb.xstart + this.hcb.xdelta * (this.hcb.size - 1.0); + var d = + this.hcb.xstart + this.hcb.xdelta * (this.hcb.size - 1.0); this.xmin = Math.min(this.hcb.xstart, d); this.xmax = Math.max(this.hcb.xstart, d); this.xdelta = this.hcb.xdelta; @@ -356,11 +379,11 @@ return { xmin: xmin, - xmax: xmax + xmax: xmax, }; }, - push: function(data, hdrmod, sync) { + push: function (data, hdrmod, sync) { if (hdrmod) { for (var k in hdrmod) { this.hcb[k] = hdrmod[k]; @@ -375,7 +398,12 @@ this.size = this.hcb.subsize; // Reset the buffer this.position = null; - this.ybufn = this.size * Math.max(this.skip * m.PointArray.BYTES_PER_ELEMENT, m.PointArray.BYTES_PER_ELEMENT); + this.ybufn = + this.size * + Math.max( + this.skip * m.PointArray.BYTES_PER_ELEMENT, + m.PointArray.BYTES_PER_ELEMENT + ); this.ybuf = new ArrayBuffer(this.ybufn); } } @@ -392,10 +420,9 @@ } return hdrmod ? true : false; - }, - prep: function(xmin, xmax) { + prep: function (xmin, xmax) { var Gx = this.plot._Gx; var Mx = this.plot._Mx; @@ -409,7 +436,7 @@ return { num: 0, start: 0, - end: 0 + end: 0, }; } @@ -427,7 +454,7 @@ var n1, n2; var mxmn; // xsub isn't really used yet, so it can largely be ignored - if ((Gx.cmode === 5) || (this.xsub > 0)) { + if (Gx.cmode === 5 || this.xsub > 0) { if (npts <= 0) { // This is a degenerate case when there are no points qmin = Gx.panxmin; @@ -470,11 +497,36 @@ n1 = 0; n2 = npts - 1; } else if (xdelta >= 0.0) { - n1 = Math.max(1.0, Math.min(d, Math.round((xmin - xstart) / xdelta))) - 1.0; - n2 = Math.max(1.0, Math.min(d, Math.round((xmax - xstart) / xdelta) + 2.0)) - 1.0; + n1 = + Math.max( + 1.0, + Math.min(d, Math.round((xmin - xstart) / xdelta)) + ) - 1.0; + n2 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmax - xstart) / xdelta) + 2.0 + ) + ) - 1.0; } else { - n1 = Math.max(1.0, Math.min(d, Math.round((xmax - xstart) / xdelta) - 1.0)) - 1.0; - n2 = Math.max(1.0, Math.min(d, Math.round((xmin - xstart) / xdelta) + 2.0)) - 1.0; + n1 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmax - xstart) / xdelta) - 1.0 + ) + ) - 1.0; + n2 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmin - xstart) / xdelta) + 2.0 + ) + ) - 1.0; } npts = n2 - n1 + 1; @@ -483,7 +535,7 @@ npts = 0; } dbuf = new m.PointArray(this.ybuf).subarray(n1 * skip); - xstart = xstart + xdelta * (n1); + xstart = xstart + xdelta * n1; for (var i = 0; i < npts; i++) { if (Gx.index) { this.xpoint[i] = this.imin + i + 1; @@ -498,7 +550,7 @@ return { num: npts, start: n1, - end: n2 + end: n2, }; } if (this.cx) { @@ -507,7 +559,12 @@ } else if (Gx.cmode === 2) { if (Gx.plab === 25) { m.cvpha(dbuf, this.ypoint, npts); - m.vsmul(this.ypoint, 1.0 / (2 * Math.PI), this.ypoint, npts); + m.vsmul( + this.ypoint, + 1.0 / (2 * Math.PI), + this.ypoint, + npts + ); } else if (Gx.plab !== 24) { m.cvpha(dbuf, this.ypoint, npts); } else { @@ -521,9 +578,11 @@ m.vmov(dbuf.subarray(1), skip, this.ypoint, 1, npts); } } else { - if (Gx.cmode === 5) { // I vs. R + if (Gx.cmode === 5) { + // I vs. R m.vfill(this.ypoint, 0, npts); - } else if ((Gx.cmode === 1) || (Gx.cmode >= 6)) { // Mag, log + } else if (Gx.cmode === 1 || Gx.cmode >= 6) { + // Mag, log for (var i = 0; i < npts; i++) { this.ypoint[i] = Math.abs(dbuf[i]); } @@ -540,7 +599,7 @@ if (Gx.cmode === 7) { dbscale = 20.0; } - if ((Gx.lyr.length > 0) && (Gx.lyr[0].cx)) { + if (Gx.lyr.length > 0 && Gx.lyr[0].cx) { dbscale = dbscale / 2.0; } m.vsmul(this.ypoint, dbscale, this.ypoint); @@ -572,17 +631,17 @@ panxmin: this.xmin, panxmax: this.xmax, panymin: qmin, - panymax: qmax + panymax: qmax, }; }, /** * Get the pan-boundaries for the layer. - * - * @param {*} view + * + * @param {*} view * - a specific view to calculate the bounds against */ - get_pan_bounds: function(view) { + get_pan_bounds: function (view) { var Mx = this.plot._Mx; var Gx = this.plot._Gx; @@ -590,12 +649,12 @@ // plot will only attempt to figure-out the // new pany using the current view-box var xmin = this.xmin; - // Minic legacy XPLOT behavior; by default the + // Minic legacy XPLOT behavior; by default the // pan boundaries are based off the first bufmax of // points. var xmax = Math.min( - xmin + (this.size * this.xdelta), - xmin + (Gx.bufmax * this.xdelta) + xmin + this.size * this.xdelta, + xmin + Gx.bufmax * this.xdelta ); if (view) { @@ -614,8 +673,14 @@ while (xmin < xmax) { let prep = this.prep(xmin, xmax); - panymin = (panymin === undefined) ? prep.panymin : Math.min(panymin, prep.panymin); - panymax = (panymax === undefined) ? prep.panymax : Math.max(panymax, prep.panymax); + panymin = + panymin === undefined + ? prep.panymin + : Math.min(panymin, prep.panymin); + panymax = + panymax === undefined + ? prep.panymax + : Math.max(panymax, prep.panymax); num += prep.num; if (Gx.all) { @@ -626,9 +691,9 @@ xmin = xmin + prep.num; } else { if (this.xdelta >= 0) { - xmin = xmin + (prep.num * this.xdelta); + xmin = xmin + prep.num * this.xdelta; } else { - xmax = xmax + (prep.num * this.xdelta); + xmax = xmax + prep.num * this.xdelta; } } } @@ -651,11 +716,11 @@ xmin: this.xmin, xmax: this.xmax, ymin: this.ymin, - ymax: this.ymax + ymax: this.ymax, }; }, - draw: function() { + draw: function () { var Mx = this.plot._Mx; var Gx = this.plot._Gx; @@ -698,7 +763,8 @@ } } - var segment = (Gx.segment) && (Gx.cmode !== 5) && (this.xsub > 0) && (mask === 0); + var segment = + Gx.segment && Gx.cmode !== 5 && this.xsub > 0 && mask === 0; var xdelta = this.xdelta; var xmin; @@ -709,13 +775,14 @@ } else { xmin = Math.max(this.xmin, Mx.stk[Mx.level].xmin); xmax = Math.min(this.xmax, Mx.stk[Mx.level].xmax); - if (xmin >= xmax) { // no data but do scaling + if (xmin >= xmax) { + // no data but do scaling Gx.panxmin = Math.min(Gx.panxmin, this.xmin); Gx.panxmax = Math.max(Gx.panxmax, this.xmax); } } - if ((line === 0) && (symbol === 0)) { + if (line === 0 && symbol === 0) { // Nothing to draw return { num: 0, @@ -736,15 +803,22 @@ var pts = this.prep(xmin, xmax); - panymin = (panymin === undefined) ? pts.panymin : Math.min(panymin, pts.panymin); - panymax = (panymax === undefined) ? pts.panymax : Math.max(panymax, pts.panymax); + panymin = + panymin === undefined + ? pts.panymin + : Math.min(panymin, pts.panymin); + panymax = + panymax === undefined + ? pts.panymax + : Math.max(panymax, pts.panymax); num += pts.num; if (pts.num > 0) { if (segment) { // TODO } else { - mx.trace(Mx, + mx.trace( + Mx, ic, new m.PointArray(this.xptr), new m.PointArray(this.yptr), @@ -754,7 +828,8 @@ line, symbol, rad, - traceoptions); + traceoptions + ); } } @@ -765,17 +840,17 @@ xmin = xmin + pts.num; } else { if (xdelta >= 0) { - xmin = xmin + (this.size * xdelta); + xmin = xmin + this.size * xdelta; } else { - xmax = xmax + (this.size * xdelta); + xmax = xmax + this.size * xdelta; } } } } - if ((this.position) && (this.drawmode === "scrolling")) { + if (this.position && this.drawmode === "scrolling") { var pnt = mx.real_to_pixel(Mx, this.position * this.xdelta, 0); - if ((pnt.x > Mx.l) && (pnt.x < Mx.r)) { + if (pnt.x > Mx.l && pnt.x < Mx.r) { mx.draw_line(Mx, "white", pnt.x, Mx.t, pnt.x, Mx.b); } } @@ -788,7 +863,7 @@ xmin: this.xmin, xmax: this.xmax, ymin: this.ymin, - ymax: this.ymax + ymax: this.ymax, }; }, @@ -811,7 +886,7 @@ * @param {String} * hightlight.id the id for the highlight */ - add_highlight: function(highlight) { + add_highlight: function (highlight) { if (!this.options.highlight) { this.options.highlight = []; } @@ -822,18 +897,18 @@ var min_nan = isNaN(xmin); var max_nan = isNaN(xmax); - if ((min_nan === true) || (xmin === null) || (xmin === undefined)) { - + if (min_nan === true || xmin === null || xmin === undefined) { this.options.highlight = []; } - if ((max_nan === true) || (xmax === null) || (xmax === undefined)) { - + if (max_nan === true || xmax === null || xmax === undefined) { this.options.highlight = []; } if (highlight instanceof Array) { this.options.highlight.push.apply( - this.options.highlight, highlight); + this.options.highlight, + highlight + ); } else { this.options.highlight.push(highlight); } @@ -847,11 +922,14 @@ * the id of the highlight to remove * or the highlight object itself */ - remove_highlight: function(highlight) { + remove_highlight: function (highlight) { if (this.options.highlight) { var i = this.options.highlight.length; while (i--) { - if ((highlight === this.options.highlight[i]) || (highlight === this.options.highlight[i].id)) { + if ( + highlight === this.options.highlight[i] || + highlight === this.options.highlight[i].id + ) { this.options.highlight.splice(i, 1); } } @@ -859,7 +937,7 @@ } }, - get_highlights: function() { + get_highlights: function () { if (this.options.highlight) { return this.options.highlight.slice(0); } else { @@ -870,12 +948,12 @@ /** * Clear all highlights from the layer. */ - clear_highlights: function() { + clear_highlights: function () { if (this.options.highlight) { this.options.highlight = undefined; this.plot.refresh(); } - } + }, }; /** @@ -893,7 +971,7 @@ * * @private */ - Layer1D.overlay = function(plot, hcb, layerOptions) { + Layer1D.overlay = function (plot, hcb, layerOptions) { var Gx = plot._Gx; var Mx = plot._Mx; @@ -906,7 +984,7 @@ // it's own layer var n1 = 0; var n2 = 1; - if ((hcb["class"] === 2) && (hcb.size > 0)) { + if (hcb["class"] === 2 && hcb.size > 0) { var num_rows = hcb.size / hcb.subsize; n2 = Math.min(num_rows, 16 - Gx.lyr.length); } @@ -922,7 +1000,7 @@ layer.init(hcb, layerOptions); // Provide a default color for the layer - var n = (Gx.lyr.length) % mixc.length; + var n = Gx.lyr.length % mixc.length; layer.color = mx.getcolor(Mx, m.Mc.colormap[3].colors, mixc[n]); // Provide the layer name @@ -935,7 +1013,10 @@ layer.name = layer_name_override[i]; } else { layer.name = layer_name_override; - layer.name = layer.name + "." + mx.pad((i + 1).toString(), 3, "0"); + layer.name = + layer.name + + "." + + mx.pad((i + 1).toString(), 3, "0"); } } // If a name hasn't been assigned yet @@ -945,7 +1026,8 @@ } else { layer.name = "layer_" + Gx.lyr.length; } - layer.name = layer.name + "." + mx.pad((i + 1).toString(), 3, "0"); + layer.name = + layer.name + "." + mx.pad((i + 1).toString(), 3, "0"); } layer.offset = i * hcb.subsize; } else { @@ -973,5 +1055,4 @@ }; module.exports = Layer1D; - -}()); +})(); diff --git a/js/sigplot.layer1dSDS.js b/js/sigplot.layer1dSDS.js index d3e7963..f72c7cf 100644 --- a/js/sigplot.layer1dSDS.js +++ b/js/sigplot.layer1dSDS.js @@ -24,479 +24,506 @@ */ /* global module */ -/* global require */ -(function() { +import m from "./m"; +import mx from "./mx"; +import common from "./common"; +import LRU from "lru-cache"; - var m = require("./m"); - var mx = require("./mx"); - var common = require("./common"); - var LRU = require("lru"); +/** + * @constructor + * @param plot + */ +const Layer1DSDS = function (plot) { + this.plot = plot; + this.options = {}; + this.size = 0; + this.color = 0; + this.line = 3; + this.thick = 1; + this.opacity = 1.0; + this.fillStyle = null; + this.symbol = 0; + this.radius = 3; + this.display = true; + this.xptr = null; + this.yptr = null; + this.xpoint = null; // PointArray backed by memory in xptr + this.ypoint = null; // PointArray backed by memory in yptr + this.server_data = null; + this.ymax = -1; + this.ymin = 0; + this.localpanymin = 0; + this.localpanymax = -1; + this.xmax = -1; + this.xmin = 0; + this.localpanxmin = 0; + this.localpanxmax = -1; + this.xlab = 0; + this.ylab = 0; + this.mode = "lds"; + this.xypos_index = 0; + this.y_value_change = false; + this.pendingurl = ""; +}; + +Layer1DSDS.prototype = { /** - * @constructor - * @param plot + * Initializes the layer to display the provided data. + * + * @param hcb + * {BlueHeader} an opened BlueHeader file + * @param lyrn + * the index of the added layer + * + * @memberOf Layer1D + * @private */ + init: function (hcb, options) { + var Gx = this.plot._Gx; + var Mx = this.plot._Mx; - var Layer1DSDS = function(plot) { - this.plot = plot; - this.options = {}; - this.size = 0; - this.color = 0; - this.line = 3; - this.thick = 1; - this.opacity = 1.0; - this.fillStyle = null; - this.symbol = 0; - this.radius = 3; - this.display = true; - this.xptr = null; - this.yptr = null; - this.xpoint = null; // PointArray backed by memory in xptr - this.ypoint = null; // PointArray backed by memory in yptr - this.server_data = null; - this.ymax = -1; - this.ymin = 0; - this.localpanymin = 0; - this.localpanymax = -1; - this.xmax = -1; - this.xmin = 0; - this.localpanxmin = 0; - this.localpanxmax = -1; - this.xlab = 0; - this.ylab = 0; - this.mode = "lds"; - this.xypos_index = 0; - this.y_value_change = false; - this.pendingurl = ""; - }; - - Layer1DSDS.prototype = { - - /** - * Initializes the layer to display the provided data. - * - * @param hcb - * {BlueHeader} an opened BlueHeader file - * @param lyrn - * the index of the added layer - * - * @memberOf Layer1D - * @private - */ - init: function(hcb, options) { - var Gx = this.plot._Gx; - var Mx = this.plot._Mx; - - this.hcb = hcb; - this.hcb.buf_type = "I"; + this.hcb = hcb; + this.hcb.buf_type = "I"; + if (hcb["file_type"] === 2000) { + m.force1000(hcb); + this.size = hcb.subsize; + } else { + this.size = hcb.size; + } + if (this.mode === "lds" || this.mode === "xcut") { + this.xmin = this.hcb.xstart; + this.xmax = this.hcb.xstart + this.hcb.xdelta * this.size; //If size is subsize for 2000 files then this logic should work. + } else if (this.mode === "ycut") { + // In y cut mode this 1D plot will have its x axis be the y axis of the original 2D file. + this.xmin = this.hcb.ystart; if (hcb["file_type"] === 2000) { - m.force1000(hcb); - this.size = hcb.subsize; + this.xmax = + this.hcb.ystart + this.hcb.ydelta * this.hcb.size; } else { - this.size = hcb.size; - } - if (this.mode ==="lds" || this.mode==="xcut") { - this.xmin = this.hcb.xstart; - this.xmax = this.hcb.xstart+ this.hcb.xdelta*this.size; //If size is subsize for 2000 files then this logic should work. - } - else if (this.mode === "ycut") { // In y cut mode this 1D plot will have its x axis be the y axis of the original 2D file. - this.xmin = this.hcb.ystart; - if (hcb["file_type"] === 2000) { - this.xmax = this.hcb.ystart + this.hcb.ydelta*this.hcb.size; - } else { - this.xmax = this.hcb.ystart + this.hcb.ydelta*(this.hcb.size/this.hcb.subsize); - } + this.xmax = + this.hcb.ystart + + this.hcb.ydelta * (this.hcb.size / this.hcb.subsize); } - this.set_pan_values(); + } + this.set_pan_values(); - this.cache = new LRU(20); + this.cache = new LRU({max: 20}); - //De-Bounce this function - this.debounceSend = common.debounce(function(oReq) { + //De-Bounce this function + this.debounceSend = common.debounce( + function (oReq) { oReq.send(null); - }, 100,false); - - }, - - get_data: function() { - - }, - - change_settings: function(settings) { - var Gx = this.plot._Gx; - if (settings.cmode !== undefined) { // If setting a new cmode then reset y values. - - if (((Gx.autoz & 1) !== 0)) { - this.ymin = 0; - this.localpanymin = 0; - } - if (((Gx.autoz & 2) !== 0)) { - this.ymax = -1; - this.localpanymax = -1; - } + }, + 100, + false + ); + }, + + get_data: function () {}, + + change_settings: function (settings) { + var Gx = this.plot._Gx; + if (settings.cmode !== undefined) { + // If setting a new cmode then reset y values. + + if ((Gx.autoz & 1) !== 0) { + this.ymin = 0; + this.localpanymin = 0; + } + if ((Gx.autoz & 2) !== 0) { + this.ymax = -1; + this.localpanymax = -1; } - }, + } + }, - reload: function(data, hdrmod) { + reload: function (data, hdrmod) {}, - }, + push: function (data, hdrmod, sync) {}, - push: function(data, hdrmod, sync) { - }, + set_pan_values() { + if (this.localpanxmin > this.localpanxmax) { + this.localpanxmin = this.xmin; + this.localpanxmax = this.xmax; + } else { + this.localpanxmin = Math.min(this.localpanxmin, this.xmin); + this.localpanxmax = Math.max(this.localpanxmax, this.xmax); + } - set_pan_values() { + if (this.localpanymin > this.localpanymax) { + this.localpanymin = this.ymin; + this.localpanymax = this.ymax; + } else { + this.localpanymin = Math.min(this.localpanymin, this.ymin); + this.localpanymax = Math.max(this.localpanymax, this.ymax); + } + }, + + prep: function (xmin, xmax) {}, + + make_request_url: function (x1, y1, x2, y2, zmin, zmax) { + var Gx = this.plot._Gx; + var Mx = this.plot._Mx; + var url; + + var urlsplit = this.hcb.url.split("/sds/hdr/"); + var url = ""; + + if (this.mode === "lds") { + url = + urlsplit[0] + + "/sds/lds/" + + x1 + + "/" + + x2 + + "/" + + Math.round(Mx.r - Mx.l) + + "/" + + Math.round(Mx.b - Mx.t) + + "/" + + urlsplit[1]; + } else if (this.mode === "xcut") { + url = + urlsplit[0] + + "/sds/rdsxcut/" + + x1 + + "/" + + this.xypos_index + + "/" + + x2 + + "/" + + Math.round(this.xypos_index + 1) + + "/" + + Math.round(Mx.r - Mx.l) + + "/" + + Math.round(Mx.b - Mx.t) + + "/" + + urlsplit[1]; + } else if (this.mode === "ycut") { + url = + urlsplit[0] + + "/sds/rdsycut/" + + this.xypos_index + + "/" + + y1 + + "/" + + Math.round(this.xypos_index + 1) + + "/" + + y2 + + "/" + + Math.round(Mx.r - Mx.l) + + "/" + + Math.round(Mx.b - Mx.t) + + "/" + + urlsplit[1]; + } - if (this.localpanxmin > this.localpanxmax) { - this.localpanxmin = this.xmin; - this.localpanxmax = this.xmax; + if (zmin !== undefined) { + if (url.includes("?")) { + url = url + "&zmin=" + zmin; } else { - this.localpanxmin = Math.min(this.localpanxmin, this.xmin); - this.localpanxmax = Math.max(this.localpanxmax, this.xmax); + url = url + "?zmin=" + zmin; } - - if (this.localpanymin > this.localpanymax) { - this.localpanymin = this.ymin; - this.localpanymax = this.ymax; + } + if (zmax !== undefined) { + if (url.includes("?")) { + url = url + "&zmax=" + zmax; } else { - this.localpanymin = Math.min(this.localpanymin, this.ymin); - this.localpanymax = Math.max(this.localpanymax, this.ymax); - } - - }, - - prep: function(xmin,xmax) { - - }, - - make_request_url: function(x1,y1,x2,y2,zmin,zmax) { - var Gx = this.plot._Gx; - var Mx = this.plot._Mx; - var url; - - var urlsplit = this.hcb.url.split("/sds/hdr/"); - var url = ""; - - if (this.mode==="lds" ) { - url = urlsplit[0]+"/sds/lds/" + - x1 + "/" + - x2 + "/" + - Math.round(Mx.r-Mx.l) + "/" + - Math.round(Mx.b-Mx.t) + "/" + - urlsplit[1]; - } else if (this.mode==="xcut" ) { - url = urlsplit[0]+"/sds/rdsxcut/" + - x1 + "/" + - this.xypos_index + "/" + - x2 + "/" + - Math.round(this.xypos_index+1) + "/" + - Math.round(Mx.r-Mx.l) + "/" + - Math.round(Mx.b-Mx.t) + "/" + - urlsplit[1]; - } else if (this.mode==="ycut" ) { - url = urlsplit[0]+"/sds/rdsycut/" + - this.xypos_index + "/" + - y1 + "/" + - Math.round(this.xypos_index +1) + "/" + - y2 + "/" + - Math.round(Mx.r-Mx.l) + "/" + - Math.round(Mx.b-Mx.t) + "/" + - urlsplit[1]; - } - - if (zmin !== undefined) { - if (url.includes("?")) { - url = url+"&zmin=" + zmin; - } else { - url = url+"?zmin=" + zmin; - } - - } - if (zmax !== undefined) { - if (url.includes("?")) { - url = url+"&zmax=" + zmax; - } else { - url = url+"?zmax=" + zmax; - } + url = url + "?zmax=" + zmax; } + } - if (Gx.cmode !== undefined) { - var cxm = ["Ma", "Ph", "Re", "Im", "IR", "Lo", "L2"]; - if (url.includes("?")) { - url = url+"&cxmode=" + cxm[Gx.cmode-1]; - } else { - url = url+"?cxmode=" + cxm[Gx.cmode-1]; - } + if (Gx.cmode !== undefined) { + var cxm = ["Ma", "Ph", "Re", "Im", "IR", "Lo", "L2"]; + if (url.includes("?")) { + url = url + "&cxmode=" + cxm[Gx.cmode - 1]; + } else { + url = url + "?cxmode=" + cxm[Gx.cmode - 1]; } - return url; - }, + } + return url; + }, - send_request_to_server: function(url) { - if (this.pendingurl === url) { - return; - } - var oReq; - oReq = new XMLHttpRequest(); - oReq.open("GET", url, true); - oReq.responseType = "arraybuffer"; - oReq.overrideMimeType('text\/plain; charset=x-user-defined'); - - var that = this; - oReq.onload = function(oEvent) { - // `this` will be oReq within this context - that.load_data_from_server(url, this, oEvent); - }; - oReq.onerror = function(oEvent) { - }; - this.debounceSend(oReq); - this.pendingurl = url; - }, - - load_data_from_server: function(url, oReq, oEvent) { - var Mx = this.plot._Mx; - - if (oReq.readyState === 4) { - if ((oReq.status === 200) || (oReq.status === 0)) { // status = 0 is necessary for file URL - var Mx = this.plot._Mx; - var Gx = this.plot._Gx; - var arrayBuffer = null; // Note: not oReq.responseText - if (oReq.response) { - arrayBuffer = oReq.response; - } - - this.server_data = new Int16Array(arrayBuffer); - - var ymin = parseFloat(oReq.getResponseHeader("Zmin")); - var ymax = parseFloat(oReq.getResponseHeader("Zmax")); - this.ymin = ymin; - this.ymax = ymax; - this.set_pan_values(); - - //cache the data for later - arrayBuffer.zmin = this.ymin; - arrayBuffer.zmax = this.ymax; - this.cache.set(url, arrayBuffer); - this.plot.refresh(); - + send_request_to_server: function (url) { + if (this.pendingurl === url) { + return; + } + var oReq; + oReq = new XMLHttpRequest(); + oReq.open("GET", url, true); + oReq.responseType = "arraybuffer"; + oReq.overrideMimeType("text/plain; charset=x-user-defined"); + + var that = this; + oReq.onload = function (oEvent) { + // `this` will be oReq within this context + that.load_data_from_server(url, this, oEvent); + }; + oReq.onerror = function (oEvent) {}; + this.debounceSend(oReq); + this.pendingurl = url; + }, + + load_data_from_server: function (url, oReq, oEvent) { + var Mx = this.plot._Mx; + + if (oReq.readyState === 4) { + if (oReq.status === 200 || oReq.status === 0) { + // status = 0 is necessary for file URL + var Mx = this.plot._Mx; + var Gx = this.plot._Gx; + var arrayBuffer = null; // Note: not oReq.responseText + if (oReq.response) { + arrayBuffer = oReq.response; } - } - - }, - - process_plot_data: function() { - var Gx = this.plot._Gx; - var Mx = this.plot._Mx; - - var numPixels = this.server_data.length/2; - this.xptr = new ArrayBuffer(numPixels*2); - this.yptr = new ArrayBuffer(numPixels*2); - this.xpoint = new Int16Array(this.xptr); - this.ypoint = new Int16Array(this.yptr); + this.server_data = new Int16Array(arrayBuffer); - // lds service returns int16 pixels with a list of all x values followed by all y values. - m.vmov(this.server_data,1,this.xpoint,1,numPixels); - m.vmov(this.server_data.subarray(numPixels),1,this.ypoint,1,numPixels); - - var traceoptions = {}; + var ymin = parseFloat(oReq.getResponseHeader("Zmin")); + var ymax = parseFloat(oReq.getResponseHeader("Zmax")); + this.ymin = ymin; + this.ymax = ymax; + this.set_pan_values(); - if (this.fillStyle) { - traceoptions.fillStyle = this.fillStyle; - } else if (Gx.fillStyle) { - traceoptions.fillStyle = Gx.fillStyle; - } - if (this.options) { - traceoptions.highlight = this.options.highlight; - traceoptions.noclip = this.options.noclip; + //cache the data for later + arrayBuffer.zmin = this.ymin; + arrayBuffer.zmax = this.ymax; + this.cache.set(url, arrayBuffer); + this.plot.refresh(); } - var line = 0; - if (this.line === 0) { - line = 0; - } else { - line = 1; - if (this.thick > 0) { - line = this.thick; - } else if (this.thick < 0) { - line = Math.abs(this.thick); - traceoptions.dashed = true; - } - if (this.line === 1) { - traceoptions.vertsym = true; - } - if (this.line === 2) { - traceoptions.horzsym = true; - } - if (this.line === 4) { - traceoptions.horzsym = true; - traceoptions.vertsym = true; - } + } + }, + + process_plot_data: function () { + var Gx = this.plot._Gx; + var Mx = this.plot._Mx; + + var numPixels = this.server_data.length / 2; + this.xptr = new ArrayBuffer(numPixels * 2); + this.yptr = new ArrayBuffer(numPixels * 2); + this.xpoint = new Int16Array(this.xptr); + this.ypoint = new Int16Array(this.yptr); + + // lds service returns int16 pixels with a list of all x values followed by all y values. + m.vmov(this.server_data, 1, this.xpoint, 1, numPixels); + m.vmov( + this.server_data.subarray(numPixels), + 1, + this.ypoint, + 1, + numPixels + ); + + var traceoptions = {}; + + if (this.fillStyle) { + traceoptions.fillStyle = this.fillStyle; + } else if (Gx.fillStyle) { + traceoptions.fillStyle = Gx.fillStyle; + } + if (this.options) { + traceoptions.highlight = this.options.highlight; + traceoptions.noclip = this.options.noclip; + } + var line = 0; + if (this.line === 0) { + line = 0; + } else { + line = 1; + if (this.thick > 0) { + line = this.thick; + } else if (this.thick < 0) { + line = Math.abs(this.thick); + traceoptions.dashed = true; } - traceoptions.pixels = true; - mx.trace(Mx, - this.color, - this.xpoint, - this.ypoint, - this.xpoint.length, - 0, - 1, - line, - this.symbol, - this.radius, - traceoptions); - - }, - - get_pan_bounds: function(view) { - var cacheData = this.get_data_from_cache(); - if (cacheData.plotData) { - this.ymin = cacheData.plotData.zmin; - this.ymax = cacheData.plotData.zmax; - this.set_pan_values(); + if (this.line === 1) { + traceoptions.vertsym = true; } - var xmin,xmax,ymin,ymax; - if (this.localpanxmin= (this.hcb.subsize * this.hcb.spa)) { - + while (m.pavail(this.hcb) >= this.hcb.subsize * this.hcb.spa) { // if we aren't scrolling, than update the values // so that the axis scrolls with the data. The below // code might seem counter intuitive, but given the @@ -187,7 +181,7 @@ if (this.drawmode !== "scrolling") { this.hcb.ystart += this.hcb.ydelta; this.ystart = this.hcb.ystart; - this.ymin = this.hcb.ystart - (this.hcb.ydelta * (this.lps)); + this.ymin = this.hcb.ystart - this.hcb.ydelta * this.lps; this.ymax = this.hcb.ystart; } @@ -206,7 +200,8 @@ this.ystart = 0; this.ymin = 0; this.ymax = ylength; - if (this.position >= this.lps) { // if lps got resized make sure we don't go out of bounds + if (this.position >= this.lps) { + // if lps got resized make sure we don't go out of bounds this.position = 0; } } else { @@ -219,8 +214,13 @@ } // grab one row worth of data - var ngot = m.grabx(this.hcb, this.buf, this.hcb.subsize * this.hcb.spa); - if (ngot === 0) { // shouldn't happen because of the pavail check + var ngot = m.grabx( + this.hcb, + this.buf, + this.hcb.subsize * this.hcb.spa + ); + if (ngot === 0) { + // shouldn't happen because of the pavail check m.log.error("Internal error"); return; } @@ -232,7 +232,12 @@ } else if (Gx.cmode === 2) { if (Gx.plab === 25) { m.cvpha(this.buf, zpoint, zpoint.length); - m.vsmul(zpoint, 1.0 / (2 * Math.PI), zpoint, zpoint.length); + m.vsmul( + zpoint, + 1.0 / (2 * Math.PI), + zpoint, + zpoint.length + ); } else if (Gx.plab !== 24) { m.cvpha(this.buf, zpoint, zpoint.length); } else { @@ -241,28 +246,44 @@ } else if (Gx.cmode === 3) { m.vmov(this.buf, this.skip, zpoint, 1, zpoint.length); } else if (Gx.cmode === 4) { - m.vmov(this.buf.subarray(1), this.skip, zpoint, 1, zpoint.length); - } else if (Gx.cmode === 5) { // IR + m.vmov( + this.buf.subarray(1), + this.skip, + zpoint, + 1, + zpoint.length + ); + } else if (Gx.cmode === 5) { + // IR m.vfill(zpoint, 0, zpoint.length); - } else if (Gx.cmode === 6) { // 10log + } else if (Gx.cmode === 6) { + // 10log m.cvmag2logscale(this.buf, Gx.dbmin, 10.0, zpoint); - } else if (Gx.cmode === 7) { // 20log + } else if (Gx.cmode === 7) { + // 20log m.cvmag2logscale(this.buf, Gx.dbmin, 20.0, zpoint); } } else { - if (Gx.cmode === 1) { // mag + if (Gx.cmode === 1) { + // mag m.vabs(this.buf, zpoint); - } else if (Gx.cmode === 2) { // phase + } else if (Gx.cmode === 2) { + // phase m.vfill(zpoint, 0, zpoint.length); - } else if (Gx.cmode === 3) { // real + } else if (Gx.cmode === 3) { + // real m.vmov(this.buf, this.skip, zpoint, 1, zpoint.length); - } else if (Gx.cmode === 4) { // imag + } else if (Gx.cmode === 4) { + // imag m.vfill(zpoint, 0, zpoint.length); - } else if (Gx.cmode === 5) { // IR + } else if (Gx.cmode === 5) { + // IR m.vfill(zpoint, 0, zpoint.length); - } else if (Gx.cmode === 6) { // 10log + } else if (Gx.cmode === 6) { + // 10log m.vlogscale(this.buf, Gx.dbmin, 10.0, zpoint); - } else if (Gx.cmode === 7) { // 20log + } else if (Gx.cmode === 7) { + // 20log m.vlogscale(this.buf, Gx.dbmin, 20.0, zpoint); } } @@ -283,7 +304,7 @@ zmin = min; zmax = max; } else if (Gx.autol > 1) { - var fac = 1.0 / (Math.max(Gx.autol, 1)); + var fac = 1.0 / Math.max(Gx.autol, 1); zmin = Gx.zmin * fac + min * (1.0 - fac); zmax = Gx.zmax * fac + max * (1.0 - fac); } else if (Gx.autol < 0) { @@ -291,15 +312,15 @@ // 5 like the original XRTRASTER; however, // don't actually override Gx.autol since // other layers may behave differently - var fac = 1.0 / (Math.max(5, 1)); + var fac = 1.0 / Math.max(5, 1); zmin = Gx.zmin * fac + min * (1.0 - fac); zmax = Gx.zmax * fac + max * (1.0 - fac); } - if (((Gx.autoz & 1) !== 0)) { + if ((Gx.autoz & 1) !== 0) { Gx.zmin = zmin; } - if (((Gx.autoz & 2) !== 0)) { + if ((Gx.autoz & 2) !== 0) { Gx.zmax = zmax; } if (Gx.p_cuts) { @@ -312,7 +333,6 @@ this.zbuf[i] = zpoint[b]; b++; } - } if (this.drawmode === "falling") { //shift and fill in the next row of data. @@ -339,7 +359,15 @@ } if (this.img) { - mx.update_image_row(Mx, this.img, zpoint, this.position, Gx.zmin, Gx.zmax, this.xcompression); + mx.update_image_row( + Mx, + this.img, + zpoint, + this.position, + Gx.zmin, + Gx.zmax, + this.xcompression + ); } this.frame += 1; if (this.drawmode === "scrolling") { @@ -355,18 +383,26 @@ } }, - get_data: function() { + get_data: function () { var HCB = this.hcb; if (!this.buf) { if (this.hcb.pipe) { // For pipes, we allocate buf and zbuf to only hold one line of // data - this.buf = this.hcb.createArray(null, 0, this.hcb.subsize * this.hcb.spa); + this.buf = this.hcb.createArray( + null, + 0, + this.hcb.subsize * this.hcb.spa + ); this.zbuf = new m.PointArray(this.hcb.subsize); } else { // Otherwise, we allocate for the entire image - this.buf = this.hcb.createArray(null, 0, this.lps * this.hcb.subsize * this.hcb.spa); + this.buf = this.hcb.createArray( + null, + 0, + this.lps * this.hcb.subsize * this.hcb.spa + ); this.zbuf = new m.PointArray(this.lps * this.hcb.subsize); } } @@ -383,41 +419,48 @@ * @param x * @param y */ - get_z: function(x, y) { + get_z: function (x, y) { var ix = Math.floor(x / this.hcb.xdelta); var iy = Math.floor(y / this.hcb.ydelta); - var zidx = (iy * this.hcb.subsize) + ix; + var zidx = iy * this.hcb.subsize + ix; return this.zbuf[zidx]; }, - change_settings: function(settings) { + change_settings: function (settings) { var Gx = this.plot._Gx; if (settings.subsize) { this.hcb.subsize = settings.subsize; this.hcb.ape = settings.subsize; - this.hcb.size = this.hcb.dview.length / (this.hcb.spa * this.hcb.ape); + this.hcb.size = + this.hcb.dview.length / (this.hcb.spa * this.hcb.ape); this.lps = Math.ceil(this.hcb.size); - var d = this.hcb.ystart + (this.hcb.ydelta * this.lps); + var d = this.hcb.ystart + this.hcb.ydelta * this.lps; this.ymin = this.hcb.ymin || Math.min(this.hcb.ystart, d); this.ymax = this.hcb.ymax || Math.max(this.hcb.ystart, d); } if (settings.cmode !== undefined) { this.img = undefined; - if (((Gx.autoz & 1) !== 0)) { + if ((Gx.autoz & 1) !== 0) { Gx.zmin = undefined; } - if (((Gx.autoz & 2) !== 0)) { + if ((Gx.autoz & 2) !== 0) { Gx.zmax = undefined; } } - if ((settings.zmin !== undefined) || - (settings.zmax !== undefined) || - (settings.autoz !== undefined)) { + if ( + settings.zmin !== undefined || + settings.zmax !== undefined || + settings.autoz !== undefined + ) { this.img = undefined; } - if ((settings.drawmode !== undefined) || (settings.xmin !== undefined) || - (settings.xmax !== undefined) || (settings.xdelta !== undefined) || - (settings.xstart !== undefined)) { + if ( + settings.drawmode !== undefined || + settings.xmin !== undefined || + settings.xmax !== undefined || + settings.xdelta !== undefined || + settings.xstart !== undefined + ) { if (settings.drawmode === undefined) { settings.drawmode = this.drawmode; } @@ -426,10 +469,18 @@ this.position = 0; this.frame = 0; if (this.hcb.pipe) { - this.buf = this.hcb.createArray(null, 0, this.hcb.subsize * this.hcb.spa); + this.buf = this.hcb.createArray( + null, + 0, + this.hcb.subsize * this.hcb.spa + ); this.zbuf = new m.PointArray(this.hcb.subsize); } else { - this.buf = this.hcb.createArray(null, 0, this.lps * this.hcb.subsize * this.hcb.spa); + this.buf = this.hcb.createArray( + null, + 0, + this.lps * this.hcb.subsize * this.hcb.spa + ); this.zbuf = new m.PointArray(this.lps * this.hcb.subsize); } this.img = undefined; @@ -456,10 +507,20 @@ // If p_cuts are enabled from streams, we need to keep the entire zbuf in memory if (this.hcb.pipe) { if (!p_cuts) { - this.buf = this.hcb.createArray(null, 0, this.lps * this.hcb.subsize * this.hcb.spa); - this.zbuf = new m.PointArray(this.lps * this.hcb.subsize); + this.buf = this.hcb.createArray( + null, + 0, + this.lps * this.hcb.subsize * this.hcb.spa + ); + this.zbuf = new m.PointArray( + this.lps * this.hcb.subsize + ); } else { - this.buf = this.hcb.createArray(null, 0, this.hcb.subsize * this.hcb.spa); + this.buf = this.hcb.createArray( + null, + 0, + this.hcb.subsize * this.hcb.spa + ); this.zbuf = new m.PointArray(this.hcb.subsize); } } @@ -492,15 +553,20 @@ } }, - reload: function(data, hdrmod) { + reload: function (data, hdrmod) { if (this.hcb.pipe) { throw "reload cannot be used with pipe, use push instead"; } - var axis_change = (this.hcb.dview.length !== data.length) || hdrmod; + var axis_change = this.hcb.dview.length !== data.length || hdrmod; if (hdrmod) { for (var k in hdrmod) { this.hcb[k] = hdrmod[k]; - if (k === "xstart" || k === "xdelta" | k === "ystart" || k === "ydelta" || k === "subsize") { + if ( + k === "xstart" || + (k === "xdelta") | (k === "ystart") || + k === "ydelta" || + k === "subsize" + ) { axis_change = true; } } @@ -523,7 +589,7 @@ var xmax = this.xmax; if (axis_change) { - var d = this.hcb.xstart + (this.hcb.xdelta * this.hcb.subsize); + var d = this.hcb.xstart + this.hcb.xdelta * this.hcb.subsize; this.xmin = Math.min(this.hcb.xstart, d); this.xmax = Math.max(this.hcb.xstart, d); this.xdelta = this.hcb.xdelta; @@ -534,11 +600,11 @@ return { xmin: xmin, - xmax: xmax + xmax: xmax, }; }, - push: function(data, hdrmod, sync) { + push: function (data, hdrmod, sync) { var Gx = this.plot._Gx; var rescale = false; var timestamp = null; @@ -550,15 +616,25 @@ } // If the subsize changes, we need to invalidate the buffer and image - if ((hdrmod.subsize) && (hdrmod.subsize !== this.hcb.subsize)) { + if (hdrmod.subsize && hdrmod.subsize !== this.hcb.subsize) { this.hcb.subsize = hdrmod.subsize; if (this.hcb.pipe && !Gx.p_cuts) { - this.buf = this.hcb.createArray(null, 0, this.hcb.subsize * this.hcb.spa); + this.buf = this.hcb.createArray( + null, + 0, + this.hcb.subsize * this.hcb.spa + ); this.zbuf = new m.PointArray(this.hcb.subsize); this.img = undefined; } else { - this.buf = this.hcb.createArray(null, 0, this.lps * this.hcb.subsize * this.hcb.spa); - this.zbuf = new m.PointArray(this.lps * this.hcb.subsize); + this.buf = this.hcb.createArray( + null, + 0, + this.lps * this.hcb.subsize * this.hcb.spa + ); + this.zbuf = new m.PointArray( + this.lps * this.hcb.subsize + ); this.img = undefined; } rescale = true; @@ -579,7 +655,8 @@ } if (rescale) { - var d = this.hcb.xstart + (this.hcb.xdelta * this.hcb.subsize); + var d = + this.hcb.xstart + this.hcb.xdelta * this.hcb.subsize; this.xmin = Math.min(this.hcb.xstart, d); this.xmax = Math.max(this.hcb.xstart, d); this.xdelta = this.hcb.xdelta; @@ -587,15 +664,14 @@ this.ystart = this.hcb.ystart; this.ydelta = this.hcb.ydelta; - var d = this.hcb.ystart + (this.hcb.ydelta * this.lps); + var d = this.hcb.ystart + this.hcb.ydelta * this.lps; this.ymin = Math.min(this.hcb.ystart, d); this.ymax = Math.max(this.hcb.ystart, d); } - } - if ((this.hcb.yunits === 1) || (this.hcb.yunits === 4)) { - if ((!this.hcb["timecode"]) && (timestamp)) { + if (this.hcb.yunits === 1 || this.hcb.yunits === 4) { + if (!this.hcb["timecode"] && timestamp) { // if we don't have a timecode set, we can use // the timestamp and reset ystart this.hcb.timecode = m.j1970toj1950(timestamp); @@ -614,10 +690,9 @@ } return rescale; - }, - get_pan_bounds: function(view) { + get_pan_bounds: function (view) { let prep = this.prep(); if (prep) { @@ -626,16 +701,16 @@ xmin: this.xmin, xmax: this.xmax, ymin: this.ymin, - ymax: this.ymax + ymax: this.ymax, }; } else { return { - num: 0 + num: 0, }; } }, - prep: function(xmin, xmax) { + prep: function (xmin, xmax) { var Gx = this.plot._Gx; var Mx = this.plot._Mx; @@ -657,7 +732,7 @@ if (!this.hcb.pipe) { // if we aren't a pipe we do a full prep - if ((Gx.cmode === 5) || (this.xsub > 0)) { + if (Gx.cmode === 5 || this.xsub > 0) { // TODO - is this mode supported in rasters? } else if (npts > 0) { var xstart = this.xstart; @@ -667,11 +742,39 @@ n1 = 0; n2 = npts - 1; } else if (xdelta >= 0.0) { - n1 = Math.max(1.0, Math.min(d, Math.round((xmin - xstart) / xdelta))) - 1.0; - n2 = Math.max(1.0, Math.min(d, Math.round((xmax - xstart) / xdelta) + 2.0)) - 1.0; + n1 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmin - xstart) / xdelta) + ) + ) - 1.0; + n2 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmax - xstart) / xdelta) + 2.0 + ) + ) - 1.0; } else { - n1 = Math.max(1.0, Math.min(d, Math.round((xmax - xstart) / xdelta) - 1.0)) - 1.0; - n2 = Math.max(1.0, Math.min(d, Math.round((xmin - xstart) / xdelta) + 2.0)) - 1.0; + n1 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmax - xstart) / xdelta) - 1.0 + ) + ) - 1.0; + n2 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmin - xstart) / xdelta) + 2.0 + ) + ) - 1.0; } npts = n2 - n1 + 1; @@ -686,7 +789,7 @@ return; } - if ((Gx.cmode === 5) || (this.ysub > 0)) { + if (Gx.cmode === 5 || this.ysub > 0) { // TODO - is this mode supported in rasters? } else if (npts > 0) { var ystart = this.ystart; @@ -696,11 +799,39 @@ n1 = 0; n2 = npts - 1; } else if (ydelta >= 0.0) { - n1 = Math.max(1.0, Math.min(d, Math.round((xmin - ystart) / ydelta))) - 1.0; - n2 = Math.max(1.0, Math.min(d, Math.round((xmax - ystart) / ydelta) + 2.0)) - 1.0; + n1 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmin - ystart) / ydelta) + ) + ) - 1.0; + n2 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmax - ystart) / ydelta) + 2.0 + ) + ) - 1.0; } else { - n1 = Math.max(1.0, Math.min(d, Math.round((xmax - ystart) / ydelta) - 1.0)) - 1.0; - n2 = Math.max(1.0, Math.min(d, Math.round((xmin - ystart) / ydelta) + 2.0)) - 1.0; + n1 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmax - ystart) / ydelta) - 1.0 + ) + ) - 1.0; + n2 = + Math.max( + 1.0, + Math.min( + d, + Math.round((xmin - ystart) / ydelta) + 2.0 + ) + ) - 1.0; } npts = n2 - n1 + 1; @@ -711,42 +842,79 @@ } if (this.cx) { - if (Gx.cmode === 1) { // mag + if (Gx.cmode === 1) { + // mag m.cvmag(this.buf, this.zbuf, this.zbuf.length); - } else if (Gx.cmode === 2) { // phase + } else if (Gx.cmode === 2) { + // phase if (Gx.plab === 25) { m.cvpha(this.buf, this.zbuf, this.zbuf.length); - m.vsmul(this.zbuf, 1.0 / (2 * Math.PI), this.zbuf, this.zbuf.length); + m.vsmul( + this.zbuf, + 1.0 / (2 * Math.PI), + this.zbuf, + this.zbuf.length + ); } else if (Gx.plab !== 24) { m.cvpha(this.buf, this.zbuf, this.zbuf.length); } else { m.cvphad(this.buf, this.zbuf, this.zbuf.length); } - } else if (Gx.cmode === 3) { // real - m.vmov(this.buf, this.skip, this.zbuf, 1, this.zbuf.length); - } else if (Gx.cmode === 4) { // imag - m.vmov(this.buf.subarray(1), this.skip, this.zbuf, 1, this.zbuf.length); - } else if (Gx.cmode === 5) { // IR - what does this mean for a raster? + } else if (Gx.cmode === 3) { + // real + m.vmov( + this.buf, + this.skip, + this.zbuf, + 1, + this.zbuf.length + ); + } else if (Gx.cmode === 4) { + // imag + m.vmov( + this.buf.subarray(1), + this.skip, + this.zbuf, + 1, + this.zbuf.length + ); + } else if (Gx.cmode === 5) { + // IR - what does this mean for a raster? m.vfill(this.zbuf, 0, this.zbuf.length); - } else if (Gx.cmode === 6) { // 10log + } else if (Gx.cmode === 6) { + // 10log m.cvmag2logscale(this.buf, Gx.dbmin, 10.0, this.zbuf); - } else if (Gx.cmode === 7) { // 20log + } else if (Gx.cmode === 7) { + // 20log m.cvmag2logscale(this.buf, Gx.dbmin, 20.0, this.zbuf); } } else { - if (Gx.cmode === 1) { // mag + if (Gx.cmode === 1) { + // mag m.vabs(this.buf, this.zbuf); - } else if (Gx.cmode === 2) { // phase + } else if (Gx.cmode === 2) { + // phase m.vfill(this.zbuf, 0, this.zbuf.length); - } else if (Gx.cmode === 3) { // real - m.vmov(this.buf, this.skip, this.zbuf, 1, this.zbuf.length); - } else if (Gx.cmode === 4) { // imag + } else if (Gx.cmode === 3) { + // real + m.vmov( + this.buf, + this.skip, + this.zbuf, + 1, + this.zbuf.length + ); + } else if (Gx.cmode === 4) { + // imag m.vfill(this.zbuf, 0, this.zbuf.length); - } else if (Gx.cmode === 5) { // IR + } else if (Gx.cmode === 5) { + // IR m.vfill(this.zbuf, 0, this.zbuf.length); - } else if (Gx.cmode === 6) { // 10log + } else if (Gx.cmode === 6) { + // 10log m.vlogscale(this.buf, Gx.dbmin, 10.0, this.zbuf); - } else if (Gx.cmode === 7) { // 20log + } else if (Gx.cmode === 7) { + // 20log m.vlogscale(this.buf, Gx.dbmin, 20.0, this.zbuf); } } @@ -758,14 +926,14 @@ var min = 0; var max = 0; - if ((Gx.autol <= 0) || this.hcb.pipe) { + if (Gx.autol <= 0 || this.hcb.pipe) { // If autol is not used or the layer is rendering // a pipe, then use the basic z-scaling method if (zpoint.length > 0) { min = zpoint[0]; max = zpoint[0]; for (var i = 0; i < zpoint.length; i++) { - if ((i / this.xframe) >= this.lpb) { + if (i / this.xframe >= this.lpb) { break; } if (zpoint[i] < min) { @@ -777,14 +945,14 @@ } } - if (((Gx.autoz & 1) !== 0)) { + if ((Gx.autoz & 1) !== 0) { if (Gx.zmin !== undefined) { Gx.zmin = Math.min(Gx.zmin, min); } else { Gx.zmin = min; } } - if (((Gx.autoz & 2) !== 0)) { + if ((Gx.autoz & 2) !== 0) { if (Gx.zmax !== undefined) { Gx.zmax = Math.min(Gx.zmax, max); } else { @@ -792,28 +960,32 @@ } } - this.img = mx.create_image(Mx, + this.img = mx.create_image( + Mx, this.zbuf, this.hcb.subsize, xsize, this.lps, Gx.zmin + Gx.zoff, Gx.zmax + Gx.zoff, - this.xcompression); + this.xcompression + ); } else { // otherwise autol > 1 var nny = this.hcb.size; - var fac = 1.0 / (Math.max(Gx.autol, 1)); + var fac = 1.0 / Math.max(Gx.autol, 1); // If the image isn't yet created, make one now if (!this.img) { - this.img = mx.create_image(Mx, + this.img = mx.create_image( + Mx, this.zbuf, this.hcb.subsize, xsize, this.lps, Gx.zmin + Gx.zoff, - Gx.zmax + Gx.zoff); + Gx.zmax + Gx.zoff + ); } Gx.zmin = 0; @@ -829,21 +1001,22 @@ } // Auto-scale this raster line - if ((Gx.autoz !== 2) && (min !== undefined)) { - Gx.zmin = (min * fac) + (Gx.zmin * (1.0 - fac)); + if (Gx.autoz !== 2 && min !== undefined) { + Gx.zmin = min * fac + Gx.zmin * (1.0 - fac); } - if ((Gx.autoz !== 1) && (max !== undefined)) { - Gx.zmax = (max * fac) + (Gx.zmax * (1.0 - fac)); + if (Gx.autoz !== 1 && max !== undefined) { + Gx.zmax = max * fac + Gx.zmax * (1.0 - fac); } // Render the row - mx.update_image_row(Mx, + mx.update_image_row( + Mx, this.img, zpoint.subarray(noff, noff + this.xframe), yy, Gx.zmin, - Gx.zmax); - + Gx.zmax + ); } } } @@ -857,14 +1030,16 @@ if (Gx.zmax === undefined) { Gx.zmax = 0; } - this.img = mx.create_image(Mx, + this.img = mx.create_image( + Mx, null, this.hcb.subsize, xsize, this.lps, Gx.zmin + Gx.zoff, Gx.zmax + Gx.zoff, - this.xcompression); + this.xcompression + ); } } @@ -873,10 +1048,10 @@ this.img.origin = Mx.origin; // Make the parts without data transparent - if (this.hcb.pipe && (this.frame < this.lps)) { + if (this.hcb.pipe && this.frame < this.lps) { var imgd = new Uint32Array(this.img); if (this.drawmode === "rising") { - for (var i = 0; i < imgd.length - (this.frame * xsize); i++) { + for (var i = 0; i < imgd.length - this.frame * xsize; i++) { imgd[i] = 0; } } else { @@ -891,7 +1066,7 @@ panxmin: this.xmin, panxmax: this.xmax, panymin: this.ymin, - panymax: this.ymax + panymax: this.ymax, }; }, @@ -902,13 +1077,12 @@ * the y-position to extract the x-cut, leave undefined to * leave xCut */ - xCut: function(ypos) { + xCut: function (ypos) { var Mx = this.plot._Mx; var Gx = this.plot._Gx; //display the x-cut of the raster if (ypos !== undefined) { - // Stash important values this.cut_stash = {}; this.cut_stash.ylabel = Gx.ylabel; @@ -925,7 +1099,7 @@ this.x_cut_data = []; var width = this.xframe; var row = Math.round((ypos - this.ystart) / this.ydelta); - if ((row < 0) || (row > this.lps)) { + if (row < 0 || row > this.lps) { return; } var start = row * width; @@ -938,15 +1112,15 @@ this.old_autol = Gx.autol; this.plot.change_settings({ drawmode: "undefined", - autol: -1 + autol: -1, }); - var cx = ((Gx.lyr.length > 0) && this.cx); + var cx = Gx.lyr.length > 0 && this.cx; if (Gx.cmode === 1) { Gx.ylabel = m.UNITS[28][0]; } else if (Gx.cmode === 2) { Gx.ylabel = Gx.plab; - } else if ((Gx.cmode === 3) && (cx)) { + } else if (Gx.cmode === 3 && cx) { Gx.ylabel = m.UNITS[21][0]; } else if (Gx.cmode === 4) { Gx.ylabel = m.UNITS[22][0]; @@ -960,7 +1134,10 @@ Gx.ylabel = "Intensity"; } - if ((m.UNITS[Gx.xlab][0] !== "None") && (m.UNITS[Gx.xlab][0] !== "Unknown")) { + if ( + m.UNITS[Gx.xlab][0] !== "None" && + m.UNITS[Gx.xlab][0] !== "Unknown" + ) { Gx.xlabel = m.UNITS[Gx.xlab][0]; } else { Gx.xlabel = "Frequency"; @@ -968,13 +1145,17 @@ Gx.xlabel += " CURRENTLY IN X_CUT MODE"; Mx.origin = 1; - this.xcut_layer = this.plot.overlay_array(this.x_cut_data, { - xstart: this.xstart, - xdelta: this.xdelta - }, { - name: "x_cut_data", - line: 3 - }); + this.xcut_layer = this.plot.overlay_array( + this.x_cut_data, + { + xstart: this.xstart, + xdelta: this.xdelta, + }, + { + name: "x_cut_data", + line: 3, + } + ); //do not display any other layers var xcut_lyrn = this.plot.get_lyrn(this.xcut_layer); @@ -1008,10 +1189,10 @@ for (var h = 1; h < Mx.level + 1; h++) { Mx.stk[h].ymin = ymin; Mx.stk[h].ymax = ymax; - Mx.stk[h].yscl = (Mx.stk[h].ymax - Mx.stk[h].ymin) / (Mx.b - Mx.t); + Mx.stk[h].yscl = + (Mx.stk[h].ymax - Mx.stk[h].ymin) / (Mx.b - Mx.t); } this.plot.rescale(); - } else if (Gx.x_cut_press_on) { // ypos wasn't provided so turn x-cut off Gx.x_cut_press_on = false; @@ -1032,13 +1213,12 @@ Gx.panxmax = this.cut_stash.panxmax; this.cut_stash = undefined; - this.plot.rescale(); this.plot.refresh(); this.xcut_layer = undefined; this.plot.change_settings({ drawmode: this.old_drawmode, - autol: this.old_autol + autol: this.old_autol, }); } } @@ -1051,7 +1231,7 @@ * the x-position to extract the y-cut, leave undefined to * leave yCut */ - yCut: function(xpos) { + yCut: function (xpos) { var Mx = this.plot._Mx; var Gx = this.plot._Gx; @@ -1076,7 +1256,7 @@ this.y_cut_data = []; var col = Math.round((xpos - this.xstart) / this.xdelta); - for (i = col; i < (width * height); i += width) { + for (i = col; i < width * height; i += width) { this.y_cut_data.push(this.buf[i]); } } @@ -1087,16 +1267,15 @@ this.plot.change_settings({ drawmode: "undefined", - autol: -1 + autol: -1, }); - - var cx = ((Gx.lyr.length > 0) && this.cx); + var cx = Gx.lyr.length > 0 && this.cx; if (Gx.cmode === 1) { Gx.ylabel = m.UNITS[28][0]; } else if (Gx.cmode === 2) { Gx.ylabel = Gx.plab; - } else if ((Gx.cmode === 3) && (cx)) { + } else if (Gx.cmode === 3 && cx) { Gx.ylabel = m.UNITS[21][0]; } else if (Gx.cmode === 4) { Gx.ylabel = m.UNITS[22][0]; @@ -1110,21 +1289,27 @@ Gx.ylabel = "Intensity"; } - if ((m.UNITS[Gx.ylab][0] !== "None") && (m.UNITS[Gx.ylab][0] !== "Unknown")) { + if ( + m.UNITS[Gx.ylab][0] !== "None" && + m.UNITS[Gx.ylab][0] !== "Unknown" + ) { Gx.xlabel = m.UNITS[Gx.ylab][0]; } else { Gx.xlabel = "Time"; } Gx.xlabel += " CURRENTLY IN Y_CUT MODE"; Mx.origin = 1; - this.ycut_layer = this.plot.overlay_array(this.y_cut_data, { - xstart: this.ystart, - xdelta: this.ydelta - }, { - name: "y_cut_data", - line: 3 - }); - + this.ycut_layer = this.plot.overlay_array( + this.y_cut_data, + { + xstart: this.ystart, + xdelta: this.ydelta, + }, + { + name: "y_cut_data", + line: 3, + } + ); //do not display any other layers var ycut_lyrn = this.plot.get_lyrn(this.ycut_layer); @@ -1160,12 +1345,14 @@ // the x-axis is now the yvalues Mx.stk[h].xmin = Mx.stk[h].ymin; Mx.stk[h].xmax = Mx.stk[h].ymax; - Mx.stk[h].xscl = (Mx.stk[h].xmax - Mx.stk[h].xmin) / (Mx.r - Mx.t); + Mx.stk[h].xscl = + (Mx.stk[h].xmax - Mx.stk[h].xmin) / (Mx.r - Mx.t); // the y-axis is now the zvalues Mx.stk[h].ymin = ymin; Mx.stk[h].ymax = ymax; - Mx.stk[h].yscl = (Mx.stk[h].ymax - Mx.stk[h].ymin) / (Mx.b - Mx.t); + Mx.stk[h].yscl = + (Mx.stk[h].ymax - Mx.stk[h].ymin) / (Mx.b - Mx.t); } this.plot.rescale(); @@ -1193,48 +1380,64 @@ this.ycut_layer = undefined; this.plot.change_settings({ drawmode: this.old_drawmode, - autol: this.old_autol + autol: this.old_autol, }); } } }, - draw: function() { + draw: function () { var Mx = this.plot._Mx; var Gx = this.plot._Gx; var HCB = this.hcb; if (this.hcb.pipe) { - var lps = this.hcb.lps || Math.ceil(Math.max(1, (Mx.b - Mx.t))); - if ((lps !== this.lps) && this.buf) { - var lps_delta = (lps - this.lps); + var lps = this.hcb.lps || Math.ceil(Math.max(1, Mx.b - Mx.t)); + if (lps !== this.lps && this.buf) { + var lps_delta = lps - this.lps; this.lps = lps; - if (this.position >= this.lps) { // if lps got resized make sure we don't go out of bounds + if (this.position >= this.lps) { + // if lps got resized make sure we don't go out of bounds this.position = 0; } if (this.drawmode === "scrolling") { // in scrolling mode, ymin should never change - var d = HCB.ystart + (HCB.ydelta * this.lps); + var d = HCB.ystart + HCB.ydelta * this.lps; this.ymin = Math.min(HCB.ystart, d); this.ymax = Math.max(HCB.ystart, d); - this.img = mx.resize_image_height(Mx, this.img, this.lps); + this.img = mx.resize_image_height( + Mx, + this.img, + this.lps + ); } else if (this.drawmode === "falling") { - this.ymax = this.ymin + (HCB.ydelta * this.lps); - this.img = mx.resize_image_height(Mx, this.img, this.lps); + this.ymax = this.ymin + HCB.ydelta * this.lps; + this.img = mx.resize_image_height( + Mx, + this.img, + this.lps + ); } else if (this.drawmode === "rising") { - this.ymin = this.ymax - (HCB.ydelta * this.lps); + this.ymin = this.ymax - HCB.ydelta * this.lps; // the img needs to be shifted if (lps_delta > 0) { - this.img = mx.resize_image_height(Mx, this.img, this.lps); + this.img = mx.resize_image_height( + Mx, + this.img, + this.lps + ); mx.shift_image_rows(Mx, this.img, lps_delta, true); } else { mx.shift_image_rows(Mx, this.img, lps_delta, true); - this.img = mx.resize_image_height(Mx, this.img, this.lps); + this.img = mx.resize_image_height( + Mx, + this.img, + this.lps + ); } } - // reset the image since we now have more lines to render // TODO - can we preserve the image data rather than resetting? this.plot.rescale(); @@ -1243,7 +1446,8 @@ var xmin = Math.max(this.xmin, Mx.stk[Mx.level].xmin); var xmax = Math.min(this.xmax, Mx.stk[Mx.level].xmax); - if (xmin >= xmax) { // no data but do scaling + if (xmin >= xmax) { + // no data but do scaling Gx.panxmin = Math.min(Gx.panxmin, this.xmin); Gx.panxmax = Math.max(Gx.panxmax, this.xmax); return; @@ -1273,23 +1477,38 @@ Gx.ye = Math.max(1, Math.round(ry)); // we might need to prep in certian situations - if ((!this.img) || (!this.buf) || (Gx.cmode !== this.img.cmode) || (Mx.origin !== this.img.origin)) { + if ( + !this.img || + !this.buf || + Gx.cmode !== this.img.cmode || + Mx.origin !== this.img.origin + ) { this.prep(xmin, xmax); } // if there is an image, render it if (this.img) { - mx.draw_image(Mx, this.img, this.xmin, this.ymin, this.xmax, this.ymax, this.opacity, Gx.rasterSmoothing, this.downscale); + mx.draw_image( + Mx, + this.img, + this.xmin, + this.ymin, + this.xmax, + this.ymax, + this.opacity, + Gx.rasterSmoothing, + this.downscale + ); } // render the scrolling pipe line if (this.position !== null && this.drawmode === "scrolling") { var pnt = mx.real_to_pixel(Mx, 0, this.position * this.ydelta); - if ((pnt.y > Mx.t) && (pnt.y < Mx.b)) { + if (pnt.y > Mx.t && pnt.y < Mx.b) { mx.draw_line(Mx, "white", Mx.l, pnt.y, Mx.r, pnt.y); } } - } + }, }; /** @@ -1297,7 +1516,7 @@ * * @private */ - Layer2D.overlay = function(plot, hcb, layerOptions) { + Layer2D.overlay = function (plot, hcb, layerOptions) { var Gx = plot._Gx; var Mx = plot._Mx; @@ -1329,5 +1548,4 @@ }; module.exports = Layer2D; - -}()); +})(); diff --git a/js/sigplot.layer2dSDS.js b/js/sigplot.layer2dSDS.js index 4eeb74f..8ccb8f9 100644 --- a/js/sigplot.layer2dSDS.js +++ b/js/sigplot.layer2dSDS.js @@ -26,32 +26,31 @@ /* global module */ /* global require */ -(function() { - +(function () { var m = require("./m"); var mx = require("./mx"); var common = require("./common"); - var decimationModeLookup ={ + var decimationModeLookup = { 1: 1, - 2:2, - 4:3, - 8:4, - 16:5, - 32:6, - 64:7, - 128:8, - 256:9, - 512:10, + 2: 2, + 4: 3, + 8: 4, + 16: 5, + 32: 6, + 64: 7, + 128: 8, + 256: 9, + 512: 10, }; - var decimationPossibilities = [512,256,128,64,32,16,8,4,2,1]; + var decimationPossibilities = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1]; /** * @constructor * @param plot */ - var LayerSDS = function(plot) { + var LayerSDS = function (plot) { this.plot = plot; this.offset = 0.0; @@ -96,7 +95,6 @@ }; LayerSDS.prototype = { - /** * Initializes the layer to display the provided data. * @@ -108,33 +106,34 @@ * @memberOf LayerSDS * @private */ - init: function(hcb) { - + init: function (hcb) { //De-Bounce this function - this.debounceSend = common.debounce(function(oReq) { - oReq.send(null); - }, 100,false); - + this.debounceSend = common.debounce( + function (oReq) { + oReq.send(null); + }, + 100, + false + ); var Gx = this.plot._Gx; var Mx = this.plot._Mx; - // Get Header Params from URL + // Get Header Params from URL this.hcb = hcb; this.hcb.buf_type = "D"; - if (hcb.file_type ===1000) { - this.lps = this.hcb.lps || Math.ceil((hcb.size/hcb.subsize)); + if (hcb.file_type === 1000) { + this.lps = this.hcb.lps || Math.ceil(hcb.size / hcb.subsize); } else { this.lps = this.hcb.lps || Math.ceil(hcb.size); } - - this.hcb.class = 2; - var LRU = require("lru"); - this.cache = new LRU(500); + this.hcb.class = 2; + var LRU = require("lru-cache"); + this.cache = new LRU({max: 500}); if (Gx.index) { this.xstart = 1.0; @@ -144,29 +143,26 @@ this.ystart = 1.0; this.ydelta = 1.0; this.ymin = 1.0; - if (hcb.file_type ===1000) { - this.ymax = (hcb.size / hcb.subsize); + if (hcb.file_type === 1000) { + this.ymax = hcb.size / hcb.subsize; } else { - this.ymax = (hcb.size); + this.ymax = hcb.size; } - } else { this.xstart = hcb.xstart; this.xdelta = hcb.xdelta; - var d = hcb.xstart + (hcb.xdelta * hcb.subsize); + var d = hcb.xstart + hcb.xdelta * hcb.subsize; this.xmin = this.hcb.xmin || Math.min(hcb.xstart, d); this.xmax = this.hcb.xmax || Math.max(hcb.xstart, d); this.ystart = hcb.ystart; this.ydelta = hcb.ydelta; - var d = hcb.ystart + (hcb.ydelta * this.lps); + var d = hcb.ystart + hcb.ydelta * this.lps; this.ymin = this.hcb.ymin || Math.min(hcb.ystart, d); this.ymax = this.hcb.ymax || Math.max(hcb.ystart, d); } }, - get_data: function() { - - }, + get_data: function () {}, /** * Provisional API @@ -175,38 +171,36 @@ * @param x * @param y */ - get_z: function(x, y) { - - }, + get_z: function (x, y) {}, - change_settings: function(settings) { + change_settings: function (settings) { var Gx = this.plot._Gx; if (settings.subsize) { this.hcb.subsize = settings.subsize; this.hcb.ape = settings.subsize; - if (this.hcb.file_type ===1000) { - this.lps = Math.ceil(this.hcb.size/this.hcb.subsize); + if (this.hcb.file_type === 1000) { + this.lps = Math.ceil(this.hcb.size / this.hcb.subsize); } else { this.lps = Math.ceil(this.hcb.size); } - var d = this.hcb.xstart + (this.hcb.xdelta * this.hcb.subsize); + var d = this.hcb.xstart + this.hcb.xdelta * this.hcb.subsize; this.xmin = this.hcb.xmin || Math.min(this.hcb.xstart, d); this.xmax = this.hcb.xmax || Math.max(this.hcb.xstart, d); - var d = this.hcb.ystart + (this.hcb.ydelta * this.lps); + var d = this.hcb.ystart + this.hcb.ydelta * this.lps; this.ymin = this.hcb.ymin || Math.min(this.hcb.ystart, d); this.ymax = this.hcb.ymax || Math.max(this.hcb.ystart, d); } if (settings.debugCanvas) { this.debugCanvas = settings.debugCanvas; } - + if (settings.cmode !== undefined) { this.img = undefined; - if (((Gx.autoz & 1) !== 0)) { + if ((Gx.autoz & 1) !== 0) { Gx.zmin = undefined; } - if (((Gx.autoz & 2) !== 0)) { + if ((Gx.autoz & 2) !== 0) { Gx.zmax = undefined; } } @@ -228,25 +222,23 @@ this.xcompression = settings.xcmp; } } - if (settings.usetiles !==undefined) { + if (settings.usetiles !== undefined) { this.usetiles = settings.usetiles; } }, - reload: function(data, hdrmod) { - - }, + reload: function (data, hdrmod) {}, - prep: function(xmin, xmax) { + prep: function (xmin, xmax) { return this.lps; }, - get_pan_bounds: function(view) { - var xmin,xmax,ymin,ymax; - if (this.xmin= xmax) { // no data + if (xmin >= xmax) { + // no data return; } var ymin = Math.max(this.ymin, Mx.stk[Mx.level].ymin); @@ -379,10 +387,10 @@ // Make sure w/h remain within limits w = Math.min(w, HCB.subsize); - if (HCB.file_type ===1000) { - h = Math.min(h, (HCB.size / HCB.subsize)); + if (HCB.file_type === 1000) { + h = Math.min(h, HCB.size / HCB.subsize); } else { - h = Math.min(h, HCB.size); + h = Math.min(h, HCB.size); } // figure out the upper-left and lower-right pixel coordinates @@ -402,62 +410,75 @@ Gx.ye = Math.max(1, Math.round(ry)); // Index values of xmax,xmin, ymax,ymin - var x1= Math.floor((xmin -HCB.xstart)/ HCB.xdelta); - var y1= Math.floor((ymin - HCB.ystart)/ HCB.ydelta) ; - var x2= x1+w; - var y2= y1+h; + var x1 = Math.floor((xmin - HCB.xstart) / HCB.xdelta); + var y1 = Math.floor((ymin - HCB.ystart) / HCB.ydelta); + var x2 = x1 + w; + var y2 = y1 + h; - if (this.usetiles) { + if (this.usetiles) { //var maxtileXsize = 200; //var maxtileYsize = 200; - var maxtileXsize = Math.min(Math.max(Math.ceil(iw/300)*100,100),500); - var maxtileYsize = Math.min(Math.max(Math.ceil(ih/300)*100,100),500); + var maxtileXsize = Math.min( + Math.max(Math.ceil(iw / 300) * 100, 100), + 500 + ); + var maxtileYsize = Math.min( + Math.max(Math.ceil(ih / 300) * 100, 100), + 500 + ); //var tileXsize = maxtilesize; //var tileYsize = maxtilesize; //var requestedDecx = Math.max(1,(w/iw)*1.2); //Allow for upscaling the number of pixels needed by 20% otherwise request the next zoom level - // var requestedDecy = Math.max(1,(h/ih)*1.2); - var requestedDecx = Math.max(1,(w/iw)); - var requestedDecy = Math.max(1,(h/ih)); + // var requestedDecy = Math.max(1,(h/ih)*1.2); + var requestedDecx = Math.max(1, w / iw); + var requestedDecy = Math.max(1, h / ih); var i = 0; - while (decimationPossibilities[i]>requestedDecx) { + while (decimationPossibilities[i] > requestedDecx) { i++; } var decfactorx = decimationPossibilities[i]; i = 0; - while (decimationPossibilities[i]>requestedDecy) { + while (decimationPossibilities[i] > requestedDecy) { i++; } var decfactory = decimationPossibilities[i]; - + var decx = decimationModeLookup[decfactorx]; var decy = decimationModeLookup[decfactory]; - - var tilexsize = maxtileXsize*decfactorx; - var tileysize = maxtileYsize*decfactory; - - var firstcolumn = Math.floor(x1/tilexsize); - var fistrow = Math.floor(y1/tileysize); - var lastcolumn = Math.ceil(x2/tilexsize); - var lastrow = Math.ceil(y2/tileysize); - + + var tilexsize = maxtileXsize * decfactorx; + var tileysize = maxtileYsize * decfactory; + + var firstcolumn = Math.floor(x1 / tilexsize); + var fistrow = Math.floor(y1 / tileysize); + var lastcolumn = Math.ceil(x2 / tilexsize); + var lastrow = Math.ceil(y2 / tileysize); + //var numtilesx = Math.ceil(w/decfactorx/maxtilesize); //var numtilesy = Math.ceil(h/decfactory/maxtilesize); // var xsize = xmax-xmin; // var ysize = ymax-ymin; - // var xsizeperfulltile = xsize*(maxtilesize/w); + // var xsizeperfulltile = xsize*(maxtilesize/w); // var ysizeperfulltile = ysize*(maxtilesize/h); - - - for (var tileY = fistrow; tileY < (lastrow); tileY++) { - for (var tileX = firstcolumn; tileX < (lastcolumn); tileX++) { - var url = this.make_tile_request_url(maxtileXsize, maxtileYsize, decx, decy, tileX, tileY); + for (var tileY = fistrow; tileY < lastrow; tileY++) { + for (var tileX = firstcolumn; tileX < lastcolumn; tileX++) { + var url = this.make_tile_request_url( + maxtileXsize, + maxtileYsize, + decx, + decy, + tileX, + tileY + ); var img = this.cache.get(url); - if (img) { //Get the data from this tile out of the cache and plot it. - mx.draw_image(Mx, + if (img) { + //Get the data from this tile out of the cache and plot it. + mx.draw_image( + Mx, img, img.xmin, // xmin img.ymin, // ymin @@ -468,49 +489,66 @@ true ); //return; - } else { // Don't already have the data for this tile to request it from the server. + } else { + // Don't already have the data for this tile to request it from the server. this.sendTileRequest(url); } } } - } else { var oReq = new XMLHttpRequest(); var urlsplit = this.hcb.url.split("/sds/hdr/"); - var url = urlsplit[0]+"/sds/rds/" + - x1 + "/" + - y1 + "/" + - x2 + "/" + - y2 + "/" + - iw + "/" + - ih + "/" + + var url = + urlsplit[0] + + "/sds/rds/" + + x1 + + "/" + + y1 + + "/" + + x2 + + "/" + + y2 + + "/" + + iw + + "/" + + ih + + "/" + urlsplit[1] + "?outfmt=RGBA" + - "&colormap="+ m.Mc.colormap[Gx.cmap].name+ - "&subsize="+HCB.subsize; - + "&colormap=" + + m.Mc.colormap[Gx.cmap].name + + "&subsize=" + + HCB.subsize; + if (Gx.zmin !== undefined) { - url = url+"&zmin=" + Gx.zmin; + url = url + "&zmin=" + Gx.zmin; } if (Gx.zmax !== undefined) { - url = url+"&zmax=" + Gx.zmax; + url = url + "&zmax=" + Gx.zmax; } - + if (Gx.cmode !== undefined) { var cxm = ["Ma", "Ph", "Re", "Im", "IR", "Lo", "L2"]; - url = url+"&cxmode=" + cxm[Gx.cmode-1]; + url = url + "&cxmode=" + cxm[Gx.cmode - 1]; } - + if (this.xcompression !== undefined) { - var xcmp = ["first", "mean", "min", "max", "first", "absmax"]; + var xcmp = [ + "first", + "mean", + "min", + "max", + "first", + "absmax", + ]; url = url + "&transform=" + xcmp[this.xcompression]; } - - + var img = this.cache.get(url); if (img) { - mx.draw_image(Mx, + mx.draw_image( + Mx, img, xmin, // xmin ymin, // ymin @@ -523,22 +561,23 @@ } else { oReq.open("GET", url, true); oReq.responseType = "arraybuffer"; - oReq.overrideMimeType('text\/plain; charset=x-user-defined'); - + oReq.overrideMimeType("text/plain; charset=x-user-defined"); + var that = this; - oReq.onload = function(oEvent) { + oReq.onload = function (oEvent) { if (oReq.readyState === 4) { - if ((oReq.status === 200) || (oReq.status === 0)) { // status = 0 is necessary for file URL + if (oReq.status === 200 || oReq.status === 0) { + // status = 0 is necessary for file URL var zmin = oReq.getResponseHeader("Zmin"); var zmax = oReq.getResponseHeader("Zmax"); - - if ((Mx.level === 0) && (Gx.zmin === undefined)) { - if (((Gx.autoz & 1) !== 0)) { + + if (Mx.level === 0 && Gx.zmin === undefined) { + if ((Gx.autoz & 1) !== 0) { Gx.zmin = zmin; } } - if ((Mx.level === 0) && (Gx.zmax === undefined)) { - if (((Gx.autoz & 2) !== 0)) { + if (Mx.level === 0 && Gx.zmax === undefined) { + if ((Gx.autoz & 2) !== 0) { Gx.zmax = zmax; } } @@ -546,13 +585,14 @@ if (oReq.response) { arrayBuffer = oReq.response; } - + //let imgd = new Uint8ClampedArray(arrayBuffer); arrayBuffer.width = iw; arrayBuffer.height = ih; arrayBuffer.contents = "rgba"; that.cache.set(url, arrayBuffer); - mx.draw_image(Mx, + mx.draw_image( + Mx, arrayBuffer, xmin, // xmin ymin, // ymin @@ -562,42 +602,36 @@ false, true ); - + return; } } }; - oReq.onerror = function(oEvent) { - }; - + oReq.onerror = function (oEvent) {}; + this.debounceSend(oReq); - } - } return { xmin: this.xmin, xmax: this.xmax, ymin: this.ymin, - ymax: this.ymax + ymax: this.ymax, }; - - }, - /** + /** * Display an xCut * * @param ypos * the y-position to extract the x-cut, leave undefined to * leave xCut */ - xCut: function(ypos) { + xCut: function (ypos) { var Mx = this.plot._Mx; var Gx = this.plot._Gx; //display the x-cut of the raster if (ypos !== undefined) { - // Stash important values this.cut_stash = {}; this.cut_stash.ylabel = Gx.ylabel; @@ -605,28 +639,30 @@ this.cut_stash.level = Mx.level; this.cut_stash.stk = JSON.parse(JSON.stringify(Mx.stk)); - var row = Math.round((ypos - this.ystart) / this.ydelta); - if ((row < 0) || (row > this.lps)) { + if (row < 0 || row > this.lps) { return; } - //Adjust the zoom stack to adjust y values to be undefined. - for (var stk_num = 0; stk_num < Mx.stk.length; stk_num ++ ) { + //Adjust the zoom stack to adjust y values to be undefined. + for (var stk_num = 0; stk_num < Mx.stk.length; stk_num++) { Mx.stk[stk_num].ymin = undefined; Mx.stk[stk_num].ymax = undefined; } Gx.panymax = undefined; Gx.panymin = undefined; - this.xcut_layer = this.plot.overlay_href(this.hcb.url, null, { - name: "x_cut_data", - layerType: "1DSDS", - mode: "xcut", - xypos_index: row, - bottom_level: Mx.level - }, - {} + this.xcut_layer = this.plot.overlay_href( + this.hcb.url, + null, + { + name: "x_cut_data", + layerType: "1DSDS", + mode: "xcut", + xypos_index: row, + bottom_level: Mx.level, + }, + {} ); Mx.origin = 1; @@ -638,7 +674,6 @@ } } Gx.x_cut_press_on = true; - } else if (Gx.x_cut_press_on) { // ypos wasn't provided so turn x-cut off Gx.x_cut_press_on = false; @@ -662,7 +697,7 @@ this.xcut_layer = undefined; this.plot.change_settings({ drawmode: this.old_drawmode, - autol: this.old_autol + autol: this.old_autol, }); } } @@ -675,7 +710,7 @@ * the x-position to extract the y-cut, leave undefined to * leave yCut */ - yCut: function(xpos) { + yCut: function (xpos) { var Mx = this.plot._Mx; var Gx = this.plot._Gx; @@ -693,15 +728,14 @@ this.cut_stash.panxmin = Gx.panxmin; this.cut_stash.panxmax = Gx.panxmax; - var column = Math.round((xpos - this.xstart) / this.xdelta); - if (column < 0) { //TODO - Check if column is out or max range. + if (column < 0) { + //TODO - Check if column is out or max range. return; } - - //Adjust the zoom stack to move y vales to x and adjust y values to be undefined. - for (var stk_num = 0; stk_num < Mx.stk.length; stk_num ++ ) { + //Adjust the zoom stack to move y vales to x and adjust y values to be undefined. + for (var stk_num = 0; stk_num < Mx.stk.length; stk_num++) { Mx.stk[stk_num].xmin = Mx.stk[stk_num].ymin; Mx.stk[stk_num].xmax = Mx.stk[stk_num].ymax; Mx.stk[stk_num].xscl = Mx.stk[stk_num].yscl; @@ -714,17 +748,20 @@ Gx.panymax = undefined; Gx.panymin = undefined; - this.ycut_layer = this.plot.overlay_href(this.hcb.url, null, + this.ycut_layer = this.plot.overlay_href( + this.hcb.url, + null, { - name: "y_cut_data", - layerType: "1DSDS", - mode: "ycut", - xypos_index: column, - bottom_level: Mx.level - }, {}); + name: "y_cut_data", + layerType: "1DSDS", + mode: "ycut", + xypos_index: column, + bottom_level: Mx.level, + }, + {} + ); Mx.origin = 1; - //do not display any other layers var ycut_lyrn = this.plot.get_lyrn(this.ycut_layer); for (var k = 0; k < Gx.lyr.length; k++) { @@ -734,7 +771,6 @@ } Gx.y_cut_press_on = true; - } else if (Gx.y_cut_press_on) { Gx.y_cut_press_on = false; for (var j = 0; j < Gx.lyr.length; j++) { @@ -759,7 +795,7 @@ this.ycut_layer = undefined; this.plot.change_settings({ drawmode: this.old_drawmode, - autol: this.old_autol + autol: this.old_autol, }); } } @@ -771,7 +807,7 @@ * * @private */ - LayerSDS.overlay = function(plot, hcb, layerOptions) { + LayerSDS.overlay = function (plot, hcb, layerOptions) { var Gx = plot._Gx; var Mx = plot._Mx; @@ -797,5 +833,4 @@ }; module.exports = LayerSDS; - -}()); +})(); diff --git a/js/sigplot.playback.js b/js/sigplot.playback.js index f952521..2e73eb1 100644 --- a/js/sigplot.playback.js +++ b/js/sigplot.playback.js @@ -26,8 +26,7 @@ /* global module */ /* global require */ -(function() { - +(function () { var m = require("./m"); var mx = require("./mx"); var common = require("./common"); @@ -37,12 +36,12 @@ * @param options * @returns {PlaybackControlsPlugin} */ - var PlaybackControlsPlugin = function(options) { + var PlaybackControlsPlugin = function (options) { this.options = { display: true, size: 25, lineWidth: 2, - fillStyle: false + fillStyle: false, }; common.update(this.options, options); this.state = "paused"; @@ -50,13 +49,13 @@ }; PlaybackControlsPlugin.prototype = { - init: function(plot) { + init: function (plot) { this.plot = plot; // Register for mouse events var self = this; var Mx = this.plot._Mx; - this.onmousemove = function(evt) { + this.onmousemove = function (evt) { if (Mx.warpbox) { return; } // Don't highlight if a warpbox is being drawn @@ -70,7 +69,7 @@ }; this.plot.addListener("mmove", this.onmousemove); - this.onmousedown = function(evt) { + this.onmousedown = function (evt) { if (Mx.warpbox) { return; } // Don't handle if a warpbox is being drawn @@ -83,7 +82,7 @@ // Prevents zooms and stuff from occuring this.plot.addListener("mdown", this.onmousedown); - this.onmouseclick = function(evt) { + this.onmouseclick = function (evt) { if (Mx.warpbox) { return; } // Don't handle if a warpbox is being drawn @@ -97,14 +96,14 @@ this.plot.addListener("mclick", this.onmouseclick); }, - set_highlight: function(ishighlight) { + set_highlight: function (ishighlight) { if (ishighlight !== this.highlight) { this.highlight = ishighlight; this.plot.redraw(); } }, - toggle: function(new_state) { + toggle: function (new_state) { if (!new_state) { if (this.state === "paused") { new_state = "playing"; @@ -116,8 +115,8 @@ if (new_state !== this.state) { if (this.plot) { var Mx = this.plot._Mx; - var evt = document.createEvent('Event'); - evt.initEvent('playbackevt', true, true); + var evt = document.createEvent("Event"); + evt.initEvent("playbackevt", true, true); evt.state = new_state; var executeDefault = mx.dispatchEvent(Mx, evt); if (executeDefault) { @@ -128,25 +127,26 @@ } }, - addListener: function(what, callback) { + addListener: function (what, callback) { var Mx = this.plot._Mx; mx.addEventListener(Mx, what, callback, false); }, - removeListener: function(what, callback) { + removeListener: function (what, callback) { var Mx = this.plot._Mx; mx.removeEventListener(Mx, what, callback, false); }, - ismouseover: function(xpos, ypos) { + ismouseover: function (xpos, ypos) { var position = this.position(); - var distance_from_ctr = Math.pow(xpos - position.x, 2) + Math.pow(ypos - position.y, 2); + var distance_from_ctr = + Math.pow(xpos - position.x, 2) + Math.pow(ypos - position.y, 2); var R = this.options.size / 2; - return (distance_from_ctr < Math.pow(R, 2)); + return distance_from_ctr < Math.pow(R, 2); }, - position: function() { + position: function () { if (this.options.position) { return this.options.position; } else if (this.plot) { @@ -154,17 +154,17 @@ var R = this.options.size / 2; return { x: Mx.l + R + this.options.lineWidth + 1, - y: Mx.t + R + this.options.lineWidth + 1 + y: Mx.t + R + this.options.lineWidth + 1, }; } else { return { x: null, - y: null + y: null, }; } }, - refresh: function(canvas) { + refresh: function (canvas) { if (!this.options.display) { return; } @@ -183,9 +183,15 @@ var position = this.position(); - ctx.beginPath(); - ctx.arc(position.x, position.y, R - ctx.lineWidth, 0, Math.PI * 2, true); + ctx.arc( + position.x, + position.y, + R - ctx.lineWidth, + 0, + Math.PI * 2, + true + ); ctx.closePath(); ctx.strokeStyle = this.options.strokeStyle || Mx.fg; @@ -199,23 +205,23 @@ if (this.state === "paused") { var p1 = { x: R * 0.8, - y: R * 0.56 + y: R * 0.56, }; var p2 = { x: R * 1.45, - y: R + y: R, }; var p3 = { x: R * 0.8, - y: R * 1.45 + y: R * 1.45, }; - p1.x += (position.x - R); - p2.x += (position.x - R); - p3.x += (position.x - R); - p1.y += (position.y - R); - p2.y += (position.y - R); - p3.y += (position.y - R); + p1.x += position.x - R; + p2.x += position.x - R; + p3.x += position.x - R; + p1.y += position.y - R; + p2.y += position.y - R; + p3.y += position.y - R; ctx.beginPath(); ctx.moveTo(p1.x, p1.y); @@ -226,21 +232,21 @@ ctx.fillStyle = this.options.strokeStyle || Mx.fg; ctx.fill(); } else { - ctx.lineCap = 'round'; + ctx.lineCap = "round"; ctx.lineWidth = Math.floor(Math.min(1, this.options.size / 8)); var p1 = { x: R * 0.8, - y: R / 2 + y: R / 2, }; var p2 = { x: R * 0.8, - y: R * 1.5 + y: R * 1.5, }; - p1.x += (position.x - R); - p2.x += (position.x - R); - p1.y += (position.y - R); - p2.y += (position.y - R); + p1.x += position.x - R; + p2.x += position.x - R; + p1.y += position.y - R; + p2.y += position.y - R; ctx.beginPath(); ctx.moveTo(p1.x, p1.y); @@ -249,17 +255,17 @@ ctx.stroke(); var p1 = { - x: R + (R / 5), - y: R / 2 + x: R + R / 5, + y: R / 2, }; var p2 = { - x: R + (R / 5), - y: R * 1.5 + x: R + R / 5, + y: R * 1.5, }; - p1.x += (position.x - R); - p2.x += (position.x - R); - p1.y += (position.y - R); - p2.y += (position.y - R); + p1.x += position.x - R; + p2.x += position.x - R; + p1.y += position.y - R; + p2.y += position.y - R; ctx.beginPath(); ctx.moveTo(p1.x, p1.y); @@ -271,12 +277,11 @@ ctx.restore(); }, - dispose: function() { + dispose: function () { this.plot = undefined; this.boxes = undefined; - } + }, }; module.exports = PlaybackControlsPlugin; - -}()); +})(); diff --git a/js/sigplot.plugin.js b/js/sigplot.plugin.js index 780a3e5..7b082b8 100644 --- a/js/sigplot.plugin.js +++ b/js/sigplot.plugin.js @@ -28,8 +28,7 @@ /* global module */ /* global require */ -(function() { - +(function () { var mx = require("./mx"); var common = require("./common"); @@ -43,7 +42,7 @@ /** * pluginInit is called afer the plugin has been added to * a plot. - * + * * @param {object} plot * The plot the plugin was added to. */ @@ -57,7 +56,7 @@ /** * pluginRefresh is called whenever the plugin need to redraw. - * + * * Plugins should render their current state to this.canvas. The canvas * is entirely under the control of the plugin can can be cleared or * completely filled @@ -67,14 +66,14 @@ /** * pluginGetMenu is called to obtain the menu structure for the * plugin. - * + * * If a plugin does not have a menu, it does not need to implement this. */ pluginGetMenu() {} /** * Construct the plugin. - * + * * @param {object} properties * The properties for this plugin. */ @@ -89,7 +88,7 @@ this.defineProperty("display", { defaultValue: true, refreshOnChange: true, - help: "changes if the plugin is rendered on the plot or not" + help: "changes if the plugin is rendered on the plot or not", }); this.pluginSetup(); @@ -100,7 +99,7 @@ /** * Called when the plugin is added to the plot. * @param plot - * The plot the plugin is attahced to + * The plot the plugin is attahced to * @param canvas * The canvas the plugin should render to */ @@ -130,11 +129,11 @@ } get Mx() { - return (this._plot) ? this._plot._Mx : null; + return this._plot ? this._plot._Mx : null; } get Gx() { - return (this._plot) ? this._plot._Gx : null; + return this._plot ? this._plot._Gx : null; } get canvas() { @@ -142,7 +141,7 @@ } get Context() { - return (this._canvas) ? this._canvas.getContext("2d") : null; + return this._canvas ? this._canvas.getContext("2d") : null; } /** @@ -181,9 +180,9 @@ /** * Defines a new Property that the Plugin exposes. - * - * @param {string} PropertyName - * @param {object} definition + * + * @param {string} PropertyName + * @param {object} definition */ defineProperty(PropertyName, definition) { if (this.definedproperties === undefined) { @@ -195,7 +194,7 @@ this.definedproperties[PropertyName] = definition; // Fluentize the API - this[PropertyName] = function() { + this[PropertyName] = function () { if (!arguments.length) { return this.properties[PropertyName]; } @@ -219,15 +218,16 @@ resetProperties(overrides) { for (let propName in this.definedproperties) { - this.properties[propName] = this.definedproperties[propName].defaultValue; + this.properties[propName] = + this.definedproperties[propName].defaultValue; } this.assignProperties(overrides); } /** * Updates the Plugin's properties with new values. - * - * @param {object} properties + * + * @param {object} properties */ assignProperties(properties) { let refresh = false; @@ -250,7 +250,9 @@ this.properties[propName] = properties[propName]; // make the callback if necessary if (this.definedproperties[propName].callback) { - this.definedproperties[propName].callback(properties[propName]); + this.definedproperties[propName].callback( + properties[propName] + ); } // if a refresh is necessary, call it later if (this.definedproperties[propName].refreshOnChange === true) { @@ -286,7 +288,7 @@ } this._events[type].push({ cb: fn, - ctx: context + ctx: context, }); } @@ -296,7 +298,7 @@ emit(type, data) { var event = Object.assign({}, data, { type: type, - target: this + target: this, }); if (this._events) { var listeners = this._events[type]; @@ -321,9 +323,7 @@ * Context that will be provided to the callback */ off(type, fn, context) { - var listeners, - i, - len; + var listeners, i, len; if (!type) { // clear all listeners if called without arguments delete this._events; @@ -376,6 +376,6 @@ } module.exports = { - Plugin: Plugin + Plugin: Plugin, }; -}()); +})(); diff --git a/js/sigplot.slider.js b/js/sigplot.slider.js index f1efd17..bdf8c44 100644 --- a/js/sigplot.slider.js +++ b/js/sigplot.slider.js @@ -26,8 +26,7 @@ /* global module */ /* global require */ -(function() { - +(function () { var m = require("./m"); var mx = require("./mx"); var common = require("./common"); @@ -38,19 +37,19 @@ * @param options * @returns {SliderPlugin} */ - var SliderPlugin = function(options) { + var SliderPlugin = function (options) { this.options = { display: true, style: { lineWidth: 1, - lineCap: "square" //, strokeStyle: "#FFFFFF", textStyle: "#FFFFFF" + lineCap: "square", //, strokeStyle: "#FFFFFF", textStyle: "#FFFFFF" }, - direction: "vertical", // "vertical","horizontal","both" + direction: "vertical", // "vertical","horizontal","both" name: "Slider", prevent_drag: false, add_box: false, // add boxes around values persistent_style: false, // highlights and/or boxes persist - slider_ID: 0 // each slider has a numerical int ID + slider_ID: 0, // each slider has a numerical int ID }; common.update(this.options, options); @@ -58,7 +57,6 @@ this.location = undefined; this.paired_slider = undefined; this.name = this.options.name; - }; SliderPlugin.prototype = { @@ -66,13 +64,13 @@ /** * Initialize the plugin */ - init: function(plot) { + init: function (plot) { this.plot = plot; var Mx = plot._Mx; // Register for mouse events var self = this; - this.onmousemove = function(evt) { + this.onmousemove = function (evt) { // Ignore if the slider isn't even visible if (self.location === undefined) { return; @@ -84,11 +82,11 @@ } // Ignore if the mouse is outside of the plot area - if ((evt.xpos < Mx.l) || (evt.xpos > Mx.r)) { + if (evt.xpos < Mx.l || evt.xpos > Mx.r) { self.set_highlight(false); return; } - if ((evt.ypos > Mx.b) || (evt.ypos < Mx.t)) { + if (evt.ypos > Mx.b || evt.ypos < Mx.t) { self.set_highlight(false); return; } @@ -103,20 +101,29 @@ return; } // Don't highlight if a warpbox is being drawn if (self.options.direction === "vertical") { - if (Math.abs(self.location - evt.xpos) < (lineWidth + 5)) { + if ( + Math.abs(self.location - evt.xpos) < + lineWidth + 5 + ) { self.set_highlight(true); } else { self.set_highlight(false); } } else if (self.options.direction === "horizontal") { - if (Math.abs(self.location - evt.ypos) < (lineWidth + 5)) { + if ( + Math.abs(self.location - evt.ypos) < + lineWidth + 5 + ) { self.set_highlight(true); } else { self.set_highlight(false); } } else if (self.options.direction === "both") { - if (Math.abs(self.location.x - evt.xpos) < (lineWidth + 5) && - Math.abs(self.location.y - evt.ypos) < (lineWidth + 5)) { + if ( + Math.abs(self.location.x - evt.xpos) < + lineWidth + 5 && + Math.abs(self.location.y - evt.ypos) < lineWidth + 5 + ) { self.set_highlight(true); } else { self.set_highlight(false); @@ -147,7 +154,7 @@ }; this.plot.addListener("mmove", this.onmousemove); - this.onmousedown = function(evt) { + this.onmousedown = function (evt) { if (self.location === undefined) { return; } @@ -157,10 +164,10 @@ return; } - if ((evt.xpos < Mx.l) || (evt.xpos > Mx.r)) { + if (evt.xpos < Mx.l || evt.xpos > Mx.r) { return; } - if ((evt.ypos > Mx.b) || (evt.ypos < Mx.t)) { + if (evt.ypos > Mx.b || evt.ypos < Mx.t) { return; } @@ -173,20 +180,22 @@ // TODO if multiple sliders are on the same position // they will become stuck together and cannot be separated if (self.options.direction === "vertical") { - if (Math.abs(self.location - evt.xpos) < (lineWidth + 5)) { + if (Math.abs(self.location - evt.xpos) < lineWidth + 5) { self.dragging = true; evt.slider_drag = true; evt.preventDefault(); } } else if (self.options.direction === "horizontal") { - if (Math.abs(self.location - evt.ypos) < (lineWidth + 5)) { + if (Math.abs(self.location - evt.ypos) < lineWidth + 5) { self.dragging = true; evt.slider_drag = true; evt.preventDefault(); } } else if (self.options.direction === "both") { - if (Math.abs(self.location.x - evt.xpos) < (lineWidth + 5) && - Math.abs(self.location.y - evt.ypos) < (lineWidth + 5)) { + if ( + Math.abs(self.location.x - evt.xpos) < lineWidth + 5 && + Math.abs(self.location.y - evt.ypos) < lineWidth + 5 + ) { self.dragging = true; evt.slider_drag = true; evt.preventDefault(); @@ -195,7 +204,7 @@ }; this.plot.addListener("mdown", this.onmousedown); - this.onmouseup = function(evt) { + this.onmouseup = function (evt) { if (!self.dragging) { return; } @@ -207,13 +216,17 @@ self.dragging = false; // Issue a slider tag event - var evt = document.createEvent('Event'); + var evt = document.createEvent("Event"); evt.source = self; - evt.initEvent('slidertag', true, true); + evt.initEvent("slidertag", true, true); if (self.options.direction === "both") { - evt.location = self.location ? JSON.parse(JSON.stringify(self.location)) : undefined; - evt.position = self.position ? JSON.parse(JSON.stringify(self.position)) : undefined; + evt.location = self.location + ? JSON.parse(JSON.stringify(self.location)) + : undefined; + evt.position = self.position + ? JSON.parse(JSON.stringify(self.position)) + : undefined; } else { evt.location = self.location; evt.position = self.position; @@ -222,11 +235,15 @@ mx.dispatchEvent(Mx, evt); // Issue a slider tag event - var evt = document.createEvent('Event'); - evt.initEvent('sliderdrag', true, true); + var evt = document.createEvent("Event"); + evt.initEvent("sliderdrag", true, true); if (self.options.direction === "both") { - evt.location = self.location ? JSON.parse(JSON.stringify(self.location)) : undefined; - evt.position = self.position ? JSON.parse(JSON.stringify(self.position)) : undefined; + evt.location = self.location + ? JSON.parse(JSON.stringify(self.location)) + : undefined; + evt.position = self.position + ? JSON.parse(JSON.stringify(self.position)) + : undefined; } else { evt.location = self.location; evt.position = self.position; @@ -237,21 +254,21 @@ this.plot.addListener("mup", this.onmouseup); }, - menu: function() { - var _display_handler = (function(self) { - return function() { + menu: function () { + var _display_handler = (function (self) { + return function () { self.options.display = !self.options.display; self.plot.redraw(); }; - }(this)); + })(this); - var _center_handler = (function(self) { - return function() { + var _center_handler = (function (self) { + return function () { var Mx = self.plot._Mx; var stk = Mx.stk[Mx.level]; - var xctr = ((stk.xmax - stk.xmin) / 2.0) + stk.xmin; - var yctr = ((stk.ymax - stk.ymin) / 2.0) + stk.ymin; + var xctr = (stk.xmax - stk.xmin) / 2.0 + stk.xmin; + var yctr = (stk.ymax - stk.ymin) / 2.0 + stk.ymin; if (self.options.direction === "vertical") { self.set_position(xctr); @@ -260,33 +277,36 @@ } else if (self.options.direction === "both") { self.set_position({ x: xctr, - y: yctr + y: yctr, }); } }; - }(this)); + })(this); return { text: this.name + "...", menu: { title: "SLIDER", - items: [{ - text: "Display", - checked: this.options.display, - style: "checkbox", - handler: _display_handler - }, { - text: "Center", - handler: _center_handler - }] - } + items: [ + { + text: "Display", + checked: this.options.display, + style: "checkbox", + handler: _display_handler, + }, + { + text: "Center", + handler: _center_handler, + }, + ], + }, }; }, - addListener: function(what, callback) { + addListener: function (what, callback) { var Mx = this.plot._Mx; var self = this; - var wrapped_cb = function(evt) { + var wrapped_cb = function (evt) { if (evt.source === self) { return callback(evt); } @@ -294,12 +314,12 @@ mx.addEventListener(Mx, what, wrapped_cb, false); }, - removeListener: function(what, callback) { + removeListener: function (what, callback) { var Mx = this.plot._Mx; mx.removeEventListener(Mx, what, callback, false); }, - pair: function(other_slider) { + pair: function (other_slider) { if (!other_slider) { this.paired_slider = null; return; @@ -311,19 +331,24 @@ this.paired_slider = other_slider; }, - set_highlight: function(ishighlight) { + set_highlight: function (ishighlight) { if (ishighlight !== this.highlight) { this.highlight = ishighlight; this.plot.redraw(); } }, - set_position: function(position) { + set_position: function (position) { if (this.dragging) { return; } - if (this.options.direction === "both") { // Object comparison - if (this.position !== undefined && this.position.x === position.x && this.position.y === position.y) { + if (this.options.direction === "both") { + // Object comparison + if ( + this.position !== undefined && + this.position.x === position.x && + this.position.y === position.y + ) { return; } } else { @@ -336,7 +361,9 @@ var Mx = this.plot._Mx; if (this.options.direction === "both") { - this.position = position ? JSON.parse(JSON.stringify(position)) : undefined; + this.position = position + ? JSON.parse(JSON.stringify(position)) + : undefined; } else { this.position = position; } @@ -355,17 +382,23 @@ } else if (this.options.direction === "both") { this.location = { x: pxl.x, - y: pxl.y + y: pxl.y, }; } // Issue a slider tag event - var evt = document.createEvent('Event'); - evt.initEvent('slidertag', true, true); - if (this.options.direction === "both") { // If both, expecting position to be an object - evt.location = this.location ? JSON.parse(JSON.stringify(this.location)) : undefined; - evt.position = this.position ? JSON.parse(JSON.stringify(this.position)) : undefined; - } else { // vertical or horizontal + var evt = document.createEvent("Event"); + evt.initEvent("slidertag", true, true); + if (this.options.direction === "both") { + // If both, expecting position to be an object + evt.location = this.location + ? JSON.parse(JSON.stringify(this.location)) + : undefined; + evt.position = this.position + ? JSON.parse(JSON.stringify(this.position)) + : undefined; + } else { + // vertical or horizontal evt.location = this.location; evt.position = this.position; } @@ -375,13 +408,17 @@ this.plot.redraw(); }, - set_location: function(location) { + set_location: function (location) { if (this.dragging) { return; } if (this.options.direction === "both") { - if (this.location !== undefined && this.location.x === location.x && this.location.y === location.y) { + if ( + this.location !== undefined && + this.location.x === location.x && + this.location.y === location.y + ) { return; } } else { @@ -394,7 +431,9 @@ var Mx = this.plot._Mx; if (this.options.direction === "both") { - this.location = location ? JSON.parse(JSON.stringify(location)) : undefined; + this.location = location + ? JSON.parse(JSON.stringify(location)) + : undefined; } else { this.location = location; } @@ -413,17 +452,21 @@ } else if (this.options.direction === "both") { this.position = { x: pos.x, - y: pos.y + y: pos.y, }; } // Issue a slider tag event - var evt = document.createEvent('Event'); - evt.initEvent('slidertag', true, true); + var evt = document.createEvent("Event"); + evt.initEvent("slidertag", true, true); if (this.options.direction === "both") { - evt.location = this.location ? JSON.parse(JSON.stringify(this.location)) : undefined; - evt.position = this.position ? JSON.parse(JSON.stringify(this.position)) : undefined; + evt.location = this.location + ? JSON.parse(JSON.stringify(this.location)) + : undefined; + evt.position = this.position + ? JSON.parse(JSON.stringify(this.position)) + : undefined; } else { evt.location = this.location; evt.position = this.position; @@ -432,15 +475,17 @@ this.plot.redraw(); }, - get_position: function() { // In real units + get_position: function () { + // In real units return this.position; }, - get_location: function() { // Pixels + get_location: function () { + // Pixels return this.location; }, - refresh: function(canvas) { + refresh: function (canvas) { if (!this.options.display) { return; } @@ -453,7 +498,10 @@ ctx.lineWidth = this.options.style.lineWidth; ctx.lineCap = this.options.style.lineCap; - ctx.strokeStyle = (this.options.style.strokeStyle !== undefined) ? this.options.style.strokeStyle : Mx.fg; + ctx.strokeStyle = + this.options.style.strokeStyle !== undefined + ? this.options.style.strokeStyle + : Mx.fg; if (this.dragging || this.highlight) { ctx.lineWidth = Math.ceil(ctx.lineWidth * 1.2); @@ -466,18 +514,22 @@ pxl = mx.real_to_pixel(Mx, this.position, this.position); } if (this.options.direction === "vertical") { - if ((pxl.x < Mx.l) || (pxl.x > Mx.r)) { + if (pxl.x < Mx.l || pxl.x > Mx.r) { return; } this.location = pxl.x; } else if (this.options.direction === "horizontal") { - if ((pxl.y < Mx.t) || (pxl.y > Mx.b)) { + if (pxl.y < Mx.t || pxl.y > Mx.b) { return; } this.location = pxl.y; } else if (this.options.direction === "both") { - if ((pxl.x < Mx.l) || (pxl.x > Mx.r) || - ((pxl.y < Mx.t) || (pxl.y > Mx.b))) { + if ( + pxl.x < Mx.l || + pxl.x > Mx.r || + pxl.y < Mx.t || + pxl.y > Mx.b + ) { return; } this.location.x = pxl.x; @@ -508,66 +560,108 @@ } // Show extra information while dragging or highlighted or if the user wants persistent highlights - if (this.dragging || this.highlight || this.options.persistent_style) { - var overlap_adjustment = 2 * Mx.text_h * (this.options.slider_ID); + if ( + this.dragging || + this.highlight || + this.options.persistent_style + ) { + var overlap_adjustment = 2 * Mx.text_h * this.options.slider_ID; if (this.options.direction === "vertical") { ctx.textBaseline = "alphabetic"; ctx.textAlign = "left"; - ctx.fillStyle = (this.options.style.textStyle !== undefined) ? this.options.style.textStyle : Mx.fg; + ctx.fillStyle = + this.options.style.textStyle !== undefined + ? this.options.style.textStyle + : Mx.fg; ctx.font = Mx.font.font; var text = mx.format_g(this.position, 6, 3, true).trim(); var text_w = ctx.measureText(text).width; - if ((this.location + 2 * text_w) > Mx.r) { + if (this.location + 2 * text_w > Mx.r) { ctx.textAlign = "right"; - ctx.fillText(text, this.location - 15, Mx.t + 40 + overlap_adjustment); + ctx.fillText( + text, + this.location - 15, + Mx.t + 40 + overlap_adjustment + ); } else { - ctx.fillText(text, this.location + 15, Mx.t + 40 + overlap_adjustment); + ctx.fillText( + text, + this.location + 15, + Mx.t + 40 + overlap_adjustment + ); } - if (this.options.add_box) { // Draw a box around the value - if ((this.location + 2 * text_w) > Mx.r) { - ctx.rect(this.location - 2 * text_w, Mx.t + 20 + overlap_adjustment, 2 * text_w, 2 * Mx.text_h); + if (this.location + 2 * text_w > Mx.r) { + ctx.rect( + this.location - 2 * text_w, + Mx.t + 20 + overlap_adjustment, + 2 * text_w, + 2 * Mx.text_h + ); ctx.strokeStyle = this.options.style.strokeStyle; ctx.stroke(); } else { - ctx.rect(this.location + 0.5, Mx.t + 20 + overlap_adjustment, 2 * text_w, 2 * Mx.text_h); + ctx.rect( + this.location + 0.5, + Mx.t + 20 + overlap_adjustment, + 2 * text_w, + 2 * Mx.text_h + ); ctx.strokeStyle = this.options.style.strokeStyle; ctx.stroke(); } - } } else if (this.options.direction === "horizontal") { ctx.textBaseline = "alphabetic"; ctx.textAlign = "left"; - ctx.fillStyle = (this.options.style.textStyle !== undefined) ? this.options.style.textStyle : Mx.fg; + ctx.fillStyle = + this.options.style.textStyle !== undefined + ? this.options.style.textStyle + : Mx.fg; ctx.font = Mx.font.font; var text = mx.format_g(this.position, 6, 3, true).trim(); var text_w = ctx.measureText(text).width; - overlap_adjustment = 2 * text_w * (this.options.slider_ID); - if ((this.location - 2 * Mx.text_h) > Mx.t) { - ctx.fillText(text, Mx.l + 20 + overlap_adjustment, this.location - 5); + overlap_adjustment = 2 * text_w * this.options.slider_ID; + if (this.location - 2 * Mx.text_h > Mx.t) { + ctx.fillText( + text, + Mx.l + 20 + overlap_adjustment, + this.location - 5 + ); } else { - ctx.fillText(text, Mx.l + 20 + overlap_adjustment, this.location + 5 + Mx.text_h); - + ctx.fillText( + text, + Mx.l + 20 + overlap_adjustment, + this.location + 5 + Mx.text_h + ); } if (this.options.add_box) { // Draw a box around the value - if ((this.location - 2 * Mx.text_h) > Mx.t) { - ctx.rect(Mx.l + 15 + overlap_adjustment, this.location - 2 * Mx.text_h, 2 * text_w, 2 * Mx.text_h); + if (this.location - 2 * Mx.text_h > Mx.t) { + ctx.rect( + Mx.l + 15 + overlap_adjustment, + this.location - 2 * Mx.text_h, + 2 * text_w, + 2 * Mx.text_h + ); ctx.strokeStyle = this.options.style.strokeStyle; ctx.stroke(); } else { - ctx.rect(Mx.l + 15 + overlap_adjustment, this.location, 2 * text_w, 2 * Mx.text_h); + ctx.rect( + Mx.l + 15 + overlap_adjustment, + this.location, + 2 * text_w, + 2 * Mx.text_h + ); ctx.strokeStyle = this.options.style.strokeStyle; ctx.stroke(); } } - } else if (this.options.direction === "both") { // TODO } @@ -575,39 +669,68 @@ if (this.paired_slider) { if (this.options.direction === "vertical") { var delta = this.position - this.paired_slider.position; - var locdelta = this.location - this.paired_slider.location; + var locdelta = + this.location - this.paired_slider.location; var ypos = Mx.t + Math.round((Mx.b - Mx.t) / 2); - mx.textline(Mx, this.location, ypos, this.paired_slider.location, ypos, { - mode: "dashed", - on: 3, - off: 3 - }); + mx.textline( + Mx, + this.location, + ypos, + this.paired_slider.location, + ypos, + { + mode: "dashed", + on: 3, + off: 3, + } + ); ctx.textBaseline = "alphabetic"; ctx.textAlign = "center"; - ctx.fillStyle = (this.options.style.textStyle !== undefined) ? this.options.style.textStyle : Mx.fg; + ctx.fillStyle = + this.options.style.textStyle !== undefined + ? this.options.style.textStyle + : Mx.fg; ctx.font = Mx.font.font; var text = mx.format_g(delta, 6, 3, true); - ctx.fillText(text, this.location - Math.round(locdelta / 2), ypos - 5); - + ctx.fillText( + text, + this.location - Math.round(locdelta / 2), + ypos - 5 + ); } else if (this.options.direction === "horizontal") { var delta = this.position - this.paired_slider.position; - var locdelta = this.location - this.paired_slider.location; + var locdelta = + this.location - this.paired_slider.location; var xpos = Mx.l + Math.round((Mx.r - Mx.l) / 2); - mx.textline(Mx, xpos, this.location, xpos, this.paired_slider.location, { - mode: "dashed", - on: 3, - off: 3 - }); + mx.textline( + Mx, + xpos, + this.location, + xpos, + this.paired_slider.location, + { + mode: "dashed", + on: 3, + off: 3, + } + ); ctx.textBaseline = "alphabetic"; ctx.textAlign = "left"; - ctx.fillStyle = (this.options.style.textStyle !== undefined) ? this.options.style.textStyle : Mx.fg; + ctx.fillStyle = + this.options.style.textStyle !== undefined + ? this.options.style.textStyle + : Mx.fg; ctx.font = Mx.font.font; var text = mx.format_g(delta, 6, 3, true); - ctx.fillText(text, xpos + 5, this.location - Math.round(locdelta / 2)); + ctx.fillText( + text, + xpos + 5, + this.location - Math.round(locdelta / 2) + ); } else if (this.options.direction === "both") { // TODO } @@ -615,14 +738,13 @@ } }, - dispose: function() { + dispose: function () { this.plot.removeListener("mmove", this.onmousemove); document.removeEventListener("mouseup", this.onmouseup, false); this.plot = undefined; this.position = undefined; - } + }, }; module.exports = SliderPlugin; - -}()); +})(); diff --git a/karma.conf.js b/karma.conf.js index b785af8..907655c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,22 +1,24 @@ -module.exports = function(config) { +module.exports = function (config) { config.set({ - files: ['benchmark/autobench.js', - "benchmark/index.html", - "benchmark/pass.html", - "benchmark/fail.html", - "benchmark/gamingbench.js", - "benchmark/tools.js", - "benchmark/benchmarks.js", - "benchmark/index.css", - "benchmark/index.js", - "dist/sigplot.js", - "dist/bluefile.js", - "dist/sigplot.plugins.js"], - browsers: ['Firefox', 'Chrome'], - frameworks: ['qunit'], + files: [ + "benchmark/autobench.js", + "benchmark/index.html", + "benchmark/pass.html", + "benchmark/fail.html", + "benchmark/gamingbench.js", + "benchmark/tools.js", + "benchmark/benchmarks.js", + "benchmark/index.css", + "benchmark/index.js", + "dist/sigplot.js", + "dist/bluefile.js", + "dist/sigplot.plugins.js", + ], + browsers: ["Firefox", "Chrome"], + frameworks: ["qunit"], concurrency: 1, browserNoActivityTimeout: 360000, singleRun: true, - logLevel: config.LOG_DEBUG + logLevel: config.LOG_DEBUG, }); }; diff --git a/package.json b/package.json index aef1a81..70ced87 100644 --- a/package.json +++ b/package.json @@ -1,88 +1,111 @@ { - "name": "sigplot", - "description": "Advanced plotting for signal processing applications", - "version": "2.0.0-rc17", - "homepage": "http://sigplot.lgsinnovations.com", - "main": "js/sigplot.js", - "files": [ - "js", - "dist/bluefile-debug.js", - "dist/bluefile-minimized.js", - "dist/matfile-debug.js", - "dist/matfile-minimized.js", - "dist/sigplot-debug.js", - "dist/sigplot-minimized.js", - "dist/sigplot.plugins-debug.js", - "dist/sigplot.plugins-minimized.js" - ], - "author": { - "name": "LGS Innovations, Inc.", - "email": "sigplot@lgsinnovations.com", - "url": "http://www.lgsinnovations.com" - }, - "repository": { - "type": "git", - "url": "git://github.com/LGSInnovations/sigplot.git" - }, - "bugs": { - "url": "https://github.com/LGSInnovations/sigplot/issues" - }, - "license": "apache-2.0", - "licenses": [ - { - "type": "apache-2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0" + "name": "sigplot", + "description": "Advanced plotting for signal processing applications", + "version": "2.0.0-rc17", + "homepage": "http://sigplot.lgsinnovations.com", + "main": "js/sigplot.js", + "files": [ + "js", + "dist/bluefile-debug.js", + "dist/bluefile-minimized.js", + "dist/matfile-debug.js", + "dist/matfile-minimized.js", + "dist/sigplot-debug.js", + "dist/sigplot-minimized.js", + "dist/sigplot.plugins-debug.js", + "dist/sigplot.plugins-minimized.js" + ], + "author": { + "name": "LGS Innovations, Inc.", + "email": "sigplot@lgsinnovations.com", + "url": "http://www.lgsinnovations.com" + }, + "repository": { + "type": "git", + "url": "git://github.com/LGSInnovations/sigplot.git" + }, + "bugs": { + "url": "https://github.com/LGSInnovations/sigplot/issues" + }, + "license": "apache-2.0", + "licenses": [ + { + "type": "apache-2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0" + } + ], + "scripts": { + "build:sigplot": "npx esbuild --outfile=sigplot.js --bundle js/sigplot.js", + "build:plugins": "npx esbuild --outfile=sigplot.js --bundle js/sigplot.js", + "build:sigplot-debug": "npx esbuild --outfile=sigplot.js --bundle js/sigplot.js", + "build:plugins-debug": "npx esbuild --outfile=sigplot.js --bundle js/sigplot.js", + "build": "npm run build:sigplot && npm run build:plugins", + "build:debug": "npm run build:sigplot-debug && npm run build:plugins-debug", + "clean": "rm -rf ./dist ./doc", + "dist": "npm run clean && npm run format:check && npm run lint:check && npm run build", + "format:check": "npx prettier --ignore-path .gitignore --check '*.json' '*.js' '{js,test,examples}/**/*.js'", + "format:cleanup": "npx prettier --ignore-path .gitignore --write '*.json' '*.js' '{js,test,examples}/**/*.js'", + "generate-docs": "rm -rf ./doc/; node_modules/.bin/jsdoc --configure .jsdoc.json --verbose; cp ./fft-white.png doc/sigplot/$npm_package_version/", + "lint:check": "npx eslint examples/ js/ test/", + "lint:cleanup": "npm run lint:check -- --fix", + "test": "grunt test" + }, + "eslintConfig": { + "extends": "eslint:recommended", + "env": { + "browser": true + }, + "globals": { + "window": true, + "module": true + }, + "parser": "@babel/eslint-parser", + "parserOptions": { + "requireConfigFile": false + }, + "rules": { + "dot-notation": "error", + "indent": [ + "error", + 4 + ], + "curly": "error", + "eqeqeq": "error", + "wrap-iife": "error", + "no-use-before-define": "error", + "new-cap": "error" + } + }, + "prettier": { + "tabWidth": 4 + }, + "dependencies": { + "loglevel": "^1.4.1", + "lru": "^3.1.0", + "lru-cache": "^6.0.0", + "sigfile": "^0.1.9", + "spin": "0.0.1", + "tinycolor2": "^1.4.1", + "underscore": "^1.13.1" + }, + "devDependencies": { + "@babel/core": "^7.14.2", + "@babel/eslint-parser": "^7.14.2", + "catharsis": "^0.8.9", + "esbuild": "^0.11.20", + "eslint": "^7.26.0", + "express": "^4.13.4", + "jasmine": "^3.1.0", + "karma": "^2.0.2", + "karma-chrome-launcher": "^2.0.2", + "karma-firefox-launcher": "^1.0.0", + "karma-jasmine": "^1.1.2", + "karma-qunit": "^2.1.0", + "marked": "^0.3.6", + "minami": "^1.2.3", + "prettier": "^2.3.0", + "qunit-assert-close": "^2.1.2", + "qunitjs": "^2.4.1", + "taffydb": "^2.7.3" } - ], - "scripts": { - "generate-docs": "rm -rf ./doc/; node_modules/.bin/jsdoc --configure .jsdoc.json --verbose; cp ./fft-white.png doc/sigplot/$npm_package_version/", - "test": "grunt test", - "prepublish": "grunt dist" - }, - "dependencies": { - "loglevel": "^1.4.1", - "lru": "^3.1.0", - "sigfile": "^0.1.9", - "spin": "0.0.1", - "tinycolor2": "^1.4.1", - "travis": "^0.1.1", - "underscore": "^1.9.2" - }, - "devDependencies": { - "@babel/core": "^7.10.5", - "@babel/preset-env": "^7.10.4", - "babelify": "^10.0.0", - "catharsis": "^0.8.9", - "express": "^4.13.4", - "grunt": "^1.0.3", - "grunt-browserify": "^5.0.0", - "grunt-cli": "^1.3.2", - "grunt-closure-compiler": "^0.0.21", - "grunt-contrib-clean": "^1.1.0", - "grunt-contrib-compress": "^1.4.3", - "grunt-contrib-jshint": "^1.1.0", - "grunt-contrib-qunit": "^2.0.0", - "grunt-express-server": "^0.5.3", - "grunt-githash": "^0.1.3", - "grunt-http-server": "^2.1.0", - "grunt-jsbeautifier": "^0.2.13", - "grunt-jsdoc": "^2.2.1", - "grunt-karma": "^2.0.0", - "grunt-open": "^0.2.3", - "grunt-services": "^0.1.0", - "grunt-shell-spawn": "^0.3.12", - "grunt-text-replace": "^0.4.0", - "jasmine": "^3.1.0", - "karma": "^2.0.2", - "karma-chrome-launcher": "^2.0.2", - "karma-firefox-launcher": "^1.0.0", - "karma-jasmine": "^1.1.2", - "karma-qunit": "^2.1.0", - "marked": "^0.3.6", - "minami": "^1.2.3", - "qunit-assert-close": "^2.1.2", - "qunitjs": "^2.4.1", - "taffydb": "^2.7.3", - "underscore": "^1.9.2" - } } diff --git a/test/tests.colormap.js b/test/tests.colormap.js index d3078cb..1f15369 100644 --- a/test/tests.colormap.js +++ b/test/tests.colormap.js @@ -28,47 +28,55 @@ ////////////////////////////////////////////////////////////////////////////// // QUnit 'ColorMap' module ////////////////////////////////////////////////////////////////////////////// -QUnit.module('ColorMap', { - setup: function() {}, - teardown: function() {} +QUnit.module("ColorMap", { + setup: function () {}, + teardown: function () {}, }); -QUnit.test('colormap', function(assert) { - var map = new ColorMap([{ - pos: 0, - red: 0, - green: 0, - blue: 15 - }, { - pos: 10, - red: 0, - green: 0, - blue: 50 - }, { - pos: 31, - red: 0, - green: 65, - blue: 75 - }, { - pos: 50, - red: 0, - green: 85, - blue: 0 - }, { - pos: 70, - red: 75, - green: 80, - blue: 0 - }, { - pos: 83, - red: 100, - green: 60, - blue: 0 - }, { - pos: 100, - red: 100, - green: 0, - blue: 0 - }]); +QUnit.test("colormap", function (assert) { + var map = new ColorMap([ + { + pos: 0, + red: 0, + green: 0, + blue: 15, + }, + { + pos: 10, + red: 0, + green: 0, + blue: 50, + }, + { + pos: 31, + red: 0, + green: 65, + blue: 75, + }, + { + pos: 50, + red: 0, + green: 85, + blue: 0, + }, + { + pos: 70, + red: 75, + green: 80, + blue: 0, + }, + { + pos: 83, + red: 100, + green: 60, + blue: 0, + }, + { + pos: 100, + red: 100, + green: 0, + blue: 0, + }, + ]); var color = map.getColor(0); assert.equal(color.red, 0); assert.equal(color.green, 0); @@ -162,5 +170,4 @@ QUnit.test('colormap', function(assert) { assert.equal(color.red, 255); assert.equal(color.green, 255); assert.equal(color.blue, 255); - }); diff --git a/test/tests.interactive-accordion.js b/test/tests.interactive-accordion.js index 51d11f6..dc15832 100644 --- a/test/tests.interactive-accordion.js +++ b/test/tests.interactive-accordion.js @@ -25,261 +25,299 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-accordion', { +QUnit.module("sigplot-interactive-accordion", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('vertical accordion', 'Do you see a vertical accordion that stays centered at zero as the axis shifts', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var framesize = 500; - var zeros = []; - for (var i = 0; i < framesize; i += 1) { - zeros.push(0); - } - var accordion = new sigplot_plugins.AccordionPlugin({ - draw_center_line: true, - shade_area: true, - draw_edge_lines: true, - direction: "vertical", - edge_line_style: { - strokeStyle: "#FF2400" - } - }); - var lyr0 = plot.overlay_array(zeros, { - type: 2000, - subsize: framesize, - file_name: "zeros", - xstart: -250, - xdelta: 1 - }, { - layerType: sigplot.Layer1D - }); - plot.add_plugin(accordion, 1); - accordion.set_center(0); - accordion.set_width(50); - var xstart = -250; - var xstart_chng = 25; - ifixture.interval = window.setInterval(function() { - if (xstart < -450 || xstart >= -25) { - xstart_chng = xstart_chng * -1; +interactiveTest( + "vertical accordion", + "Do you see a vertical accordion that stays centered at zero as the axis shifts", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var framesize = 500; + var zeros = []; + for (var i = 0; i < framesize; i += 1) { + zeros.push(0); } - xstart += xstart_chng; - plot.reload(lyr0, zeros, { - xstart: xstart + var accordion = new sigplot_plugins.AccordionPlugin({ + draw_center_line: true, + shade_area: true, + draw_edge_lines: true, + direction: "vertical", + edge_line_style: { + strokeStyle: "#FF2400", + }, }); - }, 500); -}); + var lyr0 = plot.overlay_array( + zeros, + { + type: 2000, + subsize: framesize, + file_name: "zeros", + xstart: -250, + xdelta: 1, + }, + { + layerType: sigplot.Layer1D, + } + ); + plot.add_plugin(accordion, 1); + accordion.set_center(0); + accordion.set_width(50); + var xstart = -250; + var xstart_chng = 25; + ifixture.interval = window.setInterval(function () { + if (xstart < -450 || xstart >= -25) { + xstart_chng = xstart_chng * -1; + } + xstart += xstart_chng; + plot.reload(lyr0, zeros, { + xstart: xstart, + }); + }, 500); + } +); + +interactiveTest( + "horizontal accordion", + "Do you see a horizontal accordion at zero and each multiple of 80, scrolling with the data?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + nogrid: true, + }); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "rising", + } + ); + var acc; + var accordion = function (y) { + acc = new sigplot_plugins.AccordionPlugin({ + draw_center_line: true, + shade_area: true, + draw_edge_lines: true, + direction: "horizontal", + edge_line_style: { + strokeStyle: "#FF2400", + }, + }); + acc.set_center(y); + acc.set_width(0.25 * 50); + return acc; + }; + plot.add_plugin(accordion(0), 1); + var row = 0; + ifixture.interval = window.setInterval(function () { + var zeros = []; + for (var i = 0; i < framesize; i += 1) { + zeros.push(0); + } + row += 1; + if (row % (80 / 0.25) === 0) { + var y = row * 0.25; + plot.remove_plugin(acc); + plot.deoverlay(1); + plot.add_plugin(accordion(y), 1); + } + plot.push(lyr0, zeros); + }, 100); + } +); -interactiveTest('horizontal accordion', 'Do you see a horizontal accordion at zero and each multiple of 80, scrolling with the data?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - nogrid: true - }); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: 'rising' - }); - var acc; - var accordion = function(y) { - acc = new sigplot_plugins.AccordionPlugin({ +interactiveTest( + "vertical accordion relative placement", + "Do you see a vertical accordion that doesn't move as the axis shifts?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_array( + null, + { + type: 2000, + subsize: framesize, + file_name: "zeros", + xstart: -64, + }, + { + layerType: sigplot.Layer1D, + } + ); + var accordion = new sigplot_plugins.AccordionPlugin({ + mode: "relative", draw_center_line: true, shade_area: true, draw_edge_lines: true, - direction: "horizontal", + direction: "vertical", edge_line_style: { - strokeStyle: "#FF2400" + strokeStyle: "#FF2400", + }, + }); + plot.add_plugin(accordion, 1); + accordion.set_center(0.5); + accordion.set_width(0.1); + var xstart = 0; + var xstart_chng = 16; + ifixture.interval = window.setInterval(function () { + var zeros = []; + for (var i = 0; i < framesize; i += 1) { + zeros.push(0); } + if (Math.abs(xstart) >= 64) { + xstart_chng = xstart_chng * -1; + } + xstart += xstart_chng; + plot.reload(lyr0, zeros, { + xstart: xstart, + }); + }, 500); + } +); + +interactiveTest( + "horizontal accordion relative placement", + "Do you see a horizontal accordion that doesn't move with the data?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + nogrid: true, + }); + assert.notEqual(plot, null); + var framesize = 128; + plot.change_settings({ + autol: 5, }); - acc.set_center(y); - acc.set_width(0.25 * 50); - return acc; - }; - plot.add_plugin(accordion(0), 1); - var row = 0; - ifixture.interval = window.setInterval(function() { var zeros = []; for (var i = 0; i < framesize; i += 1) { zeros.push(0); } - row += 1; - if (row % (80 / 0.25) === 0) { - var y = (row * 0.25); - plot.remove_plugin(acc); - plot.deoverlay(1); - plot.add_plugin(accordion(y), 1); - } - plot.push(lyr0, zeros); - }, 100); -}); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "zeros", + }, + { + drawmode: "rising", + } + ); + var accordion = new sigplot_plugins.AccordionPlugin({ + mode: "relative", + draw_center_line: true, + shade_area: true, + draw_edge_lines: true, + direction: "horizontal", + edge_line_style: { + strokeStyle: "#FF2400", + }, + }); + plot.add_plugin(accordion, 1); + accordion.set_center(0.5); + accordion.set_width(0.1); + var count = 0; + ifixture.interval = window.setInterval(function () { + plot.push(lyr0, zeros); + }, 100); + } +); -interactiveTest('vertical accordion relative placement', "Do you see a vertical accordion that doesn't move as the axis shifts?", function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_array(null, { - type: 2000, - subsize: framesize, - file_name: "zeros", - xstart: -64 - }, { - layerType: sigplot.Layer1D - }); - var accordion = new sigplot_plugins.AccordionPlugin({ - mode: "relative", - draw_center_line: true, - shade_area: true, - draw_edge_lines: true, - direction: "vertical", - edge_line_style: { - strokeStyle: "#FF2400" - } - }); - plot.add_plugin(accordion, 1); - accordion.set_center(0.5); - accordion.set_width(0.1); - var xstart = 0; - var xstart_chng = 16; - ifixture.interval = window.setInterval(function() { +interactiveTest( + "horizontal and vertical accordions absolute placement zoom", + "Do the accordions stay at the same Real World Coordinates when you zoom?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); var zeros = []; - for (var i = 0; i < framesize; i += 1) { + for (var i = 0; i <= 1000; i++) { zeros.push(0); } - if (Math.abs(xstart) >= 64) { - xstart_chng = xstart_chng * -1; - } - xstart += xstart_chng; - plot.reload(lyr0, zeros, { - xstart: xstart + plot.overlay_array(zeros, {}); + var vert_accordion = new sigplot_plugins.AccordionPlugin({ + mode: "absolute", + draw_center_line: true, + shade_area: true, + draw_edge_lines: true, + direction: "vertical", + edge_line_style: { + strokeStyle: "#FF2400", + }, }); - }, 500); -}); - -interactiveTest('horizontal accordion relative placement', "Do you see a horizontal accordion that doesn't move with the data?", function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - nogrid: true - }); - assert.notEqual(plot, null); - var framesize = 128; - plot.change_settings({ - autol: 5 - }); - var zeros = []; - for (var i = 0; i < framesize; i += 1) { - zeros.push(0); + var horiz_accordion = new sigplot_plugins.AccordionPlugin({ + mode: "absolute", + draw_center_line: true, + shade_area: true, + draw_edge_lines: true, + direction: "horizontal", + edge_line_style: { + strokeStyle: "#FF2400", + }, + }); + plot.add_plugin(vert_accordion, 1); + plot.add_plugin(horiz_accordion, 2); + vert_accordion.set_center(500); + vert_accordion.set_width(100); + horiz_accordion.set_center(0); + horiz_accordion.set_width(0.5); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "zeros" - }, { - drawmode: 'rising' - }); - var accordion = new sigplot_plugins.AccordionPlugin({ - mode: "relative", - draw_center_line: true, - shade_area: true, - draw_edge_lines: true, - direction: "horizontal", - edge_line_style: { - strokeStyle: "#FF2400" - } - }); - plot.add_plugin(accordion, 1); - accordion.set_center(0.5); - accordion.set_width(0.1); - var count = 0; - ifixture.interval = window.setInterval(function() { - plot.push(lyr0, zeros); - }, 100); -}); +); -interactiveTest('horizontal and vertical accordions absolute placement zoom', 'Do the accordions stay at the same Real World Coordinates when you zoom?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var zeros = []; - for (var i = 0; i <= 1000; i++) { - zeros.push(0); - } - plot.overlay_array(zeros, {}); - var vert_accordion = new sigplot_plugins.AccordionPlugin({ - mode: "absolute", - draw_center_line: true, - shade_area: true, - draw_edge_lines: true, - direction: "vertical", - edge_line_style: { - strokeStyle: "#FF2400" - } - }); - var horiz_accordion = new sigplot_plugins.AccordionPlugin({ - mode: "absolute", - draw_center_line: true, - shade_area: true, - draw_edge_lines: true, - direction: "horizontal", - edge_line_style: { - strokeStyle: "#FF2400" +interactiveTest( + "horizontal and vertical accordions relative placement zoom", + "Do the accordions stay at the same pixel location when you zoom?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var zeros = []; + for (var i = 0; i <= 1000; i++) { + zeros.push(0); } - }); - plot.add_plugin(vert_accordion, 1); - plot.add_plugin(horiz_accordion, 2); - vert_accordion.set_center(500); - vert_accordion.set_width(100); - horiz_accordion.set_center(0); - horiz_accordion.set_width(0.5); -}); - -interactiveTest('horizontal and vertical accordions relative placement zoom', 'Do the accordions stay at the same pixel location when you zoom?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var zeros = []; - for (var i = 0; i <= 1000; i++) { - zeros.push(0); + plot.overlay_array(zeros, {}); + var vert_accordion = new sigplot_plugins.AccordionPlugin({ + mode: "relative", + draw_center_line: true, + shade_area: true, + draw_edge_lines: true, + direction: "vertical", + edge_line_style: { + strokeStyle: "#FF2400", + }, + }); + var horiz_accordion = new sigplot_plugins.AccordionPlugin({ + mode: "relative", + draw_center_line: true, + shade_area: true, + draw_edge_lines: true, + direction: "horizontal", + edge_line_style: { + strokeStyle: "#FF2400", + }, + }); + plot.add_plugin(vert_accordion, 1); + plot.add_plugin(horiz_accordion, 2); + vert_accordion.set_center(0.5); + vert_accordion.set_width(0.1); + horiz_accordion.set_center(0.5); + horiz_accordion.set_width(0.1); } - plot.overlay_array(zeros, {}); - var vert_accordion = new sigplot_plugins.AccordionPlugin({ - mode: "relative", - draw_center_line: true, - shade_area: true, - draw_edge_lines: true, - direction: "vertical", - edge_line_style: { - strokeStyle: "#FF2400" - } - }); - var horiz_accordion = new sigplot_plugins.AccordionPlugin({ - mode: "relative", - draw_center_line: true, - shade_area: true, - draw_edge_lines: true, - direction: "horizontal", - edge_line_style: { - strokeStyle: "#FF2400" - } - }); - plot.add_plugin(vert_accordion, 1); - plot.add_plugin(horiz_accordion, 2); - vert_accordion.set_center(0.5); - vert_accordion.set_width(0.1); - horiz_accordion.set_center(0.5); - horiz_accordion.set_width(0.1); -}); +); diff --git a/test/tests.interactive-annotations.js b/test/tests.interactive-annotations.js index c1cf37c..4f8ae47 100644 --- a/test/tests.interactive-annotations.js +++ b/test/tests.interactive-annotations.js @@ -25,349 +25,397 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-annotations', { +QUnit.module("sigplot-interactive-annotations", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('annotations', 'Do you see a text annotation at the correct locations, fonts and colors?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - annotations.add_annotation({ - x: 0, - y: 0, - value: "0,0 (red)", - color: "red", - highlight_color: "green", - popup: "a" - }); - annotations.add_annotation({ - x: 0.5, - y: 0.5, - value: "0.5,0.5 (small)", - font: "15px monospace", - popup: "b" - }); - annotations.add_annotation({ - x: -0.5, - y: -0.5, - value: "-0.5,-0.5", - popup: "c", - onclick: function() { - alert("you clicked me"); - } - }); - annotations.add_annotation({ - x: -0.5, - y: 0.5, - value: "-0.5,0.5", - popup: "d", - textBaseline: "middle", - textAlign: "center" - }); - annotations.add_annotation({ - x: 0.5, - y: -0.5, - value: "0.5,-0.5 (small green)", - color: "green", - font: "15px monospace", - popup: "e", - popupTextColor: "red" - }); -}); - -interactiveTest('annotations png', 'Do you see a image annotation centered at 0,0 that has a popup on hover?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - var img = new Image(); // Create new img element - img.onload = function() { +interactiveTest( + "annotations", + "Do you see a text annotation at the correct locations, fonts and colors?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); annotations.add_annotation({ x: 0, y: 0, - value: img, - popup: "Hello World" + value: "0,0 (red)", + color: "red", + highlight_color: "green", + popup: "a", }); - }; - img.src = 'dat/info.png'; -}); - -interactiveTest('annotations popup', 'Do you see an popup when you hover over the annotation?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - annotations.add_annotation({ - x: -0.25, - y: 0.25, - value: "Test Popup", - popup: "This is metadata" - }); -}); - -interactiveTest('annotations custom popup', 'Do you see an popup when you hover over the annotation?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var tt; - plot.addListener("annotationhighlight", function(evt) { - // you could use tipped.js, opentip, bootstrap, etc. here - // this is just a simple test example not intended to be actually used - if (evt.state && !tt) { - tt = document.createElement("div"); - tt.setAttribute("id", "test-tooltip"); - tt.style.display = "block"; - tt.style.position = "relative"; - tt.style.top = (evt.y + 5) + "px"; - tt.style.left = (evt.x + 5) + "px"; - tt.style.width = "100px"; - tt.style.height = "50px"; - tt.style.opacity = 0.4; - tt.style.background = "red"; - container.appendChild(tt); - } else if (!evt.state && tt) { - container.removeChild(tt); - tt = null; - } - }); - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - annotations.add_annotation({ - x: 0, - y: 0, - value: "Test Custom Popup" - }); -}); - -interactiveTest('annotations shift', 'Do you see a text annotation that remains at the correct locations while the axis shifts?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - annotations.add_annotation({ - x: 0, - y: 50, - value: "0,50" - }); - annotations.add_annotation({ - x: 50, - y: 60, - value: "50,60" - }); - annotations.add_annotation({ - x: -50, - y: 60, - value: "-50,60" - }); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - xstart: -64, - ydelta: 0.25 - }); - var xstart = 0; - var xstart_chng = 16; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - if (Math.abs(xstart) >= 64) { - xstart_chng = xstart_chng * -1; - } - xstart += xstart_chng; - plot.push(lyr0, ramp, { - xstart: xstart + annotations.add_annotation({ + x: 0.5, + y: 0.5, + value: "0.5,0.5 (small)", + font: "15px monospace", + popup: "b", }); - }, 500); -}); + annotations.add_annotation({ + x: -0.5, + y: -0.5, + value: "-0.5,-0.5", + popup: "c", + onclick: function () { + alert("you clicked me"); + }, + }); + annotations.add_annotation({ + x: -0.5, + y: 0.5, + value: "-0.5,0.5", + popup: "d", + textBaseline: "middle", + textAlign: "center", + }); + annotations.add_annotation({ + x: 0.5, + y: -0.5, + value: "0.5,-0.5 (small green)", + color: "green", + font: "15px monospace", + popup: "e", + popupTextColor: "red", + }); + } +); -interactiveTest('annotation falling raster', 'Do you see annotations that scroll with the data?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var img = new Image(); // Create new img element - img.src = 'dat/info.png'; - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "falling" - }); - var row = 0; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - row += 1; - if (row % 64 === 0) { - var y = (row * 0.25); +interactiveTest( + "annotations png", + "Do you see a image annotation centered at 0,0 that has a popup on hover?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + var img = new Image(); // Create new img element + img.onload = function () { annotations.add_annotation({ - x: 64, - y: y, - value: "64," + y, - popup: "test" - }); - } else if (row % 100 === 0) { - var y = (row * 0.25); - annotations.add_annotation({ - x: 32, - y: y, + x: 0, + y: 0, value: img, - popup: "32," + y + popup: "Hello World", }); - } - plot.push(lyr0, ramp); - }, 100); -}); + }; + img.src = "dat/info.png"; + } +); -interactiveTest('annotation rising raster', 'Do you see annotations that scroll with the data?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var img = new Image(); // Create new img element - img.src = 'dat/info.png'; - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "rising" - }); - var row = 0; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - row += 1; - if (row % 64 === 0) { - var y = (row * 0.25); - annotations.add_annotation({ - x: 64, - y: y, - value: "64," + y, - popup: "test" - }); - } else if (row % 100 === 0) { - var y = (row * 0.25); - annotations.add_annotation({ - x: 32, - y: y, - value: img, - popup: "32," + y +interactiveTest( + "annotations popup", + "Do you see an popup when you hover over the annotation?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + annotations.add_annotation({ + x: -0.25, + y: 0.25, + value: "Test Popup", + popup: "This is metadata", + }); + } +); + +interactiveTest( + "annotations custom popup", + "Do you see an popup when you hover over the annotation?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var tt; + plot.addListener("annotationhighlight", function (evt) { + // you could use tipped.js, opentip, bootstrap, etc. here + // this is just a simple test example not intended to be actually used + if (evt.state && !tt) { + tt = document.createElement("div"); + tt.setAttribute("id", "test-tooltip"); + tt.style.display = "block"; + tt.style.position = "relative"; + tt.style.top = evt.y + 5 + "px"; + tt.style.left = evt.x + 5 + "px"; + tt.style.width = "100px"; + tt.style.height = "50px"; + tt.style.opacity = 0.4; + tt.style.background = "red"; + container.appendChild(tt); + } else if (!evt.state && tt) { + container.removeChild(tt); + tt = null; + } + }); + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + annotations.add_annotation({ + x: 0, + y: 0, + value: "Test Custom Popup", + }); + } +); + +interactiveTest( + "annotations shift", + "Do you see a text annotation that remains at the correct locations while the axis shifts?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + annotations.add_annotation({ + x: 0, + y: 50, + value: "0,50", + }); + annotations.add_annotation({ + x: 50, + y: 60, + value: "50,60", + }); + annotations.add_annotation({ + x: -50, + y: 60, + value: "-50,60", + }); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + xstart: -64, + ydelta: 0.25, + }); + var xstart = 0; + var xstart_chng = 16; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + if (Math.abs(xstart) >= 64) { + xstart_chng = xstart_chng * -1; + } + xstart += xstart_chng; + plot.push(lyr0, ramp, { + xstart: xstart, }); - } - plot.push(lyr0, ramp); - }, 100); -}); + }, 500); + } +); -interactiveTest('x-fixed annotation rising raster', 'Do you see annotations that do not scroll with the data?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var img = new Image(); // Create new img element - img.src = 'dat/info.png'; - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "rising" - }); - annotations.add_annotation({ - x: 32, - pxl_y: 50, - value: "A", - popup: "I should be at X=32 always" - }); - annotations.add_annotation({ - x: 96, - pxl_y: 200, - value: "B", - popup: "I should be at X=96 always" - }); - var row = 0; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); +interactiveTest( + "annotation falling raster", + "Do you see annotations that scroll with the data?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var img = new Image(); // Create new img element + img.src = "dat/info.png"; + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "falling", + } + ); + var row = 0; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + row += 1; + if (row % 64 === 0) { + var y = row * 0.25; + annotations.add_annotation({ + x: 64, + y: y, + value: "64," + y, + popup: "test", + }); + } else if (row % 100 === 0) { + var y = row * 0.25; + annotations.add_annotation({ + x: 32, + y: y, + value: img, + popup: "32," + y, + }); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "annotation rising raster", + "Do you see annotations that scroll with the data?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var img = new Image(); // Create new img element + img.src = "dat/info.png"; + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "rising", + } + ); + var row = 0; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + row += 1; + if (row % 64 === 0) { + var y = row * 0.25; + annotations.add_annotation({ + x: 64, + y: y, + value: "64," + y, + popup: "test", + }); + } else if (row % 100 === 0) { + var y = row * 0.25; + annotations.add_annotation({ + x: 32, + y: y, + value: img, + popup: "32," + y, + }); + } + plot.push(lyr0, ramp); + }, 100); + } +); -interactiveTest('lots of annotations', 'Does the plot still seem smooth?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var img = new Image(); // Create new img element - img.src = 'dat/info.png'; - var annotations = new sigplot_plugins.AnnotationPlugin(); - plot.add_plugin(annotations); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "rising" - }); - for (var j = 0; j < 1000; j += 1) { - var x = Math.random() * 128; - var y = (Math.random() * (plot._Mx.b - plot._Mx.t)) + plot._Mx.t; +interactiveTest( + "x-fixed annotation rising raster", + "Do you see annotations that do not scroll with the data?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var img = new Image(); // Create new img element + img.src = "dat/info.png"; + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "rising", + } + ); + annotations.add_annotation({ + x: 32, + pxl_y: 50, + value: "A", + popup: "I should be at X=32 always", + }); annotations.add_annotation({ - x: x, - pxl_y: y, - value: j.toString(), - popup: "Test" + x: 96, + pxl_y: 200, + value: "B", + popup: "I should be at X=96 always", }); + var row = 0; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); } - var row = 0; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); +); + +interactiveTest( + "lots of annotations", + "Does the plot still seem smooth?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var img = new Image(); // Create new img element + img.src = "dat/info.png"; + var annotations = new sigplot_plugins.AnnotationPlugin(); + plot.add_plugin(annotations); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "rising", + } + ); + for (var j = 0; j < 1000; j += 1) { + var x = Math.random() * 128; + var y = Math.random() * (plot._Mx.b - plot._Mx.t) + plot._Mx.t; + annotations.add_annotation({ + x: x, + pxl_y: y, + value: j.toString(), + popup: "Test", + }); } - plot.push(lyr0, ramp); - }, 100); -}); \ No newline at end of file + var row = 0; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); diff --git a/test/tests.interactive-appearance.js b/test/tests.interactive-appearance.js index 4bc11b8..f2ff5f3 100644 --- a/test/tests.interactive-appearance.js +++ b/test/tests.interactive-appearance.js @@ -25,127 +25,166 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-appearance', { +QUnit.module("sigplot-interactive-appearance", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('sigplot no legend', 'Is the legend button hidden?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, { - no_legend_button: true - }); -}); +interactiveTest( + "sigplot no legend", + "Is the legend button hidden?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, { + no_legend_button: true, + }); + } +); -interactiveTest('sigplot no ylabel', 'Does the label say None (U)?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, { - ylabel: null - }); -}); +interactiveTest( + "sigplot no ylabel", + "Does the label say None (U)?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, { + ylabel: null, + }); + } +); -interactiveTest('sigplot no xlabel', 'Is the label say None (U)?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, { - xlabel: null - }); -}); +interactiveTest( + "sigplot no xlabel", + "Is the label say None (U)?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, { + xlabel: null, + }); + } +); -interactiveTest('sigplot no label', 'Is the label completely hidden?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, { - xlabel: null, - ylabel: null - }); -}); +interactiveTest( + "sigplot no label", + "Is the label completely hidden?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, { + xlabel: null, + ylabel: null, + }); + } +); -interactiveTest('sigplot custom font', 'Is the font changed from the default?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, { - font_family: "Comic Sans MS, cursive, sans-serif" - }); -}); +interactiveTest( + "sigplot custom font", + "Is the font changed from the default?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, { + font_family: "Comic Sans MS, cursive, sans-serif", + }); + } +); -interactiveTest('sigplot fixed font size', 'Is the font size normal?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - container.style.width = "300px"; - var plot = new sigplot.Plot(container); -}); +interactiveTest( + "sigplot fixed font size", + "Is the font size normal?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + container.style.width = "300px"; + var plot = new sigplot.Plot(container); + } +); -interactiveTest('sigplot fixed font size', 'Is the font size large?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - container.style.width = "300px"; - var plot = new sigplot.Plot(container, { - font_width: 12 - }); -}); +interactiveTest( + "sigplot fixed font size", + "Is the font size large?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + container.style.width = "300px"; + var plot = new sigplot.Plot(container, { + font_width: 12, + }); + } +); -interactiveTest('sigplot fixed font size', 'Is the font size scaled smaller?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - container.style.width = "300px"; - var plot = new sigplot.Plot(container, { - font_scaled: true - }); -}); +interactiveTest( + "sigplot fixed font size", + "Is the font size scaled smaller?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + container.style.width = "300px"; + var plot = new sigplot.Plot(container, { + font_scaled: true, + }); + } +); -interactiveTest('sigplot bottom scrollbar', 'Is the x scrollbar on the bottom?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, { - noreadout: true, - xlabel: null, - ylabel: null, - x_scrollbar_location: "bottom" - }); -}); +interactiveTest( + "sigplot bottom scrollbar", + "Is the x scrollbar on the bottom?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, { + noreadout: true, + xlabel: null, + ylabel: null, + x_scrollbar_location: "bottom", + }); + } +); -interactiveTest('sigplot readout stays visible', 'Is the readout visible when the mouse hovers?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); +interactiveTest( + "sigplot readout stays visible", + "Is the readout visible when the mouse hovers?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); - var rt_plot = new sigplot.Plot(document.getElementById('plot'), { - autohide_readout: true, // only show the readout when the mouse is over the plot - autohide_panbars: true, // only show panbars when necessary and the mouse is over the plot - no_legend_button: true, - }); + var rt_plot = new sigplot.Plot(document.getElementById("plot"), { + autohide_readout: true, // only show the readout when the mouse is over the plot + autohide_panbars: true, // only show panbars when necessary and the mouse is over the plot + no_legend_button: true, + }); - var cnt = 0; + var cnt = 0; - var lyr0 = null; - var lyr1 = null; + var lyr0 = null; + var lyr1 = null; - update_rtplot(); - var hdl = window.setInterval(update_rtplot, 500); + update_rtplot(); + var hdl = window.setInterval(update_rtplot, 500); - function update_rtplot() { - var random = []; - var random2 = []; - for (var i = 0; i <= 1000; i += 1) { - random.push(Math.random()); - random2.push(Math.random() + 1); - } + function update_rtplot() { + var random = []; + var random2 = []; + for (var i = 0; i <= 1000; i += 1) { + random.push(Math.random()); + random2.push(Math.random() + 1); + } - var data_layer = rt_plot.get_layer(lyr0); - if (data_layer) { - /* cnt += 1; + var data_layer = rt_plot.get_layer(lyr0); + if (data_layer) { + /* cnt += 1; if (cnt === 10) { console.log("changing xstart") rt_plot.get_layer(0).hcb.xstart = -100; @@ -155,101 +194,126 @@ interactiveTest('sigplot readout stays visible', 'Is the readout visible when th xmax: -100 + 1000 }) } */ - rt_plot.reload(lyr0, random); - rt_plot.reload(lyr1, random2); - } else { - rt_plot.change_settings({ - cmode: 3, - autol: 1, - }); - lyr0 = rt_plot.overlay_array(random, { - file_name: "random" - }); - lyr1 = rt_plot.overlay_array(random2, { - file_name: "random2" - }); + rt_plot.reload(lyr0, random); + rt_plot.reload(lyr1, random2); + } else { + rt_plot.change_settings({ + cmode: 3, + autol: 1, + }); + lyr0 = rt_plot.overlay_array(random, { + file_name: "random", + }); + lyr1 = rt_plot.overlay_array(random2, { + file_name: "random2", + }); + } } } -}); +); -interactiveTest('sigplot minimal chrome', 'Is the plot devoid of chrome', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, { - noreadout: true, - xlabel: null, - ylabel: null, - nopan: true, - noxaxis: true, - noyaxis: true - }); - // display a ramp so it's easy to see the plot edges - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); - } - plot.overlay_array(ramp, { - file_name: "ramp" - }); -}); +interactiveTest( + "sigplot minimal chrome", + "Is the plot devoid of chrome", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, { + noreadout: true, + xlabel: null, + ylabel: null, + nopan: true, + noxaxis: true, + noyaxis: true, + }); + // display a ramp so it's easy to see the plot edges + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + }); + } +); -interactiveTest('colorbar in legend', 'does the colorbar show in the legend?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "colorbar in legend", + "does the colorbar show in the legend?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); -}); + plot.overlay_href("dat/penny.prm"); + } +); -interactiveTest('Legend', 'Are the correct functions modified from the legend??', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - var ramp2 = []; - for (var i = 0; i < 20; i++) { - ramp.push(i); - var contra = 20 - i; - ramp2.push(contra); - } - plot.overlay_array(ramp, null, { - name: "up", - symbol: 0, - line: 3 - }); - plot.overlay_array(ramp2, null, { - name: "down", - symbol: 0, - line: 3 - }); -}); +interactiveTest( + "Legend", + "Are the correct functions modified from the legend??", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + var ramp2 = []; + for (var i = 0; i < 20; i++) { + ramp.push(i); + var contra = 20 - i; + ramp2.push(contra); + } + plot.overlay_array(ramp, null, { + name: "up", + symbol: 0, + line: 3, + }); + plot.overlay_array(ramp2, null, { + name: "down", + symbol: 0, + line: 3, + }); + } +); -interactiveTest('Plot Note', 'Do you see the plot note saying "Test Note"?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - note: 'Test Note' - }); - assert.notEqual(plot, null); -}); +interactiveTest( + "Plot Note", + 'Do you see the plot note saying "Test Note"?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + note: "Test Note", + }); + assert.notEqual(plot, null); + } +); -interactiveTest('Plot Note with data', 'Do you see the plot note saying "Test Note"?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - note: 'Test Note' - }); - assert.notEqual(plot, null); - plot.overlay_href("dat/scalarpacked.tmp", null, { - subsize: 64, - layerType: "2D" - }); -}); +interactiveTest( + "Plot Note with data", + 'Do you see the plot note saying "Test Note"?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + note: "Test Note", + }); + assert.notEqual(plot, null); + plot.overlay_href("dat/scalarpacked.tmp", null, { + subsize: 64, + layerType: "2D", + }); + } +); -interactiveTest('Plot Note Change Settings', 'Do you see the plot note saying "Test Note"?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - note: 'Test Note' - }); -}); +interactiveTest( + "Plot Note Change Settings", + 'Do you see the plot note saying "Test Note"?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + note: "Test Note", + }); + } +); diff --git a/test/tests.interactive-boxes.js b/test/tests.interactive-boxes.js index f0b0c76..7bc360d 100644 --- a/test/tests.interactive-boxes.js +++ b/test/tests.interactive-boxes.js @@ -25,13 +25,13 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-boxes', { +QUnit.module("sigplot-interactive-boxes", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('boxes', 'Do you see a boxes?', function(assert) { - var container = document.getElementById('plot'); +interactiveTest("boxes", "Do you see a boxes?", function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); var boxes = new sigplot_plugins.BoxesPlugin(); @@ -41,7 +41,7 @@ interactiveTest('boxes', 'Do you see a boxes?', function(assert) { y: 0, w: 0.1, h: 0.1, - text: "0,0" + text: "0,0", }); boxes.add_box({ x: 0.5, @@ -49,7 +49,7 @@ interactiveTest('boxes', 'Do you see a boxes?', function(assert) { w: 0.1, h: 0.1, text: "0.5,0.5", - fill: true + fill: true, }); boxes.add_box({ x: -0.5, @@ -57,7 +57,7 @@ interactiveTest('boxes', 'Do you see a boxes?', function(assert) { w: 0.1, h: 0.1, text: "-0.5,-0.5", - fillStyle: "green" + fillStyle: "green", }); boxes.add_box({ x: 0.5, @@ -66,11 +66,11 @@ interactiveTest('boxes', 'Do you see a boxes?', function(assert) { h: 0.1, text: "0.5,-0.5", fillStyle: "red", - alpha: 0.25 + alpha: 0.25, }); }); -interactiveTest('clear boxes', 'Do you see one box?', function(assert) { - var container = document.getElementById('plot'); +interactiveTest("clear boxes", "Do you see one box?", function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); var boxes = new sigplot_plugins.BoxesPlugin(); @@ -80,16 +80,16 @@ interactiveTest('clear boxes', 'Do you see one box?', function(assert) { y: 0, w: 0.1, h: 0.1, - text: "I should be gone soon..." + text: "I should be gone soon...", }); - window.setTimeout(function() { + window.setTimeout(function () { boxes.clear_boxes(); boxes.add_box({ x: 0.5, y: 0.5, w: 0.1, h: 0.1, - text: "You should see me" + text: "You should see me", }); }, 1000); }); diff --git a/test/tests.interactive-core.js b/test/tests.interactive-core.js index bc3dad6..b8e10c3 100644 --- a/test/tests.interactive-core.js +++ b/test/tests.interactive-core.js @@ -30,677 +30,831 @@ // // This module tests all the core-basic behaviors and should be kept short // so it's easier for a developer to quickly determine if they broke anything. -// If too many tests are included in the core set then developers will be +// If too many tests are included in the core set then developers will be // discouraged from running them. // ////////////////////////////////////////////////////////////////////////////// -QUnit.module('sigplot-interactive-core', { +QUnit.module("sigplot-interactive-core", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('sigplot empty', 'Do you see an empty plot scaled from -1 to 1 on both axis?', function(assert) { - var container = document.getElementById('plot'); - assert.equal(container.childNodes.length, 0); - assert.equal(ifixture.childNodes.length, 2); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - assert.equal(container.childNodes.length, 1); - assert.equal(container.childNodes[0], plot._Mx.parent); - assert.equal(plot._Mx.parent.childNodes.length, 2); - assert.equal(plot._Mx.parent.childNodes[0], plot._Mx.canvas); - assert.equal(plot._Mx.parent.childNodes[1], plot._Mx.wid_canvas); - assert.equal(plot._Mx.canvas.width, 600); - assert.equal(plot._Mx.canvas.height, 400); - assert.equal(plot._Mx.canvas.style.position, "absolute"); - assert.equal(plot._Mx.wid_canvas.width, 600); - assert.equal(plot._Mx.wid_canvas.height, 400); - assert.equal(plot._Mx.wid_canvas.style.position, "absolute"); -}); - -interactiveTest('sigplot 1d overlay', 'Do you see a ramp from 0 to 1023?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); +interactiveTest( + "sigplot empty", + "Do you see an empty plot scaled from -1 to 1 on both axis?", + function (assert) { + var container = document.getElementById("plot"); + assert.equal(container.childNodes.length, 0); + assert.equal(ifixture.childNodes.length, 2); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + assert.equal(container.childNodes.length, 1); + assert.equal(container.childNodes[0], plot._Mx.parent); + assert.equal(plot._Mx.parent.childNodes.length, 2); + assert.equal(plot._Mx.parent.childNodes[0], plot._Mx.canvas); + assert.equal(plot._Mx.parent.childNodes[1], plot._Mx.wid_canvas); + assert.equal(plot._Mx.canvas.width, 600); + assert.equal(plot._Mx.canvas.height, 400); + assert.equal(plot._Mx.canvas.style.position, "absolute"); + assert.equal(plot._Mx.wid_canvas.width, 600); + assert.equal(plot._Mx.wid_canvas.height, 400); + assert.equal(plot._Mx.wid_canvas.style.position, "absolute"); } - plot.overlay_array(ramp, { - file_name: "ramp" - }); - - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 1023); - assert.equal(plot._Gx.panymin, -20.46); - assert.equal(plot._Gx.panymax, 1043.46); - assert.equal(plot._Mx.stk[0].xmin, 0); - assert.equal(plot._Mx.stk[0].xmax, 1023); - assert.equal(plot._Mx.stk[0].ymin, -20.46); - assert.equal(plot._Mx.stk[0].ymax, 1043.46); -}); - -interactiveTest('sigplot 1d overlay (over bufmax)', 'Do you see a small portion of the line in the upper left and can you pan x/y?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < (plot._Gx.bufmax * 2); i++) { - ramp.push(i); +); + +interactiveTest( + "sigplot 1d overlay", + "Do you see a ramp from 0 to 1023?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + }); + + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 1023); + assert.equal(plot._Gx.panymin, -20.46); + assert.equal(plot._Gx.panymax, 1043.46); + assert.equal(plot._Mx.stk[0].xmin, 0); + assert.equal(plot._Mx.stk[0].xmax, 1023); + assert.equal(plot._Mx.stk[0].ymin, -20.46); + assert.equal(plot._Mx.stk[0].ymax, 1043.46); } - plot.overlay_array(ramp, { - file_name: "ramp" - }); - // if we are over bufmax, then only the first buffer is read and used for scaling the y-axis - // you have to scroll to get the full y-axis - assert.equal(plot._Gx.bufmax, 32768); - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 65535); - assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer - assert.equal(plot._Gx.panymax, 33422.34); // based off 0.02 of the first buffer - assert.equal(plot._Mx.stk[0].xmin, 0); - assert.equal(plot._Mx.stk[0].xmax, 32767); - assert.equal(plot._Mx.stk[0].ymin, -655.34); - assert.equal(plot._Mx.stk[0].ymax, 33422.34); - - plot.set_view({ - xmin: 32678, - xmax: 65535 - }); - plot._refresh(); // force a syncronous refresh to ensure that rescaling happens - assert.equal(plot._Gx.bufmax, 32768); - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 65535); - assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer - assert.equal(plot._Gx.panymax, 66099.34); - assert.equal(plot._Mx.stk[0].xmin, 32678); - assert.equal(plot._Mx.stk[0].xmax, 65535); - assert.equal(plot._Mx.stk[0].ymin, -655.34); - assert.equal(plot._Mx.stk[0].ymax, 33422.34); -}); - -interactiveTest('sigplot 1d overlay (all)', 'Is the x-axis 0-65535 while the y-axis approximately 33400 and can you pan the y-axis up?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - all: true - }); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < (plot._Gx.bufmax * 2); i++) { - ramp.push(i); +); + +interactiveTest( + "sigplot 1d overlay (over bufmax)", + "Do you see a small portion of the line in the upper left and can you pan x/y?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < plot._Gx.bufmax * 2; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + }); + // if we are over bufmax, then only the first buffer is read and used for scaling the y-axis + // you have to scroll to get the full y-axis + assert.equal(plot._Gx.bufmax, 32768); + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 65535); + assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer + assert.equal(plot._Gx.panymax, 33422.34); // based off 0.02 of the first buffer + assert.equal(plot._Mx.stk[0].xmin, 0); + assert.equal(plot._Mx.stk[0].xmax, 32767); + assert.equal(plot._Mx.stk[0].ymin, -655.34); + assert.equal(plot._Mx.stk[0].ymax, 33422.34); + + plot.set_view({ + xmin: 32678, + xmax: 65535, + }); + plot._refresh(); // force a syncronous refresh to ensure that rescaling happens + assert.equal(plot._Gx.bufmax, 32768); + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 65535); + assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer + assert.equal(plot._Gx.panymax, 66099.34); + assert.equal(plot._Mx.stk[0].xmin, 32678); + assert.equal(plot._Mx.stk[0].xmax, 65535); + assert.equal(plot._Mx.stk[0].ymin, -655.34); + assert.equal(plot._Mx.stk[0].ymax, 33422.34); } - plot.overlay_array(ramp, { - file_name: "ramp" - }); - //plot._refresh(); - assert.equal(plot._Gx.bufmax, 32768); - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 65535); - assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer - assert.equal(plot._Gx.panymax, 33422.34); // TODO : might be wrong 65534+0.02*32767 - assert.equal(plot._Mx.stk[0].xmin, 0); - assert.equal(plot._Mx.stk[0].xmax, 65535); - assert.equal(plot._Mx.stk[0].ymin, -655.34); - assert.equal(plot._Mx.stk[0].ymax, 33422.34); -}); - - -interactiveTest('sigplot 1d overlay (expand)', 'Do you see a ramp from 0 to 65535?', function(assert) { - // Using all and expand means that the entire range of data - // will be read (i.e. the x-axis will be all the data) and the - // y-axis will be the full-scale - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - all: true, - expand: true - }); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < (plot._Gx.bufmax * 2); i++) { - ramp.push(i); +); + +interactiveTest( + "sigplot 1d overlay (all)", + "Is the x-axis 0-65535 while the y-axis approximately 33400 and can you pan the y-axis up?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + all: true, + }); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < plot._Gx.bufmax * 2; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + }); + //plot._refresh(); + assert.equal(plot._Gx.bufmax, 32768); + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 65535); + assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer + assert.equal(plot._Gx.panymax, 33422.34); // TODO : might be wrong 65534+0.02*32767 + assert.equal(plot._Mx.stk[0].xmin, 0); + assert.equal(plot._Mx.stk[0].xmax, 65535); + assert.equal(plot._Mx.stk[0].ymin, -655.34); + assert.equal(plot._Mx.stk[0].ymax, 33422.34); } - plot.overlay_array(ramp, { - file_name: "ramp" - }); - assert.equal(plot._Gx.bufmax, 32768); - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 65535); - assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer - assert.equal(plot._Gx.panymax, 66189.34); // TODO : might be wrong 65534+0.02*32767 - assert.equal(plot._Mx.stk[0].xmin, 0); - assert.equal(plot._Mx.stk[0].xmax, 65535); - assert.equal(plot._Mx.stk[0].ymin, -655.34); - assert.equal(plot._Mx.stk[0].ymax, 66189.34); -}); - -interactiveTest('sigplot 1d reload', 'Do you see a ramp from 0 to 1023?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var lyr_n = plot.overlay_array([], {}, { - layerType: sigplot.Layer1D - }); - - assert.equal(plot._Gx.panxmin, -1); - assert.equal(plot._Gx.panxmax, 1); - assert.equal(plot._Gx.panymin, 0); - assert.equal(plot._Gx.panymax, 0); - - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); +); + +interactiveTest( + "sigplot 1d overlay (expand)", + "Do you see a ramp from 0 to 65535?", + function (assert) { + // Using all and expand means that the entire range of data + // will be read (i.e. the x-axis will be all the data) and the + // y-axis will be the full-scale + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + all: true, + expand: true, + }); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < plot._Gx.bufmax * 2; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + }); + assert.equal(plot._Gx.bufmax, 32768); + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 65535); + assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer + assert.equal(plot._Gx.panymax, 66189.34); // TODO : might be wrong 65534+0.02*32767 + assert.equal(plot._Mx.stk[0].xmin, 0); + assert.equal(plot._Mx.stk[0].xmax, 65535); + assert.equal(plot._Mx.stk[0].ymin, -655.34); + assert.equal(plot._Mx.stk[0].ymax, 66189.34); } +); + +interactiveTest( + "sigplot 1d reload", + "Do you see a ramp from 0 to 1023?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var lyr_n = plot.overlay_array( + [], + {}, + { + layerType: sigplot.Layer1D, + } + ); + + assert.equal(plot._Gx.panxmin, -1); + assert.equal(plot._Gx.panxmax, 1); + assert.equal(plot._Gx.panymin, 0); + assert.equal(plot._Gx.panymax, 0); - plot.reload(lyr_n, ramp, { - file_name: "ramp" - }); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 1023); - assert.equal(plot._Gx.panymin, -20.46); - assert.equal(plot._Gx.panymax, 1043.46); + plot.reload(lyr_n, ramp, { + file_name: "ramp", + }); - plot.reload(lyr_n, ramp, { - file_name: "ramp2", - xstart: 10000 - }); + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 1023); + assert.equal(plot._Gx.panymin, -20.46); + assert.equal(plot._Gx.panymax, 1043.46); - assert.equal(plot._Gx.panxmin, 10000); - assert.equal(plot._Gx.panxmax, 11023); - assert.equal(plot._Gx.panymin, -20.46); - assert.equal(plot._Gx.panymax, 1043.46); -}); + plot.reload(lyr_n, ramp, { + file_name: "ramp2", + xstart: 10000, + }); -interactiveTest('sigplot file overlay', 'Do you see a sin wave?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); + assert.equal(plot._Gx.panxmin, 10000); + assert.equal(plot._Gx.panxmax, 11023); + assert.equal(plot._Gx.panymin, -20.46); + assert.equal(plot._Gx.panymax, 1043.46); } - plot.overlay_href("dat/sin.tmp", null, { - name: "x" - }); -}); - -interactiveTest('scrolling line', 'Do you see a scrolling random data plot (0 to 1 ) that does not scale', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - ymin: -2, - ymax: 2 - }); - var lyr0 = plot.overlay_pipe({ - type: 1000 - }, { - framesize: 32768, - drawmode: "scrolling" - }); - ifixture.interval = window.setInterval(function() { - var random = []; - for (var i = 0; i < 100; i += 1) { - random.push(Math.random()); +); + +interactiveTest( + "sigplot file overlay", + "Do you see a sin wave?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); } - plot.push(lyr0, random); - }, 100); -}); + plot.overlay_href("dat/sin.tmp", null, { + name: "x", + }); + } +); + +interactiveTest( + "scrolling line", + "Do you see a scrolling random data plot (0 to 1 ) that does not scale", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + ymin: -2, + ymax: 2, + }); + var lyr0 = plot.overlay_pipe( + { + type: 1000, + }, + { + framesize: 32768, + drawmode: "scrolling", + } + ); + ifixture.interval = window.setInterval(function () { + var random = []; + for (var i = 0; i < 100; i += 1) { + random.push(Math.random()); + } + plot.push(lyr0, random); + }, 100); + } +); /** * Test that auto-scaling works correctly using reload. */ -interactiveTest('autoy (reload)', 'Does the autoscaling properly work and keep both magenta and blue lines fully visible?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autoy: 3 - }); - assert.notEqual(plot, null); - var random = []; - var zeros = []; - for (var i = 0; i <= 1000; i += 1) { - random.push(Math.random()); - zeros.push(0); - } - var zeros_lyr = plot.overlay_array(zeros); - var rand1_lyr = plot.overlay_array(zeros); - var rand2_lyr = plot.overlay_array(zeros); - var iter = 1; - ifixture.interval = window.setInterval(function() { - plot.reload(zeros_lyr, zeros, {}); - for (var i = 0; i <= 1000; i += 1) { - random[i] = iter * Math.random(); - } - plot.reload(rand1_lyr, random, {}); +interactiveTest( + "autoy (reload)", + "Does the autoscaling properly work and keep both magenta and blue lines fully visible?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autoy: 3, + }); + assert.notEqual(plot, null); + var random = []; + var zeros = []; for (var i = 0; i <= 1000; i += 1) { - random[i] = -1 * iter * Math.random(); + random.push(Math.random()); + zeros.push(0); } - plot.reload(rand2_lyr, random, {}); - iter += 1; - }, 500); -}); + var zeros_lyr = plot.overlay_array(zeros); + var rand1_lyr = plot.overlay_array(zeros); + var rand2_lyr = plot.overlay_array(zeros); + var iter = 1; + ifixture.interval = window.setInterval(function () { + plot.reload(zeros_lyr, zeros, {}); + for (var i = 0; i <= 1000; i += 1) { + random[i] = iter * Math.random(); + } + plot.reload(rand1_lyr, random, {}); + for (var i = 0; i <= 1000; i += 1) { + random[i] = -1 * iter * Math.random(); + } + plot.reload(rand2_lyr, random, {}); + iter += 1; + }, 500); + } +); /** * Test that auto-scaling works correctly using push. */ -interactiveTest('autoy fast (pipe)', 'Does the autoscaling properly work and keep both magenta and blue lines fully visible?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autol: 2, - autoy: 3 - }); - assert.notEqual(plot, null); - var random = []; - var zeros = []; - for (var i = 0; i < 1000; i += 1) { - random.push(Math.random()); - zeros.push(0); - } - var zeros_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var rand1_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var rand2_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var iter = 1; - ifixture.interval = window.setInterval(function() { - plot.push(zeros_lyr, zeros); - for (var i = 0; i < 1000; i += 1) { - random[i] = iter * Math.random(); - } - plot.push(rand1_lyr, random); +interactiveTest( + "autoy fast (pipe)", + "Does the autoscaling properly work and keep both magenta and blue lines fully visible?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autol: 2, + autoy: 3, + }); + assert.notEqual(plot, null); + var random = []; + var zeros = []; for (var i = 0; i < 1000; i += 1) { - random[i] = -1 * iter * Math.random(); + random.push(Math.random()); + zeros.push(0); } - plot.push(rand2_lyr, random); - iter += 1; - }, 500); -}); + var zeros_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var rand1_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var rand2_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var iter = 1; + ifixture.interval = window.setInterval(function () { + plot.push(zeros_lyr, zeros); + for (var i = 0; i < 1000; i += 1) { + random[i] = iter * Math.random(); + } + plot.push(rand1_lyr, random); + for (var i = 0; i < 1000; i += 1) { + random[i] = -1 * iter * Math.random(); + } + plot.push(rand2_lyr, random); + iter += 1; + }, 500); + } +); /** * Test that auto-scaling works correctly using push. */ -interactiveTest('autoy slow (pipe)', 'Does the autoscaling properly work and keep both magenta and blue lines fully visible?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autol: 100, - autoy: 3 - }); - assert.notEqual(plot, null); - var random = []; - var zeros = []; - for (var i = 0; i < 1000; i += 1) { - random.push(Math.random()); - zeros.push(0); - } - var zeros_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var rand1_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var rand2_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var iter = 1; - ifixture.interval = window.setInterval(function() { - plot.push(zeros_lyr, zeros); - for (var i = 0; i < 1000; i += 1) { - random[i] = iter * Math.random(); - } - plot.push(rand1_lyr, random); +interactiveTest( + "autoy slow (pipe)", + "Does the autoscaling properly work and keep both magenta and blue lines fully visible?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autol: 100, + autoy: 3, + }); + assert.notEqual(plot, null); + var random = []; + var zeros = []; for (var i = 0; i < 1000; i += 1) { - random[i] = -1 * iter * Math.random(); + random.push(Math.random()); + zeros.push(0); } - plot.push(rand2_lyr, random); - iter += 1; - }, 500); -}); + var zeros_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var rand1_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var rand2_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var iter = 1; + ifixture.interval = window.setInterval(function () { + plot.push(zeros_lyr, zeros); + for (var i = 0; i < 1000; i += 1) { + random[i] = iter * Math.random(); + } + plot.push(rand1_lyr, random); + for (var i = 0; i < 1000; i += 1) { + random[i] = -1 * iter * Math.random(); + } + plot.push(rand2_lyr, random); + iter += 1; + }, 500); + } +); /** * Test that auto-scaling works correctly using push. */ -interactiveTest('autoy off (pipe)', 'Is the plot pan and view not auto-scaling?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autol: 0, - autoy: 3 - }); - assert.notEqual(plot, null); - var random = []; - var zeros = []; - for (var i = 0; i < 1000; i += 1) { - random.push(Math.random()); - zeros.push(0); - } - var zeros_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var rand1_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var rand2_lyr = plot.overlay_pipe({}, { - framesize: 1000 - }); - var iter = 1; - ifixture.interval = window.setInterval(function() { - plot.push(zeros_lyr, zeros); - for (var i = 0; i < 1000; i += 1) { - random[i] = iter * Math.random(); - } - plot.push(rand1_lyr, random); +interactiveTest( + "autoy off (pipe)", + "Is the plot pan and view not auto-scaling?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autol: 0, + autoy: 3, + }); + assert.notEqual(plot, null); + var random = []; + var zeros = []; for (var i = 0; i < 1000; i += 1) { - random[i] = -1 * iter * Math.random(); + random.push(Math.random()); + zeros.push(0); } - plot.push(rand2_lyr, random); - iter += 1; - }, 500); -}); - -interactiveTest('sigplot symbol', 'Do you see 5 triangle symbols on a line?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 5; i++) { - ramp.push(i); - } - plot.overlay_array(ramp, null, { - name: "x", - symbol: 6, - }); -}); - -interactiveTest('sigplot symbol', 'Do you see 5 triangle symbols?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 5; i++) { - ramp.push(i); + var zeros_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var rand1_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var rand2_lyr = plot.overlay_pipe( + {}, + { + framesize: 1000, + } + ); + var iter = 1; + ifixture.interval = window.setInterval(function () { + plot.push(zeros_lyr, zeros); + for (var i = 0; i < 1000; i += 1) { + random[i] = iter * Math.random(); + } + plot.push(rand1_lyr, random); + for (var i = 0; i < 1000; i += 1) { + random[i] = -1 * iter * Math.random(); + } + plot.push(rand2_lyr, random); + iter += 1; + }, 500); } - plot.overlay_array(ramp, null, { - name: "x", - symbol: 6, - line: 0 - }); -}); - -interactiveTest('complex dots', 'Do you see dots constrained to a box?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - cmode: 5 - }); - var framesize = 1024; - var lyr0 = plot.overlay_pipe({ - file_name: "constellation", - format: "CF" - }, { - framesize: framesize, - line: 0, - radius: 1, - symbol: 1 - }); - plot.change_settings({ - cmode: 5, - ymin: -2, - ymax: 2, - xmin: -2, - xmax: 2 - }); - ifixture.interval = window.setInterval(function() { - var data = []; - for (var i = 0; i < framesize; i += 1) { - data.push((Math.random() * 2) - 1); - data.push((Math.random() * 2) - 1); +); + +interactiveTest( + "sigplot symbol", + "Do you see 5 triangle symbols on a line?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 5; i++) { + ramp.push(i); } - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('rescale', 'Do you see a plot that scales -2 to 2?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var data1 = []; - for (var i = 0; i < 1024; i++) { - data1.push(i % 2); + plot.overlay_array(ramp, null, { + name: "x", + symbol: 6, + }); } - plot.overlay_array(data1, { - file_name: "data1" - }); - var data2 = []; - for (var i = 0; i < 2048; i++) { - if (i % 2) { - data2.push(2); - } else { - data2.push(-2); +); + +interactiveTest( + "sigplot symbol", + "Do you see 5 triangle symbols?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 5; i++) { + ramp.push(i); } + plot.overlay_array(ramp, null, { + name: "x", + symbol: 6, + line: 0, + }); } - plot.overlay_array(data2, { - file_name: "data2" - }); - plot.rescale(); -}); - -interactiveTest('rescaling after remove', 'do you seen a line in the upper left?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - - plot.remove_layer(0); - plot.overlay_array([1, 2, 3, 4, 5, 6]); - plot.change_settings({ - xmin: 1, - xmax: 6 - }); - - plot.remove_layer(0); - plot.overlay_array([3, 4, 5, 6, 7]); - plot.change_settings({ - xmin: 3, - xmax: 7 - }); -}); - -interactiveTest('sigplot 2d overlay', 'Do you see a raster? Is alignment of x/y axes correct?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var data = [ - [1, 2, 3, 4, 5], - [6, 7, 8, 9, 0], - [1, 2, 3, 4, 5], - [6, 7, 8, 9, 0] - ]; - plot.overlay_array(data); -}); - -interactiveTest('sigplot 2d reload', 'Do you see a raster? Is alignment of x/y axes correct?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var lyr_n = plot.overlay_array([], {}, { - layerType: sigplot.Layer2D - }); - var data = [ - [1, 2, 3, 4, 5], - [6, 7, 8, 9, 0], - [1, 2, 3, 4, 5], - [6, 7, 8, 9, 0] - ]; - plot.reload(lyr_n, data); -}); - -interactiveTest('sigplot 2d overlay ArrayBuffer', 'Do you see a raster? Is alignment of x/y axes correct?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var data = []; - - var data = [ - new Float32Array([1, 2, 3, 4, 5]), - new Float32Array([6, 7, 8, 9, 0]), - new Float32Array([1, 2, 3, 4, 5]), - new Float32Array([6, 7, 8, 9, 0]) - ]; - plot.overlay_array(data); -}); - -interactiveTest('sigplot penny', 'Do you see a raster of a penny', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); -}); - -// By default, rasters have their autolevel set by the -// first 16 raster-lines. -interactiveTest('t2000 file (default autol)', 'Is the plot red below the ~16th line?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - - var framesize = 128; - var height = 120; - - var raster = []; - for (var j = 0; j < height; j += 1) { - for (var i = 0; i < framesize; i += 1) { - raster.push(j); - } +); + +interactiveTest( + "complex dots", + "Do you see dots constrained to a box?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + cmode: 5, + }); + var framesize = 1024; + var lyr0 = plot.overlay_pipe( + { + file_name: "constellation", + format: "CF", + }, + { + framesize: framesize, + line: 0, + radius: 1, + symbol: 1, + } + ); + plot.change_settings({ + cmode: 5, + ymin: -2, + ymax: 2, + xmin: -2, + xmax: 2, + }); + ifixture.interval = window.setInterval(function () { + var data = []; + for (var i = 0; i < framesize; i += 1) { + data.push(Math.random() * 2 - 1); + data.push(Math.random() * 2 - 1); + } + plot.push(lyr0, data); + }, 100); } - - plot.overlay_array(raster, { - type: 2000, - subsize: framesize, - file_name: "raster" - }); -}); - -interactiveTest('scrolling raster', 'Do you see a scrolling raster?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(-1 * (i + 1)); +); + +interactiveTest( + "rescale", + "Do you see a plot that scales -2 to 2?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var data1 = []; + for (var i = 0; i < 1024; i++) { + data1.push(i % 2); } - plot.push(lyr0, ramp); - }, 100); -}); - -interactiveTest('falling raster', 'Do you see a falling raster?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "falling" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); + plot.overlay_array(data1, { + file_name: "data1", + }); + var data2 = []; + for (var i = 0; i < 2048; i++) { + if (i % 2) { + data2.push(2); + } else { + data2.push(-2); + } } - plot.push(lyr0, ramp); - }, 100); -}); + plot.overlay_array(data2, { + file_name: "data2", + }); + plot.rescale(); + } +); + +interactiveTest( + "rescaling after remove", + "do you seen a line in the upper left?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + + plot.remove_layer(0); + plot.overlay_array([1, 2, 3, 4, 5, 6]); + plot.change_settings({ + xmin: 1, + xmax: 6, + }); + + plot.remove_layer(0); + plot.overlay_array([3, 4, 5, 6, 7]); + plot.change_settings({ + xmin: 3, + xmax: 7, + }); + } +); + +interactiveTest( + "sigplot 2d overlay", + "Do you see a raster? Is alignment of x/y axes correct?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var data = [ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 0], + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 0], + ]; + plot.overlay_array(data); + } +); + +interactiveTest( + "sigplot 2d reload", + "Do you see a raster? Is alignment of x/y axes correct?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var lyr_n = plot.overlay_array( + [], + {}, + { + layerType: sigplot.Layer2D, + } + ); + var data = [ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 0], + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 0], + ]; + plot.reload(lyr_n, data); + } +); + +interactiveTest( + "sigplot 2d overlay ArrayBuffer", + "Do you see a raster? Is alignment of x/y axes correct?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var data = []; -interactiveTest('rising raster', 'Do you see a rising raster?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "rising" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); + var data = [ + new Float32Array([1, 2, 3, 4, 5]), + new Float32Array([6, 7, 8, 9, 0]), + new Float32Array([1, 2, 3, 4, 5]), + new Float32Array([6, 7, 8, 9, 0]), + ]; + plot.overlay_array(data); + } +); + +interactiveTest( + "sigplot penny", + "Do you see a raster of a penny", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href("dat/penny.prm"); + } +); -interactiveTest('large framesize falling raster', 'Do you see a falling raster?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5, - all: true - }); - var framesize = 128000; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i); +// By default, rasters have their autolevel set by the +// first 16 raster-lines. +interactiveTest( + "t2000 file (default autol)", + "Is the plot red below the ~16th line?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + + var framesize = 128; + var height = 120; + + var raster = []; + for (var j = 0; j < height; j += 1) { + for (var i = 0; i < framesize; i += 1) { + raster.push(j); + } } - plot.push(lyr0, ramp); - }, 100); -}); -interactiveTest('complex data falling raster', 'Do you see a falling raster?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - format: "CF", - ydelta: 0.25 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - ramp.push(-1 * (i + 1)); - } - plot.push(lyr0, ramp); - }, 100); -}); + plot.overlay_array(raster, { + type: 2000, + subsize: framesize, + file_name: "raster", + }); + } +); + +interactiveTest( + "scrolling raster", + "Do you see a scrolling raster?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(-1 * (i + 1)); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "falling raster", + "Do you see a falling raster?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "falling", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "rising raster", + "Do you see a rising raster?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "rising", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "large framesize falling raster", + "Do you see a falling raster?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + all: true, + }); + var framesize = 128000; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "complex data falling raster", + "Do you see a falling raster?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + format: "CF", + ydelta: 0.25, + }); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + ramp.push(-1 * (i + 1)); + } + plot.push(lyr0, ramp); + }, 100); + } +); diff --git a/test/tests.interactive-cuts.js b/test/tests.interactive-cuts.js index 9a0390a..05fabd0 100644 --- a/test/tests.interactive-cuts.js +++ b/test/tests.interactive-cuts.js @@ -25,287 +25,388 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-cuts', { +QUnit.module("sigplot-interactive-cuts", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('p-cuts: side and bottom plots', 'Do you see updating data when the mouse is moved in the x and y plots', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "p-cuts: side and bottom plots", + "Do you see updating data when the mouse is moved in the x and y plots", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); - plot.change_settings({ - p_cuts: true - }); -}); + plot.overlay_href("dat/penny.prm"); + plot.change_settings({ + p_cuts: true, + }); + } +); -interactiveTest('p-cuts: side and bottom plots turn on and off', 'Do the plots toggle on "p" key regardless of mouse postion?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "p-cuts: side and bottom plots turn on and off", + 'Do the plots toggle on "p" key regardless of mouse postion?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); - plot.change_settings({ - p_cuts: true - }); -}); + plot.overlay_href("dat/penny.prm"); + plot.change_settings({ + p_cuts: true, + }); + } +); -interactiveTest('p-cuts: x-cut', 'Does the x-plot show on "x" key regardless of mouse position and update when clicked open in different spot?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "p-cuts: x-cut", + 'Does the x-plot show on "x" key regardless of mouse position and update when clicked open in different spot?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); - plot.change_settings({ - p_cuts: true - }); -}); + plot.overlay_href("dat/penny.prm"); + plot.change_settings({ + p_cuts: true, + }); + } +); -interactiveTest('p-cuts: y-cut', 'Does the y-plot show on "y" key regardless of mouse position and update when clicked open in different spot?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "p-cuts: y-cut", + 'Does the y-plot show on "y" key regardless of mouse position and update when clicked open in different spot?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); - plot.change_settings({ - p_cuts: true - }); -}); + plot.overlay_href("dat/penny.prm"); + plot.change_settings({ + p_cuts: true, + }); + } +); -interactiveTest('p-cuts: turn on and off', 'Does the feature toggle with "p" key? Does everything resize correctly?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "p-cuts: turn on and off", + 'Does the feature toggle with "p" key? Does everything resize correctly?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); -}); + plot.overlay_href("dat/penny.prm"); + } +); -interactiveTest('p-cuts: x-cut and y-cut without p-cuts display', 'Do the x and y plot display when clicked without the smaller plots?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "p-cuts: x-cut and y-cut without p-cuts display", + "Do the x and y plot display when clicked without the smaller plots?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); - //console.log(plot._Gx); -}); + plot.overlay_href("dat/penny.prm"); + //console.log(plot._Gx); + } +); -interactiveTest('falling raster with p-cuts', 'Do you see a falling raster with p-cut functionality?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5, - enabled_streaming_pcut: true - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "falling" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); +interactiveTest( + "falling raster with p-cuts", + "Do you see a falling raster with p-cut functionality?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + enabled_streaming_pcut: true, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "falling", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); -interactiveTest('rising raster with p-cuts', 'Do you see a rising raster with p-cut functionality?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5, - enabled_streaming_pcut: true - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "rising" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); +interactiveTest( + "rising raster with p-cuts", + "Do you see a rising raster with p-cut functionality?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + enabled_streaming_pcut: true, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "rising", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); -interactiveTest('scrolling raster with p-cuts', 'Do you see a scrolling raster with p-cut functionality?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5, - enabled_streaming_pcut: true - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }, { - drawmode: "scrolling" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); +interactiveTest( + "scrolling raster with p-cuts", + "Do you see a scrolling raster with p-cut functionality?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + enabled_streaming_pcut: true, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }, + { + drawmode: "scrolling", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); -interactiveTest('Plot x-cut', 'Does x-cut render correctly with a valid y-axis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/raster.tmp", function() { - var lyr = plot.get_layer(0); - lyr.xCut(100); - }, {}); -}); +interactiveTest( + "Plot x-cut", + "Does x-cut render correctly with a valid y-axis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href( + "dat/raster.tmp", + function () { + var lyr = plot.get_layer(0); + lyr.xCut(100); + }, + {} + ); + } +); -interactiveTest('Plot x-cut zoom', 'Does x-cut render with a zoomed x-axis?', function(assert) { - // TODO this test doesn't work - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/raster.tmp", function() { - plot.zoom({ - x: 65e6, - y: 50 - }, { - x: 70e6, - y: 110 - }); - var lyr = plot.get_layer(0); - lyr.xCut(100); - }, {}); -}); +interactiveTest( + "Plot x-cut zoom", + "Does x-cut render with a zoomed x-axis?", + function (assert) { + // TODO this test doesn't work + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href( + "dat/raster.tmp", + function () { + plot.zoom( + { + x: 65e6, + y: 50, + }, + { + x: 70e6, + y: 110, + } + ); + var lyr = plot.get_layer(0); + lyr.xCut(100); + }, + {} + ); + } +); -interactiveTest('Plot x-cut zoom 2', 'Does x-cut render a line at 30?', function(assert) { - var container = document.getElementById('plot'); - var plot_options = { - autohide_panbars: true, - hide_note: true - }; - var x_data = []; // test data for x-cut test - var data_header = { - type: 2000, - subsize: 100, - xstart: 0.0, // the start of the x-axis - xdelta: 0.5, // the x-axis step between each data point - ystart: 0.0, - ydelta: 0.5 - }; - var layer_options = { - name: "Sample Data" - }; - // Test x-cut with vertical ramp - for (var y = 0; y < 100; y++) { - for (var x = 0; x < data_header.subsize; x++) { - x_data.push(y); +interactiveTest( + "Plot x-cut zoom 2", + "Does x-cut render a line at 30?", + function (assert) { + var container = document.getElementById("plot"); + var plot_options = { + autohide_panbars: true, + hide_note: true, + }; + var x_data = []; // test data for x-cut test + var data_header = { + type: 2000, + subsize: 100, + xstart: 0.0, // the start of the x-axis + xdelta: 0.5, // the x-axis step between each data point + ystart: 0.0, + ydelta: 0.5, + }; + var layer_options = { + name: "Sample Data", + }; + // Test x-cut with vertical ramp + for (var y = 0; y < 100; y++) { + for (var x = 0; x < data_header.subsize; x++) { + x_data.push(y); + } } + var x_plot = new sigplot.Plot(container, plot_options); + assert.notEqual(x_plot, null); + x_plot.overlay_array(x_data, data_header, layer_options); + x_plot.zoom( + { + x: 10, + y: 10, + }, + { + x: 20, + y: 20, + } + ); + var lyr = x_plot.get_layer(0); + lyr.xCut(15); } - var x_plot = new sigplot.Plot(container, plot_options); - assert.notEqual(x_plot, null); - x_plot.overlay_array(x_data, data_header, layer_options); - x_plot.zoom({ - x: 10, - y: 10 - }, { - x: 20, - y: 20 - }); - var lyr = x_plot.get_layer(0); - lyr.xCut(15); -}); +); -interactiveTest('Plot x-cut issue #25', 'Does p-cut render correctly?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - plot.change_settings({ - p_cuts: true - }); - assert.notEqual(plot, null); - plot.overlay_href("dat/raster.tmp", null, {}); -}); +interactiveTest( + "Plot x-cut issue #25", + "Does p-cut render correctly?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + plot.change_settings({ + p_cuts: true, + }); + assert.notEqual(plot, null); + plot.overlay_href("dat/raster.tmp", null, {}); + } +); -interactiveTest('Plot y-cut', 'Does y-cut render correctly?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/raster.tmp", function() { - var lyr = plot.get_layer(0); - lyr.yCut(70000000); - }, {}); -}); +interactiveTest( + "Plot y-cut", + "Does y-cut render correctly?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href( + "dat/raster.tmp", + function () { + var lyr = plot.get_layer(0); + lyr.yCut(70000000); + }, + {} + ); + } +); -interactiveTest('Plot y-cut zoom', 'Does y-cut render correctly with a valid axis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/raster.tmp", function() { - plot.zoom({ - x: 600e6, - y: 80 - }, { - x: 650e6, - y: 110 - }); - var lyr = plot.get_layer(0); - lyr.yCut(625000000); - }, {}); -}); +interactiveTest( + "Plot y-cut zoom", + "Does y-cut render correctly with a valid axis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href( + "dat/raster.tmp", + function () { + plot.zoom( + { + x: 600e6, + y: 80, + }, + { + x: 650e6, + y: 110, + } + ); + var lyr = plot.get_layer(0); + lyr.yCut(625000000); + }, + {} + ); + } +); -interactiveTest('Plot y-cut zoom 2', 'Does y-cut render a line at 30?', function(assert) { - var container = document.getElementById('plot'); - var plot_options = { - autohide_panbars: true, - hide_note: true - }; - var y_data = []; // test data for x-cut test - var data_header = { - type: 2000, - subsize: 100, - xstart: 0.0, // the start of the x-axis - xdelta: 0.5, // the x-axis step between each data point - ystart: 0.0, - ydelta: 0.5 - }; - var layer_options = { - name: "Sample Data" - }; - // Test x-cut with vertical ramp - for (var y = 0; y < 100; y++) { - for (var x = 0; x < data_header.subsize; x++) { - y_data.push(x); +interactiveTest( + "Plot y-cut zoom 2", + "Does y-cut render a line at 30?", + function (assert) { + var container = document.getElementById("plot"); + var plot_options = { + autohide_panbars: true, + hide_note: true, + }; + var y_data = []; // test data for x-cut test + var data_header = { + type: 2000, + subsize: 100, + xstart: 0.0, // the start of the x-axis + xdelta: 0.5, // the x-axis step between each data point + ystart: 0.0, + ydelta: 0.5, + }; + var layer_options = { + name: "Sample Data", + }; + // Test x-cut with vertical ramp + for (var y = 0; y < 100; y++) { + for (var x = 0; x < data_header.subsize; x++) { + y_data.push(x); + } } + var y_plot = new sigplot.Plot(container, plot_options); + assert.notEqual(y_plot, null); + y_plot.overlay_array(y_data, data_header, layer_options); + y_plot.zoom( + { + x: 10, + y: 10, + }, + { + x: 20, + y: 20, + } + ); + var lyr = y_plot.get_layer(0); + lyr.yCut(15); } - var y_plot = new sigplot.Plot(container, plot_options); - assert.notEqual(y_plot, null); - y_plot.overlay_array(y_data, data_header, layer_options); - y_plot.zoom({ - x: 10, - y: 10 - }, { - x: 20, - y: 20 - }); - var lyr = y_plot.get_layer(0); - lyr.yCut(15); -}); +); diff --git a/test/tests.interactive-layer1d.js b/test/tests.interactive-layer1d.js index c42a0ab..995e791 100644 --- a/test/tests.interactive-layer1d.js +++ b/test/tests.interactive-layer1d.js @@ -25,830 +25,1019 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-layer1d', { +QUnit.module("sigplot-interactive-layer1d", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('sigplot 1d deoverlay', 'Do you see a ramp from 0 to 1023?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var lyr_n = plot.overlay_array([], {}, { - layerType: sigplot.Layer1D - }); - - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); - } +interactiveTest( + "sigplot 1d deoverlay", + "Do you see a ramp from 0 to 1023?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var lyr_n = plot.overlay_array( + [], + {}, + { + layerType: sigplot.Layer1D, + } + ); - plot.deoverlay(lyr_n); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } - lyr_n = plot.overlay_array(ramp, { - file_name: "ramp" - }); -}); + plot.deoverlay(lyr_n); -interactiveTest('sigplot multi-file overlay', 'Do you see a sin wave and a pulse train?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/sin.tmp|dat/pulse_cx.tmp"); -}); + lyr_n = plot.overlay_array(ramp, { + file_name: "ramp", + }); + } +); -interactiveTest('empty t1000 array', 'Do you see a plot with two pulses?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var lyr0 = plot.overlay_array([], { - file_name: "data1" - }); - var lyr1 = plot.overlay_array(null, { - file_name: "data2" - }); - var pulse1 = []; - var pulse2 = []; - for (var i = 0; i < 1000; i++) { - if ((i < 490) || (i > 510)) { - pulse1.push(0); - } else { - pulse1.push(10.0); - } - if ((i < 240) || (i > 260)) { - pulse2.push(0); - } else { - pulse2.push(10.0); - } +interactiveTest( + "sigplot multi-file overlay", + "Do you see a sin wave and a pulse train?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href("dat/sin.tmp|dat/pulse_cx.tmp"); } - plot.reload(lyr0, pulse1); - plot.reload(lyr1, pulse2); -}); +); -interactiveTest('empty t2000 array', 'Do you see a plot with two pulses?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var lyr0 = plot.overlay_array([], { - type: 2000, - subsize: 1000, - file_name: "data1" - }, { - layerType: sigplot.Layer1D - }); - var lyr1 = plot.overlay_array([], { - type: 2000, - subsize: 1000, - file_name: "data2" - }, { - layerType: sigplot.Layer1D - }); - var pulse1 = []; - var pulse2 = []; - for (var i = 0; i < 1000; i++) { - if ((i < 490) || (i > 510)) { - pulse1.push(0); - } else { - pulse1.push(10.0); - } - if ((i < 240) || (i > 260)) { - pulse2.push(0); - } else { - pulse2.push(10.0); +interactiveTest( + "empty t1000 array", + "Do you see a plot with two pulses?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var lyr0 = plot.overlay_array([], { + file_name: "data1", + }); + var lyr1 = plot.overlay_array(null, { + file_name: "data2", + }); + var pulse1 = []; + var pulse2 = []; + for (var i = 0; i < 1000; i++) { + if (i < 490 || i > 510) { + pulse1.push(0); + } else { + pulse1.push(10.0); + } + if (i < 240 || i > 260) { + pulse2.push(0); + } else { + pulse2.push(10.0); + } } + plot.reload(lyr0, pulse1); + plot.reload(lyr1, pulse2); } - plot.reload(lyr0, pulse1); - plot.reload(lyr1, pulse2); -}); +); -interactiveTest('sigplot custom xmult', 'Do you see the x-axis in "hecto-" units (0-40)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xmult: 100 - }); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); +interactiveTest( + "empty t2000 array", + "Do you see a plot with two pulses?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var lyr0 = plot.overlay_array( + [], + { + type: 2000, + subsize: 1000, + file_name: "data1", + }, + { + layerType: sigplot.Layer1D, + } + ); + var lyr1 = plot.overlay_array( + [], + { + type: 2000, + subsize: 1000, + file_name: "data2", + }, + { + layerType: sigplot.Layer1D, + } + ); + var pulse1 = []; + var pulse2 = []; + for (var i = 0; i < 1000; i++) { + if (i < 490 || i > 510) { + pulse1.push(0); + } else { + pulse1.push(10.0); + } + if (i < 240 || i > 260) { + pulse2.push(0); + } else { + pulse2.push(10.0); + } + } + plot.reload(lyr0, pulse1); + plot.reload(lyr1, pulse2); } - plot.overlay_href("dat/sin.tmp", null, { - name: "x" - }); -}); - -interactiveTest('sigplot penny 1d legend default', 'Do you see a 1d penny with properly labeled legend (default)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); +); + +interactiveTest( + "sigplot custom xmult", + 'Do you see the x-axis in "hecto-" units (0-40)?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xmult: 100, + }); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } + plot.overlay_href("dat/sin.tmp", null, { + name: "x", + }); } - plot.overlay_href("dat/penny.prm", null, { - layerType: sigplot.Layer1D - }); -}); +); -interactiveTest('sigplot penny 1d legend string override', 'Do you see a penny with properly labeled legend (abc)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); +interactiveTest( + "sigplot penny 1d legend default", + "Do you see a 1d penny with properly labeled legend (default)?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } + plot.overlay_href("dat/penny.prm", null, { + layerType: sigplot.Layer1D, + }); } - plot.overlay_href("dat/penny.prm", null, { - layerType: sigplot.Layer1D, - name: "abc" - }); -}); +); -interactiveTest('sigplot penny 1d legend multiple', 'Do you see a penny with properly labeled legend (one, two, three)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); +interactiveTest( + "sigplot penny 1d legend string override", + "Do you see a penny with properly labeled legend (abc)?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } + plot.overlay_href("dat/penny.prm", null, { + layerType: sigplot.Layer1D, + name: "abc", + }); } - plot.overlay_href("dat/penny.prm", null, { - layerType: sigplot.Layer1D, - name: ["one", "two", "three"] - }); -}); +); -interactiveTest('sigplot small xrange', 'Do you see a properly formatted axis for 999.9965-999.9985?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 4096; i++) { - ramp.push(i); +interactiveTest( + "sigplot penny 1d legend multiple", + "Do you see a penny with properly labeled legend (one, two, three)?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); + } + plot.overlay_href("dat/penny.prm", null, { + layerType: sigplot.Layer1D, + name: ["one", "two", "three"], + }); } - plot.overlay_array(ramp, { - file_name: "ramp", - xstart: 999996296.08025432, - xdelta: 0.637054443359375, - format: "SF" - }); -}); +); -interactiveTest('sigplot panxpad', 'Do you see spikes at 10 and 110 with an x-axis from 0 to 120?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - panxpad: 10 - }); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 101; i++) { - if ((i === 0) || (i === 100)) { - ramp.push(100); - } else { - ramp.push(0); +interactiveTest( + "sigplot small xrange", + "Do you see a properly formatted axis for 999.9965-999.9985?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 4096; i++) { + ramp.push(i); } + plot.overlay_array(ramp, { + file_name: "ramp", + xstart: 999996296.08025432, + xdelta: 0.637054443359375, + format: "SF", + }); } - plot.overlay_array(ramp, { - xstart: 10 - }); -}); - -interactiveTest('sigplot xtimecode', 'Do you see a timecode xaxis 0 to 1h?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 4096; i++) { - ramp.push(i); +); + +interactiveTest( + "sigplot panxpad", + "Do you see spikes at 10 and 110 with an x-axis from 0 to 120?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + panxpad: 10, + }); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 101; i++) { + if (i === 0 || i === 100) { + ramp.push(100); + } else { + ramp.push(0); + } + } + plot.overlay_array(ramp, { + xstart: 10, + }); } - plot.overlay_array(ramp, { - file_name: "ramp", - format: "SF", - xunits: 4 - }); -}); +); -interactiveTest('sigplot ytimecode', 'Do you see a timecode yaxis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 31449600; i < 31449600 + 4096; i++) { - ramp.push(i); +interactiveTest( + "sigplot xtimecode", + "Do you see a timecode xaxis 0 to 1h?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 4096; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + format: "SF", + xunits: 4, + }); } - plot.overlay_array(ramp, { - file_name: "ramp", - format: "SF", - yunits: 4 - }); -}); +); -interactiveTest('sigplot ytimecode w/dates', 'Do you see a timecode yaxis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - var now = Date.now() / 1000; - for (var i = now; i < now + 2000; i++) { - ramp.push(i); +interactiveTest( + "sigplot ytimecode", + "Do you see a timecode yaxis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 31449600; i < 31449600 + 4096; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + format: "SF", + yunits: 4, + }); } - plot.overlay_array(ramp, { - file_name: "ramp", - format: "SF", - yunits: 4 - }); -}); +); -interactiveTest('sigplot custom xlabel/ylabel', 'Do you see custom xlabel/ylabel?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xlabel: "CustomX", - ylabel: "CustomY" - }); - assert.notEqual(plot, null); - var ramp = []; - var now = Date.now() / 1000; - for (var i = now; i < now + 2000; i++) { - ramp.push(i); +interactiveTest( + "sigplot ytimecode w/dates", + "Do you see a timecode yaxis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + var now = Date.now() / 1000; + for (var i = now; i < now + 2000; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + format: "SF", + yunits: 4, + }); } - plot.overlay_array(ramp, { - file_name: "ramp", - format: "SF", - yunits: 4 - }); -}); - -interactiveTest('sigplot custom function xlabel/ylabel', 'Do you see custom xlabel/ylabel?', function(assert) { - var xlabel = function(units, mult) { - return "CustomX - " + units + " " + mult; - }; - var ylabel = function(units, mult) { - return "CustomY - " + units + " " + mult; - }; - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xlabel: xlabel, - ylabel: ylabel - }); - assert.notEqual(plot, null); - var ramp = []; - var now = Date.now() / 1000; - for (var i = now; i < now + 2000; i++) { - ramp.push(i); +); + +interactiveTest( + "sigplot custom xlabel/ylabel", + "Do you see custom xlabel/ylabel?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xlabel: "CustomX", + ylabel: "CustomY", + }); + assert.notEqual(plot, null); + var ramp = []; + var now = Date.now() / 1000; + for (var i = now; i < now + 2000; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + format: "SF", + yunits: 4, + }); } - plot.overlay_array(ramp, { - file_name: "ramp", - format: "SF", - yunits: 4 - }); -}); - -// TODO this test seems broken -interactiveTest('sigplot expand full', 'Do you see a fully expanded plot?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autox: 3, - autoy: 3, - cmode: "IR", - type: 2000, - xlab: 1, - ylab: 44, - expand: true - }); - assert.notEqual(plot, null); - - function plot2(plot) { - plot.overlay_array([1, 2, 2, 3, 3, 4, 4, 5], { - subsize: 4, - type: 2000, - format: "CD", - xdelta: 7.01200008392334, - xstart: 1435763625.898, - xunits: 1, - yunits: 44 - }, { - layerType: sigplot.Layer1D, - expand: true +); + +interactiveTest( + "sigplot custom function xlabel/ylabel", + "Do you see custom xlabel/ylabel?", + function (assert) { + var xlabel = function (units, mult) { + return "CustomX - " + units + " " + mult; + }; + var ylabel = function (units, mult) { + return "CustomY - " + units + " " + mult; + }; + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xlabel: xlabel, + ylabel: ylabel, + }); + assert.notEqual(plot, null); + var ramp = []; + var now = Date.now() / 1000; + for (var i = now; i < now + 2000; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + format: "SF", + yunits: 4, }); } +); - function plot1(plot) { - plot.overlay_array([0, 0, 1, 1, 2, 2, 3, 3], { - subsize: 4, +// TODO this test seems broken +interactiveTest( + "sigplot expand full", + "Do you see a fully expanded plot?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autox: 3, + autoy: 3, + cmode: "IR", type: 2000, - format: "CD", - xdelta: 7.01200008392334, - xstart: 1435763625.898, - xunits: 1, - yunits: 44 - }, { - layerType: sigplot.Layer1D, - expand: true + xlab: 1, + ylab: 44, + expand: true, }); - } - plot1(plot); - plot2(plot); -}); + assert.notEqual(plot, null); -interactiveTest('sigplot expand full on command', 'Do you see a fully expanded plot?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < (plot._Gx.bufmax * 2); i++) { - ramp.push(i); - } - plot.overlay_array(ramp, { - file_name: "ramp" - }); - // if we are over bufmax, then only the first buffer is read and used for scaling the y-axis - // you have to scroll to get the full y-axis - assert.equal(plot._Gx.bufmax, 32768); - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 65535); - assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer - assert.equal(plot._Gx.panymax, 33422.34); // based off 0.02 of the first buffer - assert.equal(plot._Mx.stk[0].xmin, 0); - assert.equal(plot._Mx.stk[0].xmax, 32767); - assert.equal(plot._Mx.stk[0].ymin, -655.34); - assert.equal(plot._Mx.stk[0].ymax, 33422.34); - - plot.expand_full(true, true); - - assert.equal(plot._Gx.bufmax, 32768); - assert.equal(plot._Gx.panxmin, 0); - assert.equal(plot._Gx.panxmax, 65535); - assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer - assert.equal(plot._Gx.panymax, 66189.34); // based off 0.02 of the first buffer - assert.equal(plot._Mx.stk[0].xmin, 0); - assert.equal(plot._Mx.stk[0].xmax, 65535); - assert.equal(plot._Mx.stk[0].ymin, -655.34); - assert.equal(plot._Mx.stk[0].ymax, 66189.34); -}); + function plot2(plot) { + plot.overlay_array( + [1, 2, 2, 3, 3, 4, 4, 5], + { + subsize: 4, + type: 2000, + format: "CD", + xdelta: 7.01200008392334, + xstart: 1435763625.898, + xunits: 1, + yunits: 44, + }, + { + layerType: sigplot.Layer1D, + expand: true, + } + ); + } -interactiveTest('sigplot custom axis label', 'Do you see the axis label "CustomY (a) vs. Time code format"?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); + function plot1(plot) { + plot.overlay_array( + [0, 0, 1, 1, 2, 2, 3, 3], + { + subsize: 4, + type: 2000, + format: "CD", + xdelta: 7.01200008392334, + xstart: 1435763625.898, + xunits: 1, + yunits: 44, + }, + { + layerType: sigplot.Layer1D, + expand: true, + } + ); + } + plot1(plot); + plot2(plot); } - plot.overlay_href("dat/sin.tmp", null, { - xlab: 4, - ylab: ["CustomY", "a"] - }); -}); +); -interactiveTest('sigplot custom axis label', 'Do you see the axis label "CustomY (Ka) vs. CustomX"?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1024; i++) { - ramp.push(i); +interactiveTest( + "sigplot expand full on command", + "Do you see a fully expanded plot?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < plot._Gx.bufmax * 2; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, { + file_name: "ramp", + }); + // if we are over bufmax, then only the first buffer is read and used for scaling the y-axis + // you have to scroll to get the full y-axis + assert.equal(plot._Gx.bufmax, 32768); + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 65535); + assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer + assert.equal(plot._Gx.panymax, 33422.34); // based off 0.02 of the first buffer + assert.equal(plot._Mx.stk[0].xmin, 0); + assert.equal(plot._Mx.stk[0].xmax, 32767); + assert.equal(plot._Mx.stk[0].ymin, -655.34); + assert.equal(plot._Mx.stk[0].ymax, 33422.34); + + plot.expand_full(true, true); + + assert.equal(plot._Gx.bufmax, 32768); + assert.equal(plot._Gx.panxmin, 0); + assert.equal(plot._Gx.panxmax, 65535); + assert.equal(plot._Gx.panymin, -655.34); // based off 0.02 of the first buffer + assert.equal(plot._Gx.panymax, 66189.34); // based off 0.02 of the first buffer + assert.equal(plot._Mx.stk[0].xmin, 0); + assert.equal(plot._Mx.stk[0].xmax, 65535); + assert.equal(plot._Mx.stk[0].ymin, -655.34); + assert.equal(plot._Mx.stk[0].ymax, 66189.34); } - plot.overlay_array(ramp, { - file_name: "ramp" - }, { - xlab: "CustomX", - ylab: ["CustomY", "a"] - }); -}); +); -interactiveTest('check-xaxis-creep-reload', 'Do you see a pulse staying stationary on the x-axis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 2; - var pulse_position = 50; - for (var i = 0; i < 100; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "sigplot custom axis label", + 'Do you see the axis label "CustomY (a) vs. Time code format"?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); } + plot.overlay_href("dat/sin.tmp", null, { + xlab: 4, + ylab: ["CustomY", "a"], + }); } - var lyr0 = plot.overlay_array(pulse, { - type: 1000 - }); - ifixture.interval = window.setInterval(function() { - plot.reload(lyr0, pulse); - }, 100); -}); +); -interactiveTest('check-xaxis-creep-reload-oddsize', 'Do you see a pulse staying stationary on the x-axis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 2; - var pulse_position = 50; - for (var i = 0; i < 99; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "sigplot custom axis label", + 'Do you see the axis label "CustomY (Ka) vs. CustomX"?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1024; i++) { + ramp.push(i); } + plot.overlay_array( + ramp, + { + file_name: "ramp", + }, + { + xlab: "CustomX", + ylab: ["CustomY", "a"], + } + ); } - var lyr0 = plot.overlay_array(pulse, { - type: 1000 - }); - ifixture.interval = window.setInterval(function() { - plot.reload(lyr0, pulse); - }, 100); -}); +); -interactiveTest('check-xaxis-creep-push', 'Do you see a pulse staying stationary on the x-axis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 2; - var pulse_position = 50; - for (var i = 0; i < 100; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "check-xaxis-creep-reload", + "Do you see a pulse staying stationary on the x-axis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 2; + var pulse_position = 50; + for (var i = 0; i < 100; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); + } else { + pulse.push(-10.0); + } } + var lyr0 = plot.overlay_array(pulse, { + type: 1000, + }); + ifixture.interval = window.setInterval(function () { + plot.reload(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 100 - }, { - layerType: "1D" - }); - ifixture.interval = window.setInterval(function() { - plot.push(lyr0, pulse); - }, 100); -}); +); -interactiveTest('check-xaxis-creep-push-oddsize', 'Do you see a pulse staying stationary on the x-axis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 2; - var pulse_position = 50; - for (var i = 0; i < 99; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "check-xaxis-creep-reload-oddsize", + "Do you see a pulse staying stationary on the x-axis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 2; + var pulse_position = 50; + for (var i = 0; i < 99; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); + } else { + pulse.push(-10.0); + } } + var lyr0 = plot.overlay_array(pulse, { + type: 1000, + }); + ifixture.interval = window.setInterval(function () { + plot.reload(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 99 - }, { - layerType: "1D" - }); - ifixture.interval = window.setInterval(function() { - plot.push(lyr0, pulse); - }, 100); -}); +); -interactiveTest('check-xaxis-creep-push-partial', 'Do you see a pulse staying stationary on the x-axis?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 2; - var pulse_position = 50; - for (var i = 0; i < 100; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "check-xaxis-creep-push", + "Do you see a pulse staying stationary on the x-axis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 2; + var pulse_position = 50; + for (var i = 0; i < 100; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); + } else { + pulse.push(-10.0); + } } + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 100, + }, + { + layerType: "1D", + } + ); + ifixture.interval = window.setInterval(function () { + plot.push(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 100 - }, { - layerType: "1D" - }); - ifixture.interval = window.setInterval(function() { - plot.push(lyr0, pulse.slice(0, 50)); - plot.push(lyr0, pulse.slice(50, 100)); - }, 100); -}); +); -interactiveTest('reload', 'Do you see a pulse scrolling right?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 5; - var pulse_position = 0; - for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "check-xaxis-creep-push-oddsize", + "Do you see a pulse staying stationary on the x-axis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 2; + var pulse_position = 50; + for (var i = 0; i < 99; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); + } else { + pulse.push(-10.0); + } } + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 99, + }, + { + layerType: "1D", + } + ); + ifixture.interval = window.setInterval(function () { + plot.push(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_array(pulse, { - type: 1000 - }); - ifixture.interval = window.setInterval(function() { - pulse_position = (pulse_position + 1) % 1000; - for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse[i] = 10.0; +); + +interactiveTest( + "check-xaxis-creep-push-partial", + "Do you see a pulse staying stationary on the x-axis?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 2; + var pulse_position = 50; + for (var i = 0; i < 100; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); } else { - pulse[i] = -10.0; + pulse.push(-10.0); } } - plot.reload(lyr0, pulse); - }, 100); -}); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 100, + }, + { + layerType: "1D", + } + ); + ifixture.interval = window.setInterval(function () { + plot.push(lyr0, pulse.slice(0, 50)); + plot.push(lyr0, pulse.slice(50, 100)); + }, 100); + } +); -interactiveTest('xtimecode', 'Do you see a pulse scrolling right with an xtimecode axis?', function(assert) { - var epochDelta = (20.0 * 365.0 + 5.0) * (24 * 3600 * 1000); - var currentTime = (new Date().getTime() + epochDelta) / 1000; - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 5; - var pulse_position = 0; - for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "reload", + "Do you see a pulse scrolling right?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 5; + var pulse_position = 0; + for (var i = 0; i < 1000; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); + } else { + pulse.push(-10.0); + } } + var lyr0 = plot.overlay_array(pulse, { + type: 1000, + }); + ifixture.interval = window.setInterval(function () { + pulse_position = (pulse_position + 1) % 1000; + for (var i = 0; i < 1000; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse[i] = 10.0; + } else { + pulse[i] = -10.0; + } + } + plot.reload(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_array(pulse, { - type: 1000, - xstart: currentTime, - xunits: 4 - }); - ifixture.interval = window.setInterval(function() { - pulse_position = (pulse_position + 1) % 1000; +); + +interactiveTest( + "xtimecode", + "Do you see a pulse scrolling right with an xtimecode axis?", + function (assert) { + var epochDelta = (20.0 * 365.0 + 5.0) * (24 * 3600 * 1000); + var currentTime = (new Date().getTime() + epochDelta) / 1000; + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 5; + var pulse_position = 0; for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse[i] = 10.0; + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); } else { - pulse[i] = -10.0; + pulse.push(-10.0); } } - currentTime = (new Date().getTime() + epochDelta) / 1000; - plot.reload(lyr0, pulse, { - xstart: currentTime + 1 + var lyr0 = plot.overlay_array(pulse, { + type: 1000, + xstart: currentTime, + xunits: 4, }); - }, 100); -}); - -interactiveTest('t2000 odd-size layer1D (reload)', 'Do you see a stationary pulse?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 5; - var pulse_position = 8192; - for (var i = 0; i < 16385; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); - } + ifixture.interval = window.setInterval(function () { + pulse_position = (pulse_position + 1) % 1000; + for (var i = 0; i < 1000; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse[i] = 10.0; + } else { + pulse[i] = -10.0; + } + } + currentTime = (new Date().getTime() + epochDelta) / 1000; + plot.reload(lyr0, pulse, { + xstart: currentTime + 1, + }); + }, 100); } - var lyr0 = plot.overlay_array(null, { - type: 2000, - subsize: 16385 - }, { - layerType: sigplot.Layer1D - }); - ifixture.interval = window.setInterval(function() { +); + +interactiveTest( + "t2000 odd-size layer1D (reload)", + "Do you see a stationary pulse?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); var pulse = []; + var pulse_width = 5; + var pulse_position = 8192; for (var i = 0; i < 16385; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(Math.random() * 10.0); + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); } else { pulse.push(-10.0); } } - plot.reload(lyr0, pulse); - }, 100); -}); - -interactiveTest('t2000 odd-size layer1D (push)', 'Do you see a stationary pulse?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 5; - var pulse_position = 8192; - for (var i = 0; i < 16385; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); - } + var lyr0 = plot.overlay_array( + null, + { + type: 2000, + subsize: 16385, + }, + { + layerType: sigplot.Layer1D, + } + ); + ifixture.interval = window.setInterval(function () { + var pulse = []; + for (var i = 0; i < 16385; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(Math.random() * 10.0); + } else { + pulse.push(-10.0); + } + } + plot.reload(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16385 - }, { - layerType: sigplot.Layer1D - }); - ifixture.interval = window.setInterval(function() { +); + +interactiveTest( + "t2000 odd-size layer1D (push)", + "Do you see a stationary pulse?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); var pulse = []; + var pulse_width = 5; + var pulse_position = 8192; for (var i = 0; i < 16385; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(Math.random() * 10.0); + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); } else { pulse.push(-10.0); } } - plot.push(lyr0, pulse); - }, 100); -}); - -interactiveTest('t2000 layer1D', 'Do you see a pulse scrolling right (type 2000)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 5; - var pulse_position = 0; - for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); - } + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 16385, + }, + { + layerType: sigplot.Layer1D, + } + ); + ifixture.interval = window.setInterval(function () { + var pulse = []; + for (var i = 0; i < 16385; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(Math.random() * 10.0); + } else { + pulse.push(-10.0); + } + } + plot.push(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_array(null, { - type: 2000, - subsize: 1000 - }, { - layerType: sigplot.Layer1D - }); - ifixture.interval = window.setInterval(function() { - pulse_position = (pulse_position + 1) % 1000; +); + +interactiveTest( + "t2000 layer1D", + "Do you see a pulse scrolling right (type 2000)?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 5; + var pulse_position = 0; for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse[i] = 10.0; + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); } else { - pulse[i] = -10.0; + pulse.push(-10.0); } } - plot.reload(lyr0, pulse); - }, 100); -}); - -interactiveTest('zoom-xdelta', 'Is the plot fully scaled displaying a ramp?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1000; i++) { - ramp.push(i); + var lyr0 = plot.overlay_array( + null, + { + type: 2000, + subsize: 1000, + }, + { + layerType: sigplot.Layer1D, + } + ); + ifixture.interval = window.setInterval(function () { + pulse_position = (pulse_position + 1) % 1000; + for (var i = 0; i < 1000; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse[i] = 10.0; + } else { + pulse[i] = -10.0; + } + } + plot.reload(lyr0, pulse); + }, 100); } - var lyr0 = plot.overlay_array(ramp, { - type: 1000, - xstart: -500 - }); - plot.zoom({ - x: -250, - y: 5 - }, { - x: 250, - y: -5 - }); - plot.reload(lyr0, ramp, { - xstart: 0, - xdelta: 50 - }); - plot.unzoom(); -}); +); -interactiveTest('reload', 'Do you see a pulse stationary at 0 while the axis shifts?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 1; - var pulse_position = 500; - var xstart = -500; - var delta = 100; - for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "zoom-xdelta", + "Is the plot fully scaled displaying a ramp?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1000; i++) { + ramp.push(i); } + var lyr0 = plot.overlay_array(ramp, { + type: 1000, + xstart: -500, + }); + plot.zoom( + { + x: -250, + y: 5, + }, + { + x: 250, + y: -5, + } + ); + plot.reload(lyr0, ramp, { + xstart: 0, + xdelta: 50, + }); + plot.unzoom(); } - var lyr0 = plot.overlay_array(pulse, { - type: 1000, - xstart: xstart - }); - ifixture.interval = window.setInterval(function() { - pulse_position = pulse_position + delta; - xstart = xstart - delta; - if ((pulse_position >= 900) || (pulse_position <= 100)) { - delta = delta * -1; - } +); + +interactiveTest( + "reload", + "Do you see a pulse stationary at 0 while the axis shifts?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 1; + var pulse_position = 500; + var xstart = -500; + var delta = 100; for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse[i] = 10.0; + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); } else { - pulse[i] = -10.0; + pulse.push(-10.0); } } - plot.reload(lyr0, pulse, { - xstart: xstart + var lyr0 = plot.overlay_array(pulse, { + type: 1000, + xstart: xstart, }); - }, 1000); -}); + ifixture.interval = window.setInterval(function () { + pulse_position = pulse_position + delta; + xstart = xstart - delta; + if (pulse_position >= 900 || pulse_position <= 100) { + delta = delta * -1; + } + for (var i = 0; i < 1000; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse[i] = 10.0; + } else { + pulse[i] = -10.0; + } + } + plot.reload(lyr0, pulse, { + xstart: xstart, + }); + }, 1000); + } +); -interactiveTest('reload', 'Do you see a pulse stationary at 0 while the axis grows?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var pulse = []; - var pulse_width = 1; - var pulse_position = 500; - var xstart = -500; - var xdelta = 1; - for (var i = 0; i < 1000; i++) { - if ((i >= pulse_position) && (i < (pulse_position + pulse_width))) { - pulse.push(10.0); - } else { - pulse.push(-10.0); +interactiveTest( + "reload", + "Do you see a pulse stationary at 0 while the axis grows?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var pulse = []; + var pulse_width = 1; + var pulse_position = 500; + var xstart = -500; + var xdelta = 1; + for (var i = 0; i < 1000; i++) { + if (i >= pulse_position && i < pulse_position + pulse_width) { + pulse.push(10.0); + } else { + pulse.push(-10.0); + } } + var lyr0 = plot.overlay_array(pulse, { + type: 1000, + xstart: -500, + xdelta: xdelta, + }); + ifixture.interval = window.setInterval(function () { + xdelta = xdelta * 2; + xstart = -500 * xdelta; + plot.reload(lyr0, pulse, { + xstart: xstart, + xdelta: xdelta, + }); + }, 5000); } - var lyr0 = plot.overlay_array(pulse, { - type: 1000, - xstart: -500, - xdelta: xdelta - }); - ifixture.interval = window.setInterval(function() { - xdelta = xdelta * 2; - xstart = -500 * xdelta; - plot.reload(lyr0, pulse, { - xstart: xstart, - xdelta: xdelta +); + +interactiveTest( + "pipe 1D name", + 'Do you see a random data plot (0 to 1 ) properly named "Test" in the legend', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + legend: true, }); - }, 5000); -}); - -interactiveTest('pipe 1D name', 'Do you see a random data plot (0 to 1 ) properly named "Test" in the legend', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - legend: true - }); - assert.notEqual(plot, null); - var lyr0 = plot.overlay_pipe({ - type: 1000 - }, { - framesize: 100, - name: "Test" - }); - ifixture.interval = window.setInterval(function() { - var random = []; - for (var i = 0; i < 100; i += 1) { - random.push(Math.random()); - } - plot.push(lyr0, random); - }, 100); -}); - -interactiveTest('complex scrolling line', 'Do you see a scrolling random data (0 to 1) plot that auto-scales', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - cmode: 3, - autol: 5 - }); - var lyr0 = plot.overlay_pipe({ - type: 1000, - format: "CF" - }, { - framesize: 32768, - drawmode: "scrolling" - }); - ifixture.interval = window.setInterval(function() { - var random = []; - for (var i = 0; i < 100; i += 1) { - random.push(Math.random()); - } - plot.push(lyr0, random); - }, 100); -}); + assert.notEqual(plot, null); + var lyr0 = plot.overlay_pipe( + { + type: 1000, + }, + { + framesize: 100, + name: "Test", + } + ); + ifixture.interval = window.setInterval(function () { + var random = []; + for (var i = 0; i < 100; i += 1) { + random.push(Math.random()); + } + plot.push(lyr0, random); + }, 100); + } +); +interactiveTest( + "complex scrolling line", + "Do you see a scrolling random data (0 to 1) plot that auto-scales", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + cmode: 3, + autol: 5, + }); + var lyr0 = plot.overlay_pipe( + { + type: 1000, + format: "CF", + }, + { + framesize: 32768, + drawmode: "scrolling", + } + ); + ifixture.interval = window.setInterval(function () { + var random = []; + for (var i = 0; i < 100; i += 1) { + random.push(Math.random()); + } + plot.push(lyr0, random); + }, 100); + } +); // Demonstrate that changing the ymin/ymax settings // will implicitly change the autoy settings -interactiveTest('sigplot layer1d change_settings ymin/ymax ', - 'Do you see a plot scaled from -10 to 50', - function(assert) { - var container = document.getElementById('plot'); +interactiveTest( + "sigplot layer1d change_settings ymin/ymax ", + "Do you see a plot scaled from -10 to 50", + function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); @@ -864,14 +1053,16 @@ interactiveTest('sigplot layer1d change_settings ymin/ymax ', plot.overlay_array(pulse); plot.change_settings({ ymin: -10, - ymax: 50 + ymax: 50, }); - }); + } +); -interactiveTest('sigplot layer1d change_settings ymin/ymax ', - 'Do you see a plot scaled from 0.2 to 50', - function(assert) { - var container = document.getElementById('plot'); +interactiveTest( + "sigplot layer1d change_settings ymin/ymax ", + "Do you see a plot scaled from 0.2 to 50", + function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); @@ -886,14 +1077,16 @@ interactiveTest('sigplot layer1d change_settings ymin/ymax ', plot.overlay_array(pulse); plot.change_settings({ - ymax: 50 + ymax: 50, }); - }); + } +); -interactiveTest('sigplot layer1d change_settings ymin/ymax ', - 'Do you see a plot scaled from -10 to 10.2', - function(assert) { - var container = document.getElementById('plot'); +interactiveTest( + "sigplot layer1d change_settings ymin/ymax ", + "Do you see a plot scaled from -10 to 10.2", + function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); @@ -908,16 +1101,18 @@ interactiveTest('sigplot layer1d change_settings ymin/ymax ', plot.overlay_array(pulse); plot.change_settings({ - ymin: -10 + ymin: -10, }); - }); + } +); // Prove that automatic autoy works when setting ymin/ymax // back to null -interactiveTest('sigplot layer1d change_settings ymin/ymax ', - 'Do you see a plot scaled from 0.2 to 10.2', - function(assert) { - var container = document.getElementById('plot'); +interactiveTest( + "sigplot layer1d change_settings ymin/ymax ", + "Do you see a plot scaled from 0.2 to 10.2", + function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); @@ -933,29 +1128,34 @@ interactiveTest('sigplot layer1d change_settings ymin/ymax ', plot.overlay_array(pulse); plot.change_settings({ ymin: -10, - ymax: 50 + ymax: 50, }); plot.change_settings({ ymin: null, - ymax: null + ymax: null, }); - }); + } +); -interactiveTest('sigplot layer1d framesize change', - 'Do you see a plots where the x-axis grows in size and the triangle stays centered?', - function(assert) { - var container = document.getElementById('plot'); +interactiveTest( + "sigplot layer1d framesize change", + "Do you see a plots where the x-axis grows in size and the triangle stays centered?", + function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); var current_framesize = 100; - var lyr0 = plot.overlay_pipe({ - type: 1000 - }, { - framesize: current_framesize - }); + var lyr0 = plot.overlay_pipe( + { + type: 1000, + }, + { + framesize: current_framesize, + } + ); - ifixture.interval = window.setInterval(function() { + ifixture.interval = window.setInterval(function () { var data = []; for (var i = 0; i < current_framesize; i += 1) { if (i < current_framesize / 2) { @@ -966,403 +1166,430 @@ interactiveTest('sigplot layer1d framesize change', } // change the framesize plot.change_settings({ - framesize: current_framesize + framesize: current_framesize, }); // push the data plot.push(lyr0, data); // increate the framesize for the next pass current_framesize = current_framesize + 100; }, 2000); - }); - -interactiveTest('LO ymin/ymax', 'Do you see a plot that scales -100 to -20?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - ymin: 1e-10, - ymax: 1e-2, - cmode: "LO" - }); - assert.notEqual(plot, null); - var data1 = []; - for (var i = 0; i < 1024; i++) { - data1.push(i % 2); } - plot.overlay_array(data1, { - file_name: "data1" - }); - var data2 = []; - for (var i = 0; i < 2048; i++) { - if (i % 2) { - data2.push(-60); - } else { - data2.push(-40); +); + +interactiveTest( + "LO ymin/ymax", + "Do you see a plot that scales -100 to -20?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + ymin: 1e-10, + ymax: 1e-2, + cmode: "LO", + }); + assert.notEqual(plot, null); + var data1 = []; + for (var i = 0; i < 1024; i++) { + data1.push(i % 2); } + plot.overlay_array(data1, { + file_name: "data1", + }); + var data2 = []; + for (var i = 0; i < 2048; i++) { + if (i % 2) { + data2.push(-60); + } else { + data2.push(-40); + } + } + plot.overlay_array(data2, { + file_name: "data2", + }); } - plot.overlay_array(data2, { - file_name: "data2" - }); -}); - -interactiveTest('D1 ymin/ymax', 'Do you see a plot that scales -100 to -20?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - ymin: -100, - ymax: -20, - cmode: "D1" - }); - assert.notEqual(plot, null); - var data1 = []; - for (var i = 0; i < 1024; i++) { - data1.push(i % 2); - } - plot.overlay_array(data1, { - file_name: "data1" - }); - var data2 = []; - for (var i = 0; i < 2048; i++) { - if (i % 2) { - data2.push(-60); - } else { - data2.push(-40); +); + +interactiveTest( + "D1 ymin/ymax", + "Do you see a plot that scales -100 to -20?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + ymin: -100, + ymax: -20, + cmode: "D1", + }); + assert.notEqual(plot, null); + var data1 = []; + for (var i = 0; i < 1024; i++) { + data1.push(i % 2); + } + plot.overlay_array(data1, { + file_name: "data1", + }); + var data2 = []; + for (var i = 0; i < 2048; i++) { + if (i % 2) { + data2.push(-60); + } else { + data2.push(-40); + } } + plot.overlay_array(data2, { + file_name: "data2", + }); } - plot.overlay_array(data2, { - file_name: "data2" - }); -}); +); -interactiveTest('custom color line', 'Do you see an orange line?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1000; i++) { - ramp.push(i); +interactiveTest( + "custom color line", + "Do you see an orange line?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1000; i++) { + ramp.push(i); + } + var layer = plot.overlay_array( + ramp, + { + file_name: "ramp", + }, + { + color: "orange", + } + ); } - var layer = plot.overlay_array(ramp, { - file_name: "ramp" - }, { - color: "orange" - }); -}); +); -interactiveTest('custom color line (change settings)', 'Do you see an orange line?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1000; i++) { - ramp.push(i); +interactiveTest( + "custom color line (change settings)", + "Do you see an orange line?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1000; i++) { + ramp.push(i); + } + var layer = plot.overlay_array(ramp, { + file_name: "ramp", + }); + plot.get_layer(layer).color = "orange"; + plot.refresh(); } - var layer = plot.overlay_array(ramp, { - file_name: "ramp" - }); - plot.get_layer(layer).color = "orange"; - plot.refresh(); -}); +); -interactiveTest('overlapping_highlights', 'Do you see an unbroken yellow line with red on each end?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1000; i++) { - ramp.push(i); +interactiveTest( + "overlapping_highlights", + "Do you see an unbroken yellow line with red on each end?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1000; i++) { + ramp.push(i); + } + var layer = plot.overlay_array(ramp, { + file_name: "ramp", + }); + plot.get_layer(layer).add_highlight({ + xstart: 400, + xend: 600, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 600, + xend: 800, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 450, + xend: 550, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 550, + xend: 650, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 650, + xend: 750, + color: "yellow", + }); } - var layer = plot.overlay_array(ramp, { - file_name: "ramp" - }); - plot.get_layer(layer).add_highlight({ - xstart: 400, - xend: 600, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 600, - xend: 800, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 450, - xend: 550, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 550, - xend: 650, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 650, - xend: 750, - color: "yellow" - }); -}); +); -interactiveTest('overlapping_highlights', 'Do you see an unbroken red line?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1000; i++) { - ramp.push(i); +interactiveTest( + "overlapping_highlights", + "Do you see an unbroken red line?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1000; i++) { + ramp.push(i); + } + var layer = plot.overlay_array(ramp, { + file_name: "ramp", + }); + plot.get_layer(layer).add_highlight({ + xstart: 450, + xend: 550, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 550, + xend: 650, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 650, + xend: 750, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 400, + xend: 600, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 600, + xend: 800, + color: "red", + }); } - var layer = plot.overlay_array(ramp, { - file_name: "ramp" - }); - plot.get_layer(layer).add_highlight({ - xstart: 450, - xend: 550, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 550, - xend: 650, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 650, - xend: 750, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 400, - xend: 600, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 600, - xend: 800, - color: "red" - }); -}); +); -interactiveTest('overlapping_highlights', 'Do you see evenly spaced red/yellow highlights?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 1000; i++) { - ramp.push(i); +interactiveTest( + "overlapping_highlights", + "Do you see evenly spaced red/yellow highlights?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 1000; i++) { + ramp.push(i); + } + var layer = plot.overlay_array(ramp, { + file_name: "ramp", + }); + // Create various overlap conditions + plot.get_layer(layer).add_highlight({ + xstart: 375, + xend: 450, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 450, + xend: 537, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 537, + xend: 700, + color: "yellow", + }); + plot.get_layer(layer).add_highlight({ + xstart: 400, + xend: 425, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 450, + xend: 475, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 500, + xend: 525, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 550, + xend: 575, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 600, + xend: 625, + color: "red", + }); + plot.get_layer(layer).add_highlight({ + xstart: 650, + xend: 675, + color: "red", + }); } - var layer = plot.overlay_array(ramp, { - file_name: "ramp" - }); - // Create various overlap conditions - plot.get_layer(layer).add_highlight({ - xstart: 375, - xend: 450, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 450, - xend: 537, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 537, - xend: 700, - color: "yellow" - }); - plot.get_layer(layer).add_highlight({ - xstart: 400, - xend: 425, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 450, - xend: 475, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 500, - xend: 525, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 550, - xend: 575, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 600, - xend: 625, - color: "red" - }); - plot.get_layer(layer).add_highlight({ - xstart: 650, - xend: 675, - color: "red" - }); -}); +); -interactiveTest('vertical and horizontal lines', 'Is there a horizontal and vertical line on every point?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "vertical and horizontal lines", + "Is there a horizontal and vertical line on every point?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 20; i++) { - ramp.push(i); + var ramp = []; + for (var i = 0; i < 20; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, null, { + name: "x", + symbol: 0, + line: 4, + }); } - plot.overlay_array(ramp, null, { - name: "x", - symbol: 0, - line: 4 - }); -}); +); + +interactiveTest( + "change_settings", + "does the plot show a range 200-2200", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autohide_panbars: false, + cmode: "LO", + xcnt: "continuous", + }); + assert.notEqual(plot, null); -interactiveTest('change_settings', 'does the plot show a range 200-2200', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autohide_panbars: false, - cmode: 'LO', - xcnt: 'continuous' - }); - assert.notEqual(plot, null); - - var hcb = { - xunits: 3, - yunits: 26, - size: 1024, - xdelta: 20 - }; - var layerOptions = { - framesize: 1024 - }; - - var lyr_uuid = plot.overlay_pipe(hcb, layerOptions); - - var ramp = []; - for (var i = 0; i < 1024; i += 1) { - ramp.push(i + 1); - } - // do a syncronous push so we can make some assertions - plot.push(lyr_uuid, ramp, null, true); - assert.strictEqual(plot._Mx.stk[0].xmin, 0); - assert.strictEqual(plot._Mx.stk[0].xmax, 20460); - - assert.strictEqual(plot._Gx.lyr[0].xmin, 0); - assert.strictEqual(plot._Gx.lyr[0].xmax, 20460); - - plot.change_settings({ - xmin: 200, - xmax: 2200 - }); - assert.strictEqual(plot._Mx.stk[0].xmin, 200); - assert.strictEqual(plot._Mx.stk[0].xmax, 2200); - - // do a syncronous refresh - plot._refresh(); - assert.strictEqual(plot._Mx.stk[0].xmin, 200); - assert.strictEqual(plot._Mx.stk[0].xmax, 2200); - - // and another push - plot.push(lyr_uuid, ramp, null, true); - assert.strictEqual(plot._Mx.stk[0].xmin, 200); - assert.strictEqual(plot._Mx.stk[0].xmax, 2200); + var hcb = { + xunits: 3, + yunits: 26, + size: 1024, + xdelta: 20, + }; + var layerOptions = { + framesize: 1024, + }; + + var lyr_uuid = plot.overlay_pipe(hcb, layerOptions); + + var ramp = []; + for (var i = 0; i < 1024; i += 1) { + ramp.push(i + 1); + } + // do a syncronous push so we can make some assertions + plot.push(lyr_uuid, ramp, null, true); + assert.strictEqual(plot._Mx.stk[0].xmin, 0); + assert.strictEqual(plot._Mx.stk[0].xmax, 20460); -}); + assert.strictEqual(plot._Gx.lyr[0].xmin, 0); + assert.strictEqual(plot._Gx.lyr[0].xmax, 20460); -interactiveTest('headermod', 'does the plot show a range 200-2200', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autohide_panbars: false, - cmode: 'LO', - xcnt: 'continuous' - }); - assert.notEqual(plot, null); - - var hcb = { - xunits: 3, - yunits: 26, - size: 1024, - xdelta: 20 - }; - var layerOptions = { - framesize: 1024 - }; - - var lyr_uuid = plot.overlay_pipe(hcb, layerOptions); - - var ramp = []; - for (var i = 0; i < 1024; i += 1) { - ramp.push(i + 1); + plot.change_settings({ + xmin: 200, + xmax: 2200, + }); + assert.strictEqual(plot._Mx.stk[0].xmin, 200); + assert.strictEqual(plot._Mx.stk[0].xmax, 2200); + + // do a syncronous refresh + plot._refresh(); + assert.strictEqual(plot._Mx.stk[0].xmin, 200); + assert.strictEqual(plot._Mx.stk[0].xmax, 2200); + + // and another push + plot.push(lyr_uuid, ramp, null, true); + assert.strictEqual(plot._Mx.stk[0].xmin, 200); + assert.strictEqual(plot._Mx.stk[0].xmax, 2200); } - // do a syncronous push so we can make some assertions - plot.push(lyr_uuid, ramp, null, true); - assert.strictEqual(plot._Mx.stk[0].xmin, 0); - assert.strictEqual(plot._Mx.stk[0].xmax, 20460); - - assert.strictEqual(plot._Gx.lyr[0].xmin, 0); - assert.strictEqual(plot._Gx.lyr[0].xmax, 20460); - - plot.headermod(lyr_uuid, { - xmin: 200, - xmax: 2200 - }); - assert.strictEqual(plot._Mx.stk[0].xmin, 200); - assert.strictEqual(plot._Mx.stk[0].xmax, 2200); - - assert.strictEqual(plot._Gx.lyr[0].xmin, 200); - assert.strictEqual(plot._Gx.lyr[0].xmax, 2200); - - // do a syncronous refresh - plot._refresh(); - assert.strictEqual(plot._Mx.stk[0].xmin, 200); - assert.strictEqual(plot._Mx.stk[0].xmax, 2200); - - // and another push - plot.push(lyr_uuid, ramp, null, true); - assert.strictEqual(plot._Mx.stk[0].xmin, 200); - assert.strictEqual(plot._Mx.stk[0].xmax, 2200); - - assert.strictEqual(plot._Gx.lyr[0].xmin, 200); - assert.strictEqual(plot._Gx.lyr[0].xmax, 2200); -}); +); + +interactiveTest( + "headermod", + "does the plot show a range 200-2200", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autohide_panbars: false, + cmode: "LO", + xcnt: "continuous", + }); + assert.notEqual(plot, null); -interactiveTest('correct scale after cmode change', 'is the plot correctly scaled with full scroll bars', function(assert) { - var done = assert.async(); - - var plot_options = { - autohide_panbars: false, - hide_note: true - }; - var data = [1, 2, 3, 4, 5, 4, 3, 2, 1]; // the series of y-values - var data_header = { - xunits: "Time", - xstart: 100, // the start of the x-axis - xdelta: 50, // the x-axis step between each data point - yunits: "Power" - }; - var layer_options = { - name: "Sample Data" - }; - var plot = new sigplot.Plot(document.getElementById('plot'), plot_options); - plot.overlay_array(data, data_header, layer_options); - - assert.equal(plot._Mx.stk[0].xmin, 100); - assert.equal(plot._Mx.stk[0].xmax, 500); - assert.equal(plot._Mx.stk[0].ymin, 0.92); - assert.equal(plot._Mx.stk[0].ymax, 5.08); - assert.equal(plot._Gx.panymin, 0.92); - assert.equal(plot._Gx.panymax, 5.08); - - plot.change_settings({ - cmode: 6 - }); - window.setTimeout(function() { + var hcb = { + xunits: 3, + yunits: 26, + size: 1024, + xdelta: 20, + }; + var layerOptions = { + framesize: 1024, + }; + + var lyr_uuid = plot.overlay_pipe(hcb, layerOptions); + + var ramp = []; + for (var i = 0; i < 1024; i += 1) { + ramp.push(i + 1); + } + // do a syncronous push so we can make some assertions + plot.push(lyr_uuid, ramp, null, true); + assert.strictEqual(plot._Mx.stk[0].xmin, 0); + assert.strictEqual(plot._Mx.stk[0].xmax, 20460); - assert.equal(plot._Mx.stk[0].xmin, 100); - assert.equal(plot._Mx.stk[0].xmax, 500); - assert.equal(plot._Mx.stk[0].ymin, -0.13979400086720375); - assert.equal(plot._Mx.stk[0].ymax, 7.129494044227391); - assert.equal(plot._Gx.panymin, -0.13979400086720375); - assert.equal(plot._Gx.panymax, 7.129494044227391); + assert.strictEqual(plot._Gx.lyr[0].xmin, 0); + assert.strictEqual(plot._Gx.lyr[0].xmax, 20460); - plot.change_settings({ - cmode: 3 + plot.headermod(lyr_uuid, { + xmin: 200, + xmax: 2200, }); + assert.strictEqual(plot._Mx.stk[0].xmin, 200); + assert.strictEqual(plot._Mx.stk[0].xmax, 2200); + + assert.strictEqual(plot._Gx.lyr[0].xmin, 200); + assert.strictEqual(plot._Gx.lyr[0].xmax, 2200); + + // do a syncronous refresh + plot._refresh(); + assert.strictEqual(plot._Mx.stk[0].xmin, 200); + assert.strictEqual(plot._Mx.stk[0].xmax, 2200); + + // and another push + plot.push(lyr_uuid, ramp, null, true); + assert.strictEqual(plot._Mx.stk[0].xmin, 200); + assert.strictEqual(plot._Mx.stk[0].xmax, 2200); + + assert.strictEqual(plot._Gx.lyr[0].xmin, 200); + assert.strictEqual(plot._Gx.lyr[0].xmax, 2200); + } +); + +interactiveTest( + "correct scale after cmode change", + "is the plot correctly scaled with full scroll bars", + function (assert) { + var done = assert.async(); + + var plot_options = { + autohide_panbars: false, + hide_note: true, + }; + var data = [1, 2, 3, 4, 5, 4, 3, 2, 1]; // the series of y-values + var data_header = { + xunits: "Time", + xstart: 100, // the start of the x-axis + xdelta: 50, // the x-axis step between each data point + yunits: "Power", + }; + var layer_options = { + name: "Sample Data", + }; + var plot = new sigplot.Plot( + document.getElementById("plot"), + plot_options + ); + plot.overlay_array(data, data_header, layer_options); assert.equal(plot._Mx.stk[0].xmin, 100); assert.equal(plot._Mx.stk[0].xmax, 500); @@ -1371,7 +1598,29 @@ interactiveTest('correct scale after cmode change', 'is the plot correctly scale assert.equal(plot._Gx.panymin, 0.92); assert.equal(plot._Gx.panymax, 5.08); - done(); + plot.change_settings({ + cmode: 6, + }); + window.setTimeout(function () { + assert.equal(plot._Mx.stk[0].xmin, 100); + assert.equal(plot._Mx.stk[0].xmax, 500); + assert.equal(plot._Mx.stk[0].ymin, -0.13979400086720375); + assert.equal(plot._Mx.stk[0].ymax, 7.129494044227391); + assert.equal(plot._Gx.panymin, -0.13979400086720375); + assert.equal(plot._Gx.panymax, 7.129494044227391); + + plot.change_settings({ + cmode: 3, + }); + + assert.equal(plot._Mx.stk[0].xmin, 100); + assert.equal(plot._Mx.stk[0].xmax, 500); + assert.equal(plot._Mx.stk[0].ymin, 0.92); + assert.equal(plot._Mx.stk[0].ymax, 5.08); + assert.equal(plot._Gx.panymin, 0.92); + assert.equal(plot._Gx.panymax, 5.08); - }, 1000); -}); + done(); + }, 1000); + } +); diff --git a/test/tests.interactive-layer2d.js b/test/tests.interactive-layer2d.js index 95443b2..829b9a2 100644 --- a/test/tests.interactive-layer2d.js +++ b/test/tests.interactive-layer2d.js @@ -25,1415 +25,1666 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-layer2d', { +QUnit.module("sigplot-interactive-layer2d", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('sigplot 2d deoverlay', 'Do you see a raster? Is alignment of x/y axes correct?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var lyr_n = plot.overlay_array([], {}, { - layerType: sigplot.Layer2D - }); - var data = [ - [1, 2, 3, 4, 5], - [6, 7, 8, 9, 0], - [1, 2, 3, 4, 5], - [6, 7, 8, 9, 0] - ]; - plot.deoverlay(lyr_n); - lyr_n = plot.overlay_array(data); -}); - -interactiveTest('sigplot panxpad layer2d', 'Do you see spikes at 10 and 110 with an x-axis from 0 to 120?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - panxpad: 10 - }); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 101; i++) { - if ((i === 0) || (i === 100)) { - ramp.push(100); - } else { - ramp.push(0); - } - } - var data = []; - for (var r = 0; r < 100; r++) { - data.push(ramp); +interactiveTest( + "sigplot 2d deoverlay", + "Do you see a raster? Is alignment of x/y axes correct?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var lyr_n = plot.overlay_array( + [], + {}, + { + layerType: sigplot.Layer2D, + } + ); + var data = [ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 0], + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 0], + ]; + plot.deoverlay(lyr_n); + lyr_n = plot.overlay_array(data); } - - plot.overlay_array(data, { - xstart: 10, - layerType: sigplot.Layer2D, - }); -}); - -interactiveTest('pipe 2D name', 'Do you see a random data plot (0 to 1 ) properly named "Test" in the legend', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - legend: true - }); - assert.notEqual(plot, null); - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 100 - }, { - framesize: 100, - name: "Test" - }); - ifixture.interval = window.setInterval(function() { - var random = []; - for (var i = 0; i < 100; i += 1) { - random.push(Math.random()); +); + +interactiveTest( + "sigplot panxpad layer2d", + "Do you see spikes at 10 and 110 with an x-axis from 0 to 120?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + panxpad: 10, + }); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 101; i++) { + if (i === 0 || i === 100) { + ramp.push(100); + } else { + ramp.push(0); + } + } + var data = []; + for (var r = 0; r < 100; r++) { + data.push(ramp); } - plot.push(lyr0, random); - }, 100); -}); + plot.overlay_array(data, { + xstart: 10, + layerType: sigplot.Layer2D, + }); + } +); + +interactiveTest( + "pipe 2D name", + 'Do you see a random data plot (0 to 1 ) properly named "Test" in the legend', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + legend: true, + }); + assert.notEqual(plot, null); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 100, + }, + { + framesize: 100, + name: "Test", + } + ); + ifixture.interval = window.setInterval(function () { + var random = []; + for (var i = 0; i < 100; i += 1) { + random.push(Math.random()); + } + plot.push(lyr0, random); + }, 100); + } +); // When autol is used, the raster scaling will dynamically updated per-line // with autol=1 each line is scaled by itself, so this should render as vertical bars -interactiveTest('t2000 file (default autol)', 'Does the plot render a vertical bars?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autol: 1 - }); - assert.notEqual(plot, null); - - var framesize = 128; - var height = 120; - - var raster = []; - for (var j = 0; j < height; j += 1) { - for (var i = 0; i < framesize; i += 1) { - raster.push(j + i); +interactiveTest( + "t2000 file (default autol)", + "Does the plot render a vertical bars?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autol: 1, + }); + assert.notEqual(plot, null); + + var framesize = 128; + var height = 120; + + var raster = []; + for (var j = 0; j < height; j += 1) { + for (var i = 0; i < framesize; i += 1) { + raster.push(j + i); + } } - } - plot.overlay_array(raster, { - type: 2000, - subsize: framesize, - file_name: "raster" - }); -}); + plot.overlay_array(raster, { + type: 2000, + subsize: framesize, + file_name: "raster", + }); + } +); // this data is rendered where the left side of the plot will be a constant color, // the right side should start as constant red and then around 110 switch to a gradient // that gradually go back to all red. The 'height' of the rainbow grows as autol // is increased -interactiveTest('t2000 file (default autol)', 'Does the plot render a gradient on the right?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - autol: 5 - }); - assert.notEqual(plot, null); - - var framesize = 128; - var height = 120; - - var raster = []; - var val = 0; - for (var j = 0; j < height; j += 1) { - for (var i = 0; i < framesize; i += 1) { - if (i < (framesize) / 2) { - val = 1; - } else { - if (j < 60) { - val = 100; +interactiveTest( + "t2000 file (default autol)", + "Does the plot render a gradient on the right?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + autol: 5, + }); + assert.notEqual(plot, null); + + var framesize = 128; + var height = 120; + + var raster = []; + var val = 0; + for (var j = 0; j < height; j += 1) { + for (var i = 0; i < framesize; i += 1) { + if (i < framesize / 2) { + val = 1; } else { - val = 10; + if (j < 60) { + val = 100; + } else { + val = 10; + } } + raster.push(val); } - raster.push(val); } - } - - plot.overlay_array(raster, { - type: 2000, - subsize: framesize, - file_name: "raster" - }); -}); -interactiveTest('t2000 layer2D (default autol)', 'Does the plot correctly autoscale after 100 rows?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - data.push(0); + plot.overlay_array(raster, { + type: 2000, + subsize: framesize, + file_name: "raster", + }); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - if (cnt === 100) { - data = []; - for (var i = 0; i < 16384; i++) { - data.push(i); - } - } - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (smoothing)', 'Do you see evenly spaced lines?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - smoothing: true - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - if ((i % 3 === 0) && (i > 400) && (i < 800)) { - data.push(400); - } else if ((i % 3 === 0) && (i > 1200) && (i < 1600)) { - data.push(800); - } else { +); + +interactiveTest( + "t2000 layer2D (default autol)", + "Does the plot correctly autoscale after 100 rows?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { data.push(0); } - } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }, null, { - smoothing: true - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (no compression)', 'you should see lines between 20-40, 60-90, and 90-100?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 1 - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 100; i++) { - if ((i > 20) && (i < 40)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(200); - } else { - data.push(0); + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: 16384, + }); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + if (cnt === 100) { + data = []; + for (var i = 0; i < 16384; i++) { + data.push(i); + } } - } else if ((i > 60) && (i < 80)) { - if (i % 3 === 0) { - data.push(50); - } else if (i % 3 === 1) { - data.push(250); + plot.push(lyr0, data); + }, 100); + } +); + +interactiveTest( + "layer2D (smoothing)", + "Do you see evenly spaced lines?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + smoothing: true, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { + if (i % 3 === 0 && i > 400 && i < 800) { + data.push(400); + } else if (i % 3 === 0 && i > 1200 && i < 1600) { + data.push(800); } else { data.push(0); } - } else if (i > 90) { - data.push(300); - } else { - data.push(0); } + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 16384, + }, + null, + { + smoothing: true, + } + ); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 100 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (average compression)', 'Do you see evenly spaced lines of the same color?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 1 - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - if ((i > 400) && (i < 800)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(200); +); + +interactiveTest( + "layer2D (no compression)", + "you should see lines between 20-40, 60-90, and 90-100?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 1, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 100; i++) { + if (i > 20 && i < 40) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(200); + } else { + data.push(0); + } + } else if (i > 60 && i < 80) { + if (i % 3 === 0) { + data.push(50); + } else if (i % 3 === 1) { + data.push(250); + } else { + data.push(0); + } + } else if (i > 90) { + data.push(300); } else { data.push(0); } - } else if ((i > 1200) && (i < 1600)) { - if (i % 3 === 0) { - data.push(50); - } else if (i % 3 === 1) { - data.push(250); + } + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: 100, + }); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + }, 100); + } +); + +interactiveTest( + "layer2D (average compression)", + "Do you see evenly spaced lines of the same color?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 1, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { + if (i > 400 && i < 800) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(200); + } else { + data.push(0); + } + } else if (i > 1200 && i < 1600) { + if (i % 3 === 0) { + data.push(50); + } else if (i % 3 === 1) { + data.push(250); + } else { + data.push(0); + } } else { data.push(0); } - } else { - data.push(0); } + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: 16384, + }); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (min compression)', 'Do you see two lines of the same color?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 2 - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - if ((i > 400) && (i < 800)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(400); - } else { - data.push(50); - } - } else if ((i > 1200) && (i < 1600)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(400); +); + +interactiveTest( + "layer2D (min compression)", + "Do you see two lines of the same color?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 2, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { + if (i > 400 && i < 800) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(50); + } + } else if (i > 1200 && i < 1600) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(50); + } } else { - data.push(50); + data.push(0); } - } else { - data.push(0); } + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: 16384, + }); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (max compression)', 'Do you see two lines of the same color?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 3 - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - if ((i > 400) && (i < 800)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(400); +); + +interactiveTest( + "layer2D (max compression)", + "Do you see two lines of the same color?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 3, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { + if (i > 400 && i < 800) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(0); + } + } else if (i > 1200 && i < 1600) { + if (i % 3 === 0) { + data.push(200); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(0); + } } else { data.push(0); } - } else if ((i > 1200) && (i < 1600)) { - if (i % 3 === 0) { - data.push(200); - } else if (i % 3 === 1) { - data.push(400); + } + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: 16384, + }); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + }, 100); + } +); + +interactiveTest( + "layer2D (abs-max compression)", + "Do you see two lines of the same color?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 5, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { + if (i > 400 && i < 800) { + if (i % 3 === 0) { + data.push(800); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(0); + } + } else if (i > 1200 && i < 1600) { + if (i % 3 === 0) { + data.push(-800); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(0); + } } else { data.push(0); } - } else { - data.push(0); } + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: 16384, + }); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + }, 100); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (abs-max compression)', 'Do you see two lines of the same color?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 5 - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - if ((i > 400) && (i < 800)) { - if (i % 3 === 0) { - data.push(800); - } else if (i % 3 === 1) { - data.push(400); +); + +interactiveTest( + "layer2D (change compression layerAvg)", + "Do you see two lines of the same color?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 4, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { + if (i > 400 && i < 800) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(50); + } + } else if (i > 1200 && i < 1600) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(50); + } } else { data.push(0); } - } else if ((i > 1200) && (i < 1600)) { - if (i % 3 === 0) { - data.push(-800); - } else if (i % 3 === 1) { - data.push(400); + } + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 16384, + }, + { + xcmp: 2, + } + ); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + }, 100); + } +); + +interactiveTest( + "layer2D (change compression settings)", + "Do you see two lines of the same color after 100 lines?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 4, + }); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 16384; i++) { + if (i > 400 && i < 800) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(50); + } + } else if (i > 1200 && i < 1600) { + if (i % 3 === 0) { + data.push(100); + } else if (i % 3 === 1) { + data.push(400); + } else { + data.push(50); + } } else { data.push(0); } - } else { - data.push(0); } - } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (change compression layerAvg)', 'Do you see two lines of the same color?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 4 - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - if ((i > 400) && (i < 800)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(400); - } else { - data.push(50); + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: 16384, + }); + var cnt = 0; + ifixture.interval = window.setInterval(function () { + cnt = cnt + 1; + plot.push(lyr0, data); + + if (cnt === 100) { + plot.change_settings({ + xcmp: 2, + }); } - } else if ((i > 1200) && (i < 1600)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(400); - } else { - data.push(50); + }, 100); + } +); + +interactiveTest( + "raster (ystart)", + "Does the plot start at y-axis 100?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var framesize = 128; + var height = 120; + var ramp = []; + for (var j = 0; j < height; j += 1) { + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); } - } else { - data.push(0); } + plot.overlay_array(ramp, { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.5, + ystart: 100, + }); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }, { - xcmp: 2 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - }, 100); -}); - -interactiveTest('layer2D (change compression settings)', 'Do you see two lines of the same color after 100 lines?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 4 - }); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 16384; i++) { - if ((i > 400) && (i < 800)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(400); - } else { - data.push(50); - } - } else if ((i > 1200) && (i < 1600)) { - if (i % 3 === 0) { - data.push(100); - } else if (i % 3 === 1) { - data.push(400); - } else { - data.push(50); +); + +interactiveTest( + "raster (timecode)", + 'Do you see a raster that starts at 2014 July 4th for one hour (use "t" to check)?', + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var framesize = 128; + var height = 120; + var ramp = []; + for (var j = 0; j < height; j += 1) { + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); } - } else { - data.push(0); } + plot.overlay_array(ramp, { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.5, + yunits: 4, + timecode: sigplot.m.j1970toj1950(new Date("2014-07-04T00:00:00Z")), + }); } - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 16384 - }); - var cnt = 0; - ifixture.interval = window.setInterval(function() { - cnt = cnt + 1; - plot.push(lyr0, data); - - if (cnt === 100) { - plot.change_settings({ - xcmp: 2 - }); - } - }, 100); -}); - -interactiveTest('raster (ystart)', 'Does the plot start at y-axis 100?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var framesize = 128; - var height = 120; - var ramp = []; - for (var j = 0; j < height; j += 1) { - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); +); + +interactiveTest( + "raster (smoothing)", + "Is the following raster smoothed?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + rasterSmoothing: true, + }); + var framesize = 200; + var height = 100; + var ramp = []; + for (var j = 0; j < height; j += 1) { + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } } + plot.overlay_array(ramp, { + type: 2000, + subsize: framesize, + file_name: "ramp", + }); } - plot.overlay_array(ramp, { - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.5, - ystart: 100 - }); -}); - -interactiveTest('raster (timecode)', 'Do you see a raster that starts at 2014 July 4th for one hour (use "t" to check)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var framesize = 128; - var height = 120; - var ramp = []; - for (var j = 0; j < height; j += 1) { - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); +); + +interactiveTest( + "raster (smart-smoothing)", + "Is the following raster smoothed until zoomed?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + rasterSmoothing: 3.0, + }); + var framesize = 200; + var height = 100; + var ramp = []; + for (var j = 0; j < height; j += 1) { + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } } + plot.overlay_array(ramp, { + type: 2000, + subsize: framesize, + file_name: "ramp", + yunits: 4, + timecode: sigplot.m.j1970toj1950(new Date("2014-07-04T00:00:00Z")), + }); } - plot.overlay_array(ramp, { - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.5, - yunits: 4, - timecode: sigplot.m.j1970toj1950(new Date("2014-07-04T00:00:00Z")) - }); -}); - -interactiveTest('raster (smoothing)', 'Is the following raster smoothed?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - rasterSmoothing: true - }); - var framesize = 200; - var height = 100; - var ramp = []; - for (var j = 0; j < height; j += 1) { - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } +); + +interactiveTest( + "sigplot b&w penny 1", + "Do you see a b&w penny", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xc: 0, + }); + assert.notEqual(plot, null); + plot.overlay_href("dat/penny.prm"); } - plot.overlay_array(ramp, { - type: 2000, - subsize: framesize, - file_name: "ramp" - }); -}); - -interactiveTest('raster (smart-smoothing)', 'Is the following raster smoothed until zoomed?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - rasterSmoothing: 3.0 - }); - var framesize = 200; - var height = 100; - var ramp = []; - for (var j = 0; j < height; j += 1) { - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } +); +interactiveTest( + "sigplot b&w penny 2", + "Do you see a b&w penny", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + cmap: "Greyscale", + }); + assert.notEqual(plot, null); + plot.overlay_href("dat/penny.prm"); } - plot.overlay_array(ramp, { - type: 2000, - subsize: framesize, - file_name: "ramp", - yunits: 4, - timecode: sigplot.m.j1970toj1950(new Date("2014-07-04T00:00:00Z")) - }); -}); - -interactiveTest('sigplot b&w penny 1', 'Do you see a b&w penny', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xc: 0 - }); - assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); -}); -interactiveTest('sigplot b&w penny 2', 'Do you see a b&w penny', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - cmap: "Greyscale" - }); - assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); -}); -interactiveTest('sigplot b&w penny 3', 'Do you see a b&w penny', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); - plot.change_settings({ - cmap: "Greyscale" - }); -}); -interactiveTest('sigplot b&w penny 4', 'Do you see a b&w penny', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - cmap: 0 - }); - assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); -}); -interactiveTest('sigplot b&w penny 5', 'Do you see a b&w penny', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); - plot.change_settings({ - cmap: 0 - }); -}); -interactiveTest('sigplot (custom cmap) penny', 'Do you see a red penny', function(assert) { - var container = document.getElementById('plot'); - var colors = [{ - pos: 0, - red: 0, - green: 0, - blue: 0 - }, { - pos: 60, - red: 50, - green: 0, - blue: 0 - }, { - pos: 100, - red: 100, - green: 0, - blue: 0 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }, { - pos: 100, - red: 0, - green: 0, - blue: 0 - }]; - var plot = new sigplot.Plot(container, { - cmap: colors - }); - assert.notEqual(plot, null); - plot.overlay_href("dat/penny.prm"); -}); - -interactiveTest('sigplot penny (scaled)', 'Manually scale the Z-axis, does it work (i.e. all blue)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - zmin: 50, - zmax: 100 - }); - assert.notEqual(plot, null); - assert.equal(plot._Gx.zmin, 50); - assert.equal(plot._Gx.zmax, 100); - assert.equal(plot._Gx.autoz, 0); - plot.overlay_href("dat/penny.prm", function() { - assert.equal(plot._Gx.zmin, 50); - assert.equal(plot._Gx.zmax, 100); +); +interactiveTest( + "sigplot b&w penny 3", + "Do you see a b&w penny", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href("dat/penny.prm"); plot.change_settings({ - zmin: 25 + cmap: "Greyscale", }); - assert.equal(plot._Gx.zmin, 25); + } +); +interactiveTest( + "sigplot b&w penny 4", + "Do you see a b&w penny", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + cmap: 0, + }); + assert.notEqual(plot, null); + plot.overlay_href("dat/penny.prm"); + } +); +interactiveTest( + "sigplot b&w penny 5", + "Do you see a b&w penny", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href("dat/penny.prm"); plot.change_settings({ - zmax: 1000 + cmap: 0, }); - assert.equal(plot._Gx.zmax, 1000); - }); -}); - -interactiveTest('scrolling raster two pipes', 'Do you see a scrolling raster with two pipes?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - // typically when you have two raster layers you will want - // to manually fix both zmin and zmax, otherwise they will - // both be trying to adjust the zmin/zmax for autoscaling - plot.change_settings({ - zmin: -128, - zmax: 0 - }); - var framesize = 128; - var layer_0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "layer0", - ydelta: 0.25 - }); - assert.equal(plot.get_lyrn(layer_0), 0); - var layer_1 = plot.overlay_pipe({ - type: 2000, - subsize: Math.floor(framesize / 3), - file_name: "layer1", - ydelta: 0.25 - }, { - opacity: 0.5 - }); - assert.equal(plot.get_lyrn(layer_1), 1); - - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(-1 * (i + 1)); - } - plot.push(layer_0, ramp); - }, 500); - - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < Math.floor(framesize / 3); i += 1) { - ramp.push(-2 * (i + 1)); - } - plot.push(layer_1, ramp); - }, 100); -}); - -interactiveTest('scrolling raster fixed scale', 'Do you see a scrolling raster?', function(assert) { - var container = document.getElementById('plot'); - // the colors will start around 50 and max out around 100 - var plot = new sigplot.Plot(container, { - zmin: 50, - zmax: 100 - }); - assert.notEqual(plot, null); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); - -interactiveTest('scrolling raster (scaled)', 'Do you see the scaling change correctly?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - - var cnt = 0; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - cnt = cnt + 1; - if (cnt === 40) { - // After 40 lines, change the scaling changes + } +); +interactiveTest( + "sigplot (custom cmap) penny", + "Do you see a red penny", + function (assert) { + var container = document.getElementById("plot"); + var colors = [ + { + pos: 0, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 60, + red: 50, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 100, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + { + pos: 100, + red: 0, + green: 0, + blue: 0, + }, + ]; + var plot = new sigplot.Plot(container, { + cmap: colors, + }); + assert.notEqual(plot, null); + plot.overlay_href("dat/penny.prm"); + } +); + +interactiveTest( + "sigplot penny (scaled)", + "Manually scale the Z-axis, does it work (i.e. all blue)?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + zmin: 50, + zmax: 100, + }); + assert.notEqual(plot, null); + assert.equal(plot._Gx.zmin, 50); + assert.equal(plot._Gx.zmax, 100); + assert.equal(plot._Gx.autoz, 0); + plot.overlay_href("dat/penny.prm", function () { + assert.equal(plot._Gx.zmin, 50); + assert.equal(plot._Gx.zmax, 100); plot.change_settings({ - zmin: 50, - zmax: 100 + zmin: 25, }); - } - }, 100); -}); - -interactiveTest('raster (small xdelta)', 'Do you see the expected raster?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25, - xdelta: 0.0009 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); - -interactiveTest('zoomed scrolling raster', 'Do you see a scrolling raster with no render errors?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - plot.zoom({ - x: 95, - y: 0 - }, { - x: 106.9, - y: 10 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 100); -}); - -interactiveTest('xcmp raster align check', 'Do you see a line centered at 6000?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcmp: 3 - }); - assert.notEqual(plot, null); - var framesize = 9000; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "test" - }, {}); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - if (i > 5990 && i < 6010) { - ramp.push(100); - } else { - ramp.push(0); + assert.equal(plot._Gx.zmin, 25); + plot.change_settings({ + zmax: 1000, + }); + assert.equal(plot._Gx.zmax, 1000); + }); + } +); + +interactiveTest( + "scrolling raster two pipes", + "Do you see a scrolling raster with two pipes?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + // typically when you have two raster layers you will want + // to manually fix both zmin and zmax, otherwise they will + // both be trying to adjust the zmin/zmax for autoscaling + plot.change_settings({ + zmin: -128, + zmax: 0, + }); + var framesize = 128; + var layer_0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "layer0", + ydelta: 0.25, + }); + assert.equal(plot.get_lyrn(layer_0), 0); + var layer_1 = plot.overlay_pipe( + { + type: 2000, + subsize: Math.floor(framesize / 3), + file_name: "layer1", + ydelta: 0.25, + }, + { + opacity: 0.5, } - } - plot.push(lyr0, ramp); - }, 100); -}); + ); + assert.equal(plot.get_lyrn(layer_1), 1); -interactiveTest('falling raster (timecode)', 'Do you see a falling raster that starts at 2014 July 4th?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.5, // two frames a second - yunits: 4, - timecode: sigplot.m.j1970toj1950(new Date("2014-07-04T00:00:00Z")) - }, { - drawmode: "falling" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 500); -}); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(-1 * (i + 1)); + } + plot.push(layer_0, ramp); + }, 500); -interactiveTest('falling raster (timestamp)', 'Do you see a falling raster that starts at 2014 July 4th?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var now = new Date("2014-07-04T00:00:00Z"); - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.5, // two frames a second - yunits: 4 - }, { - drawmode: "falling" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp, { - timestamp: now + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < Math.floor(framesize / 3); i += 1) { + ramp.push(-2 * (i + 1)); + } + plot.push(layer_1, ramp); + }, 100); + } +); + +interactiveTest( + "scrolling raster fixed scale", + "Do you see a scrolling raster?", + function (assert) { + var container = document.getElementById("plot"); + // the colors will start around 50 and max out around 100 + var plot = new sigplot.Plot(container, { + zmin: 50, + zmax: 100, }); - now.setSeconds(now.getSeconds() + 0.5); - }, 500); -}); - -interactiveTest('rising raster (timecode)', 'Do you see a rising raster that starts at 2014 July 4th?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.5, // two frames a second - yunits: 4, - timecode: sigplot.m.j1970toj1950(new Date("2014-07-04T00:00:00Z")) - }, { - drawmode: "rising" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp); - }, 500); -}); - -interactiveTest('rising raster (timestamp)', 'Do you see a rising raster that starts at 2014 July 4th?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var now = new Date("2014-07-04T00:00:00Z"); - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.5, // two frames a second - yunits: 4 - }, { - drawmode: "rising" - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - plot.push(lyr0, ramp, { - timestamp: now + assert.notEqual(plot, null); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, }); - now.setSeconds(now.getSeconds() + 0.5); - }, 500); -}); - -interactiveTest('raster changing xstart', 'Do you see a falling raster that stays the same while the axis shifts?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - xstart: -64, - ydelta: 0.25 - }); - var xstart = 0; - var xstart_chng = 16; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - if (Math.abs(xstart) >= 64) { - xstart_chng = xstart_chng * -1; - } - xstart += xstart_chng; - plot.push(lyr0, ramp, { - xstart: xstart + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "scrolling raster (scaled)", + "Do you see the scaling change correctly?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, }); - }, 500); -}); -interactiveTest('raster changing LPS', 'Do you see a falling raster redrawn with alternating cursor speed every 10 seconds?', function(assert) { - var container = document.getElementById('plot'); - var initialLps = 50; - var alternateLps = 200; - var lpsVals = [initialLps, alternateLps]; - var currentLps = lpsVals[0]; - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr_uuid = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - xstart: 0, - ydelta: 0.25, - lps: initialLps - }); - var toggleLps = function() { - if (plot.get_layer(0).lps === lpsVals[0]) { - currentLps = lpsVals[1]; - } else { - currentLps = lpsVals[0]; - } - plot.deoverlay(lyr_uuid); - plot.overlay_pipe({ + var cnt = 0; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + cnt = cnt + 1; + if (cnt === 40) { + // After 40 lines, change the scaling changes + plot.change_settings({ + zmin: 50, + zmax: 100, + }); + } + }, 100); + } +); + +interactiveTest( + "raster (small xdelta)", + "Do you see the expected raster?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + xdelta: 0.0009, + }); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "zoomed scrolling raster", + "Do you see a scrolling raster with no render errors?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }); + plot.zoom( + { + x: 95, + y: 0, + }, + { + x: 106.9, + y: 10, + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "xcmp raster align check", + "Do you see a line centered at 6000?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcmp: 3, + }); + assert.notEqual(plot, null); + var framesize = 9000; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "test", + }, + {} + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + if (i > 5990 && i < 6010) { + ramp.push(100); + } else { + ramp.push(0); + } + } + plot.push(lyr0, ramp); + }, 100); + } +); + +interactiveTest( + "falling raster (timecode)", + "Do you see a falling raster that starts at 2014 July 4th?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.5, // two frames a second + yunits: 4, + timecode: sigplot.m.j1970toj1950( + new Date("2014-07-04T00:00:00Z") + ), + }, + { + drawmode: "falling", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 500); + } +); + +interactiveTest( + "falling raster (timestamp)", + "Do you see a falling raster that starts at 2014 July 4th?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var now = new Date("2014-07-04T00:00:00Z"); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.5, // two frames a second + yunits: 4, + }, + { + drawmode: "falling", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp, { + timestamp: now, + }); + now.setSeconds(now.getSeconds() + 0.5); + }, 500); + } +); + +interactiveTest( + "rising raster (timecode)", + "Do you see a rising raster that starts at 2014 July 4th?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.5, // two frames a second + yunits: 4, + timecode: sigplot.m.j1970toj1950( + new Date("2014-07-04T00:00:00Z") + ), + }, + { + drawmode: "rising", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp); + }, 500); + } +); + +interactiveTest( + "rising raster (timestamp)", + "Do you see a rising raster that starts at 2014 July 4th?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var now = new Date("2014-07-04T00:00:00Z"); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.5, // two frames a second + yunits: 4, + }, + { + drawmode: "rising", + } + ); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + plot.push(lyr0, ramp, { + timestamp: now, + }); + now.setSeconds(now.getSeconds() + 0.5); + }, 500); + } +); + +interactiveTest( + "raster changing xstart", + "Do you see a falling raster that stays the same while the axis shifts?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + xstart: -64, + ydelta: 0.25, + }); + var xstart = 0; + var xstart_chng = 16; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + if (Math.abs(xstart) >= 64) { + xstart_chng = xstart_chng * -1; + } + xstart += xstart_chng; + plot.push(lyr0, ramp, { + xstart: xstart, + }); + }, 500); + } +); + +interactiveTest( + "raster changing LPS", + "Do you see a falling raster redrawn with alternating cursor speed every 10 seconds?", + function (assert) { + var container = document.getElementById("plot"); + var initialLps = 50; + var alternateLps = 200; + var lpsVals = [initialLps, alternateLps]; + var currentLps = lpsVals[0]; + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, + }); + var framesize = 128; + var lyr_uuid = plot.overlay_pipe({ type: 2000, subsize: framesize, file_name: "ramp", xstart: 0, - ydelta: 0.25 + ydelta: 0.25, + lps: initialLps, }); - }; - assert.strictEqual(plot.get_layer(0).lps, initialLps); - var count = 0; - ifixture.interval = window.setInterval(function() { - count++; - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - if (count % 20 === 0) { - toggleLps(); - } - plot.push(lyr_uuid, ramp, { - lps: currentLps + var toggleLps = function () { + if (plot.get_layer(0).lps === lpsVals[0]) { + currentLps = lpsVals[1]; + } else { + currentLps = lpsVals[0]; + } + plot.deoverlay(lyr_uuid); + plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + xstart: 0, + ydelta: 0.25, + }); + }; + assert.strictEqual(plot.get_layer(0).lps, initialLps); + var count = 0; + ifixture.interval = window.setInterval(function () { + count++; + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + if (count % 20 === 0) { + toggleLps(); + } + plot.push(lyr_uuid, ramp, { + lps: currentLps, + }); + }, 500); + } +); + +interactiveTest( + "raster changing xdelta", + "Do you see a falling raster that stays the same while the axis increases?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + autol: 5, }); - }, 500); -}); - -interactiveTest('raster changing xdelta', 'Do you see a falling raster that stays the same while the axis increases?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - var xdelta = 1; - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(i + 1); - } - xdelta *= 2; - plot.push(lyr0, ramp, { - xdelta: xdelta + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, }); - }, 500); -}); - -interactiveTest('raster drawmode change (scrolling -> rising -> scrolling)', 'Do you see the scrolling line?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(-1 * (i + 1)); - } - plot.push(lyr0, ramp); - }, 100); - setTimeout(function() { + var xdelta = 1; + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(i + 1); + } + xdelta *= 2; + plot.push(lyr0, ramp, { + xdelta: xdelta, + }); + }, 500); + } +); + +interactiveTest( + "raster drawmode change (scrolling -> rising -> scrolling)", + "Do you see the scrolling line?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); plot.change_settings({ - drawmode: "rising" + autol: 5, }); - setTimeout(function() { + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(-1 * (i + 1)); + } + plot.push(lyr0, ramp); + }, 100); + setTimeout(function () { plot.change_settings({ - drawmode: "scrolling" + drawmode: "rising", }); + setTimeout(function () { + plot.change_settings({ + drawmode: "scrolling", + }); + }, 5000); }, 5000); - }, 5000); -}); - -interactiveTest('raster drawmode change (scrolling -> falling -> scrolling)', 'Do you see the scrolling line?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - autol: 5 - }); - var framesize = 128; - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: framesize, - file_name: "ramp", - ydelta: 0.25 - }); - ifixture.interval = window.setInterval(function() { - var ramp = []; - for (var i = 0; i < framesize; i += 1) { - ramp.push(-1 * (i + 1)); - } - plot.push(lyr0, ramp); - }, 100); - setTimeout(function() { + } +); + +interactiveTest( + "raster drawmode change (scrolling -> falling -> scrolling)", + "Do you see the scrolling line?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); plot.change_settings({ - drawmode: "falling" + autol: 5, }); - setTimeout(function() { + var framesize = 128; + var lyr0 = plot.overlay_pipe({ + type: 2000, + subsize: framesize, + file_name: "ramp", + ydelta: 0.25, + }); + ifixture.interval = window.setInterval(function () { + var ramp = []; + for (var i = 0; i < framesize; i += 1) { + ramp.push(-1 * (i + 1)); + } + plot.push(lyr0, ramp); + }, 100); + setTimeout(function () { plot.change_settings({ - drawmode: "scrolling" + drawmode: "falling", }); + setTimeout(function () { + plot.change_settings({ + drawmode: "scrolling", + }); + }, 5000); }, 5000); - }, 5000); -}); + } +); + +interactiveTest( + "SP format", + "Do you see a plot that looks like a checkerboard?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var bf = sigplot.m.initialize(); + bf.format = "SP"; + bf.setData(new Uint8Array([170, 85, 170, 85, 170, 85, 170, 85]).buffer); + + assert.equal(bf.dview.getBit(0), 1); + assert.equal(bf.dview.getBit(1), 0); + assert.equal(bf.dview.getBit(2), 1); + assert.equal(bf.dview.getBit(3), 0); + assert.equal(bf.dview.getBit(4), 1); + assert.equal(bf.dview.getBit(5), 0); + assert.equal(bf.dview.getBit(6), 1); + assert.equal(bf.dview.getBit(7), 0); + + assert.equal(bf.dview.getBit(56), 0); + assert.equal(bf.dview.getBit(57), 1); + assert.equal(bf.dview.getBit(58), 0); + assert.equal(bf.dview.getBit(59), 1); + assert.equal(bf.dview.getBit(60), 0); + assert.equal(bf.dview.getBit(61), 1); + assert.equal(bf.dview.getBit(62), 0); + assert.equal(bf.dview.getBit(63), 1); + + plot.overlay_bluefile(bf, { + subsize: 8, + layerType: "2D", + }); + } +); + +interactiveTest( + "B&W SP format", + "Do you see a plot that looks like a black and white checkerboard?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + cmap: 0, + }); + assert.notEqual(plot, null); + var bf = sigplot.m.initialize(); + bf.format = "SP"; + bf.setData(new Uint8Array([170, 85, 170, 85, 170, 85, 170, 85]).buffer); + + plot.overlay_bluefile(bf, { + subsize: 8, + layerType: "2D", + }); + } +); + +interactiveTest( + "SP file", + "Do you see a line plot of binary points 0 to 1?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href("dat/scalarpacked.tmp"); + } +); + +interactiveTest( + "SP file raster", + "Do you see a binary plot of random data?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.overlay_href("dat/scalarpacked.tmp", null, { + subsize: 64, + layerType: "2D", + }); + } +); -interactiveTest('SP format', 'Do you see a plot that looks like a checkerboard?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var bf = sigplot.m.initialize(); - bf.format = "SP"; - bf.setData(new Uint8Array([170, 85, 170, 85, 170, 85, 170, 85]).buffer); - - assert.equal(bf.dview.getBit(0), 1); - assert.equal(bf.dview.getBit(1), 0); - assert.equal(bf.dview.getBit(2), 1); - assert.equal(bf.dview.getBit(3), 0); - assert.equal(bf.dview.getBit(4), 1); - assert.equal(bf.dview.getBit(5), 0); - assert.equal(bf.dview.getBit(6), 1); - assert.equal(bf.dview.getBit(7), 0); - - assert.equal(bf.dview.getBit(56), 0); - assert.equal(bf.dview.getBit(57), 1); - assert.equal(bf.dview.getBit(58), 0); - assert.equal(bf.dview.getBit(59), 1); - assert.equal(bf.dview.getBit(60), 0); - assert.equal(bf.dview.getBit(61), 1); - assert.equal(bf.dview.getBit(62), 0); - assert.equal(bf.dview.getBit(63), 1); - - plot.overlay_bluefile(bf, { - subsize: 8, - layerType: "2D" - }); -}); +interactiveTest( + "Raster downscale max", + "Do you see two red lines in the middle?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); -interactiveTest('B&W SP format', 'Do you see a plot that looks like a black and white checkerboard?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - cmap: 0 - }); - assert.notEqual(plot, null); - var bf = sigplot.m.initialize(); - bf.format = "SP"; - bf.setData(new Uint8Array([170, 85, 170, 85, 170, 85, 170, 85]).buffer); - - plot.overlay_bluefile(bf, { - subsize: 8, - layerType: "2D" - }); -}); + plot.change_settings({ + cmode: "LO", + autol: 5, + }); -interactiveTest('SP file', 'Do you see a line plot of binary points 0 to 1?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/scalarpacked.tmp"); -}); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 0, + file_name: "random", + xstart: null, + xdelta: null, + }, + { + downscale: "max", + } + ); -interactiveTest('SP file raster', 'Do you see a binary plot of random data?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.overlay_href("dat/scalarpacked.tmp", null, { - subsize: 64, - layerType: "2D" - }); -}); + var hdl = window.setInterval(function () { + var random = []; + var framesize = 32768; + for (var i = 0; i < framesize; i += 1) { + random.push(Math.random() + 100); + } + random[500] = 1; + random[15990] = 1000; + random[15991] = 100; + random[15992] = 100; + random[15993] = 100; + random[15995] = 100; + random[15996] = 100; + random[15997] = 100; + random[15998] = 100; + random[15999] = 1000; + random[16000] = 1000; + random[16001] = 1000; + random[16002] = 1000; + random[18000] = 1000; + + plot.push(lyr0, random, { + subsize: framesize, + xstart: 5e6, + xdelta: 10, + }); + }, 300); + } +); -interactiveTest('Raster downscale max', 'Do you see two red lines in the middle?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - - plot.change_settings({ - cmode: 'LO', - autol: 5 - }); - - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 0, - file_name: "random", - xstart: null, - xdelta: null - }, { - downscale: "max" - }); - - var hdl = window.setInterval(function() { - var random = []; - var framesize = 32768; - for (var i = 0; i < framesize; i += 1) { - random.push(Math.random() + 100); - } - random[500] = 1; - random[15990] = 1000; - random[15991] = 100; - random[15992] = 100; - random[15993] = 100; - random[15995] = 100; - random[15996] = 100; - random[15997] = 100; - random[15998] = 100; - random[15999] = 1000; - random[16000] = 1000; - random[16001] = 1000; - random[16002] = 1000; - random[18000] = 1000; - - plot.push(lyr0, random, { - subsize: framesize, - xstart: 5e6, - xdelta: 10 - }); - }, 300); -}); +interactiveTest( + "Raster downscale min", + "Do you see one black line on the left?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); -interactiveTest('Raster downscale min', 'Do you see one black line on the left?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - - plot.change_settings({ - cmode: 'LO', - autol: 5 - }); - - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 0, - file_name: "random", - xstart: null, - xdelta: null - }, { - downscale: "min" - }); - - var hdl = window.setInterval(function() { - var random = []; - var framesize = 32768; - for (var i = 0; i < framesize; i += 1) { - random.push(Math.random() + 50); - } - random[500] = 1; - random[15990] = 1000; - random[15991] = 100; - random[15992] = 100; - random[15993] = 100; - random[15995] = 100; - random[15996] = 100; - random[15997] = 100; - random[15998] = 100; - random[15999] = 1000; - random[16000] = 1000; - random[16001] = 1000; - random[16002] = 1000; - random[18000] = 1000; - - plot.push(lyr0, random, { - subsize: framesize, - xstart: 5e6, - xdelta: 10 + plot.change_settings({ + cmode: "LO", + autol: 5, }); - }, 300); -}); -interactiveTest('Raster downscale minmax', 'Do you see one black line on the left and two red lines in the middle?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - - plot.change_settings({ - cmode: 'LO', - autol: 5 - }); - - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 0, - file_name: "random", - xstart: null, - xdelta: null - }, { - downscale: "minmax" - }); - - var hdl = window.setInterval(function() { - var random = []; - var framesize = 32768; - for (var i = 0; i < framesize; i += 1) { - random.push(Math.random() + 50); - } - random[500] = 1; - random[15990] = 1000; - random[15991] = 100; - random[15992] = 100; - random[15993] = 100; - random[15995] = 100; - random[15996] = 100; - random[15997] = 100; - random[15998] = 100; - random[15999] = 1000; - random[16000] = 1000; - random[16001] = 1000; - random[16002] = 1000; - random[18000] = 1000; - - plot.push(lyr0, random, { - subsize: framesize, - xstart: 5e6, - xdelta: 10 + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 0, + file_name: "random", + xstart: null, + xdelta: null, + }, + { + downscale: "min", + } + ); + + var hdl = window.setInterval(function () { + var random = []; + var framesize = 32768; + for (var i = 0; i < framesize; i += 1) { + random.push(Math.random() + 50); + } + random[500] = 1; + random[15990] = 1000; + random[15991] = 100; + random[15992] = 100; + random[15993] = 100; + random[15995] = 100; + random[15996] = 100; + random[15997] = 100; + random[15998] = 100; + random[15999] = 1000; + random[16000] = 1000; + random[16001] = 1000; + random[16002] = 1000; + random[18000] = 1000; + + plot.push(lyr0, random, { + subsize: framesize, + xstart: 5e6, + xdelta: 10, + }); + }, 300); + } +); + +interactiveTest( + "Raster downscale minmax", + "Do you see one black line on the left and two red lines in the middle?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + + plot.change_settings({ + cmode: "LO", + autol: 5, }); - }, 300); -}); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 0, + file_name: "random", + xstart: null, + xdelta: null, + }, + { + downscale: "minmax", + } + ); -interactiveTest('Raster downscale minmax zoom', 'Do you see a line at 16000 and 18000?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - - plot.change_settings({ - cmode: 'LO', - autol: 5 - }); - - var lyr0 = plot.overlay_pipe({ - type: 2000, - subsize: 0, - file_name: "random" - }, { - downscale: "minmax" - }); - - window.setTimeout(function() { - plot.zoom({ - x: 15000, - y: 5 - }, { - x: 19000, - y: 25 - }); - }); - - var hdl = window.setInterval(function() { - var random = []; - var framesize = 32768; - for (var i = 0; i < framesize; i += 1) { - random.push(Math.random() + 50); - } - random[500] = 1; - random[15990] = 1000; - random[15991] = 100; - random[15992] = 100; - random[15993] = 100; - random[15995] = 100; - random[15996] = 100; - random[15997] = 100; - random[15998] = 100; - random[15999] = 1000; - random[16000] = 1000; - random[16001] = 1000; - random[16002] = 1000; - random[18000] = 1000; - - plot.push(lyr0, random, { - subsize: framesize, + var hdl = window.setInterval(function () { + var random = []; + var framesize = 32768; + for (var i = 0; i < framesize; i += 1) { + random.push(Math.random() + 50); + } + random[500] = 1; + random[15990] = 1000; + random[15991] = 100; + random[15992] = 100; + random[15993] = 100; + random[15995] = 100; + random[15996] = 100; + random[15997] = 100; + random[15998] = 100; + random[15999] = 1000; + random[16000] = 1000; + random[16001] = 1000; + random[16002] = 1000; + random[18000] = 1000; + + plot.push(lyr0, random, { + subsize: framesize, + xstart: 5e6, + xdelta: 10, + }); + }, 300); + } +); + +interactiveTest( + "Raster downscale minmax zoom", + "Do you see a line at 16000 and 18000?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + + plot.change_settings({ + cmode: "LO", + autol: 5, }); - }, 300); -}); + var lyr0 = plot.overlay_pipe( + { + type: 2000, + subsize: 0, + file_name: "random", + }, + { + downscale: "minmax", + } + ); + + window.setTimeout(function () { + plot.zoom( + { + x: 15000, + y: 5, + }, + { + x: 19000, + y: 25, + } + ); + }); + + var hdl = window.setInterval(function () { + var random = []; + var framesize = 32768; + for (var i = 0; i < framesize; i += 1) { + random.push(Math.random() + 50); + } + random[500] = 1; + random[15990] = 1000; + random[15991] = 100; + random[15992] = 100; + random[15993] = 100; + random[15995] = 100; + random[15996] = 100; + random[15997] = 100; + random[15998] = 100; + random[15999] = 1000; + random[16000] = 1000; + random[16001] = 1000; + random[16002] = 1000; + random[18000] = 1000; + + plot.push(lyr0, random, { + subsize: framesize, + }); + }, 300); + } +); diff --git a/test/tests.interactive-menu.js b/test/tests.interactive-menu.js index b2c88ec..2f4b408 100644 --- a/test/tests.interactive-menu.js +++ b/test/tests.interactive-menu.js @@ -25,24 +25,32 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-menu', { +QUnit.module("sigplot-interactive-menu", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('radius menu', 'Do you see a working radius option in the traces menu?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "radius menu", + "Do you see a working radius option in the traces menu?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 25; i++) { - ramp.push(i); + var ramp = []; + for (var i = 0; i < 25; i++) { + ramp.push(i); + } + var layer = plot.overlay_array( + ramp, + { + file_name: "ramp", + }, + { + symbol: 3, + line: 0, + } + ); } - var layer = plot.overlay_array(ramp, { - file_name: "ramp" - }, { - symbol: 3, - line: 0 - }); -}); +); diff --git a/test/tests.interactive-mouse.js b/test/tests.interactive-mouse.js index 7984910..7abf828 100644 --- a/test/tests.interactive-mouse.js +++ b/test/tests.interactive-mouse.js @@ -25,136 +25,172 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-mouse', { +QUnit.module("sigplot-interactive-mouse", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('sigplot menu no mtag', 'Open the menu and move it, ensure mtag events are not alerted', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.addListener("mtag", function(evt) { - alert("Mtag occurred!"); - }); -}); +interactiveTest( + "sigplot menu no mtag", + "Open the menu and move it, ensure mtag events are not alerted", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.addListener("mtag", function (evt) { + alert("Mtag occurred!"); + }); + } +); -interactiveTest('sigplot continuous mtag', 'Ensure continuous mtag updates', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - xcnt: "continuous" - }); - assert.notEqual(plot, null); +interactiveTest( + "sigplot continuous mtag", + "Ensure continuous mtag updates", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + xcnt: "continuous", + }); + assert.notEqual(plot, null); - var output = document.createElement("p"); - output.innerHTML = ""; - ifixture.appendChild(output); - plot.addListener("mtag", function(evt) { - output.innerHTML = "X: " + evt.x.toFixed(8) + " Y: " + evt.y.toFixed(8); - }); -}); - -interactiveTest('right-click zoom', 'Can you zoom with right-click and mark with left-click?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - rightclick_rubberbox_action: "zoom", - rubberbox_action: null, - always_show_marker: true - }); - assert.notEqual(plot, null); -}); - -interactiveTest('right-click select', 'Can you select with right-click, zoom with left-click, and mark with left-click?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - rightclick_rubberbox_action: "select", - rightclick_rubberbox_mode: "horizontal", - rubberbox_action: "zoom", - always_show_marker: true - }); - assert.notEqual(plot, null); -}); + var output = document.createElement("p"); + output.innerHTML = ""; + ifixture.appendChild(output); + plot.addListener("mtag", function (evt) { + output.innerHTML = + "X: " + evt.x.toFixed(8) + " Y: " + evt.y.toFixed(8); + }); + } +); -interactiveTest('zoom-keep-marker', 'Does zooming not change the marker, but shows box size in the specs area?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - always_show_marker: true - }); - assert.notEqual(plot, null); -}); +interactiveTest( + "right-click zoom", + "Can you zoom with right-click and mark with left-click?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + rightclick_rubberbox_action: "zoom", + rubberbox_action: null, + always_show_marker: true, + }); + assert.notEqual(plot, null); + } +); -interactiveTest('Plot Mimic', 'When you zoom, unzoom, or pan on each plot, does the other plot mimic the action?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 1000; i++) { - data.push(Math.random() * 10); +interactiveTest( + "right-click select", + "Can you select with right-click, zoom with left-click, and mark with left-click?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + rightclick_rubberbox_action: "select", + rightclick_rubberbox_mode: "horizontal", + rubberbox_action: "zoom", + always_show_marker: true, + }); + assert.notEqual(plot, null); } - plot.overlay_array(data); +); - container = document.getElementById('plot2'); - container.style.display = "block"; - var plot2 = new sigplot.Plot(container, {}); - assert.notEqual(plot2, null); - data = []; - for (var i = 0; i < 1000; i++) { - data.push(Math.random() * 10); +interactiveTest( + "zoom-keep-marker", + "Does zooming not change the marker, but shows box size in the specs area?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + always_show_marker: true, + }); + assert.notEqual(plot, null); } - plot2.overlay_array(data); +); - plot.mimic(plot2, { - zoom: true, - unzoom: true, - pan: true - }); - plot2.mimic(plot, { - zoom: true, - unzoom: true, - pan: true - }); -}); +interactiveTest( + "Plot Mimic", + "When you zoom, unzoom, or pan on each plot, does the other plot mimic the action?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 1000; i++) { + data.push(Math.random() * 10); + } + plot.overlay_array(data); -interactiveTest('Plot Un-mimic', 'When you zoom, unzoom, or pan on each plot, does the other plot NOT mimic the action?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var data = []; - for (var i = 0; i < 1000; i++) { - data.push(Math.random() * 10); - } - plot.overlay_array(data); + container = document.getElementById("plot2"); + container.style.display = "block"; + var plot2 = new sigplot.Plot(container, {}); + assert.notEqual(plot2, null); + data = []; + for (var i = 0; i < 1000; i++) { + data.push(Math.random() * 10); + } + plot2.overlay_array(data); - container = document.getElementById('plot2'); - container.style.display = "block"; - var plot2 = new sigplot.Plot(container, {}); - assert.notEqual(plot2, null); - data = []; - for (var i = 0; i < 1000; i++) { - data.push(Math.random() * 10); + plot.mimic(plot2, { + zoom: true, + unzoom: true, + pan: true, + }); + plot2.mimic(plot, { + zoom: true, + unzoom: true, + pan: true, + }); } - plot2.overlay_array(data); +); - plot.mimic(plot2, { - zoom: true, - unzoom: true, - pan: true - }); - plot2.mimic(plot, { - zoom: true, - unzoom: true, - pan: true - }); - plot.unmimic(); - plot2.unmimic(); -}); +interactiveTest( + "Plot Un-mimic", + "When you zoom, unzoom, or pan on each plot, does the other plot NOT mimic the action?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var data = []; + for (var i = 0; i < 1000; i++) { + data.push(Math.random() * 10); + } + plot.overlay_array(data); -interactiveTest('dom menu', "move cursor to bottom right of plot. open menu by pressing 'm'. does the menu open and not appear to be bounded by the plot's grid", function(assert) { - var plot_options = { - useDomMenu: true - }; - var data = [1, 2, 3, 4, 5, 4, 3, 2, 1]; // the series of y-values - var plot = new sigplot.Plot(document.getElementById('plot'), plot_options); - assert.notEqual(plot, null); - plot.overlay_array(data); -}); + container = document.getElementById("plot2"); + container.style.display = "block"; + var plot2 = new sigplot.Plot(container, {}); + assert.notEqual(plot2, null); + data = []; + for (var i = 0; i < 1000; i++) { + data.push(Math.random() * 10); + } + plot2.overlay_array(data); + + plot.mimic(plot2, { + zoom: true, + unzoom: true, + pan: true, + }); + plot2.mimic(plot, { + zoom: true, + unzoom: true, + pan: true, + }); + plot.unmimic(); + plot2.unmimic(); + } +); + +interactiveTest( + "dom menu", + "move cursor to bottom right of plot. open menu by pressing 'm'. does the menu open and not appear to be bounded by the plot's grid", + function (assert) { + var plot_options = { + useDomMenu: true, + }; + var data = [1, 2, 3, 4, 5, 4, 3, 2, 1]; // the series of y-values + var plot = new sigplot.Plot( + document.getElementById("plot"), + plot_options + ); + assert.notEqual(plot, null); + plot.overlay_array(data); + } +); diff --git a/test/tests.interactive-slider.js b/test/tests.interactive-slider.js index 41c8ba2..3ac6f9c 100644 --- a/test/tests.interactive-slider.js +++ b/test/tests.interactive-slider.js @@ -25,21 +25,21 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-slider', { +QUnit.module("sigplot-interactive-slider", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('slider', 'Do you see a sliders?', function(assert) { - var container = document.getElementById('plot'); +interactiveTest("slider", "Do you see a sliders?", function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); var slider1 = new sigplot_plugins.SliderPlugin({ - name: "Slider 1" + name: "Slider 1", }); plot.add_plugin(slider1); var slider2 = new sigplot_plugins.SliderPlugin({ - name: "Slider 2" + name: "Slider 2", }); plot.add_plugin(slider2); slider1.pair(slider2); @@ -48,8 +48,8 @@ interactiveTest('slider', 'Do you see a sliders?', function(assert) { slider2.set_position(-0.5); // slidertag events happen whenever a slider is moved // programatically or by the user - plot.addListener("slidertag", function(evt) {}); + plot.addListener("slidertag", function (evt) {}); // sliderdrag events happen only when a slider is moved by // the user - plot.addListener("sliderdrag", function(evt) {}); + plot.addListener("sliderdrag", function (evt) {}); }); diff --git a/test/tests.interactive-symbols.js b/test/tests.interactive-symbols.js index fdd33b6..3a1e3ea 100644 --- a/test/tests.interactive-symbols.js +++ b/test/tests.interactive-symbols.js @@ -25,122 +25,142 @@ */ /* globals QUnit, sigplot, ColorMap, sigplot_plugins, assert, assert.strictEqual, QUnit.asyncTest, assert.notEqual, alert, BlueFileReader, start, ok, throws, interactiveBeforeEach, interactiveAfterEach, interactiveTest, fixture, ifixture */ -QUnit.module('sigplot-interactive-symbols', { +QUnit.module("sigplot-interactive-symbols", { beforeEach: interactiveBeforeEach, - afterEach: interactiveAfterEach + afterEach: interactiveAfterEach, }); -interactiveTest('sigplot triangle symbol', 'Do you see triangle symbols?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 20; i++) { - ramp.push(i); +interactiveTest( + "sigplot triangle symbol", + "Do you see triangle symbols?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 20; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, null, { + name: "x", + symbol: 6, + line: 0, + }); } - plot.overlay_array(ramp, null, { - name: "x", - symbol: 6, - line: 0 - }); -}); +); -interactiveTest('sigplot custom symbol', 'Do you see custom symbols, alternating RGB?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "sigplot custom symbol", + "Do you see custom symbols, alternating RGB?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - function custom_symbol(ctx, i, x, y) { - var n = (i % 3); - if (n === 0) { - ctx.strokeStyle = "red"; - ctx.fillStyle = "red"; - } else if (n === 1) { - ctx.strokeStyle = "green"; - ctx.fillStyle = "green"; - } else if (n === 2) { - ctx.strokeStyle = "blue"; - ctx.fillStyle = "blue"; + function custom_symbol(ctx, i, x, y) { + var n = i % 3; + if (n === 0) { + ctx.strokeStyle = "red"; + ctx.fillStyle = "red"; + } else if (n === 1) { + ctx.strokeStyle = "green"; + ctx.fillStyle = "green"; + } else if (n === 2) { + ctx.strokeStyle = "blue"; + ctx.fillStyle = "blue"; + } + ctx.beginPath(); + ctx.arc(x, y, 2, 0, 360); + ctx.fill(); + ctx.stroke(); } - ctx.beginPath(); - ctx.arc(x, y, 2, 0, 360); - ctx.fill(); - ctx.stroke(); - } - var ramp = []; - for (var i = 0; i < 20; i++) { - ramp.push(i); + var ramp = []; + for (var i = 0; i < 20; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, null, { + name: "x", + symbol: custom_symbol, + line: 0, + }); } - plot.overlay_array(ramp, null, { - name: "x", - symbol: custom_symbol, - line: 0 - }); -}); +); -interactiveTest('sigplot custom symbol complex', 'Do you see custom symbols in RGB order (groups of 3)?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, { - cmode: "RI" - }); - assert.notEqual(plot, null); +interactiveTest( + "sigplot custom symbol complex", + "Do you see custom symbols in RGB order (groups of 3)?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, { + cmode: "RI", + }); + assert.notEqual(plot, null); - function custom_symbol(ctx, i, x, y) { - var n = (i % 3); - if (n === 0) { - ctx.strokeStyle = "red"; - ctx.fillStyle = "red"; - } else if (n === 1) { - ctx.strokeStyle = "green"; - ctx.fillStyle = "green"; - } else if (n === 2) { - ctx.strokeStyle = "blue"; - ctx.fillStyle = "blue"; + function custom_symbol(ctx, i, x, y) { + var n = i % 3; + if (n === 0) { + ctx.strokeStyle = "red"; + ctx.fillStyle = "red"; + } else if (n === 1) { + ctx.strokeStyle = "green"; + ctx.fillStyle = "green"; + } else if (n === 2) { + ctx.strokeStyle = "blue"; + ctx.fillStyle = "blue"; + } + ctx.beginPath(); + ctx.arc(x, y, 2, 0, 360); + ctx.fill(); + ctx.stroke(); } - ctx.beginPath(); - ctx.arc(x, y, 2, 0, 360); - ctx.fill(); - ctx.stroke(); + // make it so the line is RRRGGGBBB + var ramp = [1, 1, 4, 4, 7, 7, 2, 2, 5, 5, 8, 8, 3, 3, 6, 6, 9, 9]; + plot.overlay_array( + ramp, + { + format: "CF", + }, + { + name: "x", + symbol: custom_symbol, + line: 0, + } + ); } - // make it so the line is RRRGGGBBB - var ramp = [1, 1, 4, 4, 7, 7, 2, 2, 5, 5, 8, 8, 3, 3, 6, 6, 9, 9]; - plot.overlay_array(ramp, { - format: "CF" - }, { - name: "x", - symbol: custom_symbol, - line: 0 - }); -}); +); -interactiveTest('sigplot custom symbol-line', 'Do you see custom symbols?', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); +interactiveTest( + "sigplot custom symbol-line", + "Do you see custom symbols?", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); - function custom_symbol(ctx, i, x, y) { - var n = (i % 3); - if (n === 0) { - ctx.strokeStyle = "red"; - ctx.fillStyle = "red"; - } else if (n === 1) { - ctx.strokeStyle = "green"; - ctx.fillStyle = "green"; - } else if (n === 2) { - ctx.strokeStyle = "blue"; - ctx.fillStyle = "blue"; + function custom_symbol(ctx, i, x, y) { + var n = i % 3; + if (n === 0) { + ctx.strokeStyle = "red"; + ctx.fillStyle = "red"; + } else if (n === 1) { + ctx.strokeStyle = "green"; + ctx.fillStyle = "green"; + } else if (n === 2) { + ctx.strokeStyle = "blue"; + ctx.fillStyle = "blue"; + } + ctx.beginPath(); + ctx.arc(x, y, 2, 0, 360); + ctx.fill(); + ctx.stroke(); } - ctx.beginPath(); - ctx.arc(x, y, 2, 0, 360); - ctx.fill(); - ctx.stroke(); - } - var ramp = []; - for (var i = 0; i < 20; i++) { - ramp.push(i); + var ramp = []; + for (var i = 0; i < 20; i++) { + ramp.push(i); + } + plot.overlay_array(ramp, null, { + name: "x", + symbol: custom_symbol, + }); } - plot.overlay_array(ramp, null, { - name: "x", - symbol: custom_symbol - }); -}); +); diff --git a/test/tests.js b/test/tests.js index 1e4a93a..3bd716a 100644 --- a/test/tests.js +++ b/test/tests.js @@ -39,7 +39,7 @@ function interactiveTest(testName, msg, callback) { if (!ifixture) { return; } - var wrapped_callback = function(assert) { + var wrapped_callback = function (assert) { var done = assert.async(); callback(assert); @@ -48,15 +48,20 @@ function interactiveTest(testName, msg, callback) { var toolbar = document.getElementById("qunit-testrunner-toolbar"); var question = document.createElement("div"); toolbar.appendChild(question); - question.innerHTML = "" + "" + "" + msg + "?"; + question.innerHTML = + "" + + "" + + "" + + msg + + "?"; var askOkYes = document.getElementById("askOkYes"); - askOkYes.onclick = function() { + askOkYes.onclick = function () { question.innerHTML = ""; assert.ok(true, msg); done(); }; var askOkNo = document.getElementById("askOkNo"); - askOkNo.onclick = function() { + askOkNo.onclick = function () { question.innerHTML = ""; assert.ok(false, msg); done(); @@ -69,7 +74,7 @@ function interactiveTest(testName, msg, callback) { } function interactiveBeforeEach() { - ifixture.innerHTML = ''; + ifixture.innerHTML = ""; var plotdiv = document.createElement("div"); plotdiv.id = "plot"; plotdiv.style.margin = "0 auto"; @@ -86,7 +91,7 @@ function interactiveBeforeEach() { } function interactiveAfterEach() { - ifixture.innerHTML = ''; + ifixture.innerHTML = ""; if (ifixture.interval) { window.clearInterval(ifixture.interval); ifixture.interval = undefined; diff --git a/test/tests.m.js b/test/tests.m.js index ff48a53..fd4697c 100644 --- a/test/tests.m.js +++ b/test/tests.m.js @@ -28,11 +28,11 @@ ////////////////////////////////////////////////////////////////////////////// // QUnit 'm' module ////////////////////////////////////////////////////////////////////////////// -QUnit.module('m', { - setup: function() {}, - teardown: function() {} +QUnit.module("m", { + setup: function () {}, + teardown: function () {}, }); -QUnit.test('m sec2tod test', function(assert) { +QUnit.test("m sec2tod test", function (assert) { var secs = 0; assert.equal(sigplot.m.sec2tod(0), "00:00:00.000000"); assert.equal(sigplot.m.sec2tod(1), "00:00:01.000000"); @@ -64,6 +64,12 @@ QUnit.test('m sec2tod test', function(assert) { assert.equal(sigplot.m.sec2tod(86400.5, true), "1::00:00:00.5"); assert.equal(sigplot.m.sec2tod(31535999.5, true), "364::23:59:59.5"); assert.equal(sigplot.m.sec2tod(-31535999.5, true), "-364::23:59:59.5"); - assert.equal(sigplot.m.sec2tod(-31536000.5, true), "1948:12:31::23:59:59.5"); - assert.equal(sigplot.m.sec2tod(-31536001.5, true), "1948:12:31::23:59:58.5"); + assert.equal( + sigplot.m.sec2tod(-31536000.5, true), + "1948:12:31::23:59:59.5" + ); + assert.equal( + sigplot.m.sec2tod(-31536001.5, true), + "1948:12:31::23:59:58.5" + ); }); diff --git a/test/tests.mx.js b/test/tests.mx.js index 1946539..25056f6 100644 --- a/test/tests.mx.js +++ b/test/tests.mx.js @@ -28,35 +28,37 @@ ////////////////////////////////////////////////////////////////////////////// // QUnit 'mx' module ////////////////////////////////////////////////////////////////////////////// -QUnit.module('mx', { - setup: function() {}, - teardown: function() {} +QUnit.module("mx", { + setup: function () {}, + teardown: function () {}, }); -QUnit.test('mx format_f', function(assert) { +QUnit.test("mx format_f", function (assert) { // the toFixed() function is limited to 0-20 assert.equal(sigplot.mx.format_f(1.0, 0, -1), "1"); assert.equal(sigplot.mx.format_f(1.0, 0, 21), "1.00000000000000000000"); assert.equal(sigplot.mx.format_f(1.0, 0, 1), "1.0"); assert.equal(sigplot.mx.format_f(1.0, 0, 20), "1.00000000000000000000"); }); -QUnit.test('mx real_to_pixel test', function(assert) { +QUnit.test("mx real_to_pixel test", function (assert) { var Mx = { origin: 1, x: 0, y: 0, level: 0, - stk: [{ - xmin: -1, - xmax: 1, - ymin: -1, - ymax: 1, - xscl: 1 / 100, - yscl: 1 / 100, - x1: 0, - y1: 0, - x2: 200, - y2: 200 - }] + stk: [ + { + xmin: -1, + xmax: 1, + ymin: -1, + ymax: 1, + xscl: 1 / 100, + yscl: 1 / 100, + x1: 0, + y1: 0, + x2: 200, + y2: 200, + }, + ], }; var result = sigplot.mx.real_to_pixel(Mx, 0, 0); assert.equal(result.x, 100); diff --git a/test/tests.sigplot.js b/test/tests.sigplot.js index e675f4c..1c29495 100644 --- a/test/tests.sigplot.js +++ b/test/tests.sigplot.js @@ -29,8 +29,8 @@ ////////////////////////////////////////////////////////////////////////////// // QUnit 'sigplot' module ////////////////////////////////////////////////////////////////////////////// -QUnit.module('sigplot', { - beforeEach: function() { +QUnit.module("sigplot", { + beforeEach: function () { var plotdiv = document.createElement("div"); plotdiv.id = "plot"; plotdiv.style.position = "absolute"; @@ -38,12 +38,12 @@ QUnit.module('sigplot', { plotdiv.style.height = "400px"; fixture.appendChild(plotdiv); }, - afterEach: function() { - fixture.innerHTML = ''; - } + afterEach: function () { + fixture.innerHTML = ""; + }, }); -QUnit.test('sigplot construction', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot construction", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container, {}); @@ -60,13 +60,13 @@ QUnit.test('sigplot construction', function(assert) { assert.equal(plot._Mx.wid_canvas.height, 400); assert.equal(plot._Mx.wid_canvas.style.position, "absolute"); }); -QUnit.test('sigplot refresh_after', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot refresh_after", function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); plot._Mx._syncRender = true; var refreshCount = 0; - plot._refresh = function() { + plot._refresh = function () { refreshCount += 1; }; @@ -76,46 +76,37 @@ QUnit.test('sigplot refresh_after', function(assert) { // during refresh_after, refresh calls are ignored and only // one refresh is called at the end - plot.refresh_after( - function(thePlot) { - thePlot.refresh(); - thePlot.refresh(); - } - ); + plot.refresh_after(function (thePlot) { + thePlot.refresh(); + thePlot.refresh(); + }); assert.equal(refreshCount, 2); // refresh_after is safe for reentrant calls - plot.refresh_after( - function(thePlot) { - thePlot.refresh_after(function(thePlot2) { - thePlot2.refresh(); - }); - thePlot.refresh_after(function(thePlot2) { - thePlot2.refresh(); - }); - } - ); + plot.refresh_after(function (thePlot) { + thePlot.refresh_after(function (thePlot2) { + thePlot2.refresh(); + }); + thePlot.refresh_after(function (thePlot2) { + thePlot2.refresh(); + }); + }); assert.equal(refreshCount, 3); // refresh_after guarantees a refresh, even with an error, but does // not swallow the error - assert.throws( - function() { - plot.refresh_after( - function(thePlot) { - throw "An Error"; - } - ); - } - ); + assert.throws(function () { + plot.refresh_after(function (thePlot) { + throw "An Error"; + }); + }); assert.equal(refreshCount, 4); - }); // Demonstrate that changing the ymin/ymax settings // will implicitly change the autoy settings -QUnit.test('sigplot layer1d change_settings ymin/ymax ', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot layer1d change_settings ymin/ymax ", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); @@ -127,7 +118,6 @@ QUnit.test('sigplot layer1d change_settings ymin/ymax ', function(assert) { assert.equal(plot._Gx.ymax, 1.0); assert.equal(plot._Gx.autoy, 3); - var pulse = []; for (var i = 0; i <= 1000; i += 1) { pulse.push(0.0); @@ -141,14 +131,14 @@ QUnit.test('sigplot layer1d change_settings ymin/ymax ', function(assert) { assert.equal(plot._Gx.autoy, 3); plot.change_settings({ - ymin: -50 + ymin: -50, }); assert.equal(plot._Gx.ymin, -50); assert.equal(plot._Gx.ymax, 10.2); assert.equal(plot._Gx.autoy, 2); plot.change_settings({ - ymax: 100 + ymax: 100, }); assert.equal(plot._Gx.ymin, -50); assert.equal(plot._Gx.ymax, 100); @@ -156,21 +146,21 @@ QUnit.test('sigplot layer1d change_settings ymin/ymax ', function(assert) { plot.change_settings({ ymin: 10, - ymax: 50 + ymax: 50, }); assert.equal(plot._Gx.ymin, 10); assert.equal(plot._Gx.ymax, 50); assert.equal(plot._Gx.autoy, 0); plot.change_settings({ - ymin: null + ymin: null, }); assert.equal(plot._Gx.ymin, -0.2); assert.equal(plot._Gx.ymax, 50); assert.equal(plot._Gx.autoy, 1); plot.change_settings({ - ymax: null + ymax: null, }); assert.equal(plot._Gx.ymin, -0.2); assert.equal(plot._Gx.ymax, 10.2); @@ -178,7 +168,7 @@ QUnit.test('sigplot layer1d change_settings ymin/ymax ', function(assert) { plot.change_settings({ ymin: -100, - ymax: 200 + ymax: 200, }); assert.equal(plot._Gx.ymin, -100); assert.equal(plot._Gx.ymax, 200); @@ -186,7 +176,7 @@ QUnit.test('sigplot layer1d change_settings ymin/ymax ', function(assert) { plot.change_settings({ ymin: -10, - ymax: 20 + ymax: 20, }); assert.equal(plot._Gx.ymin, -10); assert.equal(plot._Gx.ymax, 20); @@ -194,24 +184,24 @@ QUnit.test('sigplot layer1d change_settings ymin/ymax ', function(assert) { plot.change_settings({ ymin: null, - ymax: null + ymax: null, }); assert.equal(plot._Gx.ymin, -0.2); assert.equal(plot._Gx.ymax, 10.2); assert.equal(plot._Gx.autoy, 3); }); -QUnit.test('Cmode input test', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("Cmode input test", function (assert) { + var container = document.getElementById("plot"); // constructor accept integers var plot = new sigplot.Plot(container, { - cmode: 3 + cmode: 3, }); assert.equal(plot._Gx.cmode, 3); // or string var plot = new sigplot.Plot(container, { - cmode: "PH" + cmode: "PH", }); assert.equal(plot._Gx.cmode, 2); @@ -223,75 +213,74 @@ QUnit.test('Cmode input test', function(assert) { plot.overlay_array(ramp, null, { name: "x", symbol: 1, - line: 0 + line: 0, }); - plot.change_settings({ - cmode: "Magnitude" + cmode: "Magnitude", }); assert.equal(plot._Gx.cmode, 1); plot.change_settings({ - cmode: "Phase" + cmode: "Phase", }); assert.equal(plot._Gx.cmode, 2); plot.change_settings({ - cmode: "Real" + cmode: "Real", }); assert.equal(plot._Gx.cmode, 3); plot.change_settings({ - cmode: "Imaginary" + cmode: "Imaginary", }); assert.equal(plot._Gx.cmode, 4); plot.change_settings({ - cmode: "Imag/Real" + cmode: "Imag/Real", }); assert.equal(plot._Gx.cmode, 5); plot.change_settings({ - cmode: "Real/Imag" + cmode: "Real/Imag", }); assert.equal(plot._Gx.cmode, 5); plot.change_settings({ - cmode: "10*log10" + cmode: "10*log10", }); assert.equal(plot._Gx.cmode, 6); plot.change_settings({ - cmode: "20*log10" + cmode: "20*log10", }); assert.equal(plot._Gx.cmode, 7); plot.change_settings({ - cmode: 1 + cmode: 1, }); assert.equal(plot._Gx.cmode, 1); plot.change_settings({ - cmode: 2 + cmode: 2, }); assert.equal(plot._Gx.cmode, 2); plot.change_settings({ - cmode: 3 + cmode: 3, }); assert.equal(plot._Gx.cmode, 3); plot.change_settings({ - cmode: 4 + cmode: 4, }); assert.equal(plot._Gx.cmode, 4); plot.change_settings({ - cmode: 5 + cmode: 5, }); assert.equal(plot._Gx.cmode, 5); plot.change_settings({ - cmode: 6 + cmode: 6, }); assert.equal(plot._Gx.cmode, 6); plot.change_settings({ - cmode: 7 + cmode: 7, }); assert.equal(plot._Gx.cmode, 7); }); -QUnit.test('sigplot layer1d noautoscale', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot layer1d noautoscale", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container, {}); @@ -380,12 +369,12 @@ QUnit.test('sigplot layer1d autoscale negative', function(assert) { } }); */ -QUnit.test('sigplot layer1d autoscale xpad', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot layer1d autoscale xpad", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container, { - panxpad: 20 + panxpad: 20, }); assert.notEqual(plot, null); var pulse = []; @@ -401,12 +390,12 @@ QUnit.test('sigplot layer1d autoscale xpad', function(assert) { assert.equal(plot._Gx.panymin, -61); assert.equal(plot._Gx.panymax, -9); }); -QUnit.test('sigplot layer1d autoscale xpad %', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot layer1d autoscale xpad %", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container, { - panxpad: "20%" + panxpad: "20%", }); assert.notEqual(plot, null); var pulse = []; @@ -422,12 +411,12 @@ QUnit.test('sigplot layer1d autoscale xpad %', function(assert) { assert.equal(plot._Gx.panymin, -61); assert.equal(plot._Gx.panymax, -9); }); -QUnit.test('sigplot layer1d autoscaley pad', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot layer1d autoscaley pad", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container, { - panypad: 20 + panypad: 20, }); assert.notEqual(plot, null); var pulse = []; @@ -443,12 +432,12 @@ QUnit.test('sigplot layer1d autoscaley pad', function(assert) { assert.equal(plot._Gx.panymin, -81); assert.equal(plot._Gx.panymax, 11); }); -QUnit.test('sigplot layer1d autoscale ypad %', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot layer1d autoscale ypad %", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container, { - panypad: "20%" + panypad: "20%", }); assert.notEqual(plot, null); var pulse = []; @@ -464,8 +453,8 @@ QUnit.test('sigplot layer1d autoscale ypad %', function(assert) { assert.close(plot._Gx.panymin, -71.4, 0.0001); assert.close(plot._Gx.panymax, 1.4, 0.0001); }); -QUnit.test('sigplot 0px height', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot 0px height", function (assert) { + var container = document.getElementById("plot"); container.style.height = "0px"; assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); @@ -482,14 +471,14 @@ QUnit.test('sigplot 0px height', function(assert) { assert.equal(plot.get_layer(0), null); lyr_uuid = plot.overlay_array(zeros, { type: 2000, - subsize: zeros.length + subsize: zeros.length, }); assert.notEqual(plot.get_layer(0), null); plot.deoverlay(); assert.equal(plot.get_layer(0), null); lyr_uuid = plot.overlay_pipe({ type: 2000, - subsize: 128 + subsize: 128, }); assert.notEqual(plot.get_layer(0), null); assert.equal(plot.get_layer(0).drawmode, "scrolling"); @@ -497,24 +486,30 @@ QUnit.test('sigplot 0px height', function(assert) { assert.equal(plot.get_layer(0).position, 0); assert.equal(plot.get_layer(0).lps, 1); plot.deoverlay(); - lyr_uuid = plot.overlay_pipe({ - type: 2000, - subsize: 128 - }, { - drawmode: "rising" - }); + lyr_uuid = plot.overlay_pipe( + { + type: 2000, + subsize: 128, + }, + { + drawmode: "rising", + } + ); assert.notEqual(plot.get_layer(0), null); assert.equal(plot.get_layer(0).drawmode, "rising"); plot.push(lyr_uuid, zeros, null, true); assert.equal(plot.get_layer(0).position, 0); assert.equal(plot.get_layer(0).lps, 1); plot.deoverlay(); - lyr_uuid = plot.overlay_pipe({ - type: 2000, - subsize: 128 - }, { - drawmode: "falling" - }); + lyr_uuid = plot.overlay_pipe( + { + type: 2000, + subsize: 128, + }, + { + drawmode: "falling", + } + ); assert.notEqual(plot.get_layer(0), null); assert.equal(plot.get_layer(0).drawmode, "falling"); plot.push(lyr_uuid, zeros, null, true); @@ -523,8 +518,8 @@ QUnit.test('sigplot 0px height', function(assert) { assert.equal(plot.get_layer(0).lps, 1); plot.deoverlay(); }); -QUnit.test('sigplot resize raster 0px height', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot resize raster 0px height", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container); @@ -536,7 +531,7 @@ QUnit.test('sigplot resize raster 0px height', function(assert) { } var lyr_uuid = plot.overlay_pipe({ type: 2000, - subsize: 128 + subsize: 128, }); assert.notEqual(plot.get_layer(0), null); assert.equal(plot.get_layer(0).drawmode, "scrolling"); @@ -555,8 +550,8 @@ QUnit.test('sigplot resize raster 0px height', function(assert) { plot.push(lyr_uuid, zeros, null, true); assert.equal(plot.get_layer(0).position, 0); }); -QUnit.test('sigplot resize raster larger height', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot resize raster larger height", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container); @@ -566,12 +561,15 @@ QUnit.test('sigplot resize raster larger height', function(assert) { for (var i = 0; i <= 128; i += 1) { zeros.push(0.0); } - var lyr_uuid = plot.overlay_pipe({ - type: 2000, - subsize: 128 - }, { - drawmode: "scrolling" - }); + var lyr_uuid = plot.overlay_pipe( + { + type: 2000, + subsize: 128, + }, + { + drawmode: "scrolling", + } + ); assert.notEqual(plot.get_layer(0), null); assert.equal(plot.get_layer(0).drawmode, "scrolling"); plot.push(lyr_uuid, zeros, null, true); @@ -593,8 +591,8 @@ QUnit.test('sigplot resize raster larger height', function(assert) { plot.push(lyr_uuid, zeros, null, true); } }); -QUnit.test('sigplot change raster LPS', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot change raster LPS", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container); @@ -607,18 +605,23 @@ QUnit.test('sigplot change raster LPS', function(assert) { type: 2000, subsize: 128, lps: 100, - pipe: true + pipe: true, }); assert.notEqual(plot.get_layer(0), null); assert.strictEqual(plot.get_layer(0).lps, 100); - plot.push(lyr_uuid, zeros, { - lps: 200 - }, true); + plot.push( + lyr_uuid, + zeros, + { + lps: 200, + }, + true + ); plot._refresh(); assert.strictEqual(plot.get_layer(0).lps, 200); }); -QUnit.test('Add and remove plugins', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("Add and remove plugins", function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); var zeros = []; @@ -629,7 +632,7 @@ QUnit.test('Add and remove plugins', function(assert) { type: 2000, subsize: 128, lps: 100, - pipe: true + pipe: true, }); var accordion = new sigplot_plugins.AccordionPlugin({ draw_center_line: true, @@ -637,8 +640,8 @@ QUnit.test('Add and remove plugins', function(assert) { draw_edge_lines: true, direction: "vertical", edge_line_style: { - strokeStyle: "#FF2400" - } + strokeStyle: "#FF2400", + }, }); assert.equal(plot._Gx.plugins.length, 0, "Expected zero plugins"); plot.add_plugin(accordion, 1); @@ -646,93 +649,155 @@ QUnit.test('Add and remove plugins', function(assert) { plot.remove_plugin(accordion); assert.equal(plot._Gx.plugins.length, 0, "Expected zero plugins"); }); -QUnit.test('Plugins still exist after plot and canvas height and width are 0', function(assert) { - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - plot.change_settings({ - xmin: -4, - xmax: 10 - }); - var positions = [0.0, 5.0, 9.0, 3.0]; - for (var pos = 0; pos < positions.length; ++pos) { - var slider = new sigplot_plugins.SliderPlugin({ - style: { - strokeStyle: "#FF0000" - } +QUnit.test( + "Plugins still exist after plot and canvas height and width are 0", + function (assert) { + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + plot.change_settings({ + xmin: -4, + xmax: 10, }); - plot.add_plugin(slider, 1); - slider.set_position(positions[pos]); - } - plot.checkresize(); - assert.equal(plot._Gx.plugins.length, 4, "Expected 4 slider plugins"); - assert.equal(plot._Mx.canvas.height, container.clientHeight, "Expected plot canvas height to be container width"); - assert.equal(plot._Mx.canvas.width, container.clientWidth, "Expected plot canvas width to be container height"); - for (var pos = 0; pos < positions.length; ++pos) { - assert.equal(plot._Gx.plugins[pos].canvas.height, plot._Mx.canvas.height, "Expected #" + pos + " slider plugin height to be plot height"); - assert.equal(plot._Gx.plugins[pos].canvas.width, plot._Mx.canvas.width, "Expected #" + pos + " slider plugin width to be plot width"); - } - container.style.display = "none"; - plot.checkresize(); - plot._refresh(); // force syncronous refresh - assert.equal(plot._Mx.canvas.height, 0, "Expected plot canvas height to be 0"); - assert.equal(plot._Mx.canvas.width, 0, "Expected plot canvas width to be 0"); - for (var pos = 0; pos < positions.length; ++pos) { - assert.equal(plot._Gx.plugins[pos].canvas.height, 0, "Expected #" + pos + " slider plugin height to be 0"); - assert.equal(plot._Gx.plugins[pos].canvas.width, 0, "Expected #" + pos + " slider plugin width to be 0"); - } - container.style.display = "block"; - plot.checkresize(); - plot._refresh(); // force syncronous refresh - assert.equal(plot._Mx.canvas.height, container.clientHeight, "Expected plot canvas height to be container width"); - assert.equal(plot._Mx.canvas.width, container.clientWidth, "Expected plot canvas width to be container height"); - for (var pos = 0; pos < positions.length; ++pos) { - assert.equal(plot._Gx.plugins[pos].canvas.height, plot._Mx.canvas.height, "Expected #" + pos + " slider plugin height to be plot height"); - assert.equal(plot._Gx.plugins[pos].canvas.width, plot._Mx.canvas.width, "Expected #" + pos + " slider plugin width to be plot width"); + var positions = [0.0, 5.0, 9.0, 3.0]; + for (var pos = 0; pos < positions.length; ++pos) { + var slider = new sigplot_plugins.SliderPlugin({ + style: { + strokeStyle: "#FF0000", + }, + }); + plot.add_plugin(slider, 1); + slider.set_position(positions[pos]); + } + plot.checkresize(); + assert.equal(plot._Gx.plugins.length, 4, "Expected 4 slider plugins"); + assert.equal( + plot._Mx.canvas.height, + container.clientHeight, + "Expected plot canvas height to be container width" + ); + assert.equal( + plot._Mx.canvas.width, + container.clientWidth, + "Expected plot canvas width to be container height" + ); + for (var pos = 0; pos < positions.length; ++pos) { + assert.equal( + plot._Gx.plugins[pos].canvas.height, + plot._Mx.canvas.height, + "Expected #" + pos + " slider plugin height to be plot height" + ); + assert.equal( + plot._Gx.plugins[pos].canvas.width, + plot._Mx.canvas.width, + "Expected #" + pos + " slider plugin width to be plot width" + ); + } + container.style.display = "none"; + plot.checkresize(); + plot._refresh(); // force syncronous refresh + assert.equal( + plot._Mx.canvas.height, + 0, + "Expected plot canvas height to be 0" + ); + assert.equal( + plot._Mx.canvas.width, + 0, + "Expected plot canvas width to be 0" + ); + for (var pos = 0; pos < positions.length; ++pos) { + assert.equal( + plot._Gx.plugins[pos].canvas.height, + 0, + "Expected #" + pos + " slider plugin height to be 0" + ); + assert.equal( + plot._Gx.plugins[pos].canvas.width, + 0, + "Expected #" + pos + " slider plugin width to be 0" + ); + } + container.style.display = "block"; + plot.checkresize(); + plot._refresh(); // force syncronous refresh + assert.equal( + plot._Mx.canvas.height, + container.clientHeight, + "Expected plot canvas height to be container width" + ); + assert.equal( + plot._Mx.canvas.width, + container.clientWidth, + "Expected plot canvas width to be container height" + ); + for (var pos = 0; pos < positions.length; ++pos) { + assert.equal( + plot._Gx.plugins[pos].canvas.height, + plot._Mx.canvas.height, + "Expected #" + pos + " slider plugin height to be plot height" + ); + assert.equal( + plot._Gx.plugins[pos].canvas.width, + plot._Mx.canvas.width, + "Expected #" + pos + " slider plugin width to be plot width" + ); + } } -}); +); + +QUnit.test( + "unit strings test: x -> Power and y -> Angle rad", + function (assert) { + var container = document.getElementById("plot"); + var container = document.getElementById("plot"); + var plot = new sigplot.Plot(container, {}); + assert.notEqual(plot, null); + var ramp = []; + for (var i = 0; i < 20; i++) { + ramp.push(i); + } + var lyr_uuid = plot.overlay_array( + ramp, + { + xunits: "Power", + yunits: "Angle rad", + }, + { + name: "x", + symbol: 1, + line: 0, + } + ); -QUnit.test('unit strings test: x -> Power and y -> Angle rad', function(assert) { - var container = document.getElementById('plot'); - var container = document.getElementById('plot'); - var plot = new sigplot.Plot(container, {}); - assert.notEqual(plot, null); - var ramp = []; - for (var i = 0; i < 20; i++) { - ramp.push(i); + assert.equal(plot._Gx.HCB_UUID[lyr_uuid].xunits, 12); + assert.equal(plot._Gx.HCB_UUID[lyr_uuid].yunits, 33); + assert.equal(plot._Gx.xlab, 12); + assert.equal(plot._Gx.ylab, 33); } - var lyr_uuid = plot.overlay_array(ramp, { - xunits: "Power", - yunits: "Angle rad" - }, { - name: "x", - symbol: 1, - line: 0 - }); - - assert.equal(plot._Gx.HCB_UUID[lyr_uuid].xunits, 12); - assert.equal(plot._Gx.HCB_UUID[lyr_uuid].yunits, 33); - assert.equal(plot._Gx.xlab, 12); - assert.equal(plot._Gx.ylab, 33); -}); +); -QUnit.test('unit strings test: x -> Hz and y -> Time_sec', function(assert) { - var container = document.getElementById('plot'); - var container = document.getElementById('plot'); +QUnit.test("unit strings test: x -> Hz and y -> Time_sec", function (assert) { + var container = document.getElementById("plot"); + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); var ramp = []; for (var i = 0; i < 20; i++) { ramp.push(i); } - var lyr_uuid = plot.overlay_array(ramp, { - xunits: "Hz", - yunits: "Time_sec" - }, { - name: "x", - symbol: 1, - line: 0 - }); + var lyr_uuid = plot.overlay_array( + ramp, + { + xunits: "Hz", + yunits: "Time_sec", + }, + { + name: "x", + symbol: 1, + line: 0, + } + ); assert.equal(plot._Gx.HCB_UUID[lyr_uuid].xunits, 3); assert.equal(plot._Gx.HCB_UUID[lyr_uuid].yunits, 1); @@ -740,8 +805,8 @@ QUnit.test('unit strings test: x -> Hz and y -> Time_sec', function(assert) { assert.equal(plot._Gx.ylab, 1); }); -QUnit.test('sigplot line push smaller than framesize', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot line push smaller than framesize", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container); @@ -751,12 +816,15 @@ QUnit.test('sigplot line push smaller than framesize', function(assert) { for (var i = 0; i < 128; i += 1) { zeros.push(0.0); } - var lyr_uuid = plot.overlay_pipe({ - type: 2000, - subsize: 64 - }, { - layerType: sigplot.Layer1D - }); + var lyr_uuid = plot.overlay_pipe( + { + type: 2000, + subsize: 64, + }, + { + layerType: sigplot.Layer1D, + } + ); assert.notEqual(plot.get_layer(0), null); // the pipe should start empty @@ -782,8 +850,8 @@ QUnit.test('sigplot line push smaller than framesize', function(assert) { assert.equal(hcb.dview.length - hcb.data_free, 0); }); -QUnit.test('sigplot raster push smaller than framesize', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot raster push smaller than framesize", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container); @@ -795,7 +863,7 @@ QUnit.test('sigplot raster push smaller than framesize', function(assert) { } var lyr_uuid = plot.overlay_pipe({ type: 2000, - subsize: 64 + subsize: 64, }); assert.notEqual(plot.get_layer(0), null); @@ -821,8 +889,8 @@ QUnit.test('sigplot raster push smaller than framesize', function(assert) { plot.push(lyr_uuid, zeros, null, true); assert.equal(hcb.dview.length - hcb.data_free, 1); }); -QUnit.test('sigplot layer user_data', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("sigplot layer user_data", function (assert) { + var container = document.getElementById("plot"); assert.equal(container.childNodes.length, 0); assert.equal(fixture.childNodes.length, 1); var plot = new sigplot.Plot(container); @@ -831,48 +899,55 @@ QUnit.test('sigplot layer user_data', function(assert) { assert.equal(plot.get_layer(lyr_1).user_data, undefined); var lyr_2 = plot.overlay_array([], null, { - user_data: "test" + user_data: "test", }); assert.equal(plot.get_layer(lyr_1).user_data, undefined); assert.equal(plot.get_layer(lyr_2).user_data, "test"); }); -QUnit.test('Plot y-cut preserves pan values', function(assert) { - var container = document.getElementById('plot'); +QUnit.test("Plot y-cut preserves pan values", function (assert) { + var container = document.getElementById("plot"); var plot = new sigplot.Plot(container, {}); assert.notEqual(plot, null); var done = assert.async(); - plot.overlay_href("dat/raster.tmp", function(hcb, lyr_n) { - plot.zoom({ - x: 600e6, - y: 80 - }, { - x: 650e6, - y: 110 - }); - var orig_panxmin = plot._Gx.panxmin; - var orig_panxmax = plot._Gx.panxmax; - var orig_panymin = plot._Gx.panymin; - var orig_panymax = plot._Gx.panymax; - - var lyr = plot.get_layer(lyr_n); - lyr.yCut(625000000); - lyr.yCut(); - - assert.equal(orig_panxmin, plot._Gx.panxmin); - assert.equal(orig_panxmax, plot._Gx.panxmax); - assert.equal(orig_panymin, plot._Gx.panymin); - assert.equal(orig_panymax, plot._Gx.panymax); - - var lyr = plot.get_layer(lyr_n); - lyr.xCut(100); - lyr.xCut(); - - assert.equal(orig_panxmin, plot._Gx.panxmin); - assert.equal(orig_panxmax, plot._Gx.panxmax); - assert.equal(orig_panymin, plot._Gx.panymin); - assert.equal(orig_panymax, plot._Gx.panymax); - - done(); - }, {}); + plot.overlay_href( + "dat/raster.tmp", + function (hcb, lyr_n) { + plot.zoom( + { + x: 600e6, + y: 80, + }, + { + x: 650e6, + y: 110, + } + ); + var orig_panxmin = plot._Gx.panxmin; + var orig_panxmax = plot._Gx.panxmax; + var orig_panymin = plot._Gx.panymin; + var orig_panymax = plot._Gx.panymax; + + var lyr = plot.get_layer(lyr_n); + lyr.yCut(625000000); + lyr.yCut(); + + assert.equal(orig_panxmin, plot._Gx.panxmin); + assert.equal(orig_panxmax, plot._Gx.panxmax); + assert.equal(orig_panymin, plot._Gx.panymin); + assert.equal(orig_panymax, plot._Gx.panymax); + + var lyr = plot.get_layer(lyr_n); + lyr.xCut(100); + lyr.xCut(); + + assert.equal(orig_panxmin, plot._Gx.panxmin); + assert.equal(orig_panxmax, plot._Gx.panxmax); + assert.equal(orig_panymin, plot._Gx.panymin); + assert.equal(orig_panymax, plot._Gx.panymax); + + done(); + }, + {} + ); });