Flutter charts handle legend press - flutter

I would like to call a function and still run the default when the user clicks the chart legend as seen in the gif below.
The problem is that I couldn't find a way to just to INTERCEPT and not modify the way the legend works. Because I still want the animations to play and hide the item the user taps on, but meanwhile I would also like to setState my app. I experimented with charts.SeriesLegend.customLayout but I couldn't achieve what I wanted and I also don't want a custom layout, I need the default one.
I would like to call a function like this, so I need to know which legends are shown (see gif):
void setChartVariables(input){
setState((){
justified = input.justified;
awaitingJustification = input.awaitingJustification;
unjustified = input.unjustified;
});
}

Related

How do I get a chart to redraw itself when the model is paused?

I have a Time Stack Chart whose data set can be changed by clicking on a radio button. While the model is running, the chart instantaneously updates its appearance when a radio button is clicked. When the model is paused, however, the chart's area becomes blank when a radio button is clicked; the legend, in contrast, updates automatically. How do I manually force the chart area to redraw itself?
When you pause a model, only a part of Anylogic is actually paused. The thread that handles the GUI keeps running, which is why you can navigate around in the model while it is paused.
This also means that if you try to update a chart's data while the simulation is paused, the appearance will refresh but -- as your data is being updated in another thread that is currently paused -- it will not have received that data.
If you want to pause the simulation and still be able to switch the data being displayed in a chart, you could take a look at the Airport example model. It provides a good method to switch between different charts by making them visible/invisible and adjusting the width, height, x and y. Essentially, you make all of the charts you need, overlap them perfectly, and then make visible the one that is currently of interest to you.
If you want to create the charts programmatically, on top of creating the chart with, e.g., new TimeStackChart(...), you also have to add it to the top level presentation group with main.presenation.add(...). If you don't do this, the chart will never appear in the model as the model won't have anything to display! To find more information on how to create a chart programmatically, make a chart in Main and then open Main in the Java editor. Find the chart you created, take a look at it's constructor (there are a lot of arguments!), and use it as rough template for the charts you wish to create. The Help documentation will further make sense of the parameters you see.
have you tried the chart.refresh(); method?
Also try to update the embedding agent using agent.onChange().
hope that helps
I encountered the exact same problem, and came up with workaround.
Try this, which I know works in AnyLogic v7:
if (getEngine.getState() == getEngine().PAUSED ){
dynChart.setSelectedItemIndices( new int[]{0} );
dynChart.setSelectedItemIndices( null );
}
I was able to get the chart to refresh manually when paused or finished by selecting/deselecting one of the legend items. I spent a few hours try out API variations to no avail, so I just emulated what was actually working in the UI and it worked.
I am dynamically generating a text item as the chart title, but I have not had the same luck getting the text to refresh when paused like the chart. Any ideas on that one?

Make an image a button in MATLAB

I am developing a GUI in MATLAB and am trying to allow a user to click on an image in order to enable a push button, and then this image will change like a toggle button, but I am struggling and am hoping for some advice, how can this be done?
I've seen that you can put icons on push buttons in MATLAB and that you can extract the position of the mouse on a click, but I can't figure out if these help my situation. I don't want to put the icon on the button because a) its not the look I am going for and b) I want to be able to change the image depending on the state of the button.
Thanks
The key to your problem is ButtonDownFcn. You need to set your images ButtonDownFcn to reference come function which both changes the image displayed, and does whatever else you need it to do. So, for example, say your create you image in you operating function like so:
...
yourImHandle = image(someImage);
set(yourImHandle, 'ButtonDownFcn', {#yourPushbuttonFcn, yourImHandle, otherVar});
...
Where yourPushbuttonFcn is defined elsewhere as:
function yourPushbuttonFcn(yourImageHandle, otherVar)
set(yourImageHandle, 'CData', someOtherImage);
otherVar=otherVar+1; %# Do other things.
end
This will change the image for you, and sets up the platform for you to do other, more complicated things inside the push button function. Let me know if you have any questions.
Good Luck.

How may I force a redraw of all Vaadin charts in a dashboard to toggle dataLabels on or off?

How may I force a redraw of All Vaadin charts in a dashboard to toggle dataLabels on or off?
I would like to allow my app user to add/remove chart dataLabels for All charts on their dashboard; forcing a redraw similar to when changing themes say from VaadinTheme to GridTheme.
How may I achieve this?
How does changing themes work under the hood, what is the source code that does this?
e.g.;
I know I could redraw a single chart individually by resetting its plot options and then redrawing it:
.
.
.
PlotOptionsColumnRange columnRange = new PlotOptionsColumnRange();
columnRange.setDataLabels(new Labels(true));
columnRange.setDataLabels.setFormatter(/* some javascript about this.y */);
conf.setPlotOptions(columnRange);
chart.drawChart(conf);
But I want to do it for All charts on a dashboard; like having a Listener that does
ChartOptions.get().setTheme(new VaadinTheme())
then
ChartOptions.get().setTheme(new GridTheme())
and viceversa
Maybe I can reset the plotOption dataLabels then reset the theme to force a redraw with the new dataLabel state?
Please advise...
p.s.
I don't want to make changes to my user saved data in my database, i.e., I don't want this label toggle to be persistent. I want to toggle dataLabels just like a toggling themes.
Please look at:
http://demo.vaadin.com/charts/#ColumnRange
to see what I mean.
Ok, two solutions:
A coworker of mine that worked on the Dashboards helped me with the first answer to this question.
Basically, you have to clear all charts, then iterate through ea. chart in a particular dashboard (stored in the DB), and rebuild ea. chart w/ your decision to have or not have a dataLabel, placing it back in that dashboard; but I wanted to avoid this as it might take a performance hit.
Also I later got a response from Pekka of the Vadding team, as follows:
'You can easily hide the dataLabels with basic css. For example, if you can apply a stylename "dataLabelsHidden" to you UI, then you could write in your stylesheet a specific enough rule for hiding the labels. I quickly tested the demo with this:
.v-ui.dataLabelsHidden g.highcharts-data-labels {
display: none;
}
This way you won't have to update all your charts when the labels on/off is triggered.'

How to display our output meseeges into specified uipanel in Matlab GUI?

I want to display my output messages that have processes in a function. The message is stored in a variable.
In the GUI window, I made an uipanel with tag=uipanel1.
So, my question is how do I display my messages in the specified uipanel that I made (uipanel1)?
Any ideas?
There are many ways to do this, but it is hard to guess the most appropriate way without some information on what you already tried. I would suggest the following options:
If your uipanel is not high and is used much like statusbar in gui applications then you better add a static text component to it and update its text through its handle.
While static test can also display multiline text it will not display scrollbars. If you want to display something like a message log window with several lines visible and scroll bars, I'd suggest to add a listbox instead. However, it will be a little tricky if you want to show only limited number of most resent messages.

Ext-GWT 3.0 Grid Mouse Events

I have a grid which gets populated from the database and works fine. Now I want to add a mouseover event to this grid and display a tooltip text which shows all the column values in multi-line fashion for the highlighted record. The business case here is that there are quite a few columns that are being displayed in the grid and the user would like to have a quick preview instead of horizontally scrolling all the way to the end, before selecting the record. Squeezing all these columns to fit into the screen is not a clean solution in this case.
I have tried looking through all the available methods in the GXT 3.0 API for Grid and GridView but couldn't find anything to get the highlighted records. There are a couple of events for MouseMove, MouseDown and MouseClick but none for MouseOver.
I tried various forums as well to find a solution but there doesn't seem to be one yet so thought it might be useful for others as well if I start this thread.
Please note that this issue is not related to Ext-JS. The version I am using is Ext-GWT 3.0.1.
Thanks
MouseMove IS the one you want. It's only fired when the mouse is over the widget.
Alternatively, you can sink a DOM event to the widget by using:
DOM.sinkEvents(widget.getElement(), Event.ONMOUSEOVER);
in your widget's constructor or onLoad method, and then override the widget's onBrowserEvent:
#Override
public void onBrowserEvent(Event event){
final int eventType = DOM.eventGetType(event);
if(eventType == Event.ONMOUSEOVER) {
//DISPLAY THE INFO
}
}
This is definitely harder than directly adding a handler but pretty customizable. You can choose either one.
BTW you might want to get the position of mouse by using:
mouseX = DOM.eventGetClientX(event);
mouseY = DOM.eventGetClientY(event);
You could accomplish this by creating a custom Cell, and passing that to the grid's specific ColumnConfig.
With the custom Cell, you have access to all the events you would need.
Once you have access to the info you need, displaying it can be done in many ways. GXT provides a lot of solutions for this. Quicktips may be the way to go here though.