예제 #1
0
        /// <summary>Generate a piece of the graphics for 'x'</summary>
        private ChartGfxPiece CreatePiece(double x, RangeF missing)
        {
            Debug.Assert(missing.Contains(x));
            using (Lock())
            {
                // Find the nearest point in the data to 'x'
                var idx = m_data.BinarySearch(pt => pt.xf.CompareTo(x), find_insert_position: true);

                // Convert 'missing' to an index range within the data
                var idx_missing = new RangeI(
                    m_data.BinarySearch(pt => pt.xf.CompareTo(missing.Beg), find_insert_position: true),
                    m_data.BinarySearch(pt => pt.xf.CompareTo(missing.End), find_insert_position: true));

                // Limit the size of 'idx_missing' to the block size
                const int PieceBlockSize = 4096;
                var       idx_range      = new RangeI(
                    Math.Max(idx_missing.Beg, idx - PieceBlockSize),
                    Math.Min(idx_missing.End, idx + PieceBlockSize));

                // Create graphics over the data range 'idx_range'
                //todo: this isn't right... need to handle this function returning 'failed to create piece'
                switch (Options.PlotType)
                {
                default: throw new Exception($"Unsupported plot type: {Options.PlotType}");

                case EPlotType.Point:
                {
                    return(idx_range.Size > 0
                                                        ? CreatePointPlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }

                case EPlotType.Line:
                {
                    return(idx_range.Size > 1
                                                        ? CreateLinePlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }

                case EPlotType.StepLine:
                {
                    return(idx_range.Size > 1
                                                        ? CreateStepLinePlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }

                case EPlotType.Bar:
                {
                    return(idx_range.Size > 1
                                                        ? CreateBarPlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }
                }
            }
        }