Shinobi charts recreating every time - android-fragments

I am using shinobicharts ChartFragment. I have scenario that each time I have to load the chart with different data within same activity i.e I am not recreating that activity. But I am failed to do this. It not recreating and not clearing the series which I previously set to that chart.
Can anybody help, how can I remove old series in that chart and load new series each time? I tried shinobiChart().removeSeries() but it didn't work.
Thanks

If you wish to dynamically load new data, you do not necessarily need to remove the series. Instead you can simply add data points to your data adapter. You will find the following methods useful:
https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#add(int, com.shinobicontrols.charts.Data)
https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#add(com.shinobicontrols.charts.Data)
https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#addAll(int, java.util.Collection>)
https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#addAll(java.util.Collection>)
In these api docs you will also find similar methods to remove data points.
One thing to bear in mind is that adding or removing a data point to / from a SimpleDataAdapter class instance which is set on a series will trigger a redraw of that series. If you are working with large numbers of data points, this might not be performant. In this case a more suitable approach might be to temporarily remove the data adapter from the series, perform the modification to the data and then re add the data adapter back to the series. Alternatively you might like to implement your own DataAdapter and control when you instruct the chart to redraw that series (via the fireUpdateHandler method).
You can of course remove the series itself and add a new one, but this approach is potentially inefficient. That said, if you wish to remove a series from a chart you need to use the following method:
https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/ShinobiChart.html#removeSeries(com.shinobicontrols.charts.Series)
In order for this method to be successful you will first need to obtain a reference to the correct series, which you must pass to this method as a parameter.
I hope that you find this information useful. If you need any further help please if possible post any relevant code, such as that which you use to create your fragments and set up your chart.
Thanks and kind regards,
Kai.
Disclaimer - I work for ShinobiControls.

Related

Optimising Shiny Dashboard plot redraw

I have built a shiny dashboard which has a set of data loaded in as a data frame. It uses dplyr to then select columns, mutate new columns if needed, apply a set of filters and then plot using a variety of high-level ggplot2-based packages.
We try to do the data load, select and mutate just the once. The filtering is sat in a reactive variable, accessed by the plot, and is based upon different input values.
As far as I see this is a pretty standard and typical use case.
I'm wondering whether anyone could advise on workflow patterns to make the output more responsive.
There are two scenarios I encounter with this writing pattern which appear to cause significant user interface delay which I'd like to avoid:
Firstly, when the dashboard first loads it tries to plot the charts using NULL data. I've found I can get around this by using if(is.null(my_data_frame)) and returning geom_blank() rather than our plot. Is there a neater / faster way to do this?
Secondly (and more challengingly): to the right of my plot are a (potentially large) set of filter options to allow the user to analyse subsets. If the user clicks several of these options in rapid succession, Shiny will repeatedly recalculate our reactive() value and replot the chart for each click event: where the user actually just needed to set or clear 5 options. Is there a way to prevent this happening - so if the recalculation isn't complete we don't continue with the plot in progress as we've just made the data stale? Or do you think about grouping options with an update button to prevent this?
In response to your second bullet. Check out shiny's debounce/throttle capabilities. These should slow down the reactive response so your user can finish with the UI control before the chart or presentation element recalculates.
For your first question, try using the req function inside your reactive block. If your plot is waiting on the data frame to load, you can put the code for loading the data frame in a named reactive block (it seems like you may have already done this), then pass that to req. This will prevent the plot from attempting to render until it receives a valid value for whatever you passed to req.
For the second, I'd recommend wrapping your plot render in an observeEvent and having an 'Update' button, if you typically expect users to change multiple options between desired plot updates.
Finally, for added performance, I just saw today that Shiny v1.2.0 has either just been released or is about to be, the major feature of which is plot caching. You can find more details HERE.

turning categorical data with 'from … to …' fields into a useable graph

I have categorical data which are written every time there is a state change, the data in my case will have {state: ***, From: DateTime, To: DateTime}. The writing function also triggers every midnight, so no From-To will extend past midnight. My question is what is the most sensible way to graph this data? If possible I'd like to be able to graph it as shown in the attached image. If anyone has a better recommendation for graphing this or knows how to produce a graph like the one shown from a set of data I'd really appreciate the input.
For the language used to graph, if anyone knows of a C# extension, that would be ideal but for now any language that can give me something useable would be perfect.
Also I control the nature of the data, so if a solution requires fields to be added or changed, that's ok

Generating map between frame number and frame sample time using SampleGrabber filter in directshow

In one of my application I need to know the map between frame position (frame number) and actual frame sample time for a given video file.
I'm using Directshow SampleGrabber filter in callback mode. I'm overriding BufferCB method of ISampleGraberCB class, whenever the callback is called, I'm mapping the arrived sampletime to frame position in a map. Frame position is incremented whenever a new sample arrives starting from zero.
Though I'm able to generate the required map, the above approach is very slow when it comes to handle large video files.
Can someone provide any suggestion on how to quickly generate this map or any other better approach.
Thanks in advance.
Pradeep
There are basically no such thing as "frame number" in DirectShow, only time stamps. The only thing to do the needed is to go through the entire file and record timestamps, as you already do.
However, the process might be way faster if you set the sample grabber to receive raw/undecoded fames. This way there is no need for decoder and the whole iteration through frames happens pretty quick. Don't forget to remove clock from the graph to request ASAP processing (as opposed to default real time pace).

Making Graphite UI data cumualtive by default

I'm setting up Graphite, and hit a problem with how data is represented on the screen when there's not enough pixels.
I found this post whose first answer is very close to what I'm looking for:
No what is probably happening is that you're looking at a graph with more datapoints than pixels, which forces Graphite to aggregate the datapoints. The default aggregation method is averaging, but you can change it to summing by applying the cumulative() function to your metrics.
Is there any way to get this cumulative() behavior by default?
I've modified my storage-aggregation.conf to use 'aggregationMethod = sum', but I believe this is for historical data and not for data that's displayed in the UI.
When I apply cumulative() everything is perfect, I'm just wondering if there's a way to get this behavior by default.
I'm guessing that even though you've modified your storage-aggregation.conf to use 'aggregationMethod = sum', your metrics you've already created have not changed their aggregationMethod. The rules in storage-aggregation.conf only affect new metrics.
To change your existing metrics to be summed instead of averaged, you'll need to use whisper-resize.py. Or you can delete your existing metrics and they'll be recreated with sum.
Here's an example of what you might need to run:
whisper-resize.py --xFilesFactor=0.0 --aggregationMethod=sum /opt/graphite/storage/whisper/stats_counts/path/to/your/metric.wsp 10s:28d 1m:84d 10m:1y 1h:3y
Make sure to run that as the same user who owns the file, or at least make sure the files have the same ownership when you're done, otherwise they won't be writeable for new data.
Another possibility if you're using statsd is that you're just using metrics under stats instead of stats_counts. From the statsd README:
In the legacy setting rates were recorded under stats.counter_name
directly, whereas the absolute count could be found under
stats_count.counter_name. With disabling the legacy namespacing those
values can be found (with default prefixing) under
stats.counters.counter_name.rate and stats.counters.counter_name.count
now.
Basically, metrics are aggregated differently under the different namespaces when using statsd, and you want stuff under stats_count or stats.counters for things that should be summed.

Adding one point to a flex line series without everything getting redrawn

I have an air app that collects live data from a user's action and graphs it. It records data every second and charts it on three different line series from the same array collection.
This works out great at first, but it gets worse and worse as time goes by. When it gets close to an hour it's almost unusable.
I'd like to be able to add a point to the graph and have flex JUST draw the new point and not invalidate the whole series and redraw it. Is this possible? I'm willing to override something to make this work.
My last ditch effort is to take the average of 5 or 10 points and only adding those. This will still work poorly when the user is going for 3 hours or so, but I can't think of a better way.
First, I wouldn't use ArrayCollection, but ArrayList since it's faster than ArrayCollection. Even better would to use VectorCollection.
Second, the Flex charts are made to be easy to use, but not very good at going 'outside the specs'. What you'll need to do is override the core functionality of the chart altogether for this to work, however that is a fairly daunting task because of the sheer amount of code involved in charts.
I would recommend you either create your own very quick and dirty component that draws the lines (it's fairly easy, I've done it myself) or use another charting library out there like Flare.
I added a UIComponent that overlaid the whole graph. I then used a cartesiandatacanvas to convert the current data point to x/y coordinates on the screen and did a lineTo to draw from the last point.
This lets me keep drawing the graph without a total reload of the data.
Each point is inserted into a sqlite db. If the chart is resized I clear the uiComponent.graphics and query the sqlite db and bind the data to it. If the user plays the chart from there I leave the currently drawn lines on the chart and continue using the above method.

Resources