Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • jlhoward1
    replied
    And in the calling program... part 2

    in the module onLoad();
    GFoamTree gfoamtree = new GFoamTree(""); /// .... must be on "top"


    in my callback

    Code:
    .... 
    	if (tabset.getSelectedTabNumber() == 0) { // foamtree tab 
    	gfoamtree.show();
    				}
    				;
    
    	gfoamtree.setData(clusterdata.duplicate(), "label", "docs"); 
    ....
    And the handler ....
    Code:
    gfoamtree.addGFoamTreeHandler(new GFoamTreeHandler() {
    			@Override
    			public void onMessageReceived(GFoamTreeReceivedEvent event) {
    				// TODO Auto-generated method stub
    				super.onMessageReceived(event);
    				// Window.alert("message received" + event.getMessage());  // Window,alert("bad habit to use window alert use logWarn"); 
    				Record gfoamclusterrecord = clusterdata.findAll("label",
    						event.getMessage())[0];
    				AdvancedCriteria adCriteria = new AdvancedCriteria("_id",
    						OperatorId.IN_SET, gfoamclusterrecord
    								.getAttributeAsStringArray("FilterIds"));
    
    				grid.setData(griddata.findAll(adCriteria));
    				// Sample browser MVC debugging displays... can't use system.err
    				// in the browser side
    				grid.redraw();
    				
    			}
    		});
    Last edited by jlhoward1; 16 Apr 2014, 15:18.

    Leave a comment:


  • jlhoward1
    replied
    Thank you and here is my working but not perfect JSNI

    Thank you.... I still use say and alert at times. :(


    BTW. Here is the working GFoamTree,java JSNI code for smartgwt .... no promises as to correctness.

    Read the google gwt JSNI tutorial.


    GFOAMTREE.JAVA
    Code:
     
    package your.package.foamtree.client;
    
    
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.logging.Logger;
    
    
    
    
    
    
    import com.google.gwt.core.client.JavaScriptObject;
    import com.google.gwt.dom.client.Document;
    import com.google.gwt.event.shared.HandlerRegistration;
    import com.google.gwt.event.shared.HasHandlers;
    import com.google.gwt.json.client.JSONArray;
    import com.google.gwt.json.client.JSONNumber;
    import com.google.gwt.json.client.JSONObject;
    import com.google.gwt.json.client.JSONString;
    import com.google.gwt.user.client.Window;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.HTMLFlow;
    import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler;
    import com.smartgwt.client.widgets.grid.events.SelectionEvent;
    
    public class GFoamTree extends HTMLFlow implements HasHandlers{
    	private JavaScriptObject chart;
     //   public gfoamtreeHandler foamtreeHandler;
        final public String deadbeef = "gfoamtree deadbeef";
        static int count=0;
        
        
    
    	public GFoamTree(String elementId) {
    
    		setElement(Document.get().createElement("div"));
    		setContents("<div id=\"foamtree\" style=\"width: 450; height: 700\">tree  here</div>");
    		
    		
    	//	gfoamtree_trigger(""); // static call --- as an example only not used ... use the instance call
                // force code generation - gwtc will remove gfoamtree_trigger2 if not called by java
    		if (count==0) {
    	      gfoamtree_trigger2(""); // instance call 
    		}
    	}
    	
    
    	public void setData(Record[] data, String labelProperty, String weightProperty) {
    	//	this.gfoamtree_trigger2("");
    		Map<String, Integer> items = new HashMap<String, Integer>();
    		JSONArray records = new JSONArray();
    		
    		for (int i = 0; i < data.length; i++) {
    			Record r = data[i];
    			int current = 0;
    			String label = r.getAttribute(labelProperty);
    			if (items.containsKey(label))
    				current = items.get(label);
    			SC.logWarn(r.getAttributeAsInt("docs")+" here ");
    			items.put(label,r.getAttributeAsInt("docs"));
    		}
    		int i = 0;
    		for (Map.Entry<String, Integer> entry : items.entrySet()) {
    			JSONObject obj = new JSONObject();
    			obj.put("label", new JSONString(entry.getKey()));
    		//	 SC.logWarn("  there "+entry.getValue());
    			obj.put("weight", new JSONNumber(entry.getValue()));
    			records.set(i, obj);
    			i++;
    		}
    		
    		setChartData(this,records.getJavaScriptObject(), "foamtree");
    	}
    	@Override
    	public String getInnerHTML() {
    		// TODO Auto-generated method stub
    		return super.getInnerHTML();
    	}
    
    
    	public native void setChartData(GFoamTree thisclass, JavaScriptObject records, String id) /*-{
    		  console.log(records);
    
    		  gfoamtree = $wnd.CarrotSearchFoamTree({
    		    // Identifier of the DOM element
    		    // into which to embed FoamTree
    		    'id': id,
    		 
    		    // Other options can be set during embedding
    		    // as well. Here we set the border width to 8
    		    //'borderWidth': 8,
    		 
    		    // Group selection listener
    		    onGroupSelectionChanged: function(info) {
    		    	// don't have this working for static --- it's here to document the another approach --- use the instance
    		    	console.log("fired"); 
    		
    		    	//debugger;
    		    	//static call removed
    		           //    var returncode = @your.package.foamtree.client.GFoamTree::gfoamtree_trigger(Ljava/lang/String;)(info.group);
    		          // note 'this' is CarrotSearchFoamTree not GFoamtree
    		       var myselectedgroup= this.get("selection").groups[0].label;
    		          // GFoamtree changes 'this' in the scope to it's context so 'this.' won't work... pass in a 'thisclass' reference instead
    		       var returncode2 = thisclass.@your.package.foamtree.client.GFoamTree::gfoamtree_trigger2(Ljava/lang/String;)(myselectedgroup);
    		
    		      //  alert("ended "+myselectedgroup); // remove this ... no alerts
    		      
    		    },
    		    dataObject: { groups: records }
    		  });
    	
    		  console.log("Foam Tree - set chart data completed"); 	
    
    	}-*/;
    
    	public static int gfoamtree_trigger(String event) {
    		// 
    	
    		if (count>0){
    	
    		
    		Logger.getLogger("Events").info("Event " + event + " triggered");
    		}
    		count++;
    		return 0;
    	}
    	public int gfoamtree_trigger2(String event) {
    		// use this instance call.... 	
    		if (count>0){
    	
    			SC.logInfo("before event");
     
    	   fireEvent(new GFoamTreeReceivedEvent(event));
    
    		}
    		count++;
    		return 0;
    	}
    	
    	
    	public HandlerRegistration addGFoamTreeHandler(GFoamTreeHandler handler) {
    		SC.logInfo("Adding handler");
    		HandlerRegistration r = doAddHandler(handler, GFoamTreeReceivedEvent.TYPE);
    		return r;
    	}
    
    	
    }

    GFoamTreeHandler.java
    Code:
    /**
     * 
     */
    package your.package.foamtree.client;
    // Not needed imports.... 
    //import com.google.gwt.view.client.SelectionChangeEvent;
    // import com.google.gwt.view.client.SelectionChangeEvent.Handler;
    
    /**
     * @author howardjos
     *
     */
    public class GFoamTreeHandler implements IGFoamTreeEventHandler {
    
    	/**
    	 * 
    	 */
    	public GFoamTreeHandler() {
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public void onMessageReceived(GFoamTreeReceivedEvent event) {
    		// TODO Auto-generated method stub
    		
    		
    	}
    
    	
    
    }
    GFoamTreeReceivedEvent.java
    Code:
    /**
     * 
     */
    package your.package.foamtree.client;
    
    
    import com.google.gwt.event.shared.GwtEvent;
    
    public class GFoamTreeReceivedEvent  extends GwtEvent<GFoamTreeHandler> {
    
    	
    		    public static Type<GFoamTreeHandler> TYPE = new Type<GFoamTreeHandler>();
    
    		    private final String message;
    
    		    public GFoamTreeReceivedEvent(String message) {
    		        this.message = message;
    		    }
    
    		    @Override
    		    public Type<GFoamTreeHandler> getAssociatedType() {
    		        return TYPE;
    		    }
    
    		    @Override
    		    protected void dispatch(GFoamTreeHandler handler) {
    		        handler.onMessageReceived(this);
    		    }
    
    		    public String getMessage() {
    		        return message;
    		    }
    		
    	}
    IGFoamTreeEventHandler.java
    Code:
    package your.package.foamtree.client;
    import com.google.gwt.event.shared.EventHandler;
    
    
    	public interface IGFoamTreeEventHandler extends EventHandler {
    	    void onMessageReceived(GFoamTreeReceivedEvent event);
    	}
    Last edited by jlhoward1; 16 Apr 2014, 15:16.

    Leave a comment:


  • Isomorphic
    replied
    Never use SC.say() for debugging, you will only see the last message of a series of messages passed to it, and the fact that you are popping up a modal dialog will interfere with many behaviors you might be trying to troubleshoot (for example, it moves focus, and will prevent the second click in a double-click series).

    Never use alert() or Window.alert() either for similar reasons.

    Generally, use SC.logWarn() from SGWT, and isc.Log.logWarn() from JSNI, both of which log to the Developer Console and to the Eclipse console (since all warning-level logs appear there as well).

    Using a single logging approach (as opposed to logging some things to console.log() and some via SC.logWarn()) will mean that all logs appear in one place in the right relative order.

    We also don't recommend that developers new to SGWT start learning JSNI. The vast majority of SmartGWT developers never use JSNI. You should have a very specific and unusual need in mind before going off to learn JSNI.

    Leave a comment:


  • jlhoward1
    replied
    The above code

    To Stone...
    The above code has a significant problem that is not addressed by me. I don't need to fix the issue, but you might in other code. The code is expecting that the parent element of foamtree is drawn and visible. This code expects show and then setdata to occur. I am thinking that calling this code should be placed in it's parent's ondrawn event.

    Thanks

    Leave a comment:


  • jlhoward1
    replied
    Forum code 4.1d a nd on advice in forums

    Stone,
    Yes, it is not all correct. The correct code has to use 4.1d (which broke my visualbuilder in smartgwtpro).

    I will update the example to 4.1d with a filter on the associated grid.
    ----------------------------------------------------------------------
    Being newish to smartgwt also I am still learning. Advice isn't perfect.

    I find the following very useful in the client.

    In JSNI - I use console.log("your error"); for writing to the browser log calls
    In SMARTGWT I use SC.say(); and SC.LogWarn(); Take a close look at the SC utility classes.
    Also I use debugger; to break into the debugger in JSNI for chrome and firefox. (I periodically use "DEADBEEF" as a search string to find the generated code).


    For third party JSNI, I strongly read hint that anyone using smartgwt read this .... http://www.gwtproject.org/doc/latest...asicsJSNI.html
    In general, I find alert(); in JSNI and Window.alert(); in SmartGWT useful but too invasive in the debugging process. Especially avoid Window.alert(); as there is a Smartgwt class called Window that it collides with.

    The code below illustrates the learning process of integrating a third party (Carrot2 FoamTree) into smartgwt when you are unfamiliar. Practices will not be perfect in the code on the forum.

    Code:
    
    public class GFoamTree extends HTMLFlow {
    	private JavaScriptObject chart;
        private String localparentElement;
        private GFoamTree self;
        final private String deadbeef = "gfoamtree deadbeef";
        String thisclass;
        static int count=0;
        // Don't do this with smartgwt 
        //public static native void exportStaticMethod() /*-{
        //$wnd.gfoamtree_trigger =
        //   $entry(@my.package.foamtree.client.GFoamTree::gfoamtree_trigger(Ljava/lang/String;)(event));
     	// }-*/;
    	public GFoamTree(String elementId) {
    		// exportStaticMethod();
    		setElement(Document.get().createElement("div"));
    		setContents("<div id=\"foamtree\" style=\"width: 400; height: 400\">tree  here</div>");
    	
    		thisclass=	this.getID();
    
    		gfoamtree_trigger("");
    	}
    	
    
    	/*
    	public GFoamTree() {
    	setElement(Document.get().createElement("div"));
    	 setContents("<div id=\"foamtree\" style=\"width: 400; height: 400\">tree  here</div>");
    	}
    	public GFoamTree(Canvas canvaselementId) {
    		localparentElement = canvaselementId.getElement().getId();
    		setElement(Document.get().createElement("div"));
    		setContents("<div id=\"foamtree\" style=\"width: 400; height: 400\">tree  here</div>");
    	}
    	*/
    	public void setData(Record[] data, String labelProperty, String weightProperty) {
    		Map<String, Integer> items = new HashMap<String, Integer>();
    		JSONArray records = new JSONArray();
    		//labelProperty = "label";
    		for (int i = 0; i < data.length; i++) {
    			Record r = data[i];
    			int current = 0;
    			String label = r.getAttribute(labelProperty);
    			if (items.containsKey(label))
    				current = items.get(label);
    			SC.logWarn(r.getAttributeAsInt("docs")+" here ");
    		//	items.put(label, ++current);  changed 
    			items.put(label,r.getAttributeAsInt("docs"));
    		}
    		int i = 0;
    		for (Map.Entry<String, Integer> entry : items.entrySet()) {
    			JSONObject obj = new JSONObject();
    			obj.put("label", new JSONString(entry.getKey()));
    			 SC.logWarn(" there "+entry.getValue());
    			obj.put("weight", new JSONNumber(entry.getValue()));
    			records.set(i, obj);
    			i++;
    		}
    		
    		setChartData(records.getJavaScriptObject(), "foamtree",thisclass);
    	}
    	@Override
    	public String getInnerHTML() {
    		// TODO Auto-generated method stub
    		return super.getInnerHTML();
    	}
    	/*
    	@Override
    	public void setParentElement(Canvas parentElement)
    			throws IllegalStateException {
    		// TODO Auto-generated method stub
    		super.setParentElement(parentElement);
    		
    		
    	}
    	*/
    	public native void setChartData(JavaScriptObject records, String id,String thisclass) /*-{
    		  console.log(records);
    
    		  gfoamtree = $wnd.CarrotSearchFoamTree({
    		    // Identifier of the DOM element
    		    // into which to embed FoamTree
    		    'id': id,
    		 
    		    // Other options can be set during embedding
    		    // as well. Here we set the border width to 8
    		    //'borderWidth': 8,
    		 
    		    // Group selection listener
    		    onGroupSelectionChanged: function(info) {
    		    	// don't have this working yet
    		    	alert("fired"); 
    		    	/// $wnd.gfoamtree_trigger("this worked");
    		      //	debugger;
    		       // this.gfoamtree_trigger("group selection " + info.group);
    		        var returncode = @my.package.foamtree.client.GFoamTree::gfoamtree_trigger(Ljava/lang/String;)(info.group);
    		        alert("ended");
    		    		    },
    		    dataObject: { groups: records }
    		  });
    		  alert("hello in here");
    		  console.log("Foam Tree - set chart data completed"); 
    
    		
    
    	}-*/;
    
    	public static int gfoamtree_trigger(String event) {
    		// not there yet
    		Window.alert("DEADERBEEF"+"ER1");
    		if (count<1){
    		Window.alert("DEADERBEEF"+"ER2");
    		Logger.getLogger("Events").info("Event " + event + " triggered");
    		}
    		count++;
    		return count;
    	}
    }
    I don't apologize for the code as it is a learning process to select practices, but please don't assume forums have the correct practices. Advice should be given and corrected, as the correction improves the knowledge base (as in the wiki process). (notice that I call the static method with a count in the constructor so the javac optimization doesn't remove the code for gfoamtree_trigger(); as dead code. BTW: it should be count>0.

    Thanks. for reading ...
    Last edited by jlhoward1; 1 Nov 2013, 11:04.

    Leave a comment:


  • Isomorphic
    replied
    The advice in this thread should be ignored. This user was making attempts to work around a single bug, long since corrected. Just use the Charting examples in the Showcase as a starting point.

    Leave a comment:


  • stonebranch1
    replied
    Thanks for all the info and insight. Do you have a sample based upon 4.1 that a neophite could follow for using piecharts?

    Thank You Kindly.

    Leave a comment:


  • jlhoward1
    replied
    Project lessons learned. How to hover in a chart the easy way,

    Thank you for the fixes. I will reincorporate the fixes using 4.1 best practices and add a list grid, and repost a sample.

    So far I have learned a lot. For other readers ...

    1) In general, create a data value formatter. Don't try to use add a hover handler with mouseout and mouse move handlers for events to the hover. It's too much work. . Use ValueFormatters instead.

    Here I display a label and the number of docs, the the highlighting still works.

    Code:
    chart.setDataValueFormatter(new ValueFormatter(){
    			// TODO Auto-generated method stub
    		public String format(Object value){
    			if (chart.getNearestDrawnValue()!=null){
    			
    			Record record = chart.getNearestDrawnValue().getRecord();
    		
    			return  "" + record.getAttribute("label") + " " +  
                        "- " + record.getAttribute("docs") + "" +  
                     //
                        "";
    			}
    			else return value.toString(); // no record just return the value
    			
    		}
        	   
    	});
    BTW: I'd love a legend formatter, but ...
    2) Modify the above with settings to improve the design.
    3) There is a shocking difference in 4.1 to 4.0
    4) FacetValueMaps (especially if isomorphic implements return a getDrawnValues(fvm)[] are an excellent way to query the chart's current data and synchronize a grid to an interactive facetchart.

    Thanks .... 4.1

    Leave a comment:


  • Isomorphic
    replied
    Hello,
    We've fixed issues with Point.getX and Point.getY methods. So code below is correct and works fine now:
    Code:
    ClickHandler charthandler = new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                  Point chartcenterpoint = chart.getChartCenter();
                  int x = chartcenterpoint.getX();
                  int y = chartcenterpoint.getY();
                  SC.logWarn("radius: " + chart.getChartRadiusAsDouble() + " x: " + x + " y:" + y);
                  DrawnValue ndv = chart.getNearestDrawnValue();
                  SC.logWarn("ndv: " + ndv.getX() + " " + ndv.getY() + " " + ndv.getValueAsDouble());
                  SC.logWarn("r: " + ndv.getRecord().getAttributeAsStringArray("FilterIds").length);
              }        
    };
    Please pick up the next nightly or 4.0 build (dated Oct 15 or above) to get this fix.

    Regards
    Isomorphic Software

    Leave a comment:


  • jlhoward1
    replied
    Summary of challenges with FacetChart interactions

    Build of 9-30 Smartgwt 4.0
    So far... most of the API did not work as I would have expected or understood from the documents and examples.

    Using the api to get chart center point for a pie has not worked (returns a point of [undefined,undefined] in my code. The posted code shows that. get Radius only reliably works in the getNearestDrawnPoints. Based on this experience, the exposed api in the chart does not work.

    get nearest Drawn values () did not return multiple points in a pie chart.

    Accessing the sectors in the FacetChart by draw items (drawitem instanceof drawsector) did not work for me... Likely it's the PieSliceSector class that I can't access in the code. I have to add and remove facets from a FacetValueMap individually to access each sector iteratively.


    more coming...

    Leave a comment:


  • jlhoward1
    replied
    Getting all the drawn values - snippet.

    Iterating through a facetvalue map to get sectors. I only have one facet so I use facets[0], otherwise I should have an outer loop.

    Do not be tempted to get the draw items, Drawsector and PieSliceSector is not exposed to you in facetcharts.

    Snippet
    Code:
    FacetValueMap fvm = new FacetValueMap();
    for (int j=0;j<facets[0].getValues().length;j++) {
         fvm.addMapping(facets[0].getIdAsString(), facets[0].getValues()[j].getIdAsString());
    						
     Window.alert("start angles"+chart.getDrawnValue(fvm).getAttributeAsDouble("startAngle"));
    	fvm.removeMapping(facets[0].getIdAsString());
    }

    It seems I need to query each value with an add and remove of 1 facet and value in a map.
    Last edited by jlhoward1; 10 Oct 2013, 04:40.

    Leave a comment:


  • jlhoward1
    replied
    More facetchart experiences.

    It appears that that the getting a DrawSector centerpoint in the facet charts also does not return a centerpoint. I don't see a way around this without using the aforementioned Facetchart bodge.

    It appears that getNearestDrawnValues() only returns 1 value. There is no getDrawnValues() "to get all drawn values" to iterate through the pie chart sectors. I am creating a FacetValueMap from the facets and the facet values and iterating through the Map to get to the sectors.

    It's very inconvenient to not have getAttributes() method for DrawItems. This could be more consistent with other API items like Record getAttributes() and Chart.getNearestDrawnValues().getAttributes().

    I will try to avoid rotated DrawLabels. They don't draw cleanly compared to other fonts. I am going to try placing rotated HTML5 text (Labels) over the chart rather than blocky uneven fonts.

    Leave a comment:


  • jlhoward1
    replied
    interim sample of interactive chart showing attributes in the chart

    Illustrative example of the interactive pie.

    For any that need it.

    Code:
    /* 
     * Smart GWT (GWT for SmartClient) 
     * Copyright 2008 and beyond, Isomorphic Software, Inc. 
     * 
     * Smart GWT is free software; you can redistribute it and/or modify it 
     * under the terms of the GNU Lesser General Public License version 3 
     * as published by the Free Software Foundation.  Smart GWT is also 
     * available under typical commercial license terms - see 
     * http://smartclient.com/license 
     * 
     * This software is distributed in the hope that it will be useful, 
     * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
     * Lesser General Public License for more details. 
     */
    
    import java.util.HashMap;
    
    import gov.dtra.gkmc.shared.SimpleData;
    
    import com.smartgwt.client.data.AdvancedCriteria;
    //import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DSCallback;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DSResponse;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    //import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.RecordList;
    import com.smartgwt.client.widgets.chart.ChartDrawnEvent;
    import com.smartgwt.client.widgets.chart.ChartDrawnHandler;
    import com.smartgwt.client.widgets.chart.ChartPointClickEvent;
    import com.smartgwt.client.widgets.chart.ChartPointClickHandler;
    import com.smartgwt.client.widgets.chart.DrawnValue;
    //import com.smartgwt.client.data.ResultSet;
    //import com.smartgwt.client.data.DataSource.*;
    //import com.smartgwt.client.data.RestDataSource;
    //import com.smartgwt.client.data.XJSONDataSource;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.rpc.RPCManager;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.DSProtocol;
    import com.smartgwt.client.widgets.chart.FacetChart;
    import com.smartgwt.client.widgets.cube.Facet;
    import com.smartgwt.client.widgets.drawing.DrawSector;
    import com.smartgwt.client.widgets.drawing.Point;
    //import com.smartgwt.client.widgets.cube.Facet;
    import com.smartgwt.client.types.ChartType;
    //import com.smartgwt.client.types.ListGridFieldType;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.types.TreeModelType;
    //import com.smartgwt.client.util.JSOHelper;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.Hover;
    import com.smartgwt.client.widgets.Label;
    //import com.smartgwt.client.widgets.drawing.ColorStop;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ButtonItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    //import com.smartgwt.client.widgets.Window;
    //import com.smartgwt.client.widgets.grid.ListGrid;
    
    import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
    //import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.layout.VStack;
    import com.smartgwt.client.widgets.tab.Tab;
    import com.smartgwt.client.widgets.tab.TabSet;
    import com.smartgwt.client.widgets.tile.TileGrid;
    import com.smartgwt.client.widgets.tree.Tree;
    import com.smartgwt.client.widgets.tree.TreeGrid;
    import com.smartgwt.client.widgets.tree.TreeGridField;
    import com.smartgwt.client.widgets.tree.TreeNode;
    import com.smartgwt.client.widgets.tree.events.LeafClickEvent;
    import com.smartgwt.client.widgets.tree.events.LeafClickHandler;
    import com.smartgwt.logicalstructure.core.LogicalStructureObject;
    import com.google.gwt.core.client.EntryPoint;
    //import com.google.gwt.core.client.JavaScriptObject;
    //import com.google.gwt.core.client.JsArrayString;
    //import com.google.gwt.json.client.JSONObject;
    import com.google.gwt.user.client.Window;
    
    public class JsonXPathSample implements EntryPoint {
    
    	@Override
    	public void onModuleLoad() {
    
    		SimpleData ds;
    		final FacetChart chart = new FacetChart();
    		chart.setData(SimpleData.getData());
    		chart.setFacets(new Facet("Label", "Label"));
    		chart.setValueProperty("count");
    		chart.setChartType(ChartType.PIE);
    		chart.setStacked(true);
    		chart.setShowHover(true);
    
    		chart.setTitle("Sample");
    
    		com.smartgwt.client.widgets.events.ClickHandler charthandler = new com.smartgwt.client.widgets.events.ClickHandler() {
    			@Override
    			public void onClick(
    					com.smartgwt.client.widgets.events.ClickEvent event) {
    				// TODO Auto-generated method stub
    
    				Window.alert("Use chart.getNearestDrawnValue().getAttributeAsDouble(\"radius\") "
    						+ chart.getNearestDrawnValue().getAttributeAsDouble(
    								"radius"));
    
    				// try {
    
    				// }
    				// catch (UncaughtException e)
    				// {
    				// Window.alert(e.getMessage());
    
    				// };
    
    				double distance = Math.sqrt(Math.pow((chart
    						.getNearestDrawnValue().getX() - chart.getOffsetX()),
    						2.0)
    						+ Math.pow(
    								chart.getNearestDrawnValue().getY()
    										- chart.getOffsetY(), 2));
    
    				Window.alert(" use double distance = Math.sqrt(Math.pow((chart.getNearestDrawnValue().getX()-chart.getOffsetX()),2.0)+Math.pow(chart.getNearestDrawnValue().getY()-chart.getOffsetY(),2)); for distance "
    						+ distance
    						+ " and don't use chart.getChartRadiusAsDouble() "
    						+ chart.getChartRadiusAsDouble());
    				Window.alert("Use chart.getNearestDrawnValue().getAttributeAsDouble(\"radius\") "
    						+ chart.getNearestDrawnValue().getAttributeAsDouble(
    								"radius"));
    				// in the pie
    				// if (distance<chart.getChartRadius()) {
    				// DrawnValue dv = chart.getNearestDrawnValue().
    				// dv.getChartCenter();
    				if (distance < chart.getNearestDrawnValue()
    						.getAttributeAsDouble("radius")) {
    					Window.alert("in the Pie chart");
    
    					Window.alert("Choice = - x= "
    							+ chart.getNearestDrawnValue().getAttribute("x")
    							+ " y = "
    							+ chart.getNearestDrawnValue().getAttribute("y")
    							+ " "
    							+ chart.getNearestDrawnValue()
    									.getAttributeAsRecord("record")
    									.getAttribute("Label"));
    					for (int j = 0; j < chart.getNearestDrawnValue()
    							.getAttributes().length; j++) {
    						Window.alert("Choice = "
    								+ chart.getNearestDrawnValue().getAttributes()[j]);
    					}
    					/*
    					 * event. AdvancedCriteria adCriteria = new
    					 * AdvancedCriteria("_id", { OperatorId.IN_SET,
    					 * chart.getNearestDrawnValue
    					 * ().getAttributeAsRecord("record")
    					 * .getAttributeAsStringArray("FilterIds"));
    					 */
    					int len = chart.getNearestDrawnValue()
    							.getAttributeAsRecord("record")
    							.getAttributeAsStringArray("FilterIds").length;
    					for (int i = 0; i < len; i++) {
    						Window.alert("Choice = "
    								+ chart.getNearestDrawnValue()
    										.getAttributeAsRecord("record")
    										.getAttributeAsStringArray("FilterIds")[i]);
    					}
    
    					/* grid.setData(griddata.findAll(adCriteria)); */
    					// grid.redraw();
    					Window.alert("We finished and filtered the grid");
    					// } //outside the pie
    				}
    			}
    
    		};
    		final float chartradius;
    		VLayout layout = new VLayout(15);
    		layout.setWidth(450);
    		layout.setHeight(450);
    		layout.addMember(chart);
    
    		chart.addClickHandler(charthandler);
    	
    		chart.setWidth100();
    		chart.setHeight100();
    		layout.draw();
    
    	}
    }
    Simpledata.java
    Code:
    import java.util.Map;
    
    import com.google.gwt.core.client.JavaScriptObject;
    import com.smartgwt.client.data.Record;
    
    
    	//package com.smartgwt.sample.showcase.client.chart;  
    	  
    	import com.smartgwt.client.data.Record;  
    	  
    	public class SimpleData extends Record {  
    	  
    	    public SimpleData(int ct, String lbl, String [] filterids) {  
    	        setAttribute("count", ct);  
    	        setAttribute("Label", lbl);  
    	        setAttribute("FilterIds", filterids);  //detail filter ids.
    	    }  
    	 static String [] strarray = {"1","3"};  //  filters a list grid when pie section is selected
    	static  String [] strarray2 = {"2","6"};
    	  static String [] strarray3 = {"4","5","7"};
    	    public static SimpleData[] getData() {  
    	        return new SimpleData[] {  
    	            new SimpleData(10, "Cars",strarray),  
    	            new SimpleData(102, "Bikes",strarray2 ),
    	            new SimpleData(14, "Trukes",strarray3 )
    	        };  
    	    }  
    	  
    	}

    Leave a comment:


  • jlhoward1
    replied
    I have a workaround using the attributes for FACETCHART.

    Originally posted by Isomorphic View Post
    getNearestDrawnValue gives the information for the sector, which makes it easy to test if the sector was actually hit.

    We'll check on the report of getChartRadius()/Center() not working - again it ses to work fine in samples but perhaps something is slightly different in your test case.
    Thanks...

    Incorrect result - chart.getChartRadius() returned 165 here.

    Correct result is chart.getNearestDrawnValue().getAttributeAsDouble("radius") returned 188.8 (So I use the second value.) There is no "getNearestDrawnValue.getRadius()".


    Unexpectedly event.getX() is not correct for a chart. I needed the chart.getNearestDrawnValue().getX() to get the pie center point X and that chart.getOffsetX()) was the correct X value for click event in a chart (not event.getX()).

    The formula I needed is correctly WITHIN the event handler...
    double distance = Math.sqrt(Math.pow((chart.getNearestDrawnValue().getX()-chart.getOffsetX()),2.0)+Math.pow(chart.getNearestDrawnValue().getY()-chart.getOffsetY(),2.0));

    chart.getNearestDrawnValue().getX() and .getY() gets the correct location of the pie center not chart.getChartCenter().

    chart.getChartCenter() returned a Point of [null,null].


    In general, IMHO developers should not depend on the API for charts, but use the getNearestDrawnValue().getAttributes() to find the available types of values.

    Coding this was extremely unclear to me.

    I will upload an updated version with a listgrid filtered by selecting PIE elements. It's a useful sample and something I think I number of developers do need.

    I do not need more support.

    Leave a comment:


  • Isomorphic
    replied
    getNearestDrawnValue gives the information for the sector, which makes it easy to test if the sector was actually hit.

    We'll check on the report of getChartRadius()/Center() not working - again it ses to work fine in samples but perhaps something is slightly different in your test case.

    Leave a comment:

Working...
X