Exemplo n.º 1
0
        public void Populate(IEnumerable <object> objects)
        {
            if (Disposing || IsDisposed)
            {
                return;
            }

            if (ObjectValueGetter == null)
            {
                throw new InvalidOperationException(nameof(ObjectValueGetter) + " can't be null");
            }
            if (ObjectNameGetter == null)
            {
                throw new InvalidOperationException(nameof(ObjectNameGetter) + " can't be null");
            }

            var elements = objects.Select(x =>
            {
                var element = new Element <object>
                {
                    Object = x,
                    Text   = ObjectNameGetter(x),
                    Value  = ObjectValueGetter(x)
                };

                if (ObjectColorGetter != null)
                {
                    element.Color = ObjectColorGetter.Invoke(x);
                    if (element.Color.IsEmpty)
                    {
                        element.Color = BackColor;
                    }
                }
                else
                {
                    element.Color = BackColor;
                }

                return(element);
            }).Where(x => x.Value > 0.0001).OrderByDescending(x => x.Value).ToList();

            if (UseLogValueScaling)
            {
                ScaleValuesLog(elements);
            }

            _currentSlice = SliceMaker.GetSlice(elements, 1, MinSliceRatio);

            foreach (var c in elements.Select(x => x.Color).Distinct())
            {
                _brushCache[c] = new SolidBrush(c);
            }

            UpdateRectangles();

            Refresh();
        }
Exemplo n.º 2
0
        private void UpdateRectangles()
        {
            if (Disposing || IsDisposed)
            {
                return;
            }

            _rectangles = SliceMaker.GetRectangles(_currentSlice, ClientSize.Width, ClientSize.Height).ToList();
            foreach (var r in _rectangles)
            {
                CalculatePaintRect(r);
            }
        }