<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Scala API to the Table Widget\n",
    "\n",
    "This API is being [improved](https://github.com/twosigma/beakerx/issues/5798)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "val table = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import java.util.concurrent.TimeUnit\n",
    "\n",
    "val display = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "//show all time columns in days\n",
    "display.setStringFormatForTimes(TimeUnit.DAYS)\n",
    "//min 4, max 6 decimal places for all doubles\n",
    "display.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(4,6))\n",
    "//setting for a column takes precidence over the type\n",
    "display.setStringFormatForColumn(\"m3\", TableDisplayStringFormat.getDecimalFormat(0, 0))\n",
    "//set the alignment\n",
    "display.setAlignmentProviderForType(ColumnType.Double, TableDisplayAlignmentProvider.RIGHT_ALIGNMENT)\n",
    "display.setAlignmentProviderForColumn(\"m3\", TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "\n",
    "display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display.setStringFormatForTimes(TimeUnit.HOURS)\n",
    "\n",
    "display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import com.twosigma.beakerx.table.renderer.TableDisplayCellRenderer\n",
    "import java.util.concurrent.TimeUnit\n",
    "\n",
    "val display2 = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "//right now, the only renderer option is for data bars\n",
    "display2.setRendererForType(ColumnType.Double, TableDisplayCellRenderer.getDataBarsRenderer())\n",
    "//use the false parameter to hide the String value\n",
    "display2.setRendererForColumn(\"y10\", TableDisplayCellRenderer.getDataBarsRenderer(false))\n",
    "\n",
    "display2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import com.twosigma.beakerx.table.renderer.TableDisplayCellRenderer\n",
    "\n",
    "val display3 = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "display3.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(9,9))\n",
    "//freeze a column\n",
    "display3.setColumnFrozen(\"y1\", true)\n",
    "//hide a column\n",
    "display3.setColumnVisible(\"y30\", false)\n",
    "\n",
    "//explicitly set column order/visiblity\n",
    "display3.setColumnOrder(List(\"m3\", \"y1\", \"y5\", \"time\", \"y2\")) //Columns in the list will be shown in the provided order. Columns not in the list will be hidden.\n",
    "display3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import com.twosigma.beakerx.table.renderer.TableDisplayCellRenderer\n",
    "import com.twosigma.beakerx.table.highlight.TableDisplayCellHighlighter\n",
    "\n",
    "def display4 = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "display4.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m3\", TableDisplayCellHighlighter.FULL_ROW))\n",
    "\n",
    "//the following two overloads should also be supported\n",
    "//set the min and max used for calculating the color\n",
    "//display4.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"y1\", TableDisplayCellHighlighter.FULL_ROW, 0, 5))\n",
    "//set the colors used for the min and max\n",
    "//display4.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m6\", TableDisplayCellHighlighter.SINGLE_COLUMN, null, null, Color.YELLOW, Color.BLUE))\n",
    "\n",
    "display4"
   ]<commit_msg>#8113: fix an example, change def to val (#8126)<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Scala API to the Table Widget\n",
    "\n",
    "This API is being [improved](https://github.com/twosigma/beakerx/issues/5798)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "val table = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import java.util.concurrent.TimeUnit\n",
    "\n",
    "val display = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "//show all time columns in days\n",
    "display.setStringFormatForTimes(TimeUnit.DAYS)\n",
    "//min 4, max 6 decimal places for all doubles\n",
    "display.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(4,6))\n",
    "//setting for a column takes precidence over the type\n",
    "display.setStringFormatForColumn(\"m3\", TableDisplayStringFormat.getDecimalFormat(0, 0))\n",
    "//set the alignment\n",
    "display.setAlignmentProviderForType(ColumnType.Double, TableDisplayAlignmentProvider.RIGHT_ALIGNMENT)\n",
    "display.setAlignmentProviderForColumn(\"m3\", TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "\n",
    "display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display.setStringFormatForTimes(TimeUnit.HOURS)\n",
    "\n",
    "display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import com.twosigma.beakerx.table.renderer.TableDisplayCellRenderer\n",
    "import java.util.concurrent.TimeUnit\n",
    "\n",
    "val display2 = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "//right now, the only renderer option is for data bars\n",
    "display2.setRendererForType(ColumnType.Double, TableDisplayCellRenderer.getDataBarsRenderer())\n",
    "//use the false parameter to hide the String value\n",
    "display2.setRendererForColumn(\"y10\", TableDisplayCellRenderer.getDataBarsRenderer(false))\n",
    "\n",
    "display2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import com.twosigma.beakerx.table.renderer.TableDisplayCellRenderer\n",
    "\n",
    "val display3 = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "display3.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(9,9))\n",
    "//freeze a column\n",
    "display3.setColumnFrozen(\"y1\", true)\n",
    "//hide a column\n",
    "display3.setColumnVisible(\"y30\", false)\n",
    "\n",
    "//explicitly set column order/visiblity\n",
    "display3.setColumnOrder(List(\"m3\", \"y1\", \"y5\", \"time\", \"y2\")) //Columns in the list will be shown in the provided order. Columns not in the list will be hidden.\n",
    "display3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.twosigma.beakerx.scala.table._\n",
    "import com.twosigma.beakerx.scala.fileloader.CSV\n",
    "import com.twosigma.beakerx.table.format.TableDisplayStringFormat\n",
    "import com.twosigma.beakerx.table.renderer.TableDisplayCellRenderer\n",
    "import com.twosigma.beakerx.table.highlight.TableDisplayCellHighlighter\n",
    "\n",
    "val display4 = new TableDisplay(new CSV().readFile(\"../resources/data/interest-rates.csv\"))\n",
    "display4.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m3\", TableDisplayCellHighlighter.FULL_ROW))\n",
    "\n",
    "//the following two overloads should also be supported\n",
    "//set the min and max used for calculating the color\n",
    "//display4.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"y1\", TableDisplayCellHighlighter.FULL_ROW, 0, 5))\n",
    "//set the colors used for the min and max\n",
    "//display4.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m6\", TableDisplayCellHighlighter.SINGLE_COLUMN, null, null, Color.YELLOW, Color.BLUE))\n",
    "\n",
    "display4"
   ]
{'fraction_non_alphanumeric': 0.1735992783401824, 'fraction_numerical': 0.009421669840633458, 'mean_word_length': 3.7177304964539006, 'pattern_counts': {'":': 68, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4519272', 'n_tokens_mistral': 3521, 'n_tokens_neox': 3421, 'n_words': 564}