I'm trying to build Nim library for plotting charts and data tables. And I 
can't make the Nim DSL to be clean compact.

Is there a better way to do it? Here's the table I'm creating, [some 
portfolio](http://demos.pl0t.com/portfolio:table-dev)

The TypeScript DSL to build such table, very minimal, very clean, and fully 
type safe with compile time validations and IDE autocomplete.
    
    
    import type { TableOptions } from "./table/scheme"
    
    const options: TableOptions = {
      order:   [["mv_usd", "desc"]],
      columns: [
        {
          id:    "mv_usd",
          type:  "number",
          format: { type:  "line", ticks: [1000] }
        },
        {
          id:    "tenor",
          type:  "number",
          format: { type:  "line", ticks: [180, 360, 720] }
        },
        {
          id:    "right",
          type:  "string"
        },
        {
          id:    "symbol",
          type:  "string"
        },
        {
          id:    "contract_id",
          type:  "string",
          format: { type:  "string", small: true }
        }
      ],
      rows: []
    }
    
    
    Run

I tried to convert it to Nim, here's the Nim data scheme, 
[pl0t.nim](https://github.com/al6x/pl0t/blob/main/api/nim/pl0t.nim)

But the result is not very clean.
    
    
    import pl0t # https://github.com/al6x/pl0t/blob/main/api/nim/pl0t.nim
    
    let options = TableOptions[seq[float]](
      order:   @[("mv_usd", PlotOrder.desc_e)].some,
      columns: @[
        PlotTableColumn(
          id:     "mv_usd",
          `type`: "number",
          format: FormatOptions(
            `type`: PlotFormatType.line_e,
            ticks:  @[1000.0].some
          ).some
        ),
        PlotTableColumn(
          id:     "tenor",
          `type`: "number",
          format: FormatOptions(
            `type`: PlotFormatType.line_e,
            ticks:  @[180.0, 360.0, 720.0].some
          ).some
        ),
        PlotTableColumn(
          id:     "right",
          `type`: "string"
        ),
        PlotTableColumn(
          id:     "symbol",
          `type`: "string"
        ),
        PlotTableColumn(
          id:     "contract_id",
          `type`: "string",
          format: FormatOptions(
            `type`: "string",
            small:  true.some
          ).some
        )
      ].some,
      rows: @[]
    )
    
    
    Run

Is there way to improve it?

Reply via email to