Extension talk:Gchart4mw

From MediaWiki.org
Jump to: navigation, search

Contents

[edit] Getting Data From Templates

Many thanks for this extension. I would love to generate Google Charts from data held in wiki templates/pages. e.g.

<pie title="Bundestagswahl 2005" 3d="3d" size="300x150" xlabel="xlabel">

{{:ChartData/Bundestagswahl}}

</pie>

--86.138.17.210 23:21, 26 January 2009 (UTC)


[edit] Security Issues

This is a great wiki extension for public wikis. However, if your wiki is intranet based you may be sending info out that is sensitive (because Google renders the image from a url that is not secured). So at the very least you are sharing your data with Google and also with any one who picks up the communication.

Even with this draw back this is still a useful extension for internal wikis, it just needs to be clear that the data being charted is heading out on the internet. I modified gchart4mw.php to include a warning label. Here is the changed code:


// -----------------------------------------------------------------------------
function gfLinesRender( $input, $args, $parser ) {
  global $gchartWikiDefaults;
  global $gchartLinesDefaults;

  gfChartInit ();
  gfArgsParseCommon ($gchartWikiDefaults);
  gfArgsParseCommon ($gchartLinesDefaults);
  gfArgsParseCommon ($args);

  $retval = '';

  // Insert a dislamer caption
  $retval = '<table class="image"><caption align="bottom"><font size = "1">Image rendered By Google. Do not use proprietary or confidential data.</font></caption><tr><td>';

  $retval = $retval . gfArgsRenderCommon();
  $retval = $retval . gfArgsRenderLine();
  $retval = $retval . gfInputParseCSV($input,"line");
  $retval = $retval . '">';

  // Finish Insert caption
  $retval = $retval . '</td></tr></table>';

  return $retval;
}

function gfBarsRender( $input, $args, $parser ) {
  global $gchartWikiDefaults;
  global $gchartBarsDefaults;

  gfChartInit ();
  gfArgsParseCommon ($gchartWikiDefaults);
  gfArgsParseCommon ($gchartBarsDefaults);
  gfArgsParseCommon ($args);

  $retval = '';

  // Insert a dislamer caption
  $retval = '<table class="image"><caption align="bottom"><font size = "1">Image rendered By Google. Do not use proprietary or confidential data.</font></caption><tr><td>';

  $retval = $retval . gfArgsRenderCommon();
  $retval = $retval . gfArgsRenderBars();
  $retval = $retval . gfInputParseCSV($input,"bars");
  $retval = $retval . '">';

  // Finish Insert caption
  $retval = $retval . '</td></tr></table>';

  return $retval;
}

function gfPieRender( $input, $args, $parser ) {
  global $gchartWikiDefaults;
  global $gchartPieDefaults;

  gfChartInit ();
  gfArgsParseCommon ($gchartWikiDefaults);
  gfArgsParseCommon ($gchartPieDefaults);
  gfArgsParseCommon ($args);

  $retval = '';

  // Insert a dislamer caption
  $retval = '<table class="image"><caption align="bottom"><font size = "1">Image rendered By Google. Do not use proprietary or confidential data.</font></caption><tr><td>';

  $retval = $retval . gfArgsRenderCommon();
  $retval = $retval . gfArgsRenderPie();
  $retval = $retval . gfInputParseCSV($input,"pie");
  $retval = $retval . '">';

  // Finish Insert caption
  $retval = $retval . '</td></tr></table>';

This will render the image looking like this:
PieWithWarning.jpg


Dear Vaccano,

you are right! All data of the charts is being transmitted to google. And altough it is scaled to a value between 0 and 100 before sending, it might be a security concern for sensitive data.

If you don“t mind I would like to add a disclaimer like yours to the next release of this extension - maybe configurable with a parameter in LocalSettings.php?

sincerely

--Lef73 20:23, 23 January 2008 (UTC)

Sounds great to me! I look forward to using your updated version. --Vaccano 19:15, 28 January 2008 (UTC)

[edit] Horizontal bug

When you flip the bar chart to be horizontal, it seems to flip the array of the items displayed. For instance:

<bars title="Stuff" ymin=0 ylabel=2 xlabel horizontal>
Cars, 3
Cucumbers, 7
Iglos, 2
</bars>

This will draw a chart where the numbers show up in the right order, but the names are flipped (Iglos come first, followed by cucumbers and then cars, rather than the other way around).

[edit] Horizontal bug: Fix

Version gchart4mw.php of 2008-01-05 shows a wrong order of labels in case of a Horizontal Bar. This can be easily fixed however by applying underneath fix to gchart4mw.php.

Replace this code:

if ($type == "pie") {
    if ($hasxlabel) {
      $rslt = $rslt . "&chl=" . $xlabel;
    }
  } else {    
    if (($hasxlabel) && ($hasylabel)) {
      if ($ishorizontal)
        $rslt = $rslt . "&chxt=x,y";
      else
        $rslt = $rslt . "&chxt=y,x";
      $rslt = $rslt . "&chxl=0:|" . $ylabel . "|1:|" . $xlabel;
  }

With this:

if ($type == "pie") {
    if ($hasxlabel) {
      $rslt = $rslt . "&chl=" . $xlabel;
    }
  } else {    
    if (($hasxlabel) && ($hasylabel)) {
      if ($ishorizontal) {
        $rslt = $rslt . "&chxt=x,y";
        $xlabel = implode('|', array_reverse(explode('|', $xlabel)));
      }
      else
        $rslt = $rslt . "&chxt=y,x";
      $rslt = $rslt . "&chxl=0:|" . $ylabel . "|1:|" . $xlabel;
  }

The key to the solution is reversing the labels in case of a horizontal bar, this happens in the extra line of code:

        $xlabel = implode('|', array_reverse(explode('|', $xlabel)));

Note: The post of this fix can be deleted when this problem is fixed in a new distributed version of gchart4mw.php.

[edit] Conlict with other extension.

It conflicts with Extension:RSS. RSS readers stops working if both extensions are installed --OsvaldoGago 15:00, 29 January 2010 (UTC)

[edit] Set and get value to chart

i'm using combination of runphp and gchart4mw.


$num = 20;

printf("<pie 3d title='Bug List' size=300x150 xlabel>

Open,$num

Fixed,20

Close,91

</pie>

");


now the problem is, i'm getting string of "$num" instead of 20 in the pie tag. have any solution for this problem?

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox