Example #1
0
 public Result <Color> Process(PositionedElement element)
 {
     return(Result.Of(() => Color.FromArgb(
                          random.Next(MaxChannelValue),
                          random.Next(MaxChannelValue),
                          random.Next(MaxChannelValue))));
 }
Example #2
0
 public VisualElement(
     PositionedElement element,
     Font font,
     Color color)
 {
     Word      = element.Word;
     Position  = element.Rectangle.Center;
     Color     = color;
     Size      = element.Rectangle.Size;
     Font      = font;
     Frequency = element.Frequency;
 }
Example #3
0
 public Result <Font> Process(PositionedElement element)
 {
     return(Result.Of(() => new Font(new FontFamily(FamilyName), Size)));
 }
Example #4
0
 public Result <Color> Process(PositionedElement element)
 {
     return(Result.Of(() => Color.FromArgb(MaxChannelValue - MaxChannelDelta / element.Frequency, Color.Red)));
 }
Example #5
0
        public override void VisibleIntervalChanged(
            AxesIntervals <TX, TXSize, TY, TYSize> visible,
            AxesIntervals <TX, TXSize, TY, TYSize> limits,
            Size panelSize)
        {
            // Create extended intervals.
            Interval <TX, TXSize>  intervalX    = visible.IntervalX;
            Interval <TY, TYSize>  intervalY    = visible.IntervalY;
            Tuple <TXSize, TYSize> maxLabelSize = GetMaximumLabelSize(visible);
            var additionalX = Operator <TXSize> .Add(maxLabelSize.Item1, maxLabelSize.Item1);

            var additionalY = Operator <TYSize> .Add(maxLabelSize.Item2, maxLabelSize.Item2);

            var extendedX = Operator <TXSize> .Add(intervalX.Size, additionalX);

            var extendedY = Operator <TYSize> .Add(intervalY.Size, additionalY);

            double scaleX = Interval <TX, TXSize> .ConvertSizeToDouble(extendedX) / Interval <TX, TXSize> .ConvertSizeToDouble(intervalX.Size);

            double scaleY = Interval <TY, TYSize> .ConvertSizeToDouble(extendedY) / Interval <TY, TYSize> .ConvertSizeToDouble(intervalY.Size);

            Interval <TX, TXSize> scaledX = intervalX.Scale(scaleX, limits.IntervalX);
            Interval <TY, TYSize> scaledY = intervalY.Scale(scaleY, limits.IntervalY);
            var extendedIntervals         = new AxesIntervals <TX, TXSize, TY, TYSize>(scaledX, scaledY);

            var toPosition = new HashSet <Tuple <TX, TY> >(GetPositions(extendedIntervals, panelSize));

            // Free up labels which are no longer visible, and update those already positioned.
            var toRemove = new List <PositionedElement>();
            var toUpdate = new List <PositionedElement>();

            foreach (var positioned in _visibleLabels)
            {
                if (toPosition.Contains(positioned.Position))
                {
                    toUpdate.Add(positioned);
                    toPosition.Remove(positioned.Position);
                }
                else
                {
                    Remove(positioned.Element);
                    _availableLabels.Push(positioned.Element);
                    toRemove.Add(positioned);
                }
            }
            toRemove.ForEach(r => _visibleLabels.Remove(r));

            // Position new labels.
            var toInitialize = new List <PositionedElement>();

            foreach (var position in toPosition)
            {
                // Create a new label when needed, or retrieve existing one.
                FrameworkElement toPlace;
                if (_availableLabels.Count == 0)
                {
                    toPlace           = CreateLabel();
                    toPlace.CacheMode = new BitmapCache();
                }
                else
                {
                    toPlace = _availableLabels.Pop();
                }
                toPlace.SetValue(AxesPanel <TX, TXSize, TY, TYSize> .XProperty, position.Item1);
                toPlace.SetValue(AxesPanel <TX, TXSize, TY, TYSize> .YProperty, position.Item2);
                Add(toPlace);

                var positioned = new PositionedElement(toPlace, position);
                _visibleLabels.Add(positioned);
                toInitialize.Add(positioned);
            }

            // Only update and initialize labels at end, so that _visibleLabels is up to date.
            toInitialize.ForEach(i => InitializeLabel(i, visible, panelSize));
            toUpdate.ForEach(u => UpdateLabel(u, visible, panelSize));
        }
Example #6
0
 /// <summary>
 ///   Called for already positioned elements which might potentionally need to be updated based on a new visible interval.
 /// </summary>
 protected abstract void UpdateLabel(PositionedElement label, AxesIntervals <TX, TXSize, TY, TYSize> visible, Size panelSize);
Example #7
0
 /// <summary>
 ///   Initializes a label which has just been repositioned to a certain position.
 /// </summary>
 protected abstract void InitializeLabel(PositionedElement positioned, AxesIntervals <TX, TXSize, TY, TYSize> visible, Size panelSize);