// PUBLIC
        public void CreateVisualisation(AbstractVisualisation.VisualisationTypes visualizationType)
        {
            //destroy the previous visualisations
            AbstractVisualisation[] previousVisualizations = GetComponentsInChildren<AbstractVisualisation>();

            foreach (var item in previousVisualizations)
            {
                item.destroyView();
                DestroyImmediate(item);
            }

            //destroy the previous axes
            Axis[] previousAxes = GetComponentsInChildren<Axis>();

            foreach (var item in previousAxes)
            {
                DestroyImmediate(item.gameObject);
            }

            //destroy previous key
            if(key!=null)
            DestroyImmediate(key.gameObject);

            visualisationType = visualizationType;

            switch (visualisationType)
            {
                case AbstractVisualisation.VisualisationTypes.SCATTERPLOT:
                    theVisualizationObject = gameObject.AddComponent<ScatterplotVisualisation>();// new Simple2D3DVisualisation();                    
                    theVisualizationObject.visualisationReference = this;

                    theVisualizationObject.CreateVisualisation();
                    break;
                case AbstractVisualisation.VisualisationTypes.SCATTERPLOT_MATRIX:
        
                    int dimensionCount = dataSource.DimensionCount;
                    if (dimensionCount > MAX_INIT_SCATTERPLOTMATRIX) dimensionCount = MAX_INIT_SCATTERPLOTMATRIX;

                    xScatterplotMatrixDimensions = new DimensionFilter[dimensionCount];
                    yScatterplotMatrixDimensions = new DimensionFilter[dimensionCount];

                    for (int i = 0; i < dimensionCount; i++)
                    {
                        xScatterplotMatrixDimensions[i] = new DimensionFilter { Attribute = dataSource[i].Identifier };
                        yScatterplotMatrixDimensions[i] = new DimensionFilter { Attribute = dataSource[i].Identifier };
                    }

                    theVisualizationObject = gameObject.AddComponent<ScatterplotMatrixVisualisation>();// new Simple2D3DVisualisation();                    
                    theVisualizationObject.visualisationReference = this;

                    theVisualizationObject.CreateVisualisation();
                    break;
                case AbstractVisualisation.VisualisationTypes.PARALLEL_COORDINATES:
                    parallelCoordinatesDimensions = new DimensionFilter[dataSource.DimensionCount];

                    for (int i = 0; i < dataSource.DimensionCount; i++)
                    {
                        parallelCoordinatesDimensions[i] = new DimensionFilter { Attribute = dataSource[i].Identifier };
                    }
                    theVisualizationObject = gameObject.AddComponent<ParallelCoordinatesVisualisation>();// new ParrallelCoordinates();
                    
                    theVisualizationObject.visualisationReference = this;
                    theVisualizationObject.UpdateVisualisation(AbstractVisualisation.PropertyType.DimensionChange);

                    theVisualizationObject.CreateVisualisation();


                    break;
                case AbstractVisualisation.VisualisationTypes.GRAPH_LAYOUT:
                    break;
                default:
                    break;
            }

            theVisualizationObject.UpdateVisualisation(AbstractVisualisation.PropertyType.None);

            RuntimeEditorLoadAndSaveConfiguration();

            key = (GameObject)Instantiate(Resources.Load("Key"));
            key.transform.parent = transform;
            key.transform.localPosition = new Vector3(-1f, 1f, 0f);
        }
Esempio n. 2
0
        void RuntimeEditorLoadAndSaveConfiguration()
        {
            // get the pre existing views in the hierarchy
            View[] views = GetComponentsInChildren<View>();

            // clear the reference list of views
            theVisualizationObject.viewList.Clear();

            // create the new view reference list
            foreach (var view in views)
            {
                view.BigMesh = GetComponentInChildren<BigMesh>();
                view.onViewChangeEvent += updateView;   // Receive notifications when the view configuration changes
                theVisualizationObject.viewList.Add(view);
            }
            
            // bind the axes objects by the name of the property in the children hierarchy
            foreach (Transform child in transform)
            {
                AbstractVisualisation.PropertyType pt;
                try
                {
                    pt = (AbstractVisualisation.PropertyType)System.Enum.Parse(typeof(AbstractVisualisation.PropertyType), child.gameObject.name);
                    switch (pt)
                    {
                        case AbstractVisualisation.PropertyType.X:
                            theVisualizationObject.X_AXIS = child.gameObject;
                            break;
                        case AbstractVisualisation.PropertyType.Y:
                            theVisualizationObject.Y_AXIS = child.gameObject;
                            break;
                        case AbstractVisualisation.PropertyType.Z:
                            theVisualizationObject.Z_AXIS = child.gameObject;
                            break;
                        default:
                            break;
                    }
                }
                catch
                {
                    //handle parsing property errors here
                }
            }

            // load serialized view configuration from disk
#if UNITY_EDITOR
            //if(!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                if (File.Exists(ConfigurationFileName()))
                {
                    if (theVisualizationObject.creationConfiguration == null) theVisualizationObject.creationConfiguration = new CreationConfiguration();
                    if (!dataSource.IsLoaded) dataSource.load();

                    theVisualizationObject.creationConfiguration.Deserialize(ConfigurationFileName());
                    theVisualizationObject.creationConfiguration.disableWriting = true;

                    visualisationType = theVisualizationObject.creationConfiguration.VisualisationType;                  

                    switch (visualisationType)
                    {
                        case AbstractVisualisation.VisualisationTypes.SCATTERPLOT:
                            if (theVisualizationObject.creationConfiguration.Axies.ContainsKey(CreationConfiguration.Axis.X)) xDimension.Attribute = theVisualizationObject.creationConfiguration.Axies[CreationConfiguration.Axis.X];
                            if (theVisualizationObject.creationConfiguration.Axies.ContainsKey(CreationConfiguration.Axis.Y)) yDimension.Attribute = theVisualizationObject.creationConfiguration.Axies[CreationConfiguration.Axis.Y];
                            if (theVisualizationObject.creationConfiguration.Axies.ContainsKey(CreationConfiguration.Axis.Z)) zDimension.Attribute = theVisualizationObject.creationConfiguration.Axies[CreationConfiguration.Axis.Z];

                            linkingDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.LinkingDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.LinkingDimension;
                            geometry = theVisualizationObject.creationConfiguration.Geometry;
                            minSize = theVisualizationObject.creationConfiguration.MinSize;
                            maxSize = theVisualizationObject.creationConfiguration.MaxSize;

                            theVisualizationObject.CreateVisualisation();
                            
                            updateViewProperties(AbstractVisualisation.PropertyType.SizeValues);
                            updateViewProperties(AbstractVisualisation.PropertyType.X);
                            updateViewProperties(AbstractVisualisation.PropertyType.Y);
                            updateViewProperties(AbstractVisualisation.PropertyType.Z);
                            updateViewProperties(AbstractVisualisation.PropertyType.GeometryType);
                            updateViewProperties(AbstractVisualisation.PropertyType.LinkingDimension);

                            colourDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.ColourDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.ColourDimension;
                            sizeDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.SizeDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.SizeDimension;
                            dimensionColour = theVisualizationObject.creationConfiguration.colourKeys;
                            colour = theVisualizationObject.creationConfiguration.colour;

                            updateViewProperties(AbstractVisualisation.PropertyType.Size);
                            updateViewProperties(AbstractVisualisation.PropertyType.Colour);

                            break;
                        case AbstractVisualisation.VisualisationTypes.SCATTERPLOT_MATRIX:

                            linkingDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.LinkingDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.LinkingDimension;
                            geometry = theVisualizationObject.creationConfiguration.Geometry;
                            minSize = theVisualizationObject.creationConfiguration.MinSize;
                            maxSize = theVisualizationObject.creationConfiguration.MaxSize;

                            theVisualizationObject.CreateVisualisation();

                            updateViewProperties(AbstractVisualisation.PropertyType.SizeValues);
                            updateViewProperties(AbstractVisualisation.PropertyType.X);
                            updateViewProperties(AbstractVisualisation.PropertyType.Y);
                            updateViewProperties(AbstractVisualisation.PropertyType.Z);
                            updateViewProperties(AbstractVisualisation.PropertyType.GeometryType);
                            updateViewProperties(AbstractVisualisation.PropertyType.LinkingDimension);
                            theVisualizationObject.creationConfiguration.Deserialize(ConfigurationFileName());
                            colourDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.ColourDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.ColourDimension;
                            sizeDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.SizeDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.SizeDimension;
                            dimensionColour = theVisualizationObject.creationConfiguration.colourKeys;
                            colour = theVisualizationObject.creationConfiguration.colour;

                            updateViewProperties(AbstractVisualisation.PropertyType.Size);
                            updateViewProperties(AbstractVisualisation.PropertyType.Colour);


                            break;
                        case AbstractVisualisation.VisualisationTypes.PARALLEL_COORDINATES:
                            parallelCoordinatesDimensions = theVisualizationObject.creationConfiguration.parallelCoordinatesDimensions;
                            updateViewProperties(AbstractVisualisation.PropertyType.DimensionChange);
                            size = theVisualizationObject.creationConfiguration.Size;
                            minSize = theVisualizationObject.creationConfiguration.MinSize;
                            maxSize = theVisualizationObject.creationConfiguration.MaxSize;
                            updateViewProperties(AbstractVisualisation.PropertyType.SizeValues);
                            // TEMP_FIX:
                            // Issue: for some reason after updateViewProperties(PropertyType.DimensionChange) call
                            // the creationConfiguration object is overwritten and some properties take old values
                            // the temp fix is to deserialize again to read the correct values again. I suspect this
                            // is because the script is using an old pre-runtime reference.
                            theVisualizationObject.creationConfiguration.Deserialize(ConfigurationFileName());
                            colourDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.ColourDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.ColourDimension;
                            sizeDimension = string.IsNullOrEmpty(theVisualizationObject.creationConfiguration.SizeDimension) ? "Undefined" : theVisualizationObject.creationConfiguration.SizeDimension;
                            dimensionColour = theVisualizationObject.creationConfiguration.colourKeys;
                            colour = theVisualizationObject.creationConfiguration.colour;

                            updateViewProperties(AbstractVisualisation.PropertyType.Size);
                            updateViewProperties(AbstractVisualisation.PropertyType.Colour);

                            break;
                        case AbstractVisualisation.VisualisationTypes.GRAPH_LAYOUT:
                            break;
                        default:
                            break;
                    }

                   
                    theVisualizationObject.creationConfiguration.disableWriting = false;
                }
            }
#endif
        }