|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <title>NetJSON Cluster - ECharts Only Build Example</title> |
| 5 | + <meta charset="utf-8" /> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 7 | + <!-- Leaflet loaded externally --> |
| 8 | + <link |
| 9 | + rel="stylesheet" |
| 10 | + href=" https://unpkg.com/[email protected]/dist/leaflet.css" |
| 11 | + integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" |
| 12 | + crossorigin="" |
| 13 | + /> |
| 14 | + <script |
| 15 | + src=" https://unpkg.com/[email protected]/dist/leaflet.js" |
| 16 | + integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ==" |
| 17 | + crossorigin="" |
| 18 | + ></script> |
| 19 | + <!-- theme can be easily customized via css --> |
| 20 | + <link href="../lib/css/netjsongraph-theme.css" rel="stylesheet" /> |
| 21 | + <link href="../lib/css/netjsongraph.css" rel="stylesheet" /> |
| 22 | + <style type="text/css"> |
| 23 | + body { |
| 24 | + margin: 0; |
| 25 | + padding: 0; |
| 26 | + font-family: Arial, sans-serif; |
| 27 | + } |
| 28 | + #legend h4 { |
| 29 | + margin: 10px 0; |
| 30 | + text-align: center; |
| 31 | + } |
| 32 | + #legend { |
| 33 | + position: absolute; |
| 34 | + right: 25px; |
| 35 | + bottom: 25px; |
| 36 | + width: auto; |
| 37 | + height: auto; |
| 38 | + max-width: 250px; |
| 39 | + padding: 8px 15px; |
| 40 | + background: #fbfbfb; |
| 41 | + border-radius: 8px; |
| 42 | + color: #000; |
| 43 | + font-family: Arial, sans-serif; |
| 44 | + font-size: 14px; |
| 45 | + z-index: 1000; |
| 46 | + user-select: text; |
| 47 | + } |
| 48 | + #legend p { |
| 49 | + margin: 10px 0; |
| 50 | + display: flex; |
| 51 | + align-items: center; |
| 52 | + } |
| 53 | + #legend span { |
| 54 | + width: 16px; |
| 55 | + margin-right: 5px; |
| 56 | + } |
| 57 | + .status-ok, |
| 58 | + .status-problem, |
| 59 | + .status-critical { |
| 60 | + display: inline-block; |
| 61 | + width: 15px; |
| 62 | + height: 15px; |
| 63 | + margin-right: 5px; |
| 64 | + border-radius: 50%; |
| 65 | + } |
| 66 | + .status-ok { |
| 67 | + background-color: #1ba619; |
| 68 | + } |
| 69 | + .status-problem { |
| 70 | + background-color: #ffa500; |
| 71 | + } |
| 72 | + .status-critical { |
| 73 | + background-color: #c92517; |
| 74 | + } |
| 75 | + #build-info { |
| 76 | + position: absolute; |
| 77 | + top: 15px; |
| 78 | + right: 15px; |
| 79 | + background: rgba(251, 251, 251, 0.95); |
| 80 | + padding: 8px 12px; |
| 81 | + border-radius: 6px; |
| 82 | + font-size: 12px; |
| 83 | + font-family: monospace; |
| 84 | + color: #333; |
| 85 | + z-index: 1000; |
| 86 | + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
| 87 | + } |
| 88 | + #build-info strong { |
| 89 | + color: #1ba619; |
| 90 | + } |
| 91 | + </style> |
| 92 | + </head> |
| 93 | + <body> |
| 94 | + <div id="build-info"> |
| 95 | + Build: <strong>echarts-only</strong> | Leaflet: <strong>External</strong> |
| 96 | + </div> |
| 97 | + <script type="text/javascript"> |
| 98 | + const map = new NetJSONGraph("../assets/data/netjson-clustering.json", { |
| 99 | + render: "map", |
| 100 | + clustering: true, |
| 101 | + clusteringThreshold: 2, |
| 102 | + clusterRadius: 80, |
| 103 | + disableClusteringAtLevel: 18, |
| 104 | + clusteringAttribute: "status", |
| 105 | + clusterSeparation: 20, |
| 106 | + mapOptions: { |
| 107 | + center: [55.98, 11.54], |
| 108 | + zoom: 4, |
| 109 | + minZoom: 3, |
| 110 | + maxZoom: 18, |
| 111 | + // No label configuration to keep the view clean |
| 112 | + }, |
| 113 | + // defaults categories and colors |
| 114 | + // shown here to make customization easier |
| 115 | + // nodeCategories: [ |
| 116 | + // {name: "ok", nodeStyle: {color: "#1ba619"}}, |
| 117 | + // {name: "problem", nodeStyle: {color: "#ffa500"}}, |
| 118 | + // {name: "critical", nodeStyle: {color: "#c92517"}}, |
| 119 | + // ] |
| 120 | + }); |
| 121 | + |
| 122 | + // Build legend UI |
| 123 | + const createLegend = (key, className) => { |
| 124 | + const legendItem = document.createElement("p"); |
| 125 | + const legendIcon = document.createElement("span"); |
| 126 | + legendIcon.setAttribute("class", className); |
| 127 | + legends.appendChild(legendItem); |
| 128 | + legendItem.appendChild(legendIcon); |
| 129 | + legendItem.innerHTML += key; |
| 130 | + return legendItem; |
| 131 | + }; |
| 132 | + |
| 133 | + const legends = document.createElement("div"); |
| 134 | + legends.setAttribute("id", "legend"); |
| 135 | + const legendsHeader = document.createElement("h4"); |
| 136 | + legendsHeader.textContent = "Node Status"; |
| 137 | + legends.appendChild(legendsHeader); |
| 138 | + legends.appendChild(createLegend("OK", "status-ok")); |
| 139 | + legends.appendChild(createLegend("Problem", "status-problem")); |
| 140 | + legends.appendChild(createLegend("Critical", "status-critical")); |
| 141 | + document.body.appendChild(legends); |
| 142 | + |
| 143 | + // Render map |
| 144 | + try { |
| 145 | + map.render(); |
| 146 | + } catch (e) { |
| 147 | + console.error("Error initializing NetJSONGraph:", e); |
| 148 | + } |
| 149 | + </script> |
| 150 | + </body> |
| 151 | +</html> |
0 commit comments