Chart.js - Callback to make a point active - callback

I'm trying to navigate radar's graph point with the rotating bezel on watch and have stacked for several days on this:
A) Via click on graph
Select point (mark blue)
Write value to a HTML element
B) Via callback (inner circle in this sample)
Navigate the point +1 / -1 from A1
Write value to a HTML element (how to retrieve info from tooltip here?)
I have a trouble with B. In my case, B1 is navigating through points, but it doesn't mark the point with blue circle. It is also possible to show tooltip here correctly, but it doesn't write to HTML element like A1 does.
Can you help me please with B1 and B2 please? It's at the end of JS file in Fiddle sample - https://jsfiddle.net/Konvas/aqyrsxL3/22/
function updateView() {
chart.tooltip._active = [chart.getDatasetMeta(currentDatasetIndex).data[currentPointIndex]];
console.log(chart.tooltip);
chart.tooltip.update();
chart.update();
}
Thanks!

Related

enable context menu for specific cell or item in uitable or uilistbox in matlab

I created a uitable (new version using appdesigner) in MATLAB and wanted to support right clicking on cells and showing a cell specific context menu. Much to my surprise there seemed to be no way to support this.
The context menu only seems to trigger with right click on the uitable, but there is no way of knowing which cell was selected (I think, maybe not?). I created a workaround where I left clicked to select a cell, and during that selection I right clicked using a Java Mouse robot to trigger the context menu. This is super ugly but sort of works. Except, if you need to bring up the menu twice on the same cell. Apparently the cell selected callback only fires once for the cell, until a new cell is selected. I tried literally putting two tables in the same spot and upon selecting one toggling to the other, but the memory of cell selection is table specific, so this only worked for two clicks before both tables had been clicked on the same cell, and toggling visibility back to the first resulted in the cell selection callback not firing (since the cell had not changed) . I tried various approaches to try and deselect the cell (disable/enable, visibility change, data change, etc.), but the cell selection callback never changed.
I even tried having duplicate columns, where the goal was to hide a column, where normally columns 1 and 2 would be visible (column 3 out of view due to size), and then on clicking on column 2, column 2 would hide itself (0 width) and column 3 (an exact duplicate) would move into its place, thus seeming to the user like multi-clicking was supported. Unfortunately I can't set the column width to 0 -- or rather, setting it to 0 doesn't completely hide the column. Instead there seems to be some minimal width to the column and the whole thing looked awful.
I wanted to do something similar with a listbox (right click support), but again I couldn't figure out how to identify where I was right clicking. I eventually settled on left clicking on a listbox and using the mouse robot approach to right click to bring up the context menu. Unlike the uitable, it was fairly easy to clear the selection on the listbox (set listbox.Value = {}). However, I strongly dislike the left click instead of right click approach and I'd rather have multiple columns.
Any suggestions would be much appreciated!!!
So I found an approach that is better than using a robot. I had tried this but was missing a critical portion which I will describe below.
Upon selecting a row in the table, the open command can be used to launch a context menu. My problem was that I didn't know where to launch the menu. I tried CurrentPoint for the figure, but it was 0,0 (or in general not valid)
Here's the current documentation for CurrentPoint:
Current point, returned as a two-element vector. The vector contains
the (x, y) coordinates of the mouse pointer, measured from the
lower-left corner of the figure. The values are in units specified by
the Units property.
The coordinates update when you do any of the following:
Press the mouse button within the figure.
Release the mouse button after pressing it within the figure.
Press the mouse button within the figure, and then release it outside
the figure.
Rotate the scroll wheel within the figure.
Move the mouse within the figure (without pressing any buttons),
provided that the WindowButtonMotionFcn property is not empty.
If the figure has a callback that responds to mouse interactions, and
you trigger that callback faster than the system can execute the code,
the coordinates might not reflect the actual location of the pointer.
Instead, they are the location when the callback began execution.
If you use the CurrentPoint property to plot points, the coordinate
values might contain rounding error.
Here's the critical line again:
"Move the mouse within the figure (without pressing any buttons), provided that the WindowButtonMotionFcn property is not empty."
So when a selection of a cell happens, the CurrentPoint is not valid. However, if we simply define a WindowButtonMotionFcn, then it is!
So the general idea is to have a callback for the table when a cell is selected (SelectionChangedFcn) and to set a dummy callback for WindowButtonMotionFcn
The final point is that a context menu can be launched with the open function if you specify a given location to launch it at. This is different from attaching it to an object and having it automatically launch on right click.
Here's some example code. If you comment out the callback for windows motion then the whole thing doesn't work! Unfortunately it is a left click for targeting the cell but at least it avoids the non-sense I was using with a java robot right click.
classdef wtf < handle
properties
h %struct, this was an appdesigner handle
cm %context menu
end
methods
function obj = wtf()
h = struct;
h.UIFigure = uifigure();
h.UITable = uitable(h.UIFigure);
obj.h = h;
obj.h.UITable.CellSelectionCallback = #obj.tableCall;
%obj.h.UITable.SelectionChangedFcn = #obj.tableCall;
%Some data ...
s = struct;
s.a = (1:4)';
s.b = (5:8)';
obj.h.UITable.Data = struct2table(s);
%Our context menu
cm = uicontextmenu(obj.h.UIFigure);
m = uimenu(cm,'Text','Menu1');
obj.cm = cm;
%WTF ... without this we don't get a valid CurrentPoint
obj.h.UIFigure.WindowButtonMotionFcn = #obj.mouseMove;
end
function tableCall(obj,x,y)
%y - event info
%x - impacted object
cp = get (obj.h.UIFigure, 'CurrentPoint');
open(obj.cm,cp(1),cp(2));
selected_cell = y.Indices;
%selected_cell = y.Selection;
x.Selection = []; %allows reselecting same cell without
%needing to select another cell first
%Now we can run something on the context menu
%that targets the selected cell
end
function mouseMove(obj,x,y)
%we could store a point here
end
end
end

Dynamically reading point coordinates from Spreadsheet in GeoGebra

I was using GeoGebra and I wanted to create a point whose co-ordinates are dynamically read off of a spreadsheet. The spreadsheet would have two columns for the values of x and y co-ordinates of this point, and this point would have to dynamically move from the first (x,y) value all the way through to the last one.
I tried using a slider to refer to the elements of the spreadsheet but am unable to do so. If this could be done, all I would have to do was create an animate button for the slider and that would be it. But I cannot figure out how to name the elements of the spreadsheet while incorporating the slider name as well.
If this idea cannot be implemented, is there another way of creating moving points in GeoGebra based on coordinate values created in an external file(which I was planning to copy to the spreadsheet)?
Thanks!
Yeah , there are two methods to do that one of them is using Object[] commend as you indicate in the comment ; the seconde method is creating a list follow these steps :
select a column for exemple A by clicking in the top of column
Right Click
create
list
then you can access to any element of the list in commend line by type for creating a point : (element(list1,n),element(list2,n))
n is the slider
hope i help you

MATLAB - Using radio buttons to change units for a graph

I am very new to Matlab and I am trying to create a GUI from an equation. I have to make it so I can change the units by clicking on radio buttons.
T=MIN:10:MAX
P=10.^(A-B./(C+T));
plot(T,P)
xlabel('Temperature')
ylabel('Pressure')
This is how I plot the graph and to input the constant for A, B, C, MIN and MAX, I did this.
contents = cellstr(get(hObject,'String'));
popChoice = contents{get(hObject,'Value')};
if (strcmp(popChoice,'Acetic Acid'))
A=8.021;
B=1936.01;
C=258.451;
MIN=18
MAX=118
and then
assignin('base','A',A);
assignin('base','B',B);
assignin('base','C',C);
assignin('base','MIN',MIN);
assignin('base','MAX',MAX);
I did this for about 15 more compounds. Then I assigned the constants to the workspace. The graph works for all the compounds when I change them in the pop up menu but I don't know how to use the radio buttons to change the units of both T and P. I am very new to this. Thank you.

Trying to position a button programmatically, however not in right position according to X,Y

I'm trying to position a button.
Here is the code for the positioning..
[btnAbs setFrame:CGRectMake(57, 50, 106, 99)];
The coordinates I got are from here:
As you can see the xib stats the x & y to be at 57 and 192, which is where I want the button to be.
However when I run it in simulator, here is where its placed:
Obviously i could keep guessing and guessing the x and y coordinates, but this is very time consuming. So how come it's doing this?
Please join the links together when looking at the pics as i need more than 10 reps to post images, or a mod fix this please?
The problem is here:
The “origin” in Interface Builder doesn’t actually affect how the view gets positioned programmatically—it’s just a visual aid. If you click the dot in the top left of that box, the X and Y coordinates will change to the top-left of the view, which are the coordinates you want to pass to -setFrame:.
It looks to me as if you have the GUI designer aligning base upon the center center of your image view. When you do it in code, it is going to align based upon the top left of the image view.
Further, your code places it at a y of 50, where your GUI designer is showing a y coord. of 192.

how to get x and y coordinates of user tap/touch relative to window - android titanium mobile?

Can any one tell how to get x and y coordinates of user tap/touch relative to window - android titanium mobile??
I need to add a popup view close to tableviewrow when the user select a row. How to determine the x,y (top/left) positions?
This might help you as the window or object touch events can help you find the exact points the user have touched on screen.
thanks
you can use
row.addEventListener('click',function(e){
alert('left:'+ e.x + ' top:'+ e.y);
});
where row is an object of Titanium.UI.TableViewRow. For other objects (like window/view), you can use same eventlistener.
But remember one thing: it gives the co-ordinates with respect to the corresponding row. i.e. you may get same co-ordinates for all the rows.
Therefor, if you want to popup something on that co-ordinate, you should addEventListener to the main window.
On click event of any view or object you get x and y coordinate see this link for more reference:
Titanium.UI.Window