Dukascopy
 
 
Wiki JStore Search Login

custom widget - changes position after switching charts
 Post subject: custom widget - changes position after switching charts Post rating: 1   New post Posted: Wed 08 Jan, 2014, 10:56 
User avatar

User rating: 1
Joined: Wed 08 Jan, 2014, 10:38
Posts: 3
Location: Russian Federation, Moscow
I create a widget via
widg = chart.getChartObjectFactory().createChartWidget();
widg.setPosX(valueX);
widg.setPosY(valueY);

When I switch charts manually, the widget goes to AN ALWAYS SAME upper left corner.

Now comes the interesting part. I tracked coordinates before and after switching charts. Coordinates change accordingly! So you might think that introducing some logic to change coordinates after switching charts would fix the issue. But this logic won't work. The thing is that upon switching charts the scale of charts changes. Attention - I do not change the scale, I only switch charts. But the scale changes anyway, so the widget acquires a new position upon switching charts.

My objective - the widget must retain the position that I define if the scale of open charts does not change.


 
 Post subject: Re: custom widget - changes position after switching charts Post rating: 1   New post Posted: Wed 08 Jan, 2014, 13:07 
User avatar

User rating: 96
Joined: Mon 09 Sep, 2013, 07:09
Posts: 287
Location: Ukraine, SHostka
I confirm this bug, but in my case manual switching of the charts implies unexpected changing only X position of a widget.

DEMO 2.30.2


 
 Post subject: Re: custom widget - changes position after switching charts Post rating: 0   New post Posted: Wed 08 Jan, 2014, 13:19 
User avatar

User rating: 1
Joined: Wed 08 Jan, 2014, 10:38
Posts: 3
Location: Russian Federation, Moscow
I tried adding chart.repaint() to the OnTick method, it worked well for one strategy. It also works for another strategy, but the widget changes position.

The setPosX() method defines the x-coordinate as a proportion of the open chart. That proportion changes while switching charts. It would be great to make widgets stick to corners like labels via setCorner() (IScreenLabelChartObject).


 
 Post subject: Re: custom widget - changes position after switching charts Post rating: 0   New post Posted: Thu 09 Jan, 2014, 10:54 
User avatar

User rating: 1
Joined: Wed 08 Jan, 2014, 10:38
Posts: 3
Location: Russian Federation, Moscow
My temporary walkaround: 1) define variable for detecting switching of charts (true - switched, false - not switched), 2) detect switching and force to the initial coordinates, 3) upon manual change of the position of widget do nothing

private boolean mainChartChanged = false; // should be global

if(mainChartChanged && context.getLastActiveChart().getInstrument() == instrument){
   // Put into OnTick method, make context and instrument fixed, otherwise won't work
   // Force to the initial coordinates
   widget.setPosX(0); // First to zero, otherwise won't work
   widget.setPosX(Float.valueOf(settings[6])); // Then to the initial coordinates
   mainChartChanged = false;
}
       
if(context.getLastActiveChart().getInstrument() != instrument){mainChartChanged = true;}
else{
   if(widget.getPosX() != Float.valueOf(settings[6]) && context.getLastActiveChart().getInstrument() == instrument){
      // Do nothing as the position is changed manually by user on the active chart
      settings[6] = String.valueOf(widget.getPosX());
      settings[7] = String.valueOf(widget.getPosY());
   }
}


Still, you can't tell if the active window is a chart or a window for editing strategies. If it's the latter, the method getLastActiveChart still returns our active chart, whereas it's not active now. Otherwise if don't use anything but charts works pretty fine.


 
 Post subject: Re: custom widget - changes position after switching charts Post rating: 0   New post Posted: Tue 14 Jan, 2014, 08:18 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The issue will be fixed with JForex-API 2.9.5.5.


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com