pa7 / heatmap.js

🔥 JavaScript Library for HTML5 canvas based heatmaps
https://www.patrick-wied.at/static/heatmapjs/
MIT License
6.21k stars 1.32k forks source link

Supplements for heatmap.js plugins' usage in AMD, CommonJS/Node.js, ES6 contexts #245

Open hijiangtao opened 7 years ago

hijiangtao commented 7 years ago

I found the installation guidance of heatmap.js in different context, it's very useful because I am currently using Node.js as my developing back-end context, but the usage in how to include them into these kinds of context is rare. Because CommonJS/Node.js need to load variable from package, and heatmap.js' plugin has specific instance creation approach, I think it's good to include these content into current documents/README.md, such as when I use ES6 as my writting grammar, I should do as follows to make my heatmap display normally with leaflet.js in the front-end browser:

import HeatmapOverlay from 'heatmap.js/plugins/leaflet-heatmap/leaflet-heatmap.js'

let cfg = {...}
let heatmapLayer = new HeatmapOverlay(cfg);

Since the expression above will require('heatmap.js') internally, I don't need to import heatmap from 'heatmap.js' again any more.

I think other plugins should have their own instance creation approach, it would be clear if they can be pointed out. Thanks.

pa7 commented 7 years ago

hi @hijiangtao did you use the leaflet plugin from npm? ( npm install leaflet-heatmap ) because that was actually the rationale behind putting the plugins on npm, so it would only require a single import and the plugin takes care of its dependencies (in this case heatmap.js & leaflet)

hijiangtao commented 7 years ago

Yes, actually I use import L from 'leaflet' from package manager, and the version is "leaflet": "0.7.7", but it may not have too much impact on heatmap.js, since I saw lines of codes in heatmap.js that is dealing with the compatibility of different leaflet.js' version.

And on the other hand, it's simply a single import that really matters, but I thought if you could put more information in manual(documents) about how to create a new HeatmapOverlay via given cofiguration json format, I think it may be a little difficult for Node.js freshman to do these (they may be confused about the import directory and instance's creation process).

Thanks!

pa7 commented 7 years ago

@hijiangtao thank you for the feedback, I will add some documentation about that on the heatmap.js website :)

hijiangtao commented 7 years ago

Never mind :smile: