Application of Heatmap Heat map 3D based on HTML5 implementation

Source: Internet
Author: User

Heatmap Heat map through a number of data point information, aggregated into an intuitive visual color effect, heat map has been widely used in meteorological forecasts, medical imaging, computer room temperature monitoring and other industries, and even applied to the field of competitive sports data analysis.

There are many articles that share the principle of generating heatmap heat maps, and you can refer to "How to make heat maps" and "How to makes heat maps in Flex", this article introduces the implementation method based on HTML5 technology, Mainly based on the application of 2D and 3D Technologies of the two HTML5, Cavans and WebGL, the interface effect and operation Video realized by the final example first:

Implementation of Heatmap's open source JS Library is more famous  heatmapjs , the framework developed over 2 years, the author Patrick Wied recently decided to keep open source based on Provide paid business support services, this is a good thing, the vast majority of open-source project on Earth, the author of a barely available in the primary version, has not been updated for many years, and really can actually use the line of products which do not need continuous improvement, enhance scalability and provide special customization services, Considering the author has paid so much for the last two years (over the last 2 years, I devoted  much than hours  of work to improving heat Map.js to make it a truly great library. ), hope this article can also help the author in the domestic starting point propaganda role.

Heatmapjs uses the canvas 2D rendering method, this CPU-based drawing method for hundreds of thousands of points, but if you need to compute thousands of nodes in real-time, or rely on the more powerful GPU mode, using HTML5 can only be the WebGL solution, Fortunately Florian Boesch in the "High performance JS heatmaps" blog provides a heatmap approach based on WEBGL implementation, and open it up in Webgl-heatmap, these two open source libraries are also good quality, a canvas-based implementation, a WEBGL-based implementation, the latter performance high, but need to support WebGL browser, HEATMAPJS document example is more comprehensive, but both interfaces are very simple and easy to learn, The code is hundreds of lines, and you can choose and even optimize the code based on the project situation.

Back to the example we want to implement, I will use HEATMAPJS in memory in real-time operation of the heat map, combined with the Hightopo HT for Web 3D engine, a bunch of nodes connected to the 3D network topology diagram, wherein the node represents a heat source, the closer to the ground the higher the ground temperature, In this way, the XZ surface coordinate information of each node is used as the point XY coordinate information to be passed to Heatmapjs, the elevation of the three-dimensional node is also the Y axis information, as the distance information from the ground, the larger the distance is, the smaller the value of the Heatmapjs to pass in, and the last HT For web's three-dimensional topology auto-layout elastic algorithm, so as to visually observe the changes in the temperature and heat map of the floor when the element nodes are dynamically changing in different spatial positions.

The code core is in the overloaded forcelayout.onrelaxed function, where each automatic layout process constructs the information for all heat source nodes into heatmap required data, while passing ht.Default.setImage (' Hm-bottom ', heatmap . _renderer.canvas); The canvas of the heat map is registered as a picture of HT, and floor elements of floors are bound to the registered ' Hm-bottom ' picture, which enables the memory to be drawn to canvas and then via the HT for The web's 3D engine dynamically renders cavnas as mapping information to a 3D scene.

The entire implementation code below hundred lines, you can also use Https:// WebGL way to achieve, this is 3D to 2D to 3D of the fun process, This is how HTML5 technology can seamlessly blend the charms of various solutions!

MAX = 500; WIDTH = 1024;        HEIGHT = 512; function init () {Datamodel = new ht.            Datamodel ();                            G3d = new Ht.graph3d.Graph3dView (Datamodel);                        G3d.getmovemode = function (e) {return ' xyz ';};            view = G3d.getview ();    View.classname = ' main ';d ocument.body.appendChild (view);            Window.addeventlistener (' Resize ', function (e) {g3d.invalidate ();}, False);                                   Heatmap = H337.create ({width:width, height:height}); Ht.            Default.setimage (' Hm-bottom ', Heatmap._renderer.canvas); var floor = new Ht. Node (); Floor.s3 (WIDTH, 1, HEIGHT); Floor.s ({' 3d.selectable ': false, ' layoutable ': false, ' all.visible ': false, ' Top.visible ': True, ' top.image ': ' Hm-bottom ', ' top.reverse.flip ': true, ' bottom.visible ': true, ' bottom.transparent ':            True, ' bottom.opacity ': 0.5, ' Bottom.reverse.flip ': true});d Atamodel.add (floor);           var root = CreateNode ();        for (var i = 0; i < 3; i++) {var iNode = CreateNode ();                            Createedge (Root, INode); for (var j = 0; J < 3; J + +) {var jNode = CreateNode ();                                                         Createedge (INode, JNode);  }} forcelayout = new Ht.layout.Force3dLayout (g3d); Forcelayout.start (); forcelayout.onrelaxed = function () {var points = [];d Atamodel.each (function (data) {if (data instanceof ht. Node && Data!== floor) {var P3 = data.p3 (), if (p3[1] > MAX) {p3[1] = max;data.setelevation (MAX);}                        else if (P3[1] <-max) {p3[1] =-max;data.setelevation (-max);} Points.push ({x:p3[0] + width/2,y:p3[2] + height/2,value:max-math.abs (p3[1])});}); Heatmap.setdata ({data:points, min:0, Max:max});};} function CreateNode () {var node = new ht.             Node (); NODE.S ({' Shape3d ': ' Sphere ', ' shape3d.color ': ' #E74C3C ', ' shape3d.opacity ': 0.8, ' shape3d.transparent ': true, ' Shape3d.reverse.cull ': true}); Node.s3 (+,);d Atamodel.add (node); return node;} function Createedge (Sourcenode, TargetNode) {var edge = new ht. Edge (Sourcenode, TargetNode); Edge.s ({' Edge.width ': 3, ' Edge.offset ': Ten, ' shape3d ': ' Cylinder ', ' Shape3d.opac    ity ': 0.7, ' shape3d.transparent ': true, ' Shape3d.reverse.cull ': true});d Atamodel.add (edge); return edge;}

Application of Heatmap Heat map 3D based on HTML5 implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.