GenieFramework / StippleUI.jl

StippleUI is a library of reactive UI elements for Stipple.jl.
MIT License
84 stars 15 forks source link

Relax DataTable interface to accept Table.jl compatible types instead of DataFrame #97

Closed essenciary closed 1 year ago

hhaensel commented 1 year ago

heads up: I'm almost ready, not a big deal.

juliohm commented 1 year ago

Support can be added easily by taking DataFrames.jl as a dependency:

DataTable(table) = DataTable(DataFrame(table))

since DataFrames.jl itself already supports Tables.jl.

Of course a more professional solution would just use the Tables.jl interface directly to extract the data from the table type without conversion.

hhaensel commented 1 year ago

That's what I'm currently doing. The longer part is to move the stippleparse to DataFrames to an extension. But this will be done in two separate steps.

hhaensel commented 1 year ago

It's all set, we just need to merge https://github.com/GenieFramework/Stipple.jl/pull/209 and #99.

Then you will be able to use any Tables compatible type, e.g. Tables interface or TypedTables:

using Tables
t1 = Tables.table([1 2 3; 3 4 5], header = ["a", "b", "c"])

table(:dt)
# "<q-table :columns=\"dt.columns\" v-model=\"dt\" :data=\"dt.data\" row-key=\"__id\"></q-table>"

render(DataTable(t1))
# Dict{String, Any} with 2 entries:
#  "data"    => Dict{String, Any}[Dict("c"=>3, "__id"=>1, "b"=>2, "a"=>1), Dict("c"=>5, "__id"=>2, "b"=>4, "a"=>3)]
#  "columns" => Column[Column("a", false, "a", :left, "a", true), Column("b", false, "b", :left, "b", true), Column("c", false, "c", :left, "c", true)]

or

using TypedTables
t2 = Table(a = 1:3, b = collect("abc")) # or FlexTable or DictTable

render(DataTable(t2))
# Dict{String, Any} with 2 entries:
#  "data"    => Dict{String, Any}[Dict("__id"=>1, "b"=>'a', "a"=>1), Dict("__id"=>2, "b"=>'b', "a"=>2), Dict("__id"=>3, "b"=>'c', "a"=>3)]
#  "columns" => Column[Column("a", false, "a", :left, "a", true), Column("b", false, "b", :left, "b", true)]

And rendering of Tables compatible type is supported as well:

render(t1)
# OrderedDict{Symbol, AbstractVector} with 2 entries:
#  :a => 1:3
#  :b => ['a', 'b', 'c']
juliohm commented 1 year ago

Thank you @hhaensel , we are looking forward to use the new feature.

hhaensel commented 1 year ago

@juliohm Hope this fits your needs. Please note: With the latest PR #99 DataFrames is not loaded automatically anymore. Instead all DataFrame-specific definitions are loaded via an extension. If you need to use DataFrames, the best is to load it before loading StippleUI. Otherwise rely on the new Tables API and enjoy the shorter loading time 😉