Example #1
0
        ItemState <Path> ElementPipeline(
            int index, double valuex, double valueO, double valueH, double valueL, double valueC,
            object item, Recycler <Path, ItemState <Path> > recycler, BindingEvaluator bvl
            )
        {
            // map through axes
            var y1      = ValueAxis.For(valueO);
            var y2      = ValueAxis.For(valueC);
            var y3      = ValueAxis.For(valueH);
            var y4      = ValueAxis.For(valueL);
            var leftx   = CategoryAxis.For(valuex);
            var offsetx = BarOffset;
            var rightx  = offsetx + BarWidth;
            // force them to be a min/max
            var topy    = Math.Max(y1, y2);
            var bottomy = Math.Min(y1, y2);
            var highy   = Math.Max(y3, y4);
            var lowy    = Math.Min(y3, y4);

            _trace.Verbose($"{Name}[{index}] {valueO}/{valueH}/{valueL}/{valueC} ({offsetx},{topy}) ({rightx},{bottomy})");
            // create geometry
            var path = recycler.Next(null);

            if (path == null)
            {
                return(null);
            }
            var pg = new PathGeometry();
            // body (open/close)
            var body = PathHelper.Rectangle(offsetx, topy, rightx, bottomy);

            pg.Figures.Add(body);
            // upper shadow (high)
            var centerx = offsetx + (rightx - offsetx) / 2;
            var upper   = PathHelper.Line(centerx, topy, centerx, highy);

            pg.Figures.Add(upper);
            // lower shadow (low)
            var lower = PathHelper.Line(centerx, bottomy, centerx, lowy);

            pg.Figures.Add(lower);
            var shim = new GeometryWithOffsetShim <PathGeometry>()
            {
                PathData = pg
            };

            path.Item2.DataContext = shim;
            // establish the style for "forward" or "reverse" polarity
            BindTo(this, valueO < valueC ? nameof(PathStyle) : nameof(ReversePathStyle), path.Item2, Path.StyleProperty);
            // bind offset
            BindTo(shim, nameof(shim.Offset), path.Item2, Canvas.LeftProperty);
            var figs = new Tuple <double, PathFigure> [4];

            figs[0] = new Tuple <double, PathFigure>(y1, body);
            figs[1] = new Tuple <double, PathFigure>(y2, body);
            figs[2] = new Tuple <double, PathFigure>(y3, upper);
            figs[3] = new Tuple <double, PathFigure>(y4, lower);
            if (bvl == null)
            {
                return(new SeriesItemState(index, leftx, BarOffset, y1, path.Item2, figs));
            }
            else
            {
                var cs = bvl.For(item);
                return(new SeriesItemState_Custom(index, leftx, BarOffset, y1, cs, path.Item2, figs));
            }
        }