Vindaar / ggplotnim

A port of ggplot2 for Nim
https://vindaar.github.io/ggplotnim
MIT License
177 stars 15 forks source link

bar color loss(?) for some df columns when vega html output? #156

Closed fbpyr closed 1 year ago

fbpyr commented 1 year ago

In a couple of my simple bar graphs I seemed to loose the color information, so I checked, if I could reproduce it with an example:

I run the example rMpgStackedBarPlot, which works well in default configuration.

If I switch it to vega html output like this:

import ggplotnim
import ggplotnim/ggplot_vega

let df = readCsv("mpg.csv")

ggplot(df, aes("class", fill = "drv")) + 
  geom_bar() + 
  ggvega("rMpgStackedBarPlot.html")

I seem to lose the distinct bar colors and get a strange y-axis title.

image

When inspecting in the vega editor, it seems the color is still supposed to be driven by drv with a reasonable looking color scale :

"encoding": {
  "x": {"field": "class", "type": "nominal"},
  "y": {
    "field": "counts_GGPLOTNIM_INTERNAL",
    "type": "quantitative",
    "scale": {"domain": [0, 70]}
  },
  "color": {
    "field": "drv",
    "type": "nominal",
    "scale": {"range": ["#619BFF", "#00B938", "#F7766C"]}
  }

but the dataframe column name seems to be only intact for the first column class, which is used for the x-axis, but not for other columns like drv (?):

"values": [
  {
    "class": "2seater",
    "counts_GGPLOTNIM_INTERNAL": 5,
    "prevVals_GGPLOTNIM_INTERNAL": 0
  },
  {
    "class": "compact",
    "counts_GGPLOTNIM_INTERNAL": 0,
    "prevVals_GGPLOTNIM_INTERNAL": 0
  },
...
]

This might be the reason, why it says undefined in the color chip of the legend. 🤔

Vindaar commented 1 year ago

Heh, this clearly starts to be stuff that's not fully supported yet, oops. You probably see a bunch of "WARNING: losing information" kind of messages as well, right?

fbpyr commented 1 year ago

right 🙂 , I see 2 to 3 of: WARN: losing information inencodeType WARN: losing information in encodeGeomSpecifics!` per each plot.

Vindaar commented 1 year ago

I pushed a fix in #157 . Still, if you keep trying new things, you will likely find more things broken, haha.

It's possible that I'll need to do a complete rewrite of the backend though, as I'm not sure if the current approach can scale to support all of ggplotnim's features while at the same time taking advantage of vega-lite specific things.

fbpyr commented 1 year ago

Wow - thank you so much! 🙂
I will try it out.

fbpyr commented 1 year ago

Awesome!! 👍

image