PINE LIBRARY

Autotable

█ OVERVIEW

The library allows to automatically draw a table based on a string or float matrix (or both) controlling all of the parameters of the table (including merging cells) with parameter matrices (like, e.g. matrix of cell colors).

All things you would normally do with table.new() and table.cell() are now possible using respective parameters of library's main function, autotable() (as explained further below).

Headers can be supplied as arrays.

Merging of the cells is controlled with a special matrix of "L" and "U" values which instruct a cell to merged with the cell to the left or upwards (please see examples in the script and in this description).


█ USAGE EXAMPLES

The simplest and most straightforward:


Draws this:
snapshot


Tables with headers:


Draws this:
snapshot


█ FUNCTIONS

One main function is autotable() which has only one required argument mxValS, a string matrix.

Please see below the description of all of the function parameters:

The table:
  tbl (table) (Optional) If supplied, this table will be deleted.

The data:
  mxValS (matrix<string> ) (Required) Cell text values
  mxValF (matrix<float>) (Optional) Numerical part of cell text values. Is concatenated to the mxValS values via `string_float_separator` string (default "\n")


Table properties, have same effect as in table.new():
  defaultBgColor (color) (Optional) bgcolor to be used if mxBgColor is not supplied
  Ypos (string) (Optional) "top", "bottom" or "center"
  Xpos (string) (Optional) "left", "right", or "center"
  frame_color (color) (Optional) frame_color like in table.new()
  frame_width (int) (Optional) frame_width like in table.new()
  border_color (color) (Optional) border_color like in table.new()
  border_width (int) (Optional) border_width like in table.new()
  force_overlay (simple bool) (Optional) If true draws table on main pane.


Cell parameters, have same effect as in table.cell()):
  mxBgColor (matrix<color>) (Optional) like bgcolor argument in table.cell()
  mxTextColor (matrix<color>) (Optional) like text_color argument in table.cell()
  mxTt (matrix<string>) (Optional) like tooltip argument in table.cell()
  mxWidth (matrix<float>) (Optional) like width argument in table.cell()
  mxHeight (matrix<float>) (Optional) like height argument in table.cell()
  mxHalign (matrix<string>) (Optional) like text_halign argument in table.cell()
  mxValign (matrix<string>) (Optional) like text_valign argument in table.cell()
  mxTextSize (matrix<string>) (Optional) like text_size argument in table.cell()
  mxFontFamily (matrix<string>) (Optional) like text_font_family argument in table.cell()


Other table properties:
  tableWidth (float) (Optional) Overrides table width if cell widths are non zero. E.g. if there are four columns and cell widths are 20 (either as set via cellW or via mxWidth) then if tableWidth is set to e.g. 50 then cell widths will be 50 * (20 / 80), where 80 is 20*4 = total width of all cells. Works simialar for widths set via mxWidth - determines max sum of widths across all cloumns of mxWidth and adjusts cell widths proportionally to it. If cell widths are 0 (i.e. auto-adjust) tableWidth has no effect.
  tableHeight (float) (Optional) Overrides table height if cell heights are non zero. E.g. if there are four rows and cell heights are 20 (either as set via cellH or via mxHeight) then if tableHeigh is set to e.g. 50 then cell heights will be 50 * (20 / 80), where 80 is 20*4 = total height of all cells. Works simialar for heights set via mxHeight - determines max sum of heights across all cloumns of mxHeight and adjusts cell heights proportionally to it. If cell heights are 0 (i.e. auto-adjust) tableHeight has no effect.
  defaultTxtColor (color) (Optional) text_color to be used if mxTextColor is not supplied
  text_size (string) (Optional) text_size to be used if mxTextSize is not supplied
  font_family (string) (Optional) cell text_font_family value to be used if a value in mxFontFamily is no supplied
  cellW (float) (Optional) cell width to be used if a value in mxWidth is no supplied
  cellH (float) (Optional) cell height to be used if a value in mxHeight is no supplied
  halign (string) (Optional) cell text_halign value to be used if a value in mxHalign is no supplied
  valign (string) (Optional) cell text_valign value to be used if a value in mxValign is no supplied


Headers parameters:
  arColTitles (array<string>) (Optional) Array of column titles. If not na a header row is added.
  arRowTitles (array<string>) (Optional) Array of row titles. If not na a header column is added.
  cornerTitle (string) (Optional) If both row and column titles are supplied allows to set the value of the corner cell.
  colTitlesBgColor (color) (Optional) bgcolor for header row
  colTitlesTxtColor (color) (Optional) text_color for header row
  rowTitlesBgColor (color) (Optional) bgcolor for header column
  rowTitlesTxtColor (color) (Optional) text_color for header column
  cornerBgClr (color) (Optional) bgcolor for the corner cell
  cornerTxtClr (color) (Optional) text_color for the corner cell


Cell merge parameters:
  mxMerge (matrix<string>) (Optional) A matrix determining how cells will be merged. "L" - cell merges to the left, "U" - upwards.
  mergeAllColTitles (bool) (Optional) Allows to print a table title instead of column headers, merging all header row cells and leaving just the value of the first cell. For more flexible options use matrix arguments leaving header/row arguments na.
  mergeAllRowTitles (bool) (Optional) Allows to print one text value merging all header row cells and leaving just the value of the first cell. For more flexible options use matrix arguments leaving header/row arguments na.


Format:
  string_float_separator (string) (Optional) A string used to separate string and float parts of cell values (mxValS and mxValF). Default is "\n"
  format (string) (Optional) format string like in str.format() used to format numerical values
  nz (string) (Optional) Determines how na numerical values are displayed.



The only other available function is autotable(string,... ) with a string parameter instead of string and float matrices which draws a one cell table.

█ SAMPLE USE
E.g., CSVParser library demo uses Autotable's for generating complex tables with merged cells.

█ CREDITS
The library was inspired by kaigouthro's matrixautotable. A true master. Many thanks to him for his creative, beautiful and very helpful libraries.

displaymatrixtable

Bibliothèque Pine

Dans le plus pur esprit TradingView, l'auteur a publié ce code Pine en tant que bibliothèque open-source afin que d'autres programmeurs Pine de notre communauté puissent le réutiliser. Bravo à l'auteur! Vous pouvez utiliser cette bibliothèque en privé ou dans d'autres publications à code source ouvert, mais la réutilisation de ce code dans une publication est régie par nos Règles.

Clause de non-responsabilité