Ejemplo n.º 1
0
        protected void ProcessTypeCollection()
        {
            foreach (SemanticTypeInstance typeInstance in Program.SemanticTypeSystem.Instances.Values)
            {
                ISemanticType instance = typeInstance.Instance;
                string        name     = typeInstance.Name;

                if (!ignoreNames.Contains(name))
                {
                    // A distinct type name, used for coloration logic.
                    distinctTypes.AddIfUnique(name);

                    // Also, for each type, we have a specific location to group all instances of that type.
                    if (!typeGroups.ContainsKey(name))
                    {
                        typeGroups[name] = new TypeGroup();
                        AdjustGroupLocations();
                        ResetAllTargets();
                    }

                    VisualSemanticType vst = new VisualSemanticType(instance, name);
                    vtypes.Add(vst);                                    // Only the collections go in this space.

                    // Add all the collection elements.
                    if (name == "PopulationByStateByYear")
                    {
                        // This is a collection.
                        List <ISemanticType> stList = (List <ISemanticType>)((dynamic)vst.SemanticType).Collection.Items;
                        int items = stList.Count;

                        stList.ForEachWithIndex((st, idx2) =>
                        {
                            // Create the collection types.  This is for every item in the collection, so many will be repeated (like year and state)
                            string subname = Program.SemanticTypeSystem.GetSemanticTypeName(st);
                            distinctTypes.AddIfUnique(subname);
                            VisualSemanticType vst2  = new VisualSemanticType(st, subname);
                            CollectionSubtype cs     = new CollectionSubtype(instance, st);
                            typeVisualizationMap[cs] = vst2;
                            // vtypes.Add(vst2);
                        });
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected bool Step()
        {
            bool more = true;

            //  TODO: These 4 lines are duplicate code.  Refactor into a SizeChanged event handler.
            int hw = Visualizer.ClientRectangle.Width / 2;
            int hh = Visualizer.ClientRectangle.Height / 2;
            int n  = (hw < hh ? hw : hh);
            int m  = (n / 5);                                                   // the radius of the group's circle.

            vtypes.ForEachWithIndex((vtype, idx) =>
            {
                more = false;                   // points to plot
                if (vtype.StepNumber == 0)
                {
                    // Initialize the starting location if it's a new entry.

                    //if (targetState == false)
                    //{
                    //	// RANDOM POINT IN SPACE
                    //	vtype.TargetLocation = new Point(rnd.Next(-hw, hw), rnd.Next(-hh, hh));
                    //}
                    //else
                    {
                        if (vtype.Name == "PopulationByStateByYear")
                        {
                            // This is a collection.
                            List <ISemanticType> stList = (List <ISemanticType>)((dynamic)vtype.SemanticType).Collection.Items;
                            int items = stList.Count;

                            if (targetState == false)
                            {
                                // The collection goes somewhere random.
                                vtype.TargetLocation = new Point(rnd.Next(-hw, hw), rnd.Next(-hh, hh));
                            }

                            stList.ForEachWithIndex((st, idx2) =>
                            {
                                if (targetState == false)
                                {
                                    // Set an initial random point for the item in the collection.
                                    CollectionSubtype cs = new CollectionSubtype(vtype.SemanticType, st);
                                    typeVisualizationMap[cs].TargetLocation = new Point(rnd.Next(-hw, hw), rnd.Next(-hh, hh));
                                }
                                else
                                {
                                    // Draw each type on the edge of a small circle surrounding the collection type.
                                    Point p         = vtype.TargetLocation;
                                    Point pOnCircle = GetPointOnCircle(10, idx2, items);
                                    p.Offset(pOnCircle);
                                    // p.Offset(hw, hh);										// translate to LL corner at (0, 0)
                                    // p.Offset(-20, -20);			// UL of the circle offset.
                                    CollectionSubtype cs = new CollectionSubtype(vtype.SemanticType, st);
                                    typeVisualizationMap[cs].TargetLocation = p;
                                }
                            });
                        }
                    }


                    // RANDOM POINT WITHIN A LOCAL GROUP:

                    /*
                     * Point groupPoint = typeGroups[vtype.Name].Location;
                     * // We can figure out a random target within a circle centered here.
                     * double randomAngle = rnd.NextDouble() * 3.14159265 * 2;
                     * Point p = new Point((int)(rnd.Next(-m, m) * Math.Cos(randomAngle)), (int)(rnd.Next(-m, m) * Math.Sin(randomAngle)));
                     * // Center on the group point.
                     * p.Offset(groupPoint);
                     * vtype.TargetLocation = p;
                     */

                    // RANDOM POINT ON A CIRCLE.

                    /*
                     * int l = n - n / 6;
                     * l = (int)(l * (((idx % 3) + 1) / 3.0));		// split each radial into 3 locations along the radial.
                     * double angle = 3.14159265 * 2 * idx / vtypes.Count;
                     * Point p = new Point((int)(l * Math.Cos(angle)), (int)(l * Math.Sin(angle)));
                     * p.Offset(-20, -20);
                     * vtype.TargetLocation = p;
                     */
                }

                if (vtype.StepNumber < RenderTime)
                {
                    more = true;
                    ++vtype.StepNumber;
                    // A quasi acceleration curve:
                    double stepper = Math.Sin(((3.14159265 / 2.0) * ((double)vtype.StepNumber) / (double)RenderTime));

                    // This is the collection.
                    vtype.Location = new Point((int)(vtype.StartLocation.X + (vtype.TargetLocation.X - vtype.StartLocation.X) * stepper), ((int)(vtype.StartLocation.Y + (vtype.TargetLocation.Y - vtype.StartLocation.Y) * stepper)));

                    // These are the collection items.
                    List <ISemanticType> stList = (List <ISemanticType>)((dynamic)vtype.SemanticType).Collection.Items;
                    int items = stList.Count;
                    stList.ForEach((st) =>
                    {
                        CollectionSubtype cs   = new CollectionSubtype(vtype.SemanticType, st);
                        VisualSemanticType vst = typeVisualizationMap[cs];
                        vst.Location           = new Point((int)(vst.StartLocation.X + (vst.TargetLocation.X - vst.StartLocation.X) * stepper), ((int)(vst.StartLocation.Y + (vst.TargetLocation.Y - vst.StartLocation.Y) * stepper)));
                    });
                }
            });

            return(more);
        }
Ejemplo n.º 3
0
        protected void ProcessTypeCollection()
        {
            foreach (SemanticTypeInstance typeInstance in Program.SemanticTypeSystem.Instances.Values)
            {
                ISemanticType instance = typeInstance.Instance;
                string name = typeInstance.Name;

                if (!ignoreNames.Contains(name))
                {
                    // A distinct type name, used for coloration logic.
                    distinctTypes.AddIfUnique(name);

                    // Also, for each type, we have a specific location to group all instances of that type.
                    if (!typeGroups.ContainsKey(name))
                    {
                        typeGroups[name] = new TypeGroup();
                        AdjustGroupLocations();
                        ResetAllTargets();
                    }

                    VisualSemanticType vst = new VisualSemanticType(instance, name);
                    vtypes.Add(vst);		// Only the collections go in this space.

                    // Add all the collection elements.
                    if (name == "PopulationByStateByYear")
                    {
                        // This is a collection.
                        List<ISemanticType> stList = (List<ISemanticType>)((dynamic)vst.SemanticType).Collection.Items;
                        int items = stList.Count;

                        stList.ForEachWithIndex((st, idx2) =>
                        {
                            // Create the collection types.  This is for every item in the collection, so many will be repeated (like year and state)
                            string subname = Program.SemanticTypeSystem.GetSemanticTypeName(st);
                            distinctTypes.AddIfUnique(subname);
                            VisualSemanticType vst2 = new VisualSemanticType(st, subname);
                            CollectionSubtype cs = new CollectionSubtype(instance, st);
                            typeVisualizationMap[cs] = vst2;
                            // vtypes.Add(vst2);
                        });
                    }
                }
            }
        }