Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create a "minimum" value, but only if you're willing to fork the library and make some changes.</p> <h1>Game plan</h1> <p>The easiest and most straightforward way to do so is to create a new option that I'll call <code>FixedMin</code>. If, and only if, this new option is provided (and the other criteria for non-auto-segmentation are met) will you achieve the effect you're seeking.</p> <p>If you want a minimum to be generated without providing <code>SegmentHeight</code>, <code>Segments</code>, and <code>FixedMax</code>, you'll also need to modify <code>pImage::computeScale</code> which generates these configuration values when they're not provided.</p> <p>We need to make three changes:</p> <ol> <li>Create a new configuration option called <code>FixedMin</code></li> <li>Adjust the values' position</li> <li>Adjust the labels' text</li> </ol> <h1>Let's code</h1> <p>The <code>drawRadar</code> method is held in <code>class/pRadar.class.php</code>. Open it up. Let's walk through our game plan.</p> <p><strong>First</strong>, let's add the configuration option. I'll add it with the others (line ~38) like so:</p> <pre><code> $FixedMin = isset($Format["FixedMin"]) ? $Format["FixedMin"] : 0; </code></pre> <p>Let's have <code>FixedMin</code> default to <code>0</code> because that is the default pChart behavior.</p> <p><strong>Second</strong>, we need to somehow trick pChart into repositioning these larger values as if they were smaller to accomodate the offset <code>FixedMin</code> creates.</p> <p>We can do that where the function computes the plots position (line ~319). Find the loop <code>foreach($DataS["Data"] as $Key =&gt; $Value)</code> (line ~328). Here, we'll modify the <code>$Value</code> by adding this line at the top of the loop:</p> <pre><code>$Value -= $FixedMin; // Let's offset the perceived value by our new minimum </code></pre> <p><strong>Third</strong>, we need to change the axis labels' text values. Inside the conditional that <code>$DrawAxisValues</code> encompasses, you'll find this line of code (line ~255):</p> <pre><code>$Label = ($j * $SegmentHeight) </code></pre> <p>This works great; for each segment, it generates a label that is the segment times the height (e.g., 4 segments of 20 units should generate 4 labels with: 20, 40, 60, 80). But it won't work with our <code>FixedMin</code>. Let's reuse the offset. In this case, we're incrementing by the offset, to generate the illusion of a minimum. Replace that line with this one:</p> <pre><code>$Label = ($j * $SegmentHeight) + $FixedMin; </code></pre> <h1>Recap</h1> <p>We created a new configuration variable for a minimum segment; and for each value, we subtracted that minimum value (or offset); and rejiggered the axis labels by adding that minimum value (or offset).</p> <h1>Caveats</h1> <p>We only modified radar charts; no other chart type will be affected. Do <em>not</em> attempt to use data with values that are below the configured minimum. The hazards of doing so may be why the author didn't include this option.</p> <h1>Show and tell</h1> <p>I don't have access to your data set, so I used the pChart example and bumped the "application review" sample so that all the scores were between 20 and 40.</p> <pre><code>// FixedMin set to 0, "default" behavior $Options = array( 'SegmentHeight' =&gt; 20, 'Segments' =&gt; 2, 'FixedMax' =&gt; 40, 'FixedMin' =&gt; 0, // And so on... </code></pre> <p><img src="https://i.stack.imgur.com/88dE5.png" alt="Default behavior"></p> <p>As expected, now let's check out our new code...</p> <pre><code>// FixedMin set to 20, smaller SegmentHeight $Options = array( 'SegmentHeight' =&gt; 10, 'Segments' =&gt; 2, 'FixedMax' =&gt; 40, 'FixedMin' =&gt; 20, // And so on... </code></pre> <p><img src="https://i.stack.imgur.com/rH8WP.png" alt="With a minimum of 20"></p> <p>Ta-da.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload