Whenever you call the draw method of the chart, the selection is cleared, so if you want to save the selected state, you have to save it in a javascript variable and then call the chart's #setSelection method. That should clear up the first part. As far as your other problems go, I need to see a functional demo (either full source code, or a link to the page, or a jsfiddle, whatever works for you) that demonstrates the problem in context so I can see what is going on.
On Monday, July 29, 2013 2:17:33 PM UTC-4, [email protected] wrote: > > I'm attempting to adapt Google's organization chart library to aid in the > construction of a decision tree question workflow. > > The tree creation workflow is > > 1. Select "Create New Tree button", root node of tree is created > 2. User inserts question text > * Text is added to selected node via `setFormattedText()` > 3. User adds possible answers to question, which are added as child nodes > of selected node. > > and so on until the tree is complete. > > My issue is only one child node can be added to the root node before the > current selection object changes to undefined. > > var orgChart, nodeCount; > > var data, selection, selectionHandler; > var questionArray = []; > var answerText = ""; > > var question = { > questionText : "", > answers : [], > > clear : function(){ > this.questionText = ""; > this.answers = []; > } > } > > The drawFunction initializes the chart. Each selection event is saved in > a temporary variable, which is used to extract out the row/column > information as well as other bits and pieces. > > function drawChart() { > orgChart = new > google.visualization.OrgChart(document.getElementById("chart")); > data = new google.visualization.DataTable(); > data.addColumn("string", "question"); > data.addColumn("string", "parentQuestion"); > data.addColumn("string", "tooltip"); > > function selectHandler(){ > selection = orgChart.getSelection()[0] > var value = data.getValue(selection.row, 0); > console.log("Selected Value: " + value); > populateData(value); > $("#question_text_input").trigger("focus"); > > } > > selectionHandler = google.visualization.events.addListener(orgChart, > "select", selectHandler); > orgChart.draw(data, {allowHtml : true, allowCollapse : true}); > } > > My save handlers are > > function saveQuestionHandler(){ > > questionArray.push(question); > data.setFormattedValue(selection.row, 0, question.questionText); > orgChart.draw(data, {allowHtml : true, allowCollapse : true}); > } > > function saveAnswerHandler(){ > question.answers.push(answerText); > nodeCount++; > > $("#answers").append("<li id = " + nodeCount +"_" + > question.answers.length + " class = 'answer' >" + > wiky.process(answerText) + "</li>"); > > var count = data.addRow([{v : toString(nodeCount), f : > answerText}, data.getValue(selection.row, 0), null]); > orgChart.draw(data, {allowHtml : true, allowCollapse : true}); > > > console.log("currentNode: " + nodeCount + "\nparentNode: " + > data.getValue(selection.row, 0) + > "Insertion Count " + count); > } > > This code works for a single addition to the root node, but fails > otherwise. > > Now, there are two issues with the results. First, the > `saveAnswerHandler` is indeed firing, since the `append()` method is adding > a new list item to the unordered list, but the `draw()` method is not > responding to the new entries. > > Second issue is if I click on the newly created child node, I get a > `Selected Value : [Object Undefined]` entry. > > Any help is appreciated. > -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-visualization-api. For more options, visit https://groups.google.com/groups/opt_out.
