All Apps and Add-ons

Not able to resize a panel using script

theouhuios
Motivator

hello

I am trying to resize the panel using js in Sideview. Here is my script below,

  var Web = {
  resizePanel: function(panelRow, leftWidth, rightWidth) {
        jQuery('.' + panelRow).children('.layoutCell').each(function(index) {
          var _this = jQuery(this);
          if (_this.hasClass('firstCell')) {
            _this.css('width',leftWidth + '%');
          } else {
            _this.css('width',rightWidth + '%');            
          }
        });          
      }
  }

Then I am calling the script in the panel module but I don't see any changes

<module name="PostProcess" layoutPanel="panel_row1_col1" group="Processor Queue Length" >
            <param name="search"> search host=$host$| where counter="Processor Queue Length"| $report$ </param>



        <module name="JobProgressIndicator"></module>
    <module name="Pager">
        <param name="entityName">results</param>
<module name="HiddenChartFormatter">
  <param name="charting.axisTitleY.text"/>
  <param name="charting.chart">line</param>
  <param name="charting.chart.stackMode">stacked</param>
  <param name="charting.legend.placement">top</param>
  <param name="charting.chart.nullValueMode">zero</param>
  <param name="charting.axisTitleX.text">Processor Queue Length</param>
  <module name="JSChart">
    <param name="width">100%</param>
    <module name="HTML">
                <param name="html"><![CDATA[

                  <script>
                  Web.resizePanel('panel_row1_col1',20,80)
      </script>

                  ]]></param>
              </module>

  </module>

  </module>
       </module>
        </module>

Any idea on how to solve this?

0 Karma

sideview
SplunkTrust
SplunkTrust

Well, I think the key here is when do you want to resize the panel... My guess is that you want to resize the panel after the chart, or after all the charts, have finished rendering. That code as written will at-best resize the panel once the very instant the page loads, which is long before much of anything happens. Then it will resize again each time a new push comes down to that HTML module in the hierarchy.

You should see from this last point that the HTML module is not a great way to inject javascript into the page, because every time the HTML module receives a push from upstream, it will re-render the HTML completely. So in this case it will be calling your script each time a new push hits the HTML module. Unfortunately even that won't help you achieve your goal because that will be slightly before the charts start rendering.

There are a couple ways to do this sort of thing, but neither is easy. First you could patch all of the JSChart or FlashChart modules and override the relevant methods on each, taking care to still call the original unpatched implementation first, and then do your resizing as appropriate. Secondly you could use the long-forgotten javascript object that lives at "Splunk.PageStatus". This is part of the old print-from-browser and print-as-pdf functionality in 4.0. The code is still there so my guess is that it still works. Anyway, it watches all the HTTP traffic and all the renders, for instance chart-rendering. lots of events will get fired along the way, but you might get lucky and be able to just bind to it's "PageReady" event at the very end after everything is done loading and rendering.

UPDATE: patching the modules themselves looks to be a path fraught with peril. With FlashChart you'd have to mess with onJobProgress or onJobDone and wait for some fixed period of time within which you assume the chart can render itself to the page. With JSChart it's completely different and you'll have to experiment to figure out which method you need to override. The good news is that looking into it a bit, I think the PageStatus way is much easier. You might also look for inspiration to $SPLUNK_HOME/share/splukn/search_mrsparkle/exposed/js/dashboard.js in the core code. In this file you'll see all the various ways in which Splunk's dashboard template attempts to keep dashboard views resized correctly as the page changes. It's a bit overwhelming but on the other hand there's a lot of clues in there for you.

Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...