Пример #1
0
        protected override IEnumerator ProcessPayload(VisualPayload payload)
        {
            payload.VisualData.Bound.name = "Line Graph Bound";

            var lineGraph = VisualizerFactory.InstantiateLineGraph();

            lineGraph.Initialize(this, payload);

            AssignStates(lineGraph);

            var entries = EntryField.GetLastKeyValue(payload.Data) as IEnumerable <MutableObject>;

            if (entries == null)
            {
                throw new Exception("Illegal mutable field here!  " + EntryField.AbsoluteKey + " is not an enumerable of mutables!");
            }

            if (!entries.Any())
            {
                yield return(null);

                yield break;
            }

            foreach (var entry in entries)
            {
                Vector3 entryPosition =
                    new Vector3(
                        XAxis.GetLastKeyValue(entry),
                        YAxis.GetLastKeyValue(entry),
                        ZAxis.GetLastKeyValue(entry)
                        );

                Color pointColor = PointColor.GetLastKeyValue(entry);

                lineGraph.AddPoint(entryPosition, pointColor);

                yield return(null);
            }

            yield return(null);

            lineGraph.SetLineData(MainColor.GetLastKeyValue(payload.Data),
                                  LineWidth.GetLastKeyValue(payload.Data),
                                  ZDepthOffset.GetLastKeyValue(payload.Data),
                                  EdgeColor.GetLastKeyValue(payload.Data),
                                  EdgeWidth.GetLastKeyValue(payload.Data),
                                  PointWidth.GetLastKeyValue(payload.Data),
                                  PulseLine.GetLastKeyValue(payload.Data),
                                  PulseWidth.GetLastKeyValue(payload.Data),
                                  Wipe.GetLastKeyValue(payload.Data),
                                  StartTime.GetLastKeyValue(payload.Data),
                                  WipeDuration.GetLastKeyValue(payload.Data)
                                  );

            lineGraph.ApplyPoints();
        }
        protected override MutableObject Mutate(MutableObject mutable)
        {
            var frequencies = ByteHistogram.GetFirstValue(mutable);

            var saturation = Saturation.GetFirstValue(mutable);
            var value      = Value.GetFirstValue(mutable);

            var frequencyBands = new List <FrequencyBand>();

            var totalSize = (float)frequencies.Sum(f => f);

            var currentPosition = 0f;
            int i = 0;

            foreach (var frequency in frequencies)
            {
                frequencyBands.Add(new FrequencyBand
                {
                    Byte      = i++,
                    Color     = ColorUtility.HsvtoRgb(currentPosition / totalSize, saturation, value),
                    Start     = currentPosition / totalSize,
                    End       = (currentPosition + frequency) / totalSize,
                    Frequency = frequency
                });
                currentPosition = currentPosition + frequency;
            }

            frequencyBands.Sort((a, b) => 0 - a.Frequency.CompareTo(b.Frequency));

            var smoothGradient       = SmoothGradient.GetFirstValue(mutable);
            var numberOfPoints       = Keypoints.GetFirstValue(mutable);
            var edgeWidth            = EdgeWidth.GetFirstValue(mutable);
            var primaryColor         = PrimaryColor.GetFirstValue(mutable);
            var primaryImpactOnBands = PrimaryImpactOnBands.GetFirstValue(mutable);

            var newGradient = new ColorGradient(numberOfPoints * (smoothGradient?1:2));

            frequencyBands = frequencyBands.Take(numberOfPoints).OrderBy(f => f.Start).ToList();

            if (smoothGradient)
            {
                for (var k = 0; k < Mathf.Min(numberOfPoints, frequencyBands.Count); k++)
                {
                    {
                        newGradient.AddColorKey(new GradientColorKey(
                                                    frequencyBands[k].Color,
                                                    (frequencyBands[k].Start + frequencyBands[k].End) / 2f));
                    }
                }
            }
            else
            {
                for (var k = 1; k < Mathf.Min(numberOfPoints, frequencyBands.Count); k++)
                {
                    var k1 = frequencyBands[k - 1].Color;
                    newGradient.AddColorKey(new GradientColorKey(
                                                Color.Lerp(frequencyBands[k - 1].Color,
                                                           primaryColor, primaryImpactOnBands),
                                                frequencyBands[k - 1].Start + edgeWidth / 2f));

                    var k2 = frequencyBands[k - 1].Color;
                    newGradient.AddColorKey(new GradientColorKey(
                                                Color.Lerp(frequencyBands[k - 1].Color,
                                                           primaryColor, primaryImpactOnBands),
                                                frequencyBands[k].Start - edgeWidth / 2f));

                    if (k1 != k2)
                    {
                        throw new Exception("What?  How are these colors not matched?");
                    }
                }
            }


            HistogramGradient.SetValue(newGradient, mutable);

            return(mutable);
        }
Пример #3
0
 public void AcceptAttributeEdgeWidth(EdgeWidth edgeWidth, PrintContext parameter)
 {
     parameter.WriteLine("Edge Width: {0}", edgeWidth.Width);
 }
Пример #4
0
 public virtual void AcceptAttributeEdgeWidth(EdgeWidth edgeWidth, T parameter)
 {
     // intentionally left blank
 }