Improved Draw_Table

john's Avatar

john

03 Mar, 2024 04:34 AM

Attached is an improved version of my draw_table node.

Draw_table converts a data table to a graphical object that you can include in your output. It produces a table that looks somewhat like the data view, but with cleaner column spacing.

Like Nodebox's data view, all columns are left-justified. This can make columns of floating point numbers harder to read. Hence, my new option: "Align numbers".

If you check this option, draw_table will detect which table columns are numeric and align the numbers in those columns to their decimal points. It will automatically handle numbers with dollar and percent signs (placing minus signs in front of dollar signs when needed). For larger numbers it will insert separators (comma or period) every three digits depending on local region.

The attached demo and screenshot show one example. Try clicking the "Align numbers" option on and off to see the difference. The date column is recognized as non-numeric (even though all entries contain nothing but numbers and dashes). The other three columns are recognized as numeric and correctly aligned despite the dollar and percent signs.

Detecting and aligning numeric columns is tricky. I tried to anticipate many possible variations, but some unusual tables may fool my node. So if anyone out there uses this node and finds a case where this new option fails, I would really appreciate you sending me the example.

Enjoy!

John

Note: the demo requires dateformat.clj to quickly generate fake dates, but no external libraries are required by the draw_table node.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • draw_table_screenshot.png 890 KB
  • draw_table_demo.zip 15.1 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

23 Apr, 2024 07:54 PM
19 Apr, 2024 04:41 AM
16 Apr, 2024 06:18 PM
16 Apr, 2024 04:23 AM
08 Apr, 2024 01:28 AM

 

07 Apr, 2024 11:50 PM
05 Apr, 2024 11:47 PM
05 Apr, 2024 12:30 AM
25 Mar, 2024 08:48 PM
14 Mar, 2024 07:40 PM
14 Mar, 2024 07:38 PM