{"id":20893417,"url":"https://github.com/arction/lcjs-example-0706-onscreenmenu","last_synced_at":"2025-03-12T19:14:33.577Z","repository":{"id":98723666,"uuid":"409169815","full_name":"Arction/lcjs-example-0706-onScreenMenu","owner":"Arction","description":"On Screen Menu showcase","archived":false,"fork":false,"pushed_at":"2025-02-05T11:38:40.000Z","size":15505,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-11T11:55:13.539Z","etag":null,"topics":["demo","lightningchart-js","menu","template"],"latest_commit_sha":null,"homepage":"https://www.arction.com/lightningchart-js-interactive-examples/examples/lcjs-example-0706-onScreenMenu.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Arction.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-22T11:04:02.000Z","updated_at":"2025-02-05T11:36:24.000Z","dependencies_parsed_at":"2025-02-05T12:29:38.177Z","dependency_job_id":"f007e5a1-ebb3-4c55-95e9-777b6f6a3b3d","html_url":"https://github.com/Arction/lcjs-example-0706-onScreenMenu","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arction%2Flcjs-example-0706-onScreenMenu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arction%2Flcjs-example-0706-onScreenMenu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arction%2Flcjs-example-0706-onScreenMenu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arction%2Flcjs-example-0706-onScreenMenu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arction","download_url":"https://codeload.github.com/Arction/lcjs-example-0706-onScreenMenu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243277498,"owners_count":20265352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["demo","lightningchart-js","menu","template"],"created_at":"2024-11-18T10:15:45.905Z","updated_at":"2025-03-12T19:14:33.571Z","avatar_url":"https://github.com/Arction.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript On Screen Menu\n\n![JavaScript On Screen Menu](osm-darkGold.png)\n\nThis demo application belongs to the set of examples for LightningChart JS, data visualization library for JavaScript.\r\n\r\nLightningChart JS is entirely GPU accelerated and performance optimized charting library for presenting massive amounts of data. It offers an easy way of creating sophisticated and interactive charts and adding them to your website or web application.\r\n\r\nThe demo can be used as an example or a seed project. Local execution requires the following steps:\r\n\r\n-   Make sure that relevant version of [Node.js](https://nodejs.org/en/download/) is installed\r\n-   Open the project folder in a terminal:\r\n\r\n          npm install              # fetches dependencies\r\n          npm start                # builds an application and starts the development server\r\n\r\n-   The application is available at _http://localhost:8080_ in your browser, webpack-dev-server provides hot reload functionality.\r\n\n\n## Description\n\nExample showcasing the use of On Screen Menu.\r\n\r\nOn-Screen Menu (OSM) is part of UI that can be used to simplify interaction with charts.\r\nIn this case the default buttons are used along with a custom button that shows/hides the intersection points of lines.\r\n\r\nThe On-Screen menu can be added this way:\r\n\r\n```javascript\r\nconst chart = lightningChart().ChartXY()\r\n\r\nchart.addOnScreenMenu(\r\n    [\r\n        [\r\n            // default buttnos\r\n            OnScreenMenuButtonType.ZoomInX,\r\n            OnScreenMenuButtonType.ZoomOutX,\r\n            OnScreenMenuButtonType.ZoomInY,\r\n            OnScreenMenuButtonType.ZoomOutY,\r\n            OnScreenMenuButtonType.ZoomToFit,\r\n            OnScreenMenuButtonType.ToggleAnimations,\r\n        ],\r\n    ],\r\n    OnScreenMenuButtonShape.RoundedRectangle,\r\n)\r\n```\r\n\r\nTo add a custom button parameters must be defined.\r\n\r\n```javascript\r\nconst chart = lightningChart().ChartXY()\r\n\r\nchart.addOnScreenMenu([\r\n    [\r\n        // cusrom button\r\n        {\r\n            icon: new URL(document.head.baseURI).origin + new URL(document.head.baseURI).pathname + 'examples/assets/9999/icon.png',\r\n            dimensions: { rows: 1, columns: 1 },\r\n            label: '',\r\n            opacity: '0.8',\r\n            color: 'blue',\r\n            shape: OnScreenMenuButtonShape.RoundedRectangle,\r\n            action: show,\r\n        },\r\n    ],\r\n])\r\n```\r\n\r\n'addOnScreenMenu' takes an array of arrays as a parameter.\r\nEach sub array adds a new line on the OSM menu.\r\n\r\n![](./assets/OSM.png)\r\n\r\n```javascript\r\nconst chart = lightningChart().ChartXY()\r\n\r\nchart.addOnScreenMenu([\r\n    [\r\n        OnScreenMenuButtonType.ZoomInX,\r\n        OnScreenMenuButtonType.ZoomOutX,\r\n        OnScreenMenuButtonType.ZoomInY,\r\n        OnScreenMenuButtonType.ZoomOutY,\r\n        OnScreenMenuButtonType.ZoomIn,\r\n        OnScreenMenuButtonType.ZoomOut,\r\n    ],\r\n    [OnScreenMenuButtonType.ZoomToFit, OnScreenMenuButtonType.ToggleAnimations],\r\n    [\r\n        {\r\n            icon: new URL(document.head.baseURI).origin + new URL(document.head.baseURI).pathname + 'examples/assets/9999/icon.png',\r\n            dimensions: { rows: 1, columns: 1 },\r\n            opacity: '0.8',\r\n            color: 'blue',\r\n            shape: OnScreenMenuButtonShape.RoundedRectangle,\r\n            action: show,\r\n        },\r\n    ],\r\n])\r\n```\r\n\r\nFormula of lines intersection\r\n\r\n![](./assets/formula.png)\r\n\r\n```javascript\r\nfunction calculateIntersection(currPoint1, prevPoint1, currPoint2, prevPoint2) {\r\n    // Expressions of numerator\r\n    const exp1 = currPoint1.x * prevPoint1.y - currPoint1.y * prevPoint1.x // (x1 * y2 - y1 * x2)\r\n    const exp2 = currPoint2.x * prevPoint2.y - currPoint2.y * prevPoint2.x // (x3 * y4 - y3 * x4)\r\n\r\n    const exp3 = currPoint2.x - prevPoint2.x // (x3 - x4)\r\n    const exp4 = currPoint1.x - prevPoint1.x // (x1 - x2)\r\n    const exp5 = currPoint2.y - prevPoint2.y // (y3 - y4)\r\n    const exp6 = currPoint1.y - prevPoint1.y // (y1 - y2)\r\n\r\n    // Denominator\r\n    const d1 = (currPoint1.x - prevPoint1.x) * (currPoint2.y - prevPoint2.y) // (x1 - x2) * (y3 - y4)\r\n    const d2 = (currPoint1.y - prevPoint1.y) * (currPoint2.x - prevPoint2.x) // (y1 - y2) * (x3 - x4)\r\n    const d = d1 - d2\r\n\r\n    if (d === 0) {\r\n        throw new Error('Number of intersection points is zero or infinity.')\r\n    }\r\n\r\n    const px = (exp1 * exp3 - exp4 * exp2) / d\r\n    const py = (exp1 * exp5 - exp6 * exp2) / d\r\n\r\n    const p = { x: px, y: py }\r\n\r\n    // Return point\r\n    return p\r\n}\r\n```\r\n\n\n## API Links\n\n* [Point Series]\n* [Line Series]\n* [On Screen Menu]\n\n\n## Support\n\nIf you notice an error in the example code, please open an issue on [GitHub][0] repository of the entire example.\r\n\r\nOfficial [API documentation][1] can be found on [LightningChart][2] website.\r\n\r\nIf the docs and other materials do not solve your problem as well as implementation help is needed, ask on [StackOverflow][3] (tagged lightningchart).\r\n\r\nIf you think you found a bug in the LightningChart JavaScript library, please contact sales@lightningchart.com.\r\n\r\nDirect developer email support can be purchased through a [Support Plan][4] or by contacting sales@lightningchart.com.\r\n\r\n[0]: https://github.com/Arction/\r\n[1]: https://lightningchart.com/lightningchart-js-api-documentation/\r\n[2]: https://lightningchart.com\r\n[3]: https://stackoverflow.com/questions/tagged/lightningchart\r\n[4]: https://lightningchart.com/support-services/\r\n\n© LightningChart Ltd 2009-2022. All rights reserved.\r\n\n\n[Point Series]: https://lightningchart.com/js-charts/api-documentation/v7.0.1/classes/PointSeries.html\n[Line Series]: https://lightningchart.com/js-charts/api-documentation/v7.0.1/classes/LineSeries.html\n[On Screen Menu]: https://lightningchart.com/js-charts/api-documentation/v7.0.1/classes/ChartXY.html#addOnScreenMenu\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farction%2Flcjs-example-0706-onscreenmenu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farction%2Flcjs-example-0706-onscreenmenu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farction%2Flcjs-example-0706-onscreenmenu/lists"}