Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Add type info in data passed to voyager #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/DataVoyager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ end

row_output = Expr(:block)

format_strings = String[]

for (i,v) in enumerate(col_names)
if i>1
push!(row_output.args, :(print(buf, ", ")))
Expand All @@ -39,9 +41,17 @@ end
else
push!(row_output.args, :(print(buf, "\"", row[$i],"\"")))
end

actual_format_spec = "String"
if col_types[i] <: Number || (col_types[i] <: DataValue && eltype(col_types[i]) <: Number)
actual_format_spec = "number"
end
push!(format_strings, "\"$(col_names[i])\": \"$actual_format_spec\"")
end

quote
format_string = join(format_strings, ",")

r = quote
buf = IOBuffer()
print(buf, "{\"values\":[")
for (i,row) in enumerate(it)
Expand All @@ -53,10 +63,16 @@ end
$(row_output)
print(buf, "}")
end
print(buf, "]}")
print(buf, "],")
print(buf, "\"format\":{\"parse\":{")
print(buf, $format_string)
print(buf, "}}")
print(buf, "}")

return String(take!(buf))
end
# println(r)
return r
end

function (v::Voyager)(source)
Expand All @@ -66,6 +82,8 @@ function (v::Voyager)(source)

data = format_iterable_table_as_json(it)

# println(data)

jsdata = Blink.JSString(data)

@js v.w voyagerInstance.updateData($jsdata)
Expand Down