[reportlab-users] From intra-paragraph images to drawings?
Dinu Gherman
gherman at darwin.in-berlin.de
Thu May 9 08:09:22 EDT 2013
Robin Becker:
> On 08/05/2013 10:53, Dinu Gherman wrote:
>> Hi,
>>
>> I wonder if anybody has tried to generalize the concept of intra-para-
>> graph images to drawings? This would enable nice features like something
>> called "sparklines", which have been introduced by Edward R. Tufte, if
>> I'm not mistaken. See also this nice jQuery package:
>>
>
> I don't think it would be too hard to make a drawing produce an image that could be injected into a paragraph. The main problem would be how to identify the chart code and data in a sensible way. The img tags have a lot of control over height / width etc etc, but they don't need much more than a uri to identify them. Presumably one could inject a namespace into the parser somehow as is done for various other cases eg callbacks are identified by name and are assumed to live directly on the canvas
>
>> func = getattr(tx._canvas,name,None)
>> if not func:
>> raise AttributeError("Missing %s callback attribute '%s'" % (kind,name))
>> tx._canvas._curr_tx_info=dict(tx=tx,cur_x=cur_x,cur_y=cur_y,leading=leading,xs=tx.XtraState)
>> try:
>> func(tx._canvas,kind,cbDefn.label)
>> finally:
>> del tx._canvas._curr_tx_info
>
> that might work for a drawable object
>
>
>> http://omnipotent.net/jquery.sparkline
>
> I looked at the front page and it looks OK, but I wasn't able to see how data/chart type were selected for the charts; one of the paras is described thus
>
>> <p>
>> Inline
>> <span class="sparkline">
>> <canvas style="display: inline-block; width: 21px; height: 16px; vertical-align: top;" width="21" height="16"></canvas>
>> </span>
>> line graphs
>> <span class="sparkline">
>> <canvas style="display: inline-block; width: 63px; height: 16px; vertical-align: top;" width="63" height="16"></canvas>
>> </span>
>> </p>
>
> but the two charts are different so I guess the data / chart is being pushed into them via the class.
The docs give a better explanation:
http://omnipotent.net/jquery.sparkline/#s-docs
When not set dynamically via JS, chart attributes can be given as HTML attributes of the span tag and the chart data as its text node.
Since the current intra-paragraph images need to have a fixed size, I thought this concept could be applied ot drawings, too. Something like this:
<img src="../images/testimg.gif" />
<drawing src="my.pkg.mod.klass" />
Then we basically need to find the code to draw the thing and pass it some arguments including data. I don't quite see any rocket science in that.
Actually, why not call it a <canvas> element, like in HTML5? Or maybe even create an HTML5-Renderer? That would stir up some people's interest in cross-publishing with Reportlab, maybe, who are turning now to other solutions.
Regards,
Dinu
More information about the reportlab-users
mailing list