@lgv/heatmap 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,40 @@
1
+ stages:
2
+ - test
3
+ - version
4
+ - publish
5
+
6
+ include:
7
+ ###################################### GITLAB TEMPLATES ######################################
8
+ - template: Security/SAST.gitlab-ci.yml
9
+
10
+ - project: "lgensinger/cicd-templates"
11
+ file: "node/module/nodejs-scan-sast.yml"
12
+
13
+ - project: "lgensinger/cicd-templates"
14
+ file: "node/module/semgrep-sast.yml"
15
+
16
+ ###################################### TESTING ######################################
17
+
18
+ # unit test
19
+ - project: "lgensinger/cicd-templates"
20
+ file: "node/module/test.yml"
21
+
22
+ # coverage
23
+ - project: "lgensinger/cicd-templates"
24
+ file: "node/module/coverage.yml"
25
+
26
+ ###################################### VERSIONING ######################################
27
+
28
+ # module
29
+ - project: "lgensinger/cicd-templates"
30
+ file: "node/module/version.yml"
31
+
32
+ ###################################### PUBLISHING ######################################
33
+
34
+ # npm
35
+ - project: "lgensinger/cicd-templates"
36
+ file: "node/module/publish.yml"
37
+
38
+ # allow failure until webpack css fixed for tests
39
+ unit test:
40
+ allow_failure: true
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 lgensinger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # heatmap
2
+
3
+
4
+
5
+ ## Getting started
6
+
7
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
8
+
9
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
10
+
11
+ ## Add your files
12
+
13
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
14
+ - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
15
+
16
+ ```
17
+ cd existing_repo
18
+ git remote add origin https://gitlab.com/lgensinger/heatmap.git
19
+ git branch -M main
20
+ git push -uf origin main
21
+ ```
22
+
23
+ ## Integrate with your tools
24
+
25
+ - [ ] [Set up project integrations](https://gitlab.com/lgensinger/heatmap/-/settings/integrations)
26
+
27
+ ## Collaborate with your team
28
+
29
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
30
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
31
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
32
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
33
+ - [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
34
+
35
+ ## Test and Deploy
36
+
37
+ Use the built-in continuous integration in GitLab.
38
+
39
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
40
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
41
+ - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
42
+ - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
43
+ - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
44
+
45
+ ***
46
+
47
+ # Editing this README
48
+
49
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
50
+
51
+ ## Suggestions for a good README
52
+
53
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
54
+
55
+ ## Name
56
+ Choose a self-explaining name for your project.
57
+
58
+ ## Description
59
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
60
+
61
+ ## Badges
62
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
63
+
64
+ ## Visuals
65
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
66
+
67
+ ## Installation
68
+ Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
69
+
70
+ ## Usage
71
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
72
+
73
+ ## Support
74
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
75
+
76
+ ## Roadmap
77
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
78
+
79
+ ## Contributing
80
+ State if you are open to contributions and what your requirements are for accepting them.
81
+
82
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
83
+
84
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
85
+
86
+ ## Authors and acknowledgment
87
+ Show your appreciation to those who have contributed to the project.
88
+
89
+ ## License
90
+ For open source projects, say how it is licensed.
91
+
92
+ ## Project status
93
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
Binary file
@@ -0,0 +1,78 @@
1
+ <html>
2
+
3
+ <head>
4
+ <title>Heatmap</title>
5
+ <link rel="icon" type="image/x-icon" href="favicon.ico">
6
+ <link href="style.css" rel="stylesheet" />
7
+ <script src="main.js" defer="defer" type="module"></script>
8
+ </head>
9
+
10
+ <body>
11
+
12
+ <header>
13
+
14
+ <hgroup>
15
+ <h1>Heatmap</h1>
16
+ <p>@lgv</p>
17
+ </hgroup>
18
+
19
+ <div>
20
+ <a target="_blank" href="https://gitlab.com/lgensinger/heatmap">git</a>
21
+ <a target="_blank" href="https://www.npmjs.com/package/@lgv/heatmap">npm</a>
22
+ </div>
23
+
24
+ </header>
25
+
26
+ <main>
27
+
28
+ <figure></figure>
29
+
30
+ <section>
31
+ <h1>Source Data</h1>
32
+ <p>Minimal required to render visualization.</p>
33
+ <pre><code></code></pre>
34
+ </section>
35
+
36
+ <section>
37
+ <h1>Events</h1>
38
+ <table>
39
+ <thead>
40
+ <th>element</th>
41
+ <th>name</th>
42
+ <th>description</th>
43
+ </thead>
44
+ <tbody>
45
+ <tr>
46
+ <td>circle</td>
47
+ <td>bubble-click</td>
48
+ <td>onclick for an individual svg circle element</td>
49
+ </tr>
50
+ <tr>
51
+ <td>circle</td>
52
+ <td>bubble-mouseover</td>
53
+ <td>mouseover for an individual svg circle element</td>
54
+ </tr>
55
+ <tr>
56
+ <td>circle</td>
57
+ <td>bubbble-mouseout</td>
58
+ <td>move mouse outside the bounds of an svg circle element to clear the mouseover</td>
59
+ </tr>
60
+ </tbody>
61
+ </table>
62
+ <pre><code></code></pre>
63
+ </section>
64
+
65
+ </main>
66
+
67
+ <footer>
68
+ <a target="_blank" href="https://gitlab.com/lgensinger">
69
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 380 380"><defs><style>.cls-1{fill:#171321;}</style></defs><g id="LOGO"><path class="cls-1" d="M282.83,170.73l-.27-.69-26.14-68.22a6.81,6.81,0,0,0-2.69-3.24,7,7,0,0,0-8,.43,7,7,0,0,0-2.32,3.52l-17.65,54H154.29l-17.65-54A6.86,6.86,0,0,0,134.32,99a7,7,0,0,0-8-.43,6.87,6.87,0,0,0-2.69,3.24L97.44,170l-.26.69a48.54,48.54,0,0,0,16.1,56.1l.09.07.24.17,39.82,29.82,19.7,14.91,12,9.06a8.07,8.07,0,0,0,9.76,0l12-9.06,19.7-14.91,40.06-30,.1-.08A48.56,48.56,0,0,0,282.83,170.73Z"/></g></svg>
70
+ </a>
71
+ <a target="_blank" href="https://github.com/lgensinger">
72
+ <svg viewBox="0 0 98 96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"></svg>
73
+ </a>
74
+ </footer>
75
+
76
+ </body>
77
+
78
+ </html>
@@ -0,0 +1,238 @@
1
+ import packageJson from "../package.json";
2
+ import { Heatmap } from "../src/index.js";
3
+ import { processEvent, renderDefault } from "@lgv/visualization-chart";
4
+
5
+ let data = {
6
+ "type": "FeatureCollection",
7
+ "features": [
8
+ {
9
+ "type": "Feature",
10
+ "properties": {
11
+ count: 1,
12
+ label: "Location 1"
13
+ },
14
+ "geometry": {
15
+ "coordinates": [
16
+ 18.062765600621873,
17
+ 12.663774440419019
18
+ ],
19
+ "type": "Point"
20
+ }
21
+ },
22
+ {
23
+ "type": "Feature",
24
+ "properties": {
25
+ count: 10,
26
+ label: "Location 2"
27
+ },
28
+ "geometry": {
29
+ "coordinates": [
30
+ 29.622556347633008,
31
+ 5.115698030885994
32
+ ],
33
+ "type": "Point"
34
+ }
35
+ },
36
+ {
37
+ "type": "Feature",
38
+ "properties": {
39
+ count: 5,
40
+ label: "Location 3"
41
+ },
42
+ "geometry": {
43
+ "coordinates": [
44
+ 22.001919683771263,
45
+ 5.0783972844275524
46
+ ],
47
+ "type": "Point"
48
+ }
49
+ },
50
+ {
51
+ "type": "Feature",
52
+ "properties": {
53
+ count: 4,
54
+ label: "Location 4"
55
+ },
56
+ "geometry": {
57
+ "coordinates": [
58
+ 3.7080161063010166,
59
+ 17.385867435583762
60
+ ],
61
+ "type": "Point"
62
+ }
63
+ },
64
+ {
65
+ "type": "Feature",
66
+ "properties": {
67
+ count: 10,
68
+ label: "Location 5"
69
+ },
70
+ "geometry": {
71
+ "coordinates": [
72
+ 15.763662744611167,
73
+ 0.33649372615336404
74
+ ],
75
+ "type": "Point"
76
+ }
77
+ },
78
+ {
79
+ "type": "Feature",
80
+ "properties": {
81
+ count: 3,
82
+ label: "Location 6"
83
+ },
84
+ "geometry": {
85
+ "coordinates": [
86
+ 20.70456836788253,
87
+ 23.01271125320183
88
+ ],
89
+ "type": "Point"
90
+ }
91
+ },
92
+ {
93
+ "type": "Feature",
94
+ "properties": {
95
+ count: 10,
96
+ label: "Location 7"
97
+ },
98
+ "geometry": {
99
+ "coordinates": [
100
+ 31.337189091518155,
101
+ 24.365958828608953
102
+ ],
103
+ "type": "Point"
104
+ }
105
+ },
106
+ {
107
+ "type": "Feature",
108
+ "properties": {
109
+ count: 5,
110
+ label: "Location 8"
111
+ },
112
+ "geometry": {
113
+ "coordinates": [
114
+ 28.850876840412553,
115
+ 24.742190322913345
116
+ ],
117
+ "type": "Point"
118
+ }
119
+ },
120
+ {
121
+ "type": "Feature",
122
+ "properties": {
123
+ count: 4,
124
+ label: "Location 9"
125
+ },
126
+ "geometry": {
127
+ "coordinates": [
128
+ 32.37619704771498,
129
+ 24.256530145993054
130
+ ],
131
+ "type": "Point"
132
+ }
133
+ },
134
+ {
135
+ "type": "Feature",
136
+ "properties": {
137
+ count: 4,
138
+ label: "Location 10"
139
+ },
140
+ "geometry": {
141
+ "coordinates": [
142
+ 30.275664062537686,
143
+ 21.682011648964462
144
+ ],
145
+ "type": "Point"
146
+ }
147
+ },
148
+ {
149
+ "type": "Feature",
150
+ "properties": {
151
+ count: 2,
152
+ label: "Location 11"
153
+ },
154
+ "geometry": {
155
+ "coordinates": [
156
+ 39.022152577684665,
157
+ 10.875401127042196
158
+ ],
159
+ "type": "Point"
160
+ }
161
+ },
162
+ {
163
+ "type": "Feature",
164
+ "properties": {
165
+ count: 1,
166
+ label: "Location 12"
167
+ },
168
+ "geometry": {
169
+ "coordinates": [
170
+ 41.840330659695155,
171
+ 10.435191953454591
172
+ ],
173
+ "type": "Point"
174
+ }
175
+ },
176
+ {
177
+ "type": "Feature",
178
+ "properties": {
179
+ count: 8,
180
+ label: "Location 13"
181
+ },
182
+ "geometry": {
183
+ "coordinates": [
184
+ 41.580757204890375,
185
+ 9.488254743480155
186
+ ],
187
+ "type": "Point"
188
+ }
189
+ }
190
+ ]
191
+ };
192
+
193
+ class aMap extends Heatmap {
194
+ constructor(dom,data,width,height,tileserver) {
195
+ super(dom,data,width,height,null,tileserver);
196
+ }
197
+ }
198
+
199
+ // get elements
200
+ let container = document.getElementsByTagName("figure")[0];
201
+ let sourceContainer = document.getElementsByTagName("code")[0];
202
+ let outputContainer = document.getElementsByTagName("code")[1];
203
+
204
+ /**
205
+ * Render initial visualization.
206
+ * @param {element} container - DOM element
207
+ * @param {array} data - object with key/value pairs of path
208
+ */
209
+ function startup(data,container) {
210
+
211
+ // update version in header
212
+ let h1 = document.querySelector("h1");
213
+ let title = h1.innerText;
214
+ h1.innerHTML = `${title} <span>v${packageJson.version}</span>`;
215
+
216
+ // render source data
217
+ renderDefault(data,sourceContainer,outputContainer);
218
+
219
+ // determine configs
220
+ let width = container.offsetWidth;
221
+ let height = width*0.75;
222
+
223
+ // initialize
224
+ const m = new aMap(null,data,width,height);
225
+
226
+ // render visualization
227
+ m.render(container);
228
+
229
+ }
230
+
231
+ // load document
232
+ document.onload = startup(data,container);
233
+
234
+ // attach events
235
+ container.outputContainer = outputContainer;
236
+ //container.addEventListener("bubble-click",processEvent);
237
+ //container.addEventListener("bubble-mouseover", processEvent);
238
+ //container.addEventListener("bubble-mouseout", processEvent);
@@ -0,0 +1,59 @@
1
+ @import "~highlight.js/styles/atom-one-dark.css";
2
+ @import "~@lgv/visualization-chart/src/example/style/index.css";
3
+
4
+ main > hgroup {
5
+ align-items: center;
6
+ display: flex;
7
+ justify-content: space-between;
8
+ margin-bottom: 1em;
9
+ }
10
+
11
+ main > hgroup h1 {
12
+ font-size: 1.5em;
13
+ font-weight: 700;
14
+ margin-right: 1em;
15
+ }
16
+
17
+ main hgroup div {
18
+ display: flex;
19
+ }
20
+
21
+ main button {
22
+ border: 0.2em;
23
+ border-style: solid;
24
+ cursor: pointer;
25
+ font-size: 0.75em;
26
+ padding: 0.5em;
27
+ text-transform: uppercase;
28
+ }
29
+
30
+ main hgroup div button {
31
+ border: 0 none;
32
+ background: #525252;
33
+ border-radius: 1em;
34
+ color: white;
35
+ text-transform: none;
36
+ }
37
+
38
+ main hgroup div button:first-of-type {
39
+ border-bottom-right-radius: 0;
40
+ border-top-right-radius: 0;
41
+ }
42
+
43
+ main hgroup div button:last-of-type {
44
+ background: #292929;
45
+ border-bottom-left-radius: 0;
46
+ border-top-left-radius: 0;
47
+ }
48
+
49
+ main button:hover {
50
+ background: grey;
51
+ }
52
+
53
+ main figure {
54
+ max-width: 100%;
55
+ }
56
+
57
+ .leaflet-tile-pane {
58
+ filter: saturate(0)
59
+ }
@@ -0,0 +1,38 @@
1
+ import path from "path";
2
+ import { dirname } from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ import HtmlBundlerPlugin from "html-bundler-webpack-plugin";
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+
9
+ const commonConfig = {
10
+
11
+ module: {
12
+ rules: [
13
+ {
14
+ test: /\.(ico|png|jp?g|svg)/,
15
+ type: "asset",
16
+ generator: { filename: "img/[name].[hash:8][ext]" },
17
+ parser: { dataUrlCondition: { maxSize: 2 * 1024 } }
18
+ }
19
+ ]
20
+ },
21
+
22
+ output: {
23
+ path: path.resolve(__dirname, "dist"),
24
+ clean: true
25
+ },
26
+
27
+ plugins: [
28
+ new HtmlBundlerPlugin({
29
+ entry: { index: "./example/index.html" },
30
+ js: { filename: "[name].[contenthash:8].js" },
31
+ css: { filename: "[name].[contenthash:8].css" }
32
+ })
33
+ ]
34
+
35
+ };
36
+
37
+ export { commonConfig };
38
+ export default commonConfig;
@@ -0,0 +1,42 @@
1
+ import path from "path";
2
+ import { dirname } from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ import { merge } from "webpack-merge";
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+
9
+ import { commonConfig as visConfig } from "../webpack.common.js";
10
+ import { commonConfig } from "./webpack.common.js";
11
+
12
+ const webpackConfig = merge(visConfig, commonConfig, {
13
+
14
+ devServer: {
15
+ allowedHosts: ["all"],
16
+ client: {
17
+ webSocketURL: {
18
+ hostname: "0.0.0.0",
19
+ pathname: "/ws",
20
+ password: "dev-server",
21
+ port: 8080,
22
+ protocol: "ws",
23
+ username: "webpack",
24
+ }
25
+ },
26
+ static: {
27
+ directory: path.resolve(__dirname, "dist"),
28
+ publicPath: "/"
29
+ },
30
+ watchFiles: {
31
+ paths: ["example/**/*.*"],
32
+ options: { usePolling: true },
33
+ },
34
+ webSocketServer: "ws"
35
+ },
36
+
37
+ mode: "development"
38
+
39
+ });
40
+
41
+ export { webpackConfig };
42
+ export default webpackConfig;
@@ -0,0 +1,19 @@
1
+ import { commonConfig } from "./webpack.common.js";
2
+
3
+ import { merge } from "webpack-merge";
4
+
5
+ const webpackConfig = merge(commonConfig, {
6
+
7
+ mode: "production",
8
+
9
+ output: {
10
+ library: {
11
+ name: "HeatmapExample",
12
+ type: "umd"
13
+ }
14
+ }
15
+
16
+ });
17
+
18
+ export { webpackConfig };
19
+ export default webpackConfig;
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@lgv/heatmap",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "ES6 heatmap visualization for leaflet using vega/d3.js.",
6
+ "main": "src/index.js",
7
+ "module": "src/index.js",
8
+ "directories": {
9
+ "test": "tests"
10
+ },
11
+ "scripts": {
12
+ "build": "webpack build --config webpack.prod.js",
13
+ "build-example": "webpack build --config example/webpack.dev.js",
14
+ "coverage": "c8 --reporter=html --reporter=text ava --node-arguments='--experimental-json-modules'",
15
+ "example": "webpack serve --config example/webpack.dev.js",
16
+ "start": "webpack serve --config webpack.dev.js",
17
+ "test": "npx ava --verbose --serial --timeout 1m --node-arguments='--experimental-json-modules'"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://gitlab.com/lgensinger/heatmap.git"
22
+ },
23
+ "keywords": [
24
+ "leaflet",
25
+ "visualization",
26
+ "d3"
27
+ ],
28
+ "author": "lgensinger",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://gitlab.com/lgensinger/heatmap/issues"
32
+ },
33
+ "homepage": "https://gitlab.com/lgensinger/heatmap#readme",
34
+ "devDependencies": {
35
+ "@fontsource/inter": "^5.1.0",
36
+ "ava": "^4.2.0",
37
+ "browser-env": "^3.3.0",
38
+ "c8": "^7.11.3",
39
+ "css-loader": "^7.1.2",
40
+ "file-loader": "^6.2.0",
41
+ "highlight.js": "^11.10.0",
42
+ "html-bundler-webpack-plugin": "^4.4.1",
43
+ "html-webpack-plugin": "^5.3.2",
44
+ "webpack": "^5.86.0",
45
+ "webpack-cli": "^5.1.4",
46
+ "webpack-dev-server": "^5.0.4"
47
+ },
48
+ "dependencies": {
49
+ "@deck.gl/core": "^9.0.34",
50
+ "@deck.gl/layers": "^9.0.34",
51
+ "@lgv/visualization-map": "^1.0.0",
52
+ "@luma.gl/core": "^9.0.27",
53
+ "@msrvida/vega-deck.gl": "^3.3.6",
54
+ "leaflet": "^1.9.4",
55
+ "vega": "^5.30.0"
56
+ },
57
+ "ava": {
58
+ "files": [
59
+ "tests/*_test.js"
60
+ ],
61
+ "require": [
62
+ "./tests/_setup-browser-env.js"
63
+ ]
64
+ }
65
+ }
@@ -0,0 +1,12 @@
1
+ import packagejson from "../package.json";
2
+ import { configurationLayout } from "@lgv/visualization-map";
3
+
4
+ const configuration = {
5
+ branding: "lgv",
6
+ name: packagejson.name.replace("/", "-").slice(1)
7
+ };
8
+
9
+ const configurationColor = ["lightgrey","grey","black"];
10
+
11
+ export { configuration, configurationColor, configurationLayout };
12
+ export default configuration;
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { HeatLayout } from "./layout/index.js";
2
+
3
+ import { Heatmap } from "./visualization/index.js";
4
+
5
+ export { HeatLayout, Heatmap };
@@ -0,0 +1,59 @@
1
+ import L from "leaflet";
2
+
3
+ import { MapLayout } from "@lgv/visualization-map";
4
+
5
+ /**
6
+ * HeatLayout is a data-bound layout abstraction for a heatmap.
7
+ * @param {array} data - geojson
8
+ * @param {class} map - Leaflet map object
9
+ */
10
+ class HeatLayout extends MapLayout {
11
+
12
+ constructor(data,map) {
13
+
14
+ // initialize inheritance
15
+ super(data,map);
16
+
17
+ }
18
+
19
+ /**
20
+ * Condition data for visualization requirements.
21
+ * @param {array} data - geojson
22
+ * @returns An object or array of data specifically formatted to the visualization type.
23
+ */
24
+ condition(data) {
25
+
26
+ let result = data;
27
+
28
+ if (this.map && data.type == "FeatureCollection") {
29
+
30
+ let bounds = this.map.getBounds();
31
+
32
+ // project to xy
33
+ result = data.features
34
+ .filter(d => d.geometry.coordinates[1] >= bounds._southWest.lat && d.geometry.coordinates[1] <= bounds._northEast.lat && d.geometry.coordinates[0] >= bounds._southWest.lng && d.geometry.coordinates[0] <= bounds._northEast.lng)
35
+ .map(d => {
36
+
37
+ // convert to xy
38
+ let xy = this.map.latLngToContainerPoint(L.latLng(d.geometry.coordinates[1], d.geometry.coordinates[0]));
39
+
40
+ return {
41
+ count: d.properties.count,
42
+ id: d.properties.id,
43
+ label: d.properties.name,
44
+ x: xy.x,
45
+ y: xy.y
46
+ }
47
+
48
+ });
49
+
50
+ }
51
+
52
+ return result;
53
+
54
+ }
55
+
56
+ }
57
+
58
+ export { HeatLayout };
59
+ export default HeatLayout;
@@ -0,0 +1,166 @@
1
+ import * as deck from "@deck.gl/core";
2
+ import * as layers from "@deck.gl/layers";
3
+ import * as luma from "@luma.gl/core";
4
+ import L from "leaflet";
5
+ import * as vega from "vega";
6
+ import * as VegaDeckGl from "@msrvida/vega-deck.gl";
7
+
8
+ import { VisualizationMap } from "@lgv/visualization-map";
9
+ import { HeatLayout as HL } from "../layout/index.js";
10
+
11
+ import { configuration, configurationColor, configurationLayout } from "../configuration.js";
12
+
13
+ /**
14
+ * Heatmap is a map abstraction for a heatmap visualization.
15
+ * @param {object} data - usually array; occasionally object
16
+ * @param {node} dom - HTML dom node
17
+ * @param {string} label - identifer for chart brand
18
+ * @param {float} height - specified height of chart
19
+ * @param {class} MapData - lgv data class
20
+ * @param {string} name - name of chart
21
+ * @param {float} width - specified width of chart
22
+ */
23
+ class Heatmap extends VisualizationMap {
24
+
25
+ constructor(dom=null, data, width=configurationLayout.width, height=configurationLayout.height, HeatLayout=null, tileServerUrl=configurationLayout.tileserver, color=configurationColor, label=configuration.branding, name=configuration.name) {
26
+
27
+ // initialize inheritance
28
+ super(dom, data, width, height, HeatLayout ? HeatLayout : new HL(data), tileServerUrl, label, name);
29
+
30
+ // initialize vega
31
+ VegaDeckGl.use(vega, deck, layers, luma);
32
+
33
+ // update self
34
+ this.color = color;
35
+ this.imageOverlay = null;
36
+
37
+ }
38
+
39
+ /**
40
+ * Determine if data is array of objects with xy precomputed.
41
+ */
42
+ get isXY() {
43
+ return this.data && this.data.length > 0 && Object.keys(this.data[0]).some(k => ["count","x","y"].includes(k));
44
+ }
45
+
46
+ /**
47
+ * Generate mark size.
48
+ * @returns An integer representing the render size of a visual mark.
49
+ */
50
+ get mark() {
51
+
52
+ let isHighDensityDisplay = window.devicePixelRatio > 1 && window.innerWidth * window.devicePixelRatio > 3360 && window.innerHeight * window.devicePixelRatio > 1942;
53
+
54
+ // set starting size
55
+ let base = isHighDensityDisplay ? this.unit * 1.75 : this.unit * 2;
56
+ let mark = base;
57
+
58
+ // determine mark size
59
+ switch (true) {
60
+ case (this.zoom >= 16):
61
+ mark = base - 1;
62
+ break;
63
+ case (this.zoom >= 14):
64
+ mark = base - 2;
65
+ break;
66
+ case (this.zoom >= 12):
67
+ mark = base - 3;
68
+ break;
69
+ case (this.zoom >= 8):
70
+ mark = base - 4;
71
+ break;
72
+ case (this.zoom >= 0):
73
+ mark = base - 5;
74
+ break;
75
+ }
76
+
77
+ return mark;
78
+
79
+ }
80
+
81
+ /**
82
+ * Generate main visualization, i.e. everything that sits inside the map.
83
+ */
84
+ generateChart() {
85
+
86
+ // generate vega specification
87
+ let spec = this.generateSpecification();
88
+
89
+ // render vega with deck.gl
90
+ let view = new VegaDeckGl.ViewGl(vega.parse(spec))
91
+ .renderer("deck.gl")
92
+ .run();
93
+
94
+ // generate url blob
95
+ view.toImageURL("svg")
96
+ .then(url => {
97
+
98
+ // get bounds of map
99
+ let b = this.map.getBounds();
100
+ let bounds = [[b._northEast.lat,b._northEast.lng],[b._southWest.lat,b._southWest.lng]];
101
+
102
+ // check if overlay exists
103
+ if (this.imageOverlay) {
104
+
105
+ // update existing
106
+ this.imageOverlay.setUrl(url);
107
+ this.imageOverlay.setBounds(bounds);
108
+
109
+ } else {
110
+
111
+ // initialize
112
+ this.imageOverlay = L.imageOverlay(url, bounds);
113
+
114
+ // update map
115
+ this.imageOverlay.addTo(this.map);
116
+
117
+ }
118
+
119
+ });
120
+
121
+ }
122
+
123
+ /**
124
+ * Generate vega specification in prep for render.
125
+ */
126
+ generateSpecification() {
127
+
128
+ // register custom scheme
129
+ vega.scheme(this.name, this.color);
130
+
131
+ return {
132
+ width: this.width,
133
+ height: this.height,
134
+ data: [{ name: this.name, values: this.data }],
135
+ scales: [
136
+ {
137
+ name: "color",
138
+ type: "linear",
139
+ domain: { data: this.name, field: "count" },
140
+ range: { scheme: this.name, count: this.color.length }
141
+ }
142
+ ],
143
+ marks: [
144
+ {
145
+ type: "symbol",
146
+ from: { data: this.name },
147
+ encode: {
148
+ update: {
149
+ shape: { value: "square" },
150
+ x: { field: "x" },
151
+ y: { field: "y" },
152
+ size: { value: this.mark },
153
+ fill: { scale: "color", field: "count" },
154
+ opacity: { value: 1 }
155
+ },
156
+ },
157
+ }
158
+ ]
159
+ }
160
+
161
+ }
162
+
163
+ }
164
+
165
+ export { Heatmap };
166
+ export default Heatmap;
@@ -0,0 +1,3 @@
1
+ import browserEnv from "browser-env";
2
+
3
+ browserEnv(["document"]);
@@ -0,0 +1,10 @@
1
+ import test from "ava";
2
+
3
+ import { configuration } from "../src/configuration.js";
4
+
5
+ test("init", t => {
6
+
7
+ // INIT TEST //
8
+ t.true(typeof(configuration) === "object");
9
+
10
+ });
@@ -0,0 +1,51 @@
1
+ import path from "path";
2
+ import { dirname } from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ import webpack from "webpack";
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+
9
+ const commonConfig = {
10
+
11
+ entry: {
12
+ index: "./src/index.js"
13
+ },
14
+
15
+ plugins: [
16
+ new webpack.DefinePlugin({
17
+ "process.env": {
18
+ "LGV_HEIGHT": JSON.stringify(process.env.LGV_HEIGHT),
19
+ "LGV_TILESERVER": JSON.stringify(process.env.LGV_TILESERVER),
20
+ "LGV_WIDTH": JSON.stringify(process.env.LGV_WIDTH)
21
+ }
22
+ })
23
+ ],
24
+
25
+ output: {
26
+ filename: "heatmap.bundle.js",
27
+ path: path.resolve(__dirname, "dist"),
28
+ clean: true
29
+ },
30
+
31
+ module: {
32
+ rules: [
33
+ {
34
+ test: /\.css$/i,
35
+ use: ["css-loader"]
36
+ },
37
+ {
38
+ test: /\.(png|jpe?g|gif)$/i,
39
+ use: [
40
+ {
41
+ loader: 'file-loader',
42
+ }
43
+ ]
44
+ }
45
+ ]
46
+ }
47
+
48
+ };
49
+
50
+ export { commonConfig };
51
+ export default commonConfig;
package/webpack.dev.js ADDED
@@ -0,0 +1,19 @@
1
+ import { commonConfig } from "./webpack.common.js";
2
+
3
+ import HtmlWebpackPlugin from "html-webpack-plugin";
4
+ import { merge } from "webpack-merge";
5
+
6
+ const webpackConfig = merge(commonConfig, {
7
+
8
+ mode: "development",
9
+
10
+ plugins: [
11
+ new HtmlWebpackPlugin({
12
+ title: "Development",
13
+ })
14
+ ]
15
+
16
+ });
17
+
18
+ export { webpackConfig };
19
+ export default webpackConfig;
@@ -0,0 +1,19 @@
1
+ import { commonConfig } from "./webpack.common.js";
2
+
3
+ import { merge } from "webpack-merge";
4
+
5
+ const webpackConfig = merge(commonConfig, {
6
+
7
+ mode: "production",
8
+
9
+ output: {
10
+ library: {
11
+ name: "Heatmap",
12
+ type: "umd"
13
+ }
14
+ }
15
+
16
+ });
17
+
18
+ export { webpackConfig };
19
+ export default webpackConfig;