{"id":20601385,"url":"https://github.com/tmccarthy/tmm-scala-plotly","last_synced_at":"2025-03-06T16:19:20.434Z","repository":{"id":57715044,"uuid":"279055816","full_name":"tmccarthy/tmm-scala-plotly","owner":"tmccarthy","description":"Yet another Scala API for Plotly.js","archived":false,"fork":false,"pushed_at":"2021-03-08T10:34:54.000Z","size":231,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T01:47:00.116Z","etag":null,"topics":["plotly","plotlyjs","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmccarthy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-12T12:03:46.000Z","updated_at":"2024-12-09T19:54:17.000Z","dependencies_parsed_at":"2022-09-02T22:01:33.020Z","dependency_job_id":null,"html_url":"https://github.com/tmccarthy/tmm-scala-plotly","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Ftmm-scala-plotly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Ftmm-scala-plotly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Ftmm-scala-plotly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Ftmm-scala-plotly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmccarthy","download_url":"https://codeload.github.com/tmccarthy/tmm-scala-plotly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242241246,"owners_count":20095339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["plotly","plotlyjs","scala"],"created_at":"2024-11-16T09:09:51.832Z","updated_at":"2025-03-06T16:19:20.406Z","avatar_url":"https://github.com/tmccarthy.png","language":"Scala","readme":"# `tmm-scala-plotly`\n[![CircleCI](https://circleci.com/gh/tmccarthy/tmm-scala-plotly/tree/master.svg?style=svg)](https://circleci.com/gh/tmccarthy/tmm-scala-plotly/tree/master)\n[![Maven Central](https://img.shields.io/maven-central/v/au.id.tmm.tmm-scala-plotly/tmm-scala-plotly-core_2.13.svg)](https://repo.maven.apache.org/maven2/au/id/tmm/tmm-scala-plotly/tmm-scala-plotly-core_2.13/)\n\nYet another library for integration between [Plotly](https://plotly.com/javascript/) and Scala.\n\n## Getting started\n\nIn your `build.sbt` file.\n\n```scala\ntmmScalaPlotlyVersion = 0.0.2\n\nlibraryDependencies += \"au.id.tmm.tmm-scala-plotly\" %% \"tmm-scala-plotly-core\" % tmmScalaPlotlyVersion\n```\n\n## Rationale\n\nThis library is a representation of the [Plotly JavaScript API](https://plotly.com/javascript/) in Scala. It is a\nhand-written and almost complete representation of the Plotly API as documented in [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/53e3fb2/types/plotly.js/index.d.ts),\nand informed by the official documentation.\n\nThere are already at least two other libraries that provide Scala integration for Plotly:\n\n* [`facultyai/scala-plotly-client`](https://github.com/facultyai/scala-plotly-client) is an older library that is \n  documented on the [Plotly website](https://plotly.com/scala/). It does not appear to be under active development.\n* [`alexarchambault/plotly-scala`](https://github.com/alexarchambault/plotly-scala/), which is a modern and mature \n  offering.\n\nMy advice would be that if you are looking for a library to use Plotly from Scala, you should use [`alexarchambault/plotly-scala`](https://github.com/alexarchambault/plotly-scala/).\nIt is more mature and better tested than this library, and I've had a lot of success with it.\n\nThis library has a couple of key philosophical differences with `alexarchambault/plotly-scala`, which is why I decided \nto write it:\n\n* **Completeness:** This library is an almost exhaustive representation of the Plotly Javascript API. You should be able \n  to produce every kind of plot supported by the official Javascript library.\n* **Self-documenting:** This library makes extensive use of value classes and algebraic data types to attempt to clarify \n  the meaning of fields within the Plotly API. Implicit conversions are opt-in and are intended only for ease-of-use \n  (see [below](#usage)).\n* **Incorrect:** This library does not (yet) use the power of the Scala type system to ensure valid use of Plotly. For \n  example, you can provide `z` co-ordinates to two-dimensional scatter plots. This is an intentional tradeoff to make it\n  simpler to produce an exhaustive representation of the Javascript API.\n* **No ScalaJS support:** I don't use ScalaJS, so I haven't provided support for it.\n* **Circe as a first-class citizen:** This project uses [`circe`](https://github.com/circe/circe) to encode the model to \n  Json. The `circe` integrations are deliberately exposed by the main library to give clients as much flexibility as \n  possible when encoding.\n  \nNote that I've hand-written this interface over Plotly but have done almost no thorough testing. Many of the corners of \nthis library are unlikely to have seen any use. *Caveat emptor*.\n\n## Usage\n\nTo draw a pie chart:\n\n```scala\nimport au.id.tmm.plotly._\nimport au.id.tmm.plotly.model._\nimport au.id.tmm.plotly.model.utilities._\n\nval (labels, values, colours) = List(\n  (\"Coalition\", 5_906_875, Color(\"blue\")),\n  (\"Labor\", 4_752_160, Color(\"red\")),\n  (\"Greens\", 1_482_923, Color(\"green\")),\n  (\"Other\", 2_111_435, Color(\"grey\")),\n).unzip3\n\nval plot = Plot(\n  data = List(\n    Trace(\n      `type` = OptArg.Of(Trace.Type.Pie),\n      labels = OptArg.Of(DataArray.OfStrings(labels)),\n      values = OptArg.Of(DataArray.OfInts(values)),\n      marker = OptArg.Of(\n        PlotMarker(\n          colors = OptArg.Of(colours),\n        ),\n      ),\n    ),\n  ),\n  layout = OptArg.Of(\n    Layout(\n      title = OptArg.Of(\n        Layout.Title(\n          text = OptArg.Of(\"2019 primary votes\"),\n        ),\n      ),\n      width = OptArg.Of(300d),\n      height = OptArg.Of(300d),\n    ),\n  ),\n)\n\nPlotting.openInBrowser(plot)\n```\n\n![A pie chart showing the primary votes at the 2019 Australian Federal Election](/docs/pie.png)\n\n### Implicit conversions for ergonomics\n\nIn the above you should note that we make use of types like `OptArg` and `DataArray`. These allow us to have explicit \nand type-safe representations of optional parameters and the different types of data array respectively. Using these\neverywhere gets tiring, so we can import `au.id.tmm.plotly.syntax._` to make things a little less verbose \nwhile retaining type safety. With this import, the above becomes:\n\n```scala\nimport au.id.tmm.plotly._\nimport au.id.tmm.plotly.model._\nimport au.id.tmm.plotly.syntax._\n\nval (labels, values, colours) = List(\n  (\"Coalition\", 5_906_875, Color(\"blue\")),\n  (\"Labor\", 4_752_160, Color(\"red\")),\n  (\"Greens\", 1_482_923, Color(\"green\")),\n  (\"Other\", 2_111_435, Color(\"grey\")),\n).unzip3\n\nval plot = Plot(\n  data = List(\n    Trace(\n      `type` = Trace.Type.Pie,\n      labels = labels,\n      values = values,\n      marker = PlotMarker(colors = colours),\n    ),\n  ),\n  layout = Layout(\n    title = Layout.Title(text = \"2019 primary votes\"),\n    width = 300,\n    height = 300,\n  ),\n)\n\nPlotting.openInBrowser(plot)\n```\n\n### Dedicated trace interfaces\n\nAs discussed in the [Rationale section above](#Rationale), the [`Trace`](/core/src/main/scala/au/id/tmm/plotly/model/Trace.scala) \nclass provides an almost-exhaustive representation of the Plotly Javascript interface. While this allows us to use most\nof the features of Plotly, it also allows us to provide useless or invalid parameters. For example, we could provide the\n`z` co-ordinates for a two-dimensional scatter plot.\n\nAs a partial solution to this, the project includes some dedicated constructors for traces based on the trace type. \nThese are available in the [`au.id.tmm.plotly.model.traceinterfaces`](/core/src/main/scala/au/id/tmm/plotly/model/traceinterfaces)\npackage. For example, an interface is provided for sunburst plots and is demoed in [the examples project](/examples/src/main/scala/au/id/tmm/plotly/examples/Sunburst.scala).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccarthy%2Ftmm-scala-plotly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmccarthy%2Ftmm-scala-plotly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccarthy%2Ftmm-scala-plotly/lists"}