sghaskell / maps-plus

Maps+ for Splunk
Other
18 stars 3 forks source link

heatmapColorGradient Change heatmap (gps path) based on pingms along path on each lat/long movement of device. (Ping test usecase) #44

Open sudoritz opened 10 months ago

sudoritz commented 10 months ago

Im looking to see if we can use heatmapColorGradient with results to change the heatmap color on the GPS path or along the device that is in path. so where ever we are moving we have a consistent ping going to a server but it would be cool to show red when ping is over >100ms range or >300ms and green between. I think i did the eval but to use maps+ i cant seem to get the colors to display along the GPS path track

|eval pingms = if(packetloss="100", "0", pingms) |timechart span=1m avg(pingms) as ping avg(latitude) as latitude  avg(longitude) as longitude
|eval description=ping
|eval heatmapLayer="ping"
| eval normalized_ping = case(
    ping = 0, 0,
    ping <= 60, 1,
    ping <= 90, 0.6 + (120 - ping) / 60 * 0.4,
    ping <= 100, 0.4 + (300 - ping) / 180 * 0.2,
    ping <= 600, 0.2 + (600 - ping) / 300 * 0.2,
    1=1, 0.1
  )
| eval heatmapColorGradient = case(
    normalized_ping = 0, "{\"1\":\"red\", \"0.6\":\"orange\", \"0.4\":\"yellow\", \"0.2\":\"blue\", \"0.1\":\"green\"}",
    normalized_ping <= 0.2, "{\"1\":\"orange\", \"0.6\":\"red\", \"0.4\":\"yellow\", \"0.2\":\"yellow\", \"0.1\":\"green\"}",
    normalized_ping <= 0.4, "{\"1\":\"yellow\", \"0.6\":\"orange\", \"0.4\":\"red\", \"0.2\":\"yellow\", \"0.1\":\"green\"}",
    normalized_ping <= 0.6, "{\"1\":\"blue\", \"0.6\":\"yellow\", \"0.4\":\"orange\", \"0.2\":\"red\", \"0.1\":\"green\"}",
    normalized_ping > 0.6, "{\"1\":\"green\", \"0.6\":\"yellow\", \"0.4\":\"yellow\", \"0.2\":\"orange\", \"0.1\":\"red\"}"
  )
sudoritz commented 10 months ago

i wonder if i might have to update the heatLayer.js to add another variable maybe we can add like like heatmapStatus i wonder if heatmapColorGradient is only 1 value it sees and not dynamic per drawing

https://github.com/sghaskell/maps-plus/blob/aae0cbff8c6b8bb78816fe52b927c2292c4ac511/appserver/static/visualizations/maps-plus/contrib/js/HeatLayer.js

// Example of extending the data model to include 'status'
initialize: function (latlngs, options) {
    // Example latlngs format: [{lat: x, lng: y, alt: z, status: s}, ...]
    this._latlngs = latlngs;
    // ... rest of the initialization
},

// Example of customizing the gradient calculation based on 'status'
_redraw: function () {
    // ... existing code to process points ...

    for (let i = 0, len = grid.length; i < len; i++) {
        // ... existing code to process grid cells ...
        if (cell) {
            let status = this._latlngs[i].status;
            let color = this.getStatusBasedColor(status); // Custom function to determine color
            data.push([
                Math.round(cell[0]),
                Math.round(cell[1]),
                Math.min(cell[2], this._max),
                color // Include color in the data
            ]);
        }
    }

    // ... existing drawing code, modified to use the color ...
},

// Example of a custom function to determine color based on 'status'
getStatusBasedColor: function (status) {
    // Implement logic to return a color based on the status value
    // For example, return 'red' for high status, 'blue' for low status
},