aysark / dashing-timeline

Stylish timeline widget for Dashing.io
MIT License
28 stars 7 forks source link

Cannot get the widget to read data from excel file, and with original widget date don't show up! #2

Closed makenstein closed 8 years ago

makenstein commented 8 years ago

HI, i created a new job file that extracts information from an excel file and send it to the widget. i tried that job file with "List" widget and "birthday" and data shows correctly, but when i try it with the TIMELINE widget, data never shows up, i just get an empty grey rectangle with the title on the top, that's it.

can someone help me with it please? thanks

this is my code:

require 'date' require 'roo' require 'active_support' require 'active_support/core_ext'

timeline_FILENAME = 'timeline_data.xlsx'

SCHEDULER.every '3s', :first_in => '1s' do timeline = [] timeline_report = Roo::Excelx.new(timeline_FILENAME) (2..timeline_report.last_row).each do |row| name = timelinereport.cell(row, 1) name.sub!(/(\S+),\s(\S+)._/, '\2 \1')

date = timeline_report.cell(row, 2)
date = Date.new(Date.today.year, date.month, date.day)
if date < Date.today then
  date += 1.year
end

timeline.push({name: name, date: date})

end

get next 10 timeline

timeline = timeline.sort{|a, b| a[:date] <=> b[:date]}[0..9]

assemble data to send to client

timeline_data = [] timeline.each do |timeline| timeline_data.push({ 'label' => timeline[:name], 'value' => timeline[:date].strftime("%-m/%-d") }) end

send_event('data', { items: timeline_data, class: 'icon icon-background icon-calendar'}) end

aysark commented 8 years ago

Have a look at the jobs/timeline.rb file in the repo... you need to send your data in the same format as is being sent in that job. Basically its an array of json objects, where each json object is an event.

events << {
          name: event["name"],
          date: event["date"],
          background: event["background"],
          opacity: 0.5
        }
makenstein commented 8 years ago

Thanks a lot, i'll give it a shot! :)