djblue / portal

A clojure tool to navigate through your data.
https://djblue.github.io/portal/
MIT License
872 stars 81 forks source link

VegaLite data values using TableCloth rows as maps #232

Closed timothypratley closed 1 month ago

timothypratley commented 2 months ago

TableCloth is a popular way to work with datasets. Visualizing with VegaLite via Portal is very convenient.

Sadly, the most natural way to assign the data of the visualization:

(tc/rows flip-frequency-distribution :as-maps)

Produces exactly the right thing, but because the maps are actually tech.v3.datatype.FastStruct, Portal serialization produces the wrong output:

"values": {
      "object": {
        "meta": null,
        "Y": 6,
        "O": [
          {
            "Kb": null,
            "name": "tag",
            "la": "tag",
            "_hash": null,
            "P": 2153775105,
            "aa": 4096
          },

These "objects" should be serialized as "maps".

(first (tc/rows flip-frequency-distribution :as-maps))
=> {:score 6, :count 1}
(map? (first (tc/rows flip-frequency-distribution :as-maps)))
=> true
(type (first (tc/rows flip-frequency-distribution :as-maps)))
=> tech.v3.datatype.FastStruct

There are several workarounds including using a CSV string instead or manually making (non-record) plain maps. But it seems like maybe an easy thing to fix in the way the json is serialized.

djblue commented 2 months ago

Hi @timothypratley, thanks for reporting this issue.

I feel like https://github.com/djblue/portal/commit/dc33869fef516195290c2cc35e901bbf07208fb0 should fix this issue. Did you want to give it a try locally?

timothypratley commented 1 month ago

Hi @djblue Yes that fixed it. Confirmed locally with steps: in portal directory bb jar clj -Spom then in my deps djblue/portal {:local/root "../portal"} renders the chart correctly. Thankyou!

djblue commented 1 month ago

Thanks for verifying this, I should get a release out within the next week.