In [ ]:
import com.twosigma.beakerx.table.*
import com.twosigma.beakerx.fileloader.CSV
import com.twosigma.beakerx.table.format.TableDisplayStringFormat
// 1 setAlignmentProviderForColumn defaults
def colNames = ["string column", "integer column", "double column","time column", "boolean column"]
def row1 = ["0", 0, 0, 0, 0]
def row2 = ["June", 22, 33, 1391000000, true]
def row3 = ["July", 200, 300, 1491000000, false]
def row4 = ["August", 222, 333, 1591000000, true]
table1 = new TableDisplay([row1, row2, row3, row4], colNames, ['string', 'integer', 'double', 'time', 'boolean'])
table1.setStringFormatForTimes(TimeUnit.DAYS)
table1
In [ ]:
// expected result of cell 1
Image("../../resources/img/groovy/tableAPI/cell1_case1.png")
In [ ]:
// 1_2 setAlignmentProviderForColumn
def colNames = ["string column", "integer column", "double column","time column", "boolean column"]
def row1 = ["0", 0, 0, 0, 0]
def row2 = ["June", 22, 33, 1391000000, true]
def row3 = ["July", 200, 300, 1491000000, false]
def row4 = ["August", 222, 333, 1591000000, true]
table1_2 = new TableDisplay([row1, row2, row3, row4], colNames, ['string', 'integer', 'double', 'time', 'boolean'])
table1_2.setStringFormatForTimes(TimeUnit.DAYS)
table1_2.setAlignmentProviderForColumn(colNames[0], TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
table1_2.setAlignmentProviderForColumn(colNames[1], TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
table1_2.setAlignmentProviderForColumn(colNames[2], TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
table1_2.setAlignmentProviderForColumn(colNames[3], TableDisplayAlignmentProvider.LEFT_ALIGNMENT)
table1_2.setAlignmentProviderForColumn(colNames[4], TableDisplayAlignmentProvider.RIGHT_ALIGNMENT)
table1_2
In [ ]:
// expected result of cell 1_2
Image("../../resources/img/groovy/tableAPI/cell1_case2.png")
In [ ]:
// 2 setAlignmentProviderForType
def colNames = ["string column", "integer column", "double column","time column", "boolean column"]
def row1 = ["0", 0, 0, 0, 0]
def row2 = ["June", 22, 33, 1391000000, true]
def row3 = ["July", 200, 300, 1491000000, false]
def row4 = ["August", 222, 333, 1591000000, true]
table2 = new TableDisplay([row1, row2, row3, row4], colNames, ['string', 'integer', 'double', 'time', 'boolean'])
table2.setStringFormatForTimes(TimeUnit.DAYS)
table2.setAlignmentProviderForType(ColumnType.String, TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
table2.setAlignmentProviderForType(ColumnType.Integer, TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
table2.setAlignmentProviderForType(ColumnType.Double, TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
table2.setAlignmentProviderForType(ColumnType.Time, TableDisplayAlignmentProvider.LEFT_ALIGNMENT)
table2.setAlignmentProviderForType(ColumnType.Boolean, TableDisplayAlignmentProvider.RIGHT_ALIGNMENT)
table2
In [ ]:
// expected result of cell 2
Image("../../resources/img/groovy/tableAPI/cell2_case1.png")
In [ ]:
// 3
table3 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table3.setRendererForType(ColumnType.Double, TableDisplayCellRenderer.getDataBarsRenderer(true))
// use the false parameter to hide value
table3.setRendererForColumn("y10", TableDisplayCellRenderer.getDataBarsRenderer(false))
table3
In [ ]:
// expected result of cell 3
Image("../../resources/img/groovy/tableAPI/cell3_case1.png")
In [ ]:
// 4
table4 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table4.setStringFormatForTimes(TimeUnit.DAYS)
table4.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(2,3))
table4.setStringFormatForColumn("m3", TableDisplayStringFormat.getDecimalFormat(0, 0))
table4
In [ ]:
// expected result of cell 4
Image("../../resources/img/groovy/tableAPI/cell4_case1.png")
In [ ]:
// 5
table5 = new TableDisplay([x: '<em style="color:red">italic red</em>',
y: '<b style="color:blue">bold blue</b>',
z: 'multiline strings<br/>work fine too']);
table5.setStringFormatForColumn("Value", TableDisplayStringFormat.getHTMLFormat())
table5
In [ ]:
// expected result of cell 5
Image("../../resources/img/groovy/tableAPI/cell5_case1.png")
In [ ]:
// 6
table6 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
//freeze a column
table6.setColumnFrozen("y1", true)
//hide a column
table6.setColumnVisible("y30", false)
table6
In [ ]:
// expected result of cell 6
Image("../../resources/img/groovy/tableAPI/cell6_case1.png")
In [ ]:
// 7
table7 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
// Columns in the list will be shown in the provided order. Columns not in the list will be hidden.
table7.setColumnOrder(["m3", "y1", "y10", "time", "y2"])
table7
In [ ]:
// expected result of cell 7
Image("../../resources/img/groovy/tableAPI/cell7_case1.png")
In [ ]:
// 8 highlighter for row
table8 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table8.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter("m3", TableDisplayCellHighlighter.FULL_ROW))
table8
In [ ]:
// expected result of cell 8
Image("../../resources/img/groovy/tableAPI/cell8_case1.png")
In [ ]:
// 9 highlighter for column
table9 = new TableDisplay(new CSV().read("../../resources/data/interest-rates-small.csv"))
table9.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter("m6", TableDisplayCellHighlighter.SINGLE_COLUMN, 6, 8, Color.BLACK, Color.PINK))
table9.addCellHighlighter(new ThreeColorHeatmapHighlighter("y1", TableDisplayCellHighlighter.SINGLE_COLUMN, 4, 6, 8, new Color(247,106,106), new Color(239,218,82), new Color(100,189,122)))
table9
In [ ]:
// expected result of cell 9
Image("../../resources/img/groovy/tableAPI/cell9_case1.png")
In [ ]:
// 9_2
table9.removeAllCellHighlighters()
table9
In [ ]:
// expected result of cell 9_2
Image("../../resources/img/groovy/tableAPI/cell9_case2.png")
In [ ]:
// 9_3 set HeatmapHighlighter for type
def colNames = ["xxx column", "integer column", "double column", "number column"]
def row1 = [6, 6, 0.5, 6]
def row2 = [3, 3, 2.0, 3]
def row3 = [2, 2, 3.0, 2]
def row4 = [0, 0, 6.0, 0]
table93 = new TableDisplay([row1, row2, row3, row4], colNames, ['xxx type', 'integer', 'double', 'number'])
table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[0], TableDisplayCellHighlighter.SINGLE_COLUMN))
table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[1], TableDisplayCellHighlighter.SINGLE_COLUMN))
table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[2], TableDisplayCellHighlighter.SINGLE_COLUMN))
table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[3], TableDisplayCellHighlighter.SINGLE_COLUMN))
table93
In [ ]:
// expected result of cell 9_3
Image("../../resources/img/groovy/tableAPI/cell9_case3.png")
In [ ]:
// 10
table10 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table10.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter("m3"))
table10
In [ ]:
// expected result of cell 10
Image("../../resources/img/groovy/tableAPI/cell10_case1.png")
In [ ]:
// 11
table11 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table11.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter("y30", TableDisplayCellHighlighter.SINGLE_COLUMN))
table11.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter("m6", TableDisplayCellHighlighter.SINGLE_COLUMN))
table11
In [ ]:
// expected result of cell 11
Image("../../resources/img/groovy/tableAPI/cell11_case1.png")
In [ ]:
// 12
table12 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table12.setDataFontSize(10)
table12.setHeaderFontSize(16)
table12
In [ ]:
// expected result of cell 12
Image("../../resources/img/groovy/tableAPI/cell12_case1.png")
In [ ]:
// 13
table13 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table13.setHeadersVertical(true)
table13
In [ ]:
// expected result of cell 13
Image("../../resources/img/groovy/tableAPI/cell13_case1.png")
In [ ]:
// 14
def mapListColorProvider = [
[firstCol:1, secondCol:2, thirdCol:3],
[firstCol:4, secondCol:5, thirdCol:6],
[firstCol:9, secondCol:8, thirdCol:9]
]
table14 = new TableDisplay(mapListColorProvider)
colors = [
[Color.LIGHT_GRAY, Color.GRAY, Color.RED],
[Color.DARK_GREEN, Color.ORANGE, Color.RED],
[Color.MAGENTA, Color.BLUE, Color.BLACK]
]
table14.setFontColorProvider { row, col, td ->
colors[row][col]
}
table14
In [ ]:
// expected result of cell 14
Image("../../resources/img/groovy/tableAPI/cell14_case1.png")
In [ ]:
// 15
table15 = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
table15.setToolTip { row, col, display ->
"The value is: " + display.values[row][col]
}
table15
In [ ]:
// 16_1
table16_1 = new TableDisplay([['Peacock': '../../resources/img/butterfly1.jpg',
'Morpho': '../../resources/img/butterfly2.jpg',
'Swallowtail': '../../resources/img/butterfly3.jpg']]);
table16_1.setStringFormatForColumn('Peacock', TableDisplayStringFormat.getImageFormat());
table16_1.setStringFormatForColumn('Morpho', TableDisplayStringFormat.getImageFormat());
table16_1
In [ ]:
// expected result of cell 16_1
Image("../../resources/img/groovy/tableAPI/cell16_case1.png")
In [ ]:
// 16_2
table16_2 = new TableDisplay(['up': 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgaGVpZ2h0PSI2NCIgd2lkdGg9IjY0IiB2aWV3Qm94PSIwIDAgNjQgNjQiPg0KICA8cG9seWdvbiBmaWxsPSIjNmJhMmM3IiBwb2ludHM9IjMwLDQgNCw2MCA2MCw2MCI+PC9wb2x5Z29uPg0KPC9zdmc+DQo=',
'down': 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIGhlaWdodD0iNjQiIHdpZHRoPSI2NCIgdmlld0JveD0iMCAwIDY0IDY0Ij4KICA8cG9seWdvbiBmaWxsPSIjNmJhMmM3IiBwb2ludHM9IjMwLDYwIDYwLDQgNCw0Ij48L3BvbHlnb24+Cjwvc3ZnPgo=']);
table16_2.setStringFormatForColumn("Value", TableDisplayStringFormat.getImageFormat())
table16_2
In [ ]:
// expected result of cell 16_2
Image("../../resources/img/groovy/tableAPI/cell16_case2.png")
In [ ]:
// 19
def mapListToUpdate = [
[a:1, b:2, c:3],
[a:4, b:5, c:6],
[a:7, b:8, c:9]
]
table19 = new TableDisplay(mapListToUpdate)
table19
In [ ]:
// table19.values[0][0] = 99
// table19.sendModel()
table19.values
In [ ]:
// expected result of cell 19
Image("../../resources/img/groovy/tableAPI/cell19_case1.png")
In [ ]:
// expected result of cell 19 after sendModel()
Image("../../resources/img/groovy/tableAPI/cell19_case2.png")
In [ ]:
def mapList20 = [
[firstCol:1, secondCol:2, thirdCol:3],
[firstCol:4, secondCol:8, thirdCol:6],
[firstCol:9, secondCol:8, thirdCol:9]
]
table20 = new TableDisplay(mapList20)
table20.setRowFilter { row, model ->
model[row][1] == 8
}
table20
In [ ]:
// expected result of cell 20
Image("../../resources/img/groovy/tableAPI/cell20_case1.png")
In [ ]:
// expected result is error message
def colNames = ["column 1", "column 2", "column 3"]
def row1 = [6, 6, 0.5]
def row2 = [3, 3, 2.0]
table94 = new TableDisplay([row1, row2], colNames, ['integer', 'double' ])
table94
In [ ]:
TableDisplay.setTimeZoneGlobally("Europe/London")
In [ ]:
tableGTZ = new TableDisplay(new CSV().read('../../resources/data/interest-rates-small.csv'))
tableGTZ
In [ ]:
tableGTZ.setTimeZone("America/Los_Angeles")