Render a table content with Google barchart

This feature took me some time to figure out how to render the content of a normal table with the google chart mashup. Believe it or not it’s just one line of code and a trick when you have headers in the table.

The one line looks like the following:
{{google.piechart(400,200,xml.list(page.xml, “//tr/td[2]”),xml.list(page.xml, “//tr/td[1]”), _,true)}}

How it works:
Dekiscript is a powerful language to manipulate content inside and between wikipages. The google barchart expect to “list”, one with the labels and one with the values. The trick is to extract the table content with dekiscript by using xml.list and page.xml. with xml.list you perform the XPath-Query “//tr/td[2]” on the XML representation of a page (page.xml). When you call page.xml without any parameter the actual page is returned.

Hint 2: when you have a header line in your table you must manually change the tags of the first row to which means in HTML this is a header row. The google barchart will then exclude this row. Maybe someone has an idea to solve this more elegant.

Simple as possible. Great job of mindtouch.

Display several locations in Google Maps

Here is one simple example which explains how to display several adresses with google mashup and display them in parallel as table.

Dekiwiki pages provide something called a pagebus which allows several “objects” e.g. mashup to communicate. The basic idea how to solve this problem is to publish the adresses on the page bus and configure the google mashup and dhtml table to listen on one specific channel. As additional example I show how to add dynamically adresses via a dynamic form.

Hint:

  • dhtml fetches all messages from the pagebus
  • google maps only fetches those messages which are published after it is displayed
  • google maps looks for messages with attributes “address” and “label”. Every other attribute is ignored
  • if you have an error it’s likely you have a typo


{{ dhtml.form([ { field:”restaurant”, label:”restaurant” }, { field:”address”, label:”address” } ] , “Add”,100,”data1″) }}

{{dhtml.table( [ { field:”restaurant”, label:”restaurant” }, { field:”address”, label:”address” } ] , “data1” ) }}

{{ google.Map{address: ” Vienna, Austria”, zoom: “12”,subscribe:”data1″} }}

{{ pagebus.publish { channel:”data1″, message: { restaurant:’Asian noodles’, address: ‘Karlsplatz 1, Vienna, Austria’, label: ‘Asian noodles’ } } }}

Add styles for ok, alert and todo

One simple trick to enhance the layout of your dekiwiki is to add custom styles to your editor.

Goto Control Panel>Customize>CustomCSS and add the following css fragment to the “Content CSS” section of the page:

.qok {background:#FFFBC5 url(/deki-cp/assets/images/icons/tick.gif) no-repeat scroll 10px center;border:1px solid #DEDEDE;margin:8px 0 0;padding:8px 8px 8px 35px}
.qinfo {background:#F2F7FA url(/deki-cp/assets/images/icons/information.gif) no-repeat scroll 10px center;border:1px solid #DEDEDE;margin:8px 0 0;padding:8px 8px 8px 35px}
.qerror {background:#FFFBC5 url(/deki-cp/assets/images/icons/cross.gif) no-repeat scroll 10px center;border:1px solid #DEDEDE;margin:8px 0 0;padding:8px 8px 8px 35px}
.qalert {background:#FFFBC5 url(/deki-cp/assets/images/icons/error.gif) no-repeat scroll 10px center;border:1px solid #DEDEDE;margin:8px 0 0;padding:8px 8px 8px 35px}
.comment {color:blue;font-style:italic;padding:8px 35px 8px 35px}

Maybe the URL for the icons is not working on your installation. In that case deploy your own icons to the webserver and update the image URLs to reflect the changes.