public void EnableLegendToggleFilter(GameObject legendGameObject) { HoloToolkit.Examples.InteractiveElements.InteractiveSet checkBoxSet = legendGameObject.GetComponent <HoloToolkit.Examples.InteractiveElements.InteractiveSet>(); if (checkBoxSet == null) { return; } checkBoxSet.SelectedIndices.Clear(); string fieldName = ""; List <string> domain = new List <string>(); // Go through each checkbox and set them to active: int checkBoxIndex = 0; for (int i = 0; i < legendGameObject.transform.childCount; i++) { Transform child = legendGameObject.transform.GetChild(i); if (child.GetComponent <LegendValue>() != null) { fieldName = child.GetComponent <LegendValue>().dataFieldName; domain.Add(child.GetComponent <LegendValue>().categoryName); Transform box = child.Find("Title/CheckBox"); if (box != null) { box.gameObject.SetActive(true); HoloToolkit.Examples.InteractiveElements.InteractiveToggle toggle = box.gameObject.GetComponent <HoloToolkit.Examples.InteractiveElements.InteractiveToggle>(); if (toggle != null) { checkBoxSet.Interactives.Add(toggle); checkBoxSet.SelectedIndices.Add(checkBoxIndex); checkBoxIndex++; } } } } // Add the call back function to update marks visibility when any checkbox is updated. checkBoxSet.OnSelectionEvents.AddListener(LegendToggleFilterUpdated); domains.Add(fieldName, domain); // Update the results vector int numMarks = targetVis.markInstances.Count; List <bool> results = new List <bool>(new bool[numMarks]); for (int j = 0; j < results.Count; j++) { results[j] = true; } filterResults.Add(fieldName, results); }
private void UpdateFilterResultsForCategory(string field, string category) { GameObject toggleFilter = gameObject.transform.Find(field).gameObject; if (toggleFilter == null) { return; } HoloToolkit.Examples.InteractiveElements.InteractiveSet checkBoxSet = toggleFilter.GetComponent <HoloToolkit.Examples.InteractiveElements.InteractiveSet>(); if (checkBoxSet == null) { return; } List <string> visibleCategories = new List <string>(); foreach (int checkedCategoryIndex in checkBoxSet.SelectedIndices) { visibleCategories.Add(domains[field][checkedCategoryIndex]); Debug.Log("showing index: " + checkedCategoryIndex.ToString() + (domains[field][checkedCategoryIndex])); } Debug.Log("Updating filter results for field, category " + field + ", " + category); List <bool> res = filterResults[field]; for (int b = 0; b < res.Count; b++) { if (visibleCategories.Contains(targetVis.markInstances[b].GetComponent <Mark>().datum[field])) { res[b] = true; } else { res[b] = false; } } filterResults[field] = res; if (targetVis.GetIsLinked()) { for (int i = 0; i < DxRVisObjects.Length; i++) { if (DxRVisObjects[i].GetComponent <Vis>().GetIsLinked()) { if (DxRVisObjects[i].GetComponent <Vis>().GetDataName() == targetVis.GetDataName()) { GameObject DxRInteraction = DxRVisObjects[i].transform.Find("DxRInteractions").gameObject; List <bool> t_res = new List <bool>(new bool[res.Count]); if (!DxRInteraction.GetComponent <Interactions>().filterResults.ContainsKey(field)) { DxRInteraction.GetComponent <Interactions>().filterResults.Add(field, t_res); } for (int b = 0; b < t_res.Count; b++) { if (visibleCategories.Contains(DxRVisObjects[i].GetComponent <Vis>().markInstances[b].GetComponent <Mark>().datum[field])) { t_res[b] = true; } else { t_res[b] = false; } } DxRInteraction.GetComponent <Interactions>().filterResults[field] = t_res; DxRVisObjects[i].GetComponent <Vis>().FiltersUpdated(); } } } } // if (targetVis.GetIsLinked()) Synchronize(field); }
internal void AddToggleFilter(JSONObject interactionSpecs) { /* * if (gameObject.transform.Find(interactionSpecs["field"].Value) != null) * { * Debug.Log("Will not duplicate existing filter for field " + interactionSpecs["field"].Value); * return; * } */ GameObject toggleFilterPrefab = Resources.Load("GUI/ToggleFilter", typeof(GameObject)) as GameObject; if (toggleFilterPrefab == null) { return; } GameObject toggleFilterInstance = Instantiate(toggleFilterPrefab, gameObject.transform); toggleFilterInstance.transform.Find("ToggleFilterLabel").gameObject.GetComponent <TextMesh>().text = interactionSpecs["field"].Value + ":"; toggleFilterInstance.name = interactionSpecs["field"]; HoloToolkit.Unity.Collections.ObjectCollection collection = toggleFilterInstance.GetComponent <HoloToolkit.Unity.Collections.ObjectCollection>(); if (collection == null) { return; } // Use the provided domain of the data field to create check boxes. // For each checkbox, add it to the interactiveset object, and add it to the object // collection object and update the layout. GameObject checkBoxPrefab = Resources.Load("GUI/CheckBox", typeof(GameObject)) as GameObject; if (checkBoxPrefab == null) { return; } HoloToolkit.Examples.InteractiveElements.InteractiveSet checkBoxSet = toggleFilterInstance.GetComponent <HoloToolkit.Examples.InteractiveElements.InteractiveSet>(); if (checkBoxSet == null) { return; } List <string> domain = new List <string>(); checkBoxSet.SelectedIndices.Clear(); int i = 0; foreach (JSONNode category in interactionSpecs["domain"].AsArray) { GameObject checkBoxInstance = Instantiate(checkBoxPrefab, toggleFilterInstance.transform); Debug.Log("Creating toggle button for " + category.Value); checkBoxInstance.transform.Find("CheckBoxOutline/Label").gameObject.GetComponent <TextMesh>().text = category.Value; domain.Add(category.Value); checkBoxSet.Interactives.Add(checkBoxInstance.GetComponent <HoloToolkit.Examples.InteractiveElements.InteractiveToggle>()); checkBoxSet.SelectedIndices.Add(i); i++; } domains.Add(interactionSpecs["field"].Value, domain); int numRows = interactionSpecs["domain"].AsArray.Count + 1; collection.Rows = numRows; collection.UpdateCollection(); // Add the call back function to update marks visibility when any checkbox is updated. checkBoxSet.OnSelectionEvents.AddListener(ToggleFilterUpdated); // Update the results vector int numMarks = targetVis.markInstances.Count; List <bool> results = new List <bool>(new bool[numMarks]); for (int j = 0; j < results.Count; j++) { results[j] = true; } filterResults.Add(interactionSpecs["field"], results); toggleFilterInstance.transform.Translate(0, -curYOffset / 2.0f, 0); curYOffset = curYOffset + (0.085f * numRows) + 0.1f; }