PINE LIBRARY

TableBuilder

Telah dikemas kini
TableBuilder is a library designed to make it easier to create tables in PineScript.
It allows you to more flexibly define the structure of a table before actually building it.

Features:
  • Style inheritance: styles are inherited from Table, to Column, to Row, and then Cell.
  • Columns are useful for propagating/reusing style but they are not required.
  • Add rows with different numbers of cells. The resultant number of columns in the table will be determined by the max number of cells vs the number of defined columns.
  • Auto text color: Instead of having to set the font color for every cell, the color is automatically determined by the luminosity of the background color.


See the 'Demo' section of the code for an example.
Nota Keluaran
Improved thumbnail.
Nota Keluaran
v3: More segmentation of functions.

Added:
gridSize(tbl)
  Parameters:
    tbl: The table to get the dimensions of.
  Returns: [columns, rows]

updateStyle(tbl, style)
  Updates the style of a table but not the cells.
  Parameters:
    tbl: The table to update the style of.
    style: The new style to use for the table.

initialize(tbl)
  Initializes a table with the given size and style.
  Parameters:
    tbl: The table to initialize.
  Returns: A tuple containing the initialized table, the number of columns, and the number of rows. [table, columns, rows]

update(pineTable, tbl)
  Updates an existing PineScript table with the data and style from a Table object.
  Parameters:
    pineTable: The existing PineScript table to update.
    tbl: The Table object containing the data and style to update the existing table with.
Nota Keluaran
v4 Heavy revision in order to use more shallow User Defined Types (UDTs).

Added:
createRow(contents, height, tooltip)
  Creates a new row with an array of cells containing the given contents.
  Parameters:
    contents: An array of strings representing the cell contents.
    height: The height of the row.
    tooltip: The tooltip of the row.
  Returns: A new Row object.

updateRow(t, row, cells, tooltip)
  Updates a row of cells in a table with the given cell content.
  Parameters:
    t: The table to update.
    row: The index of the row to update.
    cells: The array of cell content to set in the row.
    tooltip: The optional default tooltip to use if the cell's value is na.

style(t, firstCol, lastCol, firstRow, lastRow, bgColor)
  Styles the cells in the given range of the table with the given background color while automatically chosing a foreground color.
  Parameters:
    t: The table to style.
    firstCol: The index of the first column in the range.
    lastCol: The index of the last column in the range.
    firstRow: The index of the first row in the range.
    lastRow: The index of the last row in the range.
    bgColor: The background color to apply.

styleColumns(t, first, last, bgColor)
  Parameters:
    t
    first
    last
    bgColor

styleColumn(t, col, bgColor)
  Parameters:
    t
    col
    bgColor

styleRows(t, first, last, bgColor)
  Parameters:
    t
    first
    last
    bgColor

styleRow(t, col, bgColor)
  Parameters:
    t
    col
    bgColor

CellAlign
  Fields:
    horizontal
    vertical

CellStyle
  Fields:
    bgColor
    width
    height

TableSize
  Fields:
    columns
    rows

Updated:
addCell(row, contents, format, tooltip)
  Adds a new cell with the given integer contents to the row.
  Parameters:
    row: The row to add the cell to.
    contents: The contents of the new cell, an integer.
    format: The format string for the integer.
    tooltip: The tooltip of the new cell.
  Returns: The new Cell object.

addRow(rows, contents, height, tooltip)
  Adds a new row to the array of rows using the given array of cell contents.
  Parameters:
    rows: An array of rows.
    contents: The array of cell contents to use for the new row.
    height: The height of the new row.
    tooltip: The tooltip of the new row.
  Returns: The new Row object.

updateStyle(t, style)
  Updates a PineScript table with the style properties of the given TableStyle.
  Parameters:
    t: The PineScript table to update.
    style: The TableStyle containing the style properties to apply.

initialize(rows, position, border, frame)
  Initializes a new PineScript table with the given data rows and table style.
  Parameters:
    rows: An array of Rows to populate the table with.
    position: The position of the table within the chart.
    border: The optional border style for the table.
    frame: The optional frame style for the table.
  Returns: The new PineScript table.

Removed:
create(position, style)
  Creates a new table with an optional style.

equals(a, b)
  Determines if two TableStyles are equal.

inherit(child, parent)
  Creates a TableStyle with the same property values as the child but inherits properties from the parent if the child property is na.

getStyleChange(child, parent)
  Creates a TableStyle that only uses property values from the child that differ from the parent.

addColumn(table, style)
  Adds a new column to the given table with optional style.

gridSize(tbl)

update(pineTable, tbl)
  Updates an existing PineScript table with the data and style from a Table object.

build(tbl)
  Builds a table in PineScript based on a given Table object. Any values that are 'na' will simply not be set.

Column
Nota Keluaran
v5 Added function for styling all cells.
Nota Keluaran
v6 Added a styleRows function for updating background color using an array.
Nota Keluaran
v7 Leave na values blank when adding cells.
Nota Keluaran
v8 Fixed row tooltip.
Nota Keluaran
v9 Updated color lib
Nota Keluaran
v10 Fix and demonstrate row tooltips.
Nota Keluaran
v11 Fixed looping issues.
Nota Keluaran
v12 More loop fixes.
Nota Keluaran
v13 Fix out of bounds issue.
Nota Keluaran
v14 Extend types with methods.
CELLcellscolumncolumnsdisplayformattingROWrowstabletables

Perpustakaan Pine

Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai satu perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman.

Penafian