GithubHelp home page GithubHelp logo

Run Job at startup about dashing HOT 26 CLOSED

shopify avatar shopify commented on June 19, 2024
Run Job at startup

from dashing.

Comments (26)

chrisspang avatar chrisspang commented on June 19, 2024 1

Also just stumbled across this thread - the issue for me seems to be that 'onData' is fired before 'ready'. I'm currently using a work-around that:

  1. First call to onData() (with the old data) does create the (d3) svg successfully, but this gets lost (DOM not ready or something - I'm new to this stuff)

  2. First call to ready() just calls onData()

  3. onData() uses the stored values (@get("value")) to build the visualiation

    Untested rough example below:

  ready: ->
    @onData({ value: 0 })

  onData: (dataFull) ->
    data = dataFull.value    
    if (!data)
      data = @get("value")

    if (!data)
      return

from dashing.

pushmatrix avatar pushmatrix commented on June 19, 2024

When someone loads the dashboard in their browser, all widgets will automatically receive the last values that the job server fetched -- you shouldn't need to tell the job to re-run. Your widget should receive the daily value.

Is this behaviour not showing for you?

from dashing.

aaldrich avatar aaldrich commented on June 19, 2024

I think the problem is that the object data needs to be created on the client side which means on the initial load I have to create a new object Highcharts.Chart. However I don't have the data to feed it at that point because that is populated by the job which also creates a new Highcharts.Chart with the values.

I'm not sure how to store and get the latest Highcharts.Chart object so that it is available in the ready: event.

from dashing.

pushmatrix avatar pushmatrix commented on June 19, 2024

It won't be available in the ready event. However, if the job has already run, then the onData callback inside your widget will be called as soon as the page loads (but only after the ready event is triggered). Can you initialize the chart within ready, but update its data within onData? Perhaps I'm not fully understanding the issue.

from dashing.

aaldrich avatar aaldrich commented on June 19, 2024

Let me try to better explain it:

In my widget ready event I initialize a blank chart.
In my widget onData event I take the data passed from the job and recreate that chart with the values

Here are the steps I'm performing

  1. I start the server
  2. I go to my page http://localhost:3030/sample and my chart is empty (I Would have expected the chart to have data at this point but there isn't any)
  3. I stop the server
  4. I start the server and my chart receives the data (I'm assuming it is because the job is run when the server starts and the page is listening for it properly)
  5. I refresh the page and the chart is blank again

So basically I want to make step 4 work whenever the page is loaded so it loads the chart with data. I hope this helps. If I need to I can record a video of the events. Thank you so much for your help.

from dashing.

aaldrich avatar aaldrich commented on June 19, 2024

I dug into it some more and it might be a bug in the highcharts.js that is causing this. I have a function that ensures the container exists in the dom before building the chart however I still get an error 13 which means the chart can't attach to the container. I see it executing in the ready event and then I see the onData event firing after that so I think Dashing is doing what is supposed to.

from dashing.

pushmatrix avatar pushmatrix commented on June 19, 2024

There was mention to an error 13 happening over here: #42

We were able to get highcharts running in there.

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

@aaldrich would you be willing to share your highcharts widget implementation code ? With that I mean the widget.coffee, widget.html and widget.scss and possibly a sample erb ?
Thanks in advance..

from dashing.

aaldrich avatar aaldrich commented on June 19, 2024

Absolutely I have it mostly just showing line charts but here is what I have right now:

Screen Shot 2013-01-10 at 12 42 22 AM

highchartline.coffee

class Dashing.Highchartline extends Dashing.Widget

  createChart: (series,x_axis,y_axis) ->
    container = $(@node).find('.highchart-container')
    if $(container)[0]
      @chart = new Highcharts.Chart
        chart:
          renderTo: $(container)[0]
          type: "line"
        series: series
        xAxis: {
          categories: x_axis
        }
        yAxis: {
          title: {
            text: y_axis
          }
        }
        plotOptions: {
          line: {
            dataLabels: {
              enabled: true
            }
          }
        }

  onData: (data) ->
    @createChart(data.series,data.x_axis,data.y_axis)

highchartline.html

<h1 class="title" data-bind="title"></h1>

<div class="highchart-container" style="width: 100%; height: 400px"></div>

highchartline.scss

// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color:  #ff9618;

// ----------------------------------------------------------------------------
// Widget-text styles
// ----------------------------------------------------------------------------
.widget-highchartline { 

  background-color: $background-color;  

  &.large h3 {
    font-size: 65px;
  }
}

erb snippet

<li data-row="1" data-col="1" data-sizex="2" data-sizey="2">
      <div data-id="csat_history" data-view="Highchartline" data-title="CSAT History" style="background-color:#efad1b;">></div>
</li>

job to feed data. scaled down to hide private data

SCHEDULER.every '5s', :first_in => 0 do |job|
  updated_at = Time.now.strftime('%m/%d/%Y')

  points = [{name: "Blah", data: blah_csat_points},
            {name:"CE", data: ce_csat_points},
            {name:"Ops", data: ops_csat_points},
            {name:"Acct", data: acct_csat_points}
           ]

  x_axis = ["Q4 2010","Q2 2011","Q4 2011","Q2 2012","Q4 2012"]
  y_axis_text = "Score"

  send_event('csat_history', {series: points, x_axis: x_axis, y_axis: y_axis_text, updated_at: updated_at})
end

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

@aaldrich Thanks for sharing.... I'm trying to create a highchart pie chart but i'm having some issues with this..
My javascript knowledge is somewhat limited..

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

@aaldrich I'm making some progress... Currently, I can display a pie chart but i'm having some problems adding a formatter to the plotoptions. This seems to break my widget...

This is what I have so far:

plotOptions: {
          pie: {
            dataLabels: {
              enabled: true,
              formatter: function() { return '<b>'+ this.point.name +'</b>: '+ this.point.y; }
            }
          }
        }

It seems the formatter is causing problems.
Do you happen to know a solution to my problem ?
It would help me a lot..

Thanks in advance.

from dashing.

mikechau avatar mikechau commented on June 19, 2024

Are you still having issues?

This seemed to get pie charts to render correctly for me:

class Dashing.Piechart extends Dashing.Widget

  ready: ->
    @chart = new Highcharts.Chart
      chart:
        renderTo: "HCcontainer"
        plotBackgroundColor: null
        plotBorderWidth: null
        plotShadow: false

      title:
        text: "Daily Indicators"

      tooltip: 
        pointFormat: "{series.name}: <b>{point.percentage}%></b>"
        percentageDecimals: 1

      plotOptions:
        pie:
          allowPointSelect: true
          cursor: "pointer"
          showInLegend: true
          dataLabels:
            enabled: false
            color: "#000000"
            connectorColor: "#000000"
            formatter: ->
              "<b>" + @point.name + "</b>: " + @percentage + " %"

      series: [
        type: "pie"
        name: "Indicators"
        data: [["REG", 1], ["CANC", 2], ["OSEQ", 3], ["CNCL", 4], ["LATE", 5], ["ISOI", 6]]
      ]

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

Just tried it but it doesn't seem to work for me....

from dashing.

mikechau avatar mikechau commented on June 19, 2024

I had dataLabels set to false, did you change it true?

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

@mikechau It was true, but I changed it to false...
Also tried some other variations of your formatter example but without any luck..

This is what I have now:

class Dashing.Highchartpie extends Dashing.Widget

  createChart: (chart_title,series) ->
    container = $(@node).find('.highchartpie-container')
    if $(container)[0]
      @chart = new Highcharts.Chart
        chart:
          renderTo: $(container)[0]
          type: "pie"
        series: series
        title:
          text: chart_title
        tooltip:
          pointFormat: '<b>{point.y}</b>'
        plotOptions: {
          pie: {
            dataLabels: {
              enabled: false
              formatter: "<b>" + @point.name + "</b>: "
            }
          }
        }

  onData: (data) ->
    @createChart(data.chart_title,data.series)

from dashing.

mikechau avatar mikechau commented on June 19, 2024

Oh I mean you should leave it true if you want labels. I think your formatting is off since its coffeescript, perhaps try this:

class Dashing.Highchartpie extends Dashing.Widget

  createChart: (chart_title,series) ->
    container = $(@node).find('.highchartpie-container')
    if $(container)[0]
      @chart = new Highcharts.Chart(
        chart:
          renderTo: $(container)[0]

        series: series

        title:
          text: chart_title

        tooltip:
          pointFormat: '<b>{point.y}</b>'

        plotOptions:
          pie:
            dataLabels:
              enabled: true
              formatter: ->
                "<b>" + @point.name + "</b>"
      )

  onData: (data) ->
    @createChart(data.chart_title,data.series)

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

@mikechau
Your formatting seems to work (don't really understand why..)
I really suck at coffeescript 😄

Thanks a lot for your help !

from dashing.

mikechau avatar mikechau commented on June 19, 2024

@dieterdemeyer
Hooray! 💥

Yeah, I am just starting to learn coffeescript myself, formatting seems to be very important.

I found http://js2coffee.org/ pretty helpful to convert my js to coffeescript so I could get a better idea of how it should look in coffeescript.

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

@mikechau Thanks! I'll check it out...

from dashing.

mikechau avatar mikechau commented on June 19, 2024

@dieterdemeyer How are you posting data to the piechart? Can I see your job rb file?

Thanks!

from dashing.

dieterdemeyer avatar dieterdemeyer commented on June 19, 2024

@mikechau This is what I'm using as a backend job:

SCHEDULER.every '1m', :first_in => 0 do
    updated_at = Time.now.strftime('%m/%d/%Y')

    title = 'Insert title here'

    uri = URI.parse(BACKEND_URL)
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new("/dashboard?format=json")
    response = http.request(request)
    dashboard_info = JSON.parse(response.body)

    dashboard_info_new = Hash.new
    DASHBOARD_LABELS.each { |key, value|
      dashboard_info_new.store(value, dashboard_info[key])
    }

    data = []
    dashboard_info_new.each { |key, value|
      data << [key, value.to_i]
      puts "#{key}: #{value}\n"
    }

    series = [{
                type: 'pie',
                name: 'Activity Overview',
                data: data
          }]

    send_event('dashboard', {chart_title: title, series: series, updated_at: updated_at})
end

from dashing.

nccmike avatar nccmike commented on June 19, 2024

@aaldrich, did you finally get everything working? I have implemented two highcart widgets on my dashboard using the sample in this post. Everything displays correctly, however, my jobs are only running every 10 minutes. Most times, the widget will load but the graph won't display until the job is run the next time.

Suggestions?

from dashing.

aaldrich avatar aaldrich commented on June 19, 2024

I did but I can't remember what I did. I eventually abandoned it and went
to geckoboard. I was getting too frustrated with all the random workarounds
and wasting too much time so I cheated and went the paid route :) sorry I
can't be of more help.

Sent from my iPhone

On Aug 2, 2013, at 9:17 PM, nccmike [email protected] wrote:

@aaldrich https://github.com/aaldrich, did you finally get everything
working? I have implemented two highcart widgets on my dashboard using the
sample in this post. Everything displays correctly, however, my jobs are
only running every 10 minutes. Most times, the widget will load but the
graph won't display until the job is run the next time.

Suggestions?


Reply to this email directly or view it on
GitHubhttps://github.com//issues/50#issuecomment-22046772
.

from dashing.

nccmike avatar nccmike commented on June 19, 2024

@aaldrich, no worries. My widgets load fine but my charts don't load with data until the job runs. I am currently loading blank charts gut I will check into updating them with the staff from the job that has aleardy run.

from dashing.

CmdrCody avatar CmdrCody commented on June 19, 2024

I'm reviving this old thread, as I recently found myself implementing dashing for a project using highcharts and have been unable to turn anything up in the interwebs about this chicken-or-the-egg issue with initializing the charts. My highcharts charts work great once they're loaded with data, but if users happen to hit the page before a send_event hits their client from the ruby job, they could be waiting until the next interval before they see anything.

In my case, my data lives in Oracle, and I have my RB jobs are using OCI8 to retrieve the data and then building the various series objects for the different charts. I'm now facing the same problem as the OP, where my highcharts initialize as blank, since the series data comes from the server in the subsequentsend_event.

I cannot figure out how to initialize the chart with some valid data from the first fetch. I've seen other posts around where people talk about "emiting" the series data in the DOM and then consuming it in the chart from the DOM on load; however, I can't figure out how to dynamically update the DOM from the Ruby Job.

Has anyone figured a workaround for this? As it stands my charts are blank until the next 15-minute Send_Event. Obviously this won't work for my users, so I gotta figure something out.

from dashing.

oaknguyen avatar oaknguyen commented on June 19, 2024

thanks for the work around @chrisspang. Worked nicely.

from dashing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.