最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Are there any tutorials or examples for cubism.js + WebSocket? - Stack Overflow

programmeradmin1浏览0评论

Are there any tutorials specifically about connecting WebSockets (or other non-polling data source) and cubism.js?

In particular, I'd like to be able to create a real time graph of data streaming from server, visually similar to example on the cubism page.

References: - - / - Using Other Data Sources for cubism.js

Are there any tutorials specifically about connecting WebSockets (or other non-polling data source) and cubism.js?

In particular, I'd like to be able to create a real time graph of data streaming from server, visually similar to example on the cubism page.

References: - https://github./square/cubism/issues/5 - http://xaranke.github.io/articles/cubism-intro/ - Using Other Data Sources for cubism.js

Share Improve this question edited May 23, 2017 at 12:23 CommunityBot 11 silver badge asked Aug 5, 2013 at 23:23 MartinMartin 8147 silver badges24 bronze badges 1
  • I'd be interested to know a solution – user1125394 Commented Aug 8, 2013 at 17:10
Add a ment  | 

2 Answers 2

Reset to default 2

Here's something I'm toying with. It's not authoritative but it seems to work: https://gist.github./cuadue/6427101

When data es in from the websocket, put it in a buffer. Pump the callbacks (I'll explain those below), sending the buffer as the argument. Check the return code for "success" or "wait for more data". Success means data was sent to cubism and we can remove this callback.

When cubism requests a frame of data, set up a callback which checks if the last point in the buffer is after the last point cubism requested. Otherwise, wait for more data.

If there's data to cover the stop of the requested frame, we'll fulfill this request. Without an API to request history, we have to drop data going into the past.

Then, just interpolate the buffer onto the cubism step size.

It seems like cubism requests data from the same point in time multiple times, so it's up to you how to prune your buffer. I don't think it's safe to just drop all data earlier than the requested start time.

I did a quick and dirty hack:

  • Websocket fill a realTimeData array
  • Cubism does the initial fetch from some Web services, then pull from realTimeData array

    var firstTime = true;
    context.metric(function(start, stop, step, callback) {
      if (firstTime) {
        firstTime = false;
        d3.json("... {
          var historicalData = [];
          callback(null, historicalData);
        }
      } else {
        callback(null, realTimeData);
      }

Note that cubism.js expects 6 points per fetch (cubism_metricOverlap) so make sure to keep 6 points in realTimeData

发布评论

评论列表(0)

  1. 暂无评论