Click event on Donut Highchart with GWT - java

I'm using the Highchart librairy with GWT to display multiseries Donut charts.
I would like to be able to click on one point (one series' subpart) and retrieve within the event handler the name of this point.
I tried "setPointLegendItemClickEventHandler" in the "PiePlotOption" that I set to my series but that's not working.
I can't find anything in the documentation that helps me.
Any idea ?

You just need to add click event listeners in your highcharts. For capturing the click event on the inner level series, add the following code in the Series (browsers) tag inside highcharts:
point: {
events: {
click: function(event) {
alert("Name: "+this.name + " X: " + this.y + " Y: " + this.x);
}
}
}
and for capturing the click on on the outer level 2 series, add the following inside plotOptions>Pie tag:
point: {
events: {
click: function(event) {
alert(this.name);
}
}
}
You will get the name as well as X, Y values of each point clicked.
See the DEMO here.

So I found the solution. See below :
myDonutChart.setSeriesPlotOptions(new SeriesPlotOptions().setPointClickEventHandler(new PointClickEventHandler() {
#Override
public boolean onClick(PointClickEvent pointClickEvent) {
// log pointClickEvent.getPointName();
return false;
}
}));
There you go.

Related

Javafx Control EventHandler MouseClicked All isxDown() methods false

I can't just know which button is clicked because all below methods are returning false. I am trying to grab the click type on a HBox control and using the code below. How to differentiate right and left click?
hb.addEventHandler(MouseEvent.MOUSE_CLICKED, event ->
{
System.out.println("Meta Down?" + event.isMetaDown());
System.out.println("Middle Down?" + event.isMiddleButtonDown());
System.out.println("Primary Down?" + event.isPrimaryButtonDown());
System.out.println("Secondary Down?" + event.isSecondaryButtonDown());
System.out.println("Synthesized?" + event.isSynthesized());
}
Output;
Meta Down?false
Middle Down?false
Primary Down?false
Secondary Down?false
Synthesized?false
The reason none of them are down is because MouseClicked gets called when a mouse button is pressed and then released, in other words, it's a Mouse Pressed event followed by a Mouse Released event.
If you need to know what triggered it, look at the event.getButton() and see if it is any of the MouseButtons. Try changing your code to something like this:
hb.addEventHandler(MouseEvent.MOUSE_CLICKED, event ->
{
System.out.println("Middle Clicked?" + event.getButton()== MouseButton.MIDDLE);
System.out.println("Primary Clicked?" + event.getButton()== MouseButton.PRIMARY);
System.out.println("Secondary Clicked?" + event.getButton()== MouseButton.SECONDARY);
System.out.println("None Clicked?" + event.getButton()== MouseButton.NONE);
}

Libgdx actor position resets after adding another action

I'm making some simple animation using Actors (Labels, to be precize) and Actions.
My initial plan was to move one of them far to the left instantly, then make it smoothly appear through the edge of screen, replacing another. But every time a new Action is executed, Label's position resets, so I can't get the effect I planned. How do I avoid it?
Here's code, if you need it:
newAttack.addAction(Actions.moveBy(-1 * game.W, 0));
newAttack.setText(game.local.get(_attack));
newAttackType.background = game.skin.getDrawable("attack_" + getAttackType(_attack));
lastAttack.addAction(Actions.sequence(Actions.moveBy(game.W, 0, 1.5f),
Actions.run(new Runnable() {
public void run() {
System.out.println(lastAttack.getX() + " " + lastAttack.getY());
newAttack.addAction(Actions.sequence(Actions.moveBy(game.W, 0, 1.5f), Actions.run(new Runnable() {
public void run() {
lastAttack.addAction(Actions.moveBy(-1 * game.W, 0));
newAttack.addAction(Actions.moveBy(-1 * game.W, 0));
System.out.println(lastAttack.getX() + " " + lastAttack.getY() + "\n" + "--");
lastAttack.setText(game.local.get(_attack));
lastAttackType.background = game.skin.getDrawable("attack_" + getAttackType(_attack));
}
})));
}
})));
This may not work, but looking into the source code of Label.setText() reveals that the method calls Actor.invalidateHierarchy. This means that whatever is containing the lastAttack actor will reset the lastAttack's position.
So since you are adding the actions before you are calling Label.setText(), the position will be reset and then the actions won't work properly.
You should try setting the text, then setting the position of the actor to off screen, and then adding the slide in Action.

Appium - Java Action Check

I'm working on a test script that works with Appium (Selenium) on Java for mobile devices.
In the script, there's following codes:
_driver2.swipe(startXL, startYL, endXL, endYL, 100);
and
_driver2.tap(1, startX, startY, 100);
These methods swipe a game object or click on a button in a game.
Here are some details:
Swiping method is using absolute locations on screen. Tap method is using a location that is calculated by an image recognition function.
Here's my question:
While the test is running; if device's screen is different than expected, like push notifications or native dialogs, test doesn't stop and still tries to find an image/location and then clicks/swipes.
I want to make it stop if there's a different screen than expected or the game object didn't move.
My question is probably not clear but I can give you details comment by comment.
Thank you in advance.
You can use an simple if else condition
If element is found { Swipe }
Else { Perform other action }
Step 1:
public boolean isElementFound(String element)
{
try{
WebElement webElement = driver.findElement(By.xpath(element));
System.out.println("isElementFound : true :"+element);
}catch(NoSuchElementException e){
System.out.println("isElementFound : false :"+element);
return false;
}
Step 2 : while(isElementFound(String element))
{
TouchAction touchAction = new TouchAction(appiumDriver);
System.out.println(startx+" "+starty);
System.out.println("Entering swipe");
System.out.println("Swipe from "+startx +" " +starty +"to" +endx +" " +endy );
touchAction.press(startx, starty).waitAction(duration).moveTo(endx,endy).release().perform();
// WebElement webElement = appiumDriver.findElement(By.xpath(element));
webElement.click();
}

JavaFX Popup under Node

Resources and examples for this Popup widget are vague.
Suppose I have a random Node somewhere on the stage. How do I open a Popup exactly under it (e.g. like a dropdown menu, but with other nodes inside it).
I'm trying to avoid boilerplate code (i.e. fine-tuning the position myself).
Update 1:
Either Point2D point = node.localToScene(0.0, 0.0); does not work as I imagine it should, or I'm using it wrong.
Update 2:
See here a simple example, but lacking the functionality I'm needing
Let's say you have the node node
you can get its position by
Point2D point = node.localToScene(0.0, 0.0);
// now get point.getX() and point.getY() here
Considering the example that you have given (in Update 2):
I removed this bit:
popup.setX(300);
popup.setY(200);
and modified this code:
show.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
popup.show(primaryStage);
Point2D point = show.localToScene(0.0, 0.0);
popup.setX(primaryStage.getX() + point.getX());
popup.setY(primaryStage.getY() + point.getY() + 40);
// this 40 could be show.getPrefHeight() if height of button is set
}
});
Since Popup is a separate window, you need to set its position by adding the offset of the Stage.

Stacked Bar Chart: Changing appearance of entire bar?

I am using achartengine in my Android app to display a stacked bar chart (something similar to this). I use the ChartFactory.getBarChartView to get a GraphicalView object that I then place in my layout.
My objective is to provide touch feedback to the user when one of the stacked bars is touched by the user. I intend to do this by changing some of the UI properties (probably color) of the bar that the user touched. However, I want to designate the entire stacked bar as touched. This is as opposed to designating just the selected section of the bar.
Taking the SalesStackedBarChart example from the demo, I want to designate the entire bar for, say, March as selected (not just the section for March 2008).
I already know how to set up onClickListener on the GraphicalView object and to use the getCurrentSeriesAndPoint() method. However, using this approach, I have been able to only designate the same section on all bars as selected. For example, the 2008 sections on all 12 bars are highlighted.
Question:
How do I change the appearance of all sections in a single stacked bar?
Here's my code. It works as designed (i.e, sets the selected section on all 12 bars to gray), but this is not what I want.
mGraph.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
SeriesSelection seriesSelection = mGraph.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(mContext, "No chart element was long pressed",
Toast.LENGTH_SHORT).show();
return false; // no chart element was long pressed, so let
// something
// else handle the event
} else {
SimpleSeriesRenderer renderer = mMultiRenderer.getSeriesRendererAt(seriesSelection.getSeriesIndex());
Toast.makeText(mContext, "Chart element in series index "
+ seriesSelection.getSeriesIndex() + " data point index "
+ seriesSelection.getPointIndex() + " was long pressed",
Toast.LENGTH_SHORT).show();
renderer.setColor(Color.LTGRAY);
return true;
}
}
});
Setting the color of a series will change the colors of all bars in that series.
One potential solution would be to create an extra series containing only the bars you want to highlight as selected. Quite tricky.

Categories