Skip to content
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