emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Table formula and text properties
@ 2015-01-07 17:11 Willem Rein Oudshoorn
  2015-01-08 17:26 ` Michael Brand
  0 siblings, 1 reply; 3+ messages in thread
From: Willem Rein Oudshoorn @ 2015-01-07 17:11 UTC (permalink / raw)
  To: emacs-orgmode

I am trying to insert an image into a table by using a table formula.
My basic approach is by using a string with a display property like:


  (propertize "TEXT" 'display (list image))


Or to be more precise

   (propertize "SPARKLINE" 'display
               (list (sparkline-make-sparkline
                        100 10
                           '(1 20 12 13 141 13 24 90))))

In which the `sparkline-make-sparkline' function returns an image.

Inserting the resulting string with `insert' into a buffer will ensure
the image is displayed.

However org mode table formula code seems to strip the display property
from the string returned by the formula.  So this trick will not work.

Is there a way to insert a calculated image into an org table?

Kind regards,
Wim Oudshoorn.


   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Table formula and text properties
  2015-01-07 17:11 Table formula and text properties Willem Rein Oudshoorn
@ 2015-01-08 17:26 ` Michael Brand
  2015-01-08 18:52   ` Willem Rein Oudshoorn
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Brand @ 2015-01-08 17:26 UTC (permalink / raw)
  To: Willem Rein Oudshoorn; +Cc: Org Mode

Hi Wim

On Wed, Jan 7, 2015 at 6:11 PM, Willem Rein Oudshoorn
<woudshoo@xs4all.nl> wrote:
> I am trying to insert an image into a table by using a table formula.
> My basic approach is by using a string with a display property like:
>
>
>   (propertize "TEXT" 'display (list image))
>
>
> Or to be more precise
>
>    (propertize "SPARKLINE" 'display
>                (list (sparkline-make-sparkline
>                         100 10
>                            '(1 20 12 13 141 13 24 90))))
>
> In which the `sparkline-make-sparkline' function returns an image.

Very interesting. Your package to insert a sparkline image
http://en.wikipedia.org/wiki/Sparkline
into an Emacs buffer is nice:
https://github.com/woudshoo/sparkline

> Inserting the resulting string with `insert' into a buffer will ensure
> the image is displayed.
>
> However org mode table formula code seems to strip the display property
> from the string returned by the formula.  So this trick will not work.

I think this is by design. If someone wants to change current behavior
then there are other issues to be considered: An 80 by 8 pixel image
that is inserted with

    (insert-image
     (sparkline-make-sparkline 80 8 '(1 20 12 13 141 13 24 90))
     "SPARKLINE")

with point in a table is first visible as an image but will change to
the text "SPARKLINE" after e. g. table realignment. And determining
column width around an image for table realignment would not be
trivial.

> Is there a way to insert a calculated image into an org table?

Below is a unicode ASCII art solution with Zach Holman's shell script
package Spark:
https://github.com/holman/spark

| Measurement | t0 | t1 | t2 | t3 |  t4 | t5 | t6 | t7 | Sparkline |
|-------------+----+----+----+----+-----+----+----+----+-----------|
|           1 |  1 | 20 | 12 | 13 | 141 | 13 | 24 | 90 | ▁▁▁▁█▁▂▅  |
|           2 |  0 |  1 |  2 |  3 |   4 |  5 |  6 |  7 | ▁▂▃▄▅▆▇█  |
|           3 |  0 |  2 |  4 |  6 |   8 | 10 | 12 | 14 | ▁▂▃▄▅▆▇█  |
|           4 | -7 | -6 | -5 | -4 |  -3 | -2 | -1 |  0 | ▁▂▃▄▅▆▇█  |
|           5 |  0 |  0 |  0 |  0 |   0 |  0 |  0 |  0 | ▅▅▅▅▅▅▅▅  |
#+TBLFM: $10 = '(org-trim (shell-command-to-string "spark $2..$9")); L

It would be nice if in your package someone could support one of

    (sparkline-make-sparkline nil nil
                              '(1 20 12 13 141 13 24 90)) => "▁▁▁▁█▁▂▅"
    (sparkline-make-unicode 1 20 12 13 141 13 24 90) => "▁▁▁▁█▁▂▅"

to work like Zach Holman's Spark to replace the above TBLFM with one
of

    #+TBLFM: $10 = '(sparkline-make-sparkline nil nil '($2..$9)); L
    #+TBLFM: $10 = '(sparkline-make-unicode $2..$9); L

For completeness I would like to mention Thierry Banel's
orgtbl-ascii-plot which has been added to Org core meanwhile:
http://orgmode.org/worg/org-contrib/orgtbl-ascii-plot.html

Michael

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Table formula and text properties
  2015-01-08 17:26 ` Michael Brand
@ 2015-01-08 18:52   ` Willem Rein Oudshoorn
  0 siblings, 0 replies; 3+ messages in thread
From: Willem Rein Oudshoorn @ 2015-01-08 18:52 UTC (permalink / raw)
  To: emacs-orgmode

Michael Brand <michael.ch.brand@gmail.com> writes:

> Hi Wim
>
> On Wed, Jan 7, 2015 at 6:11 PM, Willem Rein Oudshoorn
> <woudshoo@xs4all.nl> wrote:

>> ...
>> However org mode table formula code seems to strip the display property
>> from the string returned by the formula.  So this trick will not work.
>
> I think this is by design. If someone wants to change current behavior
> then there are other issues to be considered: An 80 by 8 pixel image
> that is inserted with
>
>     (insert-image
>      (sparkline-make-sparkline 80 8 '(1 20 12 13 141 13 24 90))
>      "SPARKLINE")
>
> with point in a table is first visible as an image but will change to
> the text "SPARKLINE" after e. g. table realignment. And determining
> column width around an image for table realignment would not be
> trivial.

Thank you for your thoughtful answer.

You mention two issues here

1.  After realignment the image will be replaced by text
2.  The difficulty of determining the width of an image

The first item should in theory not be a problem, text properties come
witht the string, so as long as org mode does not remove the text
properties the image should stay with the string, even after realigment.
(However this is spoken as someone with no experience with the org code,
so take this with some bucket loads of salt.)

The second problem is indeed much harder.  One way I can see this
working is if org mode would use the 'space :align-to specification to
align the table, and trust the underlying string to ensure enough space
is reserved for the image.  This would indeed be tricky.
Another potential hack is by querying the font width and use that in the
calculation of the width for the image when generating.

However, it seems not be possible at the moment, and I do not know how
much work changing org-mode is to deal with text properties.

If it is not too hard, it might be worth it anyway, formulas could attach
a face to the result and this might be useful.

> It would be nice if in your package someone could support one of
>
>     (sparkline-make-sparkline nil nil
>                               '(1 20 12 13 141 13 24 90)) => "▁▁▁▁█▁▂▅"
>     (sparkline-make-unicode 1 20 12 13 141 13 24 90) => "▁▁▁▁█▁▂▅"
>

That would not be too hard.  But I am not sure I am too interested.
At the moment I have a CSV mode that uses sparkline to generate graphs of
series with 100's of data points and I fear that the ASCII art version
will not give nearly the same information as the graphical version.

Unfortunately I do not have much time now, so looking into
this might not happen :-(.

> For completeness I would like to mention Thierry Banel's
> orgtbl-ascii-plot which has been added to Org core meanwhile:
> http://orgmode.org/worg/org-contrib/orgtbl-ascii-plot.html

A that looks nice too, thank you for mentioning this.

Kind regards,
Wim Oudshoorn.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-08 18:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-07 17:11 Table formula and text properties Willem Rein Oudshoorn
2015-01-08 17:26 ` Michael Brand
2015-01-08 18:52   ` Willem Rein Oudshoorn

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).