Aligment


In [ ]:
import com.twosigma.beakerx.scala.table._
import com.twosigma.beakerx.scala.fileloader.CSV
import com.twosigma.beakerx.table.format.TableDisplayStringFormat
import java.util.concurrent.TimeUnit

// 1 setAlignmentProviderForColumn defaults
val colNames = Seq("string column", "integer column", "double column","time column", "boolean column")
val table1 = new TableDisplay(Seq(Seq("0", 0, 0, 0, 0), 
                                 Seq("June", 22, 33, 1391000000, true), 
                                 Seq("July", 200, 300, 1491000000, false),
                                 Seq("August", 222, 333, 1591000000, true)),
                                 colNames,
                                 Seq("string", "integer", "double", "time", "boolean"))
table1.setStringFormatForTimes(TimeUnit.DAYS)
table1

In [ ]:
// expected result of cell 1
Image("../../resources/img/scala/tableAPI/cell1_case1.png")

In [ ]:
// 1_2 setAlignmentProviderForColumn
val colNames = Seq("string column", "integer column", "double column","time column", "boolean column")
val table1_2 = new TableDisplay(Seq(Seq("0", 0, 0, 0, 0), 
                                 Seq("June", 22, 33, 1391000000, true), 
                                 Seq("July", 200, 300, 1491000000, false),
                                 Seq("August", 222, 333, 1591000000, true)),
                                 colNames,
                                 Seq("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/scala/tableAPI/cell1_case1.png")

In [ ]:
// 2 setAlignmentProviderForType
val colNames = Seq("string column", "integer column", "double column","time column", "boolean column")
val table2 = new TableDisplay(Seq(Seq("0", 0, 0, 0, 0), 
                                 Seq("June", 22, 33, 1391000000, true), 
                                 Seq("July", 200, 300, 1491000000, false),
                                 Seq("August", 222, 333, 1591000000, true)),
                                 colNames,
                                 Seq("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/scala/tableAPI/cell2_case1.png")

Bar Charts Renderer


In [ ]:
// 3
val table3 = new TableDisplay(new CSV().readFile("../../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/scala/tableAPI/cell3_case1.png")

Formatting


In [ ]:
// 4
val table4 = new TableDisplay(new CSV().readFile("../../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/scala/tableAPI/cell4_case1.png")

HTML format


In [ ]:
// 5
val map5 = Map("x" -> "<em style=\"color:red\">italic red</em>", "y" -> "<b style=\"color:blue\">bold blue</b>", "z" -> "multiline strings<br/>work fine too")
val table5 = new TableDisplay(map5)
table5.setStringFormatForColumn("Value", TableDisplayStringFormat.getHTMLFormat())
table5

In [ ]:
// expected result of cell 5
Image("../../resources/img/scala/tableAPI/cell5_case1.png")

Column Visibility and Placement


In [ ]:
// 6
val table6 = new TableDisplay(new CSV().readFile("../../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/scala/tableAPI/cell6_case1.png")

In [ ]:
// 7
val table7 = new TableDisplay(new CSV().readFile("../../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(Seq("m3", "y1", "y10", "time", "y2"))
table7

In [ ]:
// expected result of cell 7
Image("../../resources/img/scala/tableAPI/cell7_case1.png")

HeatmapHighlighter


In [ ]:
// 8 highlighter for row
val table8 = new TableDisplay(new CSV().readFile("../../resources/data/interest-rates-small.csv"))
table8.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter("m3", TableDisplayCellHighlighter.FULL_ROW))
table8

In [ ]:
// expected result of cell 8
Image("../../resources/img/scala/tableAPI/cell8_case1.png")

In [ ]:
// 9 highlighter for column
val table9 = new TableDisplay(new CSV().readFile("../../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/scala/tableAPI/cell9_case1.png")

In [ ]:
// 9_2
table9.removeAllCellHighlighters()
table9

In [ ]:
// expected result of cell 9_2
Image("../../resources/img/scala/tableAPI/cell9_case2.png")

In [ ]:
// 9_3 set HeatmapHighlighter for type
val colNames = Seq("xxx column", "integer column", "double column", "number column")
val row1 = Seq(6, 6, 0.5, 6)
val row2 = Seq(3, 3, 2.0, 3)
val row3 = Seq(2, 2, 3.0, 2)
val row4 = Seq(0, 0, 6.0, 0)
val table93 = new TableDisplay(Seq(row1, row2, row3, row4), colNames, Seq("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/scala/tableAPI/cell9_case3.png")

UniqueEntriesHighlighter


In [ ]:
// 10
val table10 = new TableDisplay(new CSV().readFile("../../resources/data/interest-rates-small.csv"))
table10.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter("m3"))
table10

In [ ]:
// expected result of cell 10
Image("../../resources/img/scala/tableAPI/cell10_case1.png")

In [ ]:
// 11
val table11 = new TableDisplay(new CSV().readFile("../../resources/data/interest-rates-small.csv"))
table11.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter("y1", TableDisplayCellHighlighter.SINGLE_COLUMN))
table11.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter("y3", TableDisplayCellHighlighter.SINGLE_COLUMN))
table11

In [ ]:
// expected result of cell 11
Image("../../resources/img/scala/tableAPI/cell11_case1.png")

FontSize


In [ ]:
// 12
val table12 = new TableDisplay(new CSV().readFile("../../resources/data/interest-rates-small.csv"))
table12.setDataFontSize(10)
table12.setHeaderFontSize(16)
table12

In [ ]:
// expected result of cell 12
Image("../../resources/img/scala/tableAPI/cell12_case1.png")

In [ ]:
// 13
val table13 = new TableDisplay(new CSV().readFile("../../resources/data/interest-rates-small.csv"))
table13.setHeadersVertical(true)
table13

In [ ]:
// expected result of cell 13
Image("../../resources/img/scala/tableAPI/cell13_case1.png")

ColorProvider


In [ ]:
// 14
val mapList14 = List(
 Map("firstCol" -> 1, "secondCol" -> 2, "thirdCol" -> 3),
 Map("firstCol" -> 4, "secondCol" -> 5, "thirdCol" -> 6),
 Map("firstCol" -> 9, "secondCol" -> 8, "thirdCol" -> 9)
)
val table14 = new TableDisplay(mapList14)

val colors = Seq(
            Seq(Color.LIGHT_GRAY, Color.GRAY, Color.RED),
            Seq(Color.YELLOW, Color.ORANGE, Color.RED),
            Seq(Color.MAGENTA, Color.BLUE, Color.BLACK))

table14.setFontColorProvider(new FontColorProvider {
    override def apply(row: Integer, col: Integer, display: com.twosigma.beakerx.table.TableDisplay): Color = {
        colors(row)(col)
    }
})

table14

In [ ]:
// expected result of cell 14
Image("../../resources/img/scala/tableAPI/cell14_case1.png")

ToolTip


In [ ]:
// 15
val table15 = new TableDisplay(new CSV().readFile("../../resources/data/interest-rates-small.csv"))

table15.setTooltip(new TooltipAction {
    override def apply(row: Integer, col: Integer, display: com.twosigma.beakerx.table.TableDisplay): String = {
         "The value is: " + display.getValues().get(row).get(col)
    }
})

table15

Image format


In [ ]:
// 16_1
val table16_1 = new TableDisplay(Seq(
    Map("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/scala/tableAPI/cell16_case1.png")

In [ ]:
// 16_2
val table16_2 = new TableDisplay(Map(
    "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/scala/tableAPI/cell16_case2.png")

Seamless Update


In [ ]:
// 19
val table19 = new TableDisplay(Seq(
    Map("a" -> 1, "b" -> 2, "c" -> 3),
    Map("a" -> 4, "b" -> 5, "c" -> 6),
    Map("a" -> 7, "b" -> 8, "c" -> 9),
));
table19

In [ ]:
table19.updateCell(2,"c",121)
table19.sendModel()

In [ ]:
// expected result of cell 19_1
Image("../../resources/img/scala/tableAPI/cell19_case1.png")

In [ ]:
// expected result of cell 19_2
Image("../../resources/img/scala/tableAPI/cell19_case2.png")

RowFilter


In [ ]:
//20
import java.{lang, util}

val table20 = new TableDisplay(Seq(
    Map("firstCol" -> 1, "secondCol" -> 2, "thirdCol" -> 3),
    Map("firstCol" -> 4, "secondCol" -> 8, "thirdCol" -> 6),
    Map("firstCol" -> 7, "secondCol" -> 8, "thirdCol" -> 9)
));
// table20.setRowFilter { row, model ->
//  model[row][1] == 8
// }
table20.setRowFilter(new RowFilter {
override def apply(row: Integer, values: util.List[util.List[_]]): lang.Boolean = {
        if (values.get(row).get(1).asInstanceOf[Int] == 8) true else false
    }
})
table20

In [ ]:
// expected result of cell 20_1
Image("../../resources/img/scala/tableAPI/cell20_case1.png")

The length of types should be same as number of cols.


In [ ]:
val colNames = Seq("column 1", "column 2", "column 3")
val row1 = Seq(6, 6, 0.5)
val row2 = Seq(3, 3, 2.0)
val table94 = new TableDisplay(Seq(row1, row2), colNames, Seq("integer", "double"))
table94

Rows to show


In [ ]:
// 
val tableRTS = new TableDisplay(new CSV().readFile("../../resources/data/interest-rates.csv"))
tableRTS.setRowsToShow(RowsToShow.SHOW_10)
tableRTS

In [ ]: