Пример #1
0
        /// <summary>
        /// Creates a request to format cells
        /// <para></para>
        /// THROWS: InvalidOperationException
        /// </summary>
        /// <param name="spreadsheetId">The id of the sheets doc</param>
        /// <param name="tabName">The name of the tab to be formatted</param>
        /// <param name="format">The cell format to apply to the cells</param>
        /// <param name="range">The range to apply the format to</param>
        /// <returns></returns>
        private static Request requestFormatCells(string spreadsheetId, string tabName, CellFormat format, GridRange range)
        {
            int?sheetIndex = getTabIndex(spreadsheetId, tabName);

            // if the name was not found return
            if (sheetIndex == null)
            {
                throw new InvalidOperationException(m_errorTabDoesNotExist);
            }

            CellData cellData = new CellData();

            cellData.UserEnteredFormat = format;

            GridRange grid = range;

            RepeatCellRequest repeatRequest = new RepeatCellRequest();

            repeatRequest.Cell   = cellData;
            repeatRequest.Fields = "UserEnteredFormat";
            repeatRequest.Range  = grid;

            Request request = new Request();

            request.RepeatCell = repeatRequest;

            return(request);
        }
Пример #2
0
        /// <summary>
        /// Applies the data and format of a list of rows to a range.
        /// </summary>
        /// <param name="spreadsheetId">The id of the sheets doc</param>
        /// <param name="tabName">The name of the tab to write to</param>
        /// <param name="startCell">The top-left cell in the range to be written to</param>
        /// <param name="endCell">The bottom-right cell in the range to be written to</param>
        /// <param name="rows">The list of rows to be written</param>
        /// <returns></returns>
        public static bool updateCells(string spreadsheetId, string tabName, string startCell, string endCell, List <RowData> rows)
        {
            if (m_shouldRun == false)
            {
                return(false);
            }

            Point startPoint = convertCellToPoint(startCell);
            Point endPoint   = convertCellToPoint(endCell);

            GridRange range = new GridRange();

            range.SheetId          = getTabIndex(spreadsheetId, tabName);
            range.StartColumnIndex = startPoint.X;
            range.StartRowIndex    = startPoint.Y;
            range.EndColumnIndex   = endPoint.X + 1;
            range.EndRowIndex      = endPoint.Y + 1;

            Request updateCells = requestUpdateCells(spreadsheetId, tabName, rows, range, "*");
            Request autoSize    = requestDimensionAutoSize(spreadsheetId, tabName, 0);

            BatchUpdateSpreadsheetRequest batchRequest = new BatchUpdateSpreadsheetRequest();

            batchRequest.Requests = new List <Request>();
            batchRequest.Requests.Add(autoSize);
            batchRequest.Requests.Add(updateCells);

            return(ExecuteBatchRequest(batchRequest, spreadsheetId));
        }
Пример #3
0
        /// <summary>
        /// Formats a range of cells
        /// </summary>
        /// <param name="spreadsheetId">The id of the sheets doc</param>
        /// <param name="tabName">The name of the tab to format</param>
        /// <param name="startCell">The top-left cell in the range to be formatted</param>
        /// <param name="endCell">The bottom right cell in the range to be formatted</param>
        /// <param name="format">The cell format to apply to the range</param>
        /// <returns></returns>
        public static bool FormatCellRange(string spreadsheetId, string tabName, string startCell, string endCell, CellFormat format)
        {
            if (m_shouldRun == false)
            {
                return(false);
            }

            Point startPoint = convertCellToPoint(startCell);
            Point endPoint   = convertCellToPoint(endCell);

            GridRange gridRange = new GridRange();

            gridRange.SheetId          = getTabIndex(spreadsheetId, tabName);
            gridRange.StartColumnIndex = startPoint.X;
            gridRange.StartRowIndex    = startPoint.Y - 1;
            gridRange.EndColumnIndex   = endPoint.X + 1;
            gridRange.EndRowIndex      = endPoint.Y + 1;

            Request formatCells = requestFormatCells(spreadsheetId, tabName, format, gridRange);

            BatchUpdateSpreadsheetRequest batchRequest = new BatchUpdateSpreadsheetRequest();

            batchRequest.Requests = new List <Request>();
            batchRequest.Requests.Add(formatCells);

            return(ExecuteBatchRequest(batchRequest, spreadsheetId));
        }
Пример #4
0
        public void Draw(
            GridRange range,
            IPoints points) {

            DrawingContext drawingContext = RenderOpen();
            DoubleCollection xCollection = new DoubleCollection();
            DoubleCollection yCollection = new DoubleCollection();

            try {
                // vertical line
                double renderHeight = points.yPosition[range.Rows.Start + range.Rows.Count] - points.yPosition[range.Rows.Start];
                Rect verticalLineRect = new Rect(new Size(GridLineThickness, renderHeight));
                foreach (int i in range.Columns.GetEnumerable()) {
                    verticalLineRect.X = points.xPosition[i + 1] - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, verticalLineRect);
                    xCollection.Add(verticalLineRect.X);
                }

                // horizontal line
                double renderWidth = points.xPosition[range.Columns.Start + range.Columns.Count] - points.xPosition[range.Columns.Start];
                Rect horizontalLineRect = new Rect(new Size(renderWidth, GridLineThickness));
                foreach (int i in range.Rows.GetEnumerable()) {
                    horizontalLineRect.Y = points.yPosition[i + 1] - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, horizontalLineRect);
                    yCollection.Add(horizontalLineRect.Y);
                }

                XSnappingGuidelines = xCollection;
                YSnappingGuidelines = yCollection;
            } finally {
                drawingContext.Close();
            }
        }
Пример #5
0
        public List <string> GetGames()
        {
            IList <IList <object> > values = Response.Values;

            if (values != null && values.Count > 0)
            {
                List <string> Games = new List <string>();
                for (int i = 3; i < values.Count; ++i)
                {
                    var row = values[i];
                    if (row.Count > 4 && row[4] != null && !string.IsNullOrWhiteSpace(row[4].ToString()))
                    {
                        Games.Add(row[4].ToString());
                        LastGameId = i;
                    }
                }
                Sheet     sh    = Service.Spreadsheets.Get(SpreadsheetId).Execute().Sheets.Where(s => s.Properties.Title == Name).FirstOrDefault();
                GridRange merge = sh.Merges.Where(m => m.StartRowIndex == LastGameId && m.StartColumnIndex == 4).FirstOrDefault();
                int?      index = merge?.EndRowIndex;
                if (index != null)
                {
                    LastGameId = index.GetValueOrDefault() - 1;
                }
                return(Games);
            }
            else
            {
                Console.WriteLine("No data found.");
                return(null);
            }
        }
Пример #6
0
        /// <summary>
        /// Default constructor for the class.
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="range"></param>
        public MergedRegion(Sheet sheet, GridRange range)
        {
            _sheet = sheet;
            Range  = range;

            A1FirstCell = CalculateFirstCellA1();
        }
Пример #7
0
 /// <summary>
 /// As opposed to Adding a range, this will remove a range.
 /// It might happend that removing a range is dividing one bigger range into two
 /// smaller ones. So practically the number of ranges might increase.
 ///
 /// It might be that this method might carry more exact meaning with "Exclude", instead
 /// of "RemoveRange"
 /// </summary>
 /// <param name="rangeToRemove"></param>
 /// <returns></returns>
 public RangeMergerByRows RemoveRange(GridRange rangeToRemove)
 {
     while (RemoveRangeRecursive(rangeToRemove))
     {
     }
     return(this);
 }
Пример #8
0
 /// <summary>
 /// Construct a quadtree node with the given bounds
 /// </summary>
 public QuadTreeNode(GridRange bounds, int currentDepth, QuadTree quadTree)
     : this(bounds)
 {
     m_bounds = bounds;
     QuadTree = quadTree;
     Depth    = currentDepth + 1;
 }
Пример #9
0
 private bool IntersectWithCurrentRangesRecursive(RangeRegion rangeRegionToIntersect)
 {
     // check against each range
     foreach (GridRange range in m_ranges)
     {
         RangeRegion excludedResults = null;
         GridRange   remove          = GridRange.Empty;
         bool        excluded        = false;
         // loop through our new ranges
         foreach (GridRange rangeToIntersect in rangeRegionToIntersect)
         {
             // if we intersect with at least one range
             // get the exclusion range.
             // mark a flag, that we need to remove our
             // range, and add an excluded range
             if (range.IntersectsWith(rangeToIntersect))
             {
                 excludedResults = rangeToIntersect.Exclude(range);
                 excluded        = true;
                 remove          = rangeToIntersect;
                 break;
             }
         }
         if (excluded)
         {
             rangeRegionToIntersect.Remove(remove);
             rangeRegionToIntersect.Add(excludedResults);
             return(true);
         }
     }
     return(false);
 }
Пример #10
0
 private void VerifyVerticalStretches()
 {
     if (GridRange.VerticallyIntersectsWith(Template.GridRows.Count - Template.Stretches))
     {
         throw new InvalidOperationException(DiagnosticMessages.ScalarBinding_InvalidStretches(Ordinal));
     }
 }
Пример #11
0
        public QuadTreeNode CreateNewRoot(QuadTreeNode currentRoot)
        {
            var bounds   = currentRoot.Bounds;
            int startRow = bounds.Start.Row;
            int startCol = bounds.Start.Column;
            int halfCol  = bounds.ColumnsCount;
            int halfRow  = bounds.RowsCount;
            var Depth    = currentRoot.Depth;
            var QuadTree = currentRoot.QuadTree;

            var newRoot = new QuadTreeNode(
                new GridRange(startRow, startCol, halfCol * 2, halfRow * 2),
                currentRoot.Depth, currentRoot.QuadTree);


            newRoot.Nodes.Add(currentRoot);
            newRoot.Nodes.Add(new QuadTreeNode(GridRange.From(
                                                   new Position(startRow, startCol + halfCol),
                                                   halfRow, halfCol), Depth, QuadTree));
            newRoot.Nodes.Add(new QuadTreeNode(GridRange.From(
                                                   new Position(startRow + halfRow, startCol),
                                                   halfRow, halfCol), Depth, QuadTree));
            newRoot.Nodes.Add(new QuadTreeNode(GridRange.From(
                                                   new Position(startRow + halfRow, startCol + halfCol),
                                                   halfRow, halfCol), Depth, QuadTree));
            return(newRoot);
        }
Пример #12
0
        public void CreateSubNodes(QuadTreeNode parentNode)
        {
            var m_bounds = parentNode.Bounds;

            // the smallest subnode has an area
            if ((parentNode.Bounds.ColumnsCount * parentNode.Bounds.RowsCount) <= 10)
            {
                return;
            }

            int startRow = m_bounds.Start.Row;
            int startCol = m_bounds.Start.Column;
            int halfCol  = (m_bounds.ColumnsCount / 2);
            int halfRow  = (m_bounds.RowsCount / 2);

            var Depth    = parentNode.Depth;
            var QuadTree = parentNode.QuadTree;

            parentNode.Nodes.Add(new QuadTreeNode(GridRange.From(m_bounds.Start, halfRow, halfCol), Depth, QuadTree));
            parentNode.Nodes.Add(new QuadTreeNode(GridRange.From(
                                                      new Position(startRow, startCol + halfCol),
                                                      halfRow, halfCol), Depth, QuadTree));
            parentNode.Nodes.Add(new QuadTreeNode(GridRange.From(
                                                      new Position(startRow + halfRow, startCol),
                                                      halfRow, halfCol), Depth, QuadTree));
            parentNode.Nodes.Add(new QuadTreeNode(GridRange.From(
                                                      new Position(startRow + halfRow, startCol + halfCol),
                                                      halfRow, halfCol), Depth, QuadTree));
        }
Пример #13
0
        public virtual System.Drawing.Bitmap Export(GridVirtual grid, GridRange rangeToExport)
        {
            System.Drawing.Bitmap bitmap = null;

            try
            {
                System.Drawing.Size size = grid.RangeToSize(rangeToExport);

                bitmap = new System.Drawing.Bitmap(size.Width, size.Height);

                using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bitmap))
                {
                    Export(grid, graphic, rangeToExport, new System.Drawing.Point(0, 0));
                }
            }
            catch (Exception)
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                    bitmap = null;
                }

                throw;
            }

            return(bitmap);
        }
Пример #14
0
        internal override void VerifyRowRange(GridRange rowRange)
        {
            if (GridRange.IntersectsWith(rowRange))
            {
                throw new InvalidOperationException(DiagnosticMessages.ScalarBinding_IntersectsWithRowRange(Ordinal));
            }

            if (!RepeatsWhenFlow)
            {
                return;
            }

            if (Template.Flowable(Orientation.Horizontal))
            {
                if (!rowRange.Contains(GridRange.Left) || !rowRange.Contains(GridRange.Right))
                {
                    throw new InvalidOperationException(DiagnosticMessages.ScalarBinding_OutOfHorizontalRowRange(Ordinal));
                }
            }
            else if (Template.Flowable(Orientation.Vertical))
            {
                if (!rowRange.Contains(GridRange.Top) || !rowRange.Contains(GridRange.Bottom))
                {
                    throw new InvalidOperationException(DiagnosticMessages.ScalarBinding_OutOfVerticalRowRange(Ordinal));
                }
            }
            else
            {
                throw new InvalidOperationException(DiagnosticMessages.ScalarBinding_FlowRepeatableNotAllowedByTemplate(Ordinal));
            }
        }
Пример #15
0
        public bool Remove(GridRange range)
        {
            // if the item is not contained in this quad, there's a problem
            if (!m_bounds.Contains(range))
            {
                throw new ArgumentException("range is out of the bounds of this quadtree node");
            }

            // for each subnode:
            // if the node contains the item, add the item to that node and return
            // this recurses into the node that is just large enough to fit this item
            foreach (QuadTreeNode node in m_nodes)
            {
                if (node.Bounds.Contains(range))
                {
                    return(node.Remove(range));
                }
            }

            for (int i = 0; i < Contents.Count; i++)
            {
                if (Contents[i].Equals(range))
                {
                    Contents.RemoveAt(i);
                    return(true);
                }
            }
            return(false);
        }
Пример #16
0
 public override void SelectRange(GridRange range, bool select)
 {
     for (int c = range.Start.Column; c <= range.End.Column; c++)
     {
         SelectColumn(c, select);
     }
 }
Пример #17
0
        public TileRegionFilter(SQuantizedExtentGrid <int> grid, SQuantizedExtent3D quantizedExtent, GridRange tileRange)
        {
            m_range = tileRange;
            m_grid  = grid;

            m_quantizedExtent = quantizedExtent;
        }
Пример #18
0
        /// <summary>
        /// Insert an item to this node
        /// </summary>
        /// <param name="item"></param>
        public void Insert(GridRange item)
        {
            // if the item is not contained in this quad, there's a problem
            if (!m_bounds.Contains(item))
            {
                throw new ArgumentException("range is out of the bounds of this quadtree node");
            }

            // if the subnodes are null create them. may not be sucessfull: see below
            // we may be at the smallest allowed size in which case the subnodes will not be created
            if (m_nodes.Count == 0)
            {
                QuadTree.QuadTreeNodeDivider.CreateSubNodes(this);
            }

            // for each subnode:
            // if the node contains the item, add the item to that node and return
            // this recurses into the node that is just large enough to fit this item
            foreach (QuadTreeNode node in m_nodes)
            {
                if (node.Bounds.Contains(item))
                {
                    node.Insert(item);
                    return;
                }
            }

            // if we make it to here, either
            // 1) none of the subnodes completely contained the item. or
            // 2) we're at the smallest subnode size allowed
            // add the item to this node's contents.
            this.Contents.Add(item);
        }
Пример #19
0
        internal override void VerifyRowRange(GridRange rowRange)
        {
            if (GridRange.IntersectsWith(rowRange))
            {
                throw new InvalidOperationException(DiagnosticMessages.BlockBinding_IntersectsWithRowRange(Ordinal));
            }

            if (!Template.Orientation.HasValue)
            {
                throw new InvalidOperationException(DiagnosticMessages.BlockBinding_NullOrientation);
            }

            var orientation = Template.Orientation.GetValueOrDefault();

            if (orientation == Orientation.Horizontal)
            {
                if (!rowRange.Contains(GridRange.Left) || !rowRange.Contains(GridRange.Right))
                {
                    throw new InvalidOperationException(DiagnosticMessages.BlockBinding_OutOfHorizontalRowRange(Ordinal));
                }
            }
            else
            {
                Debug.Assert(orientation == Orientation.Vertical);
                if (!rowRange.Contains(GridRange.Top) || !rowRange.Contains(GridRange.Bottom))
                {
                    throw new InvalidOperationException(DiagnosticMessages.BlockBinding_OutOfVerticalRowRange(Ordinal));
                }
            }
        }
Пример #20
0
 internal sealed override void VerifyRowRange(GridRange rowRange)
 {
     if (!rowRange.Contains(GridRange))
     {
         throw new InvalidOperationException(DiagnosticMessages.RowBinding_OutOfRowRange(Ordinal));
     }
 }
Пример #21
0
 /// <summary>
 /// Add a range to collection. If the range can be added (merged)
 /// to existing range, it will be added so. This will guarantee
 /// that the number of different ranges is kept to minimal.
 /// In theory only if user selects every second row, this would produce
 /// RowCount / 2 number of ranges. In practice, there are rarely
 /// more than 3 - 5 different selection regions
 /// </summary>
 /// <param name="rangeToAdd">columns values are ignored, so simply
 /// put 0 as start colum and 1 as end column. Only row values matter</param>
 /// <returns></returns>
 public RangeMergerByRows AddRange(GridRange rangeToAdd)
 {
     rangeToAdd = NormalizeRange(rangeToAdd);
     Merge(rangeToAdd);
     JoinAdjanced();
     return(this);
 }
Пример #22
0
 public Task <IGridData <string> > GetAsync(GridRange range)
 {
     return(Task.Run(async() => {
         await Task.Delay(TimeSpan.FromMilliseconds(100));
         return (IGridData <string>) new MockGridData(range);
     }));
 }
Пример #23
0
        /// <summary>
        /// Query the QuadTree for items that are in the given area
        /// </summary>
        /// <returns></returns>
        public List <GridRange> QueryInternal(GridRange queryArea, bool stopOnFirst)
        {
            // create a list of the items that are found
            List <GridRange> results = new List <GridRange>();

            // this quad contains items that are not entirely contained by
            // it's four sub-quads. Iterate through the items in this quad
            // to see if they intersect.
            foreach (var item in this.Contents)
            {
                if (queryArea.IntersectsWith(item))
                {
                    results.Add(item);
                    if (stopOnFirst == true)
                    {
                        return(results);
                    }
                }
            }

            foreach (QuadTreeNode node in m_nodes)
            {
                if (node.IsEmpty)
                {
                    continue;
                }

                // Case 1: search area completely contained by sub-quad
                // if a node completely contains the query area, go down that branch
                // and skip the remaining nodes (break this loop)
                if (node.Bounds.Contains(queryArea))
                {
                    results.AddRange(node.QueryInternal(queryArea, stopOnFirst));
                    break;
                }

                // Case 2: Sub-quad completely contained by search area
                // if the query area completely contains a sub-quad,
                // just add all the contents of that quad and it's children
                // to the result set. You need to continue the loop to test
                // the other quads
                if (queryArea.Contains(node.Bounds))
                {
                    results.AddRange(node.SubTreeContents);
                    continue;
                }

                // Case 3: search area intersects with sub-quad
                // traverse into this quad, continue the loop to search other
                // quads
                if (node.Bounds.IntersectsWith(queryArea))
                {
                    results.AddRange(node.QueryInternal(queryArea, stopOnFirst));
                }
            }


            return(results);
        }
Пример #24
0
        private void Join(GridRange range1, GridRange range2)
        {
            GridRange result = GridRange.GetBounds(range1, range2);

            m_ranges.Remove(range1);
            m_ranges.Remove(range2);
            m_ranges.Add(result);
        }
Пример #25
0
    /*------------------------------------------------------------------------------------------------------------------*/
    /********************************************************************************************************************/
    /*************************************************** Behaviours *****************************************************/
    /********************************************************************************************************************/
    /*------------------------------------------------------------------------------------------------------------------*/


    /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DEBUG ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

    /// <summary>
    /// Ensures there is always at least some room to deploy.
    /// </summary>
    protected void InitializeDeploymentZone()
    {
        deployArea = new GridRange(deployRangeTopLeftTile, deployRangeBottomRightTile);
        if (deployArea.Area == 0)
        {
            throw new InvalidDeployAreaException("The deployment area contains 0 valid tiles.");
        }
    }
Пример #26
0
        public MockGridData(GridRange range)
        {
            ColumnHeader = new DefaultHeaderData(range.Columns, DefaultHeaderData.Mode.Column);

            RowHeader = new DefaultHeaderData(range.Rows, DefaultHeaderData.Mode.Row);

            Grid = new Grid <string>(range, (r, c) => Invariant($"{r}:{c}"));
        }
Пример #27
0
 public void MergeRange(GridRange range)
 {
     if (_sheet.Merges == null)
     {
         _sheet.Merges = new List <GridRange>();
     }
     range.SheetId = _sheet.Properties.SheetId;
     _sheet.Merges.Add(range);
 }
Пример #28
0
        public override bool IntersectsWith(GridRange rng)
        {
            for (int c = rng.Start.Column; c <= rng.End.Column; c++)
            {
                if (IsSelectedColumn(c))
                    return true;
            }

            return false;
        }
Пример #29
0
        public override bool IsSelectedRange(GridRange range)
        {
            for (int c = range.Start.Column; c <= range.End.Column; c++)
            {
                if (IsSelectedColumn(c) == false)
                    return false;
            }

            return true;
        }
Пример #30
0
        private void SetHeight(GridVirtual grid, Position position, int height)
        {
            GridRange range        = grid.PositionToCellRange(position);
            int       heightForCol = height / range.RowsCount;

            for (int r = range.Start.Row; r <= range.End.Row; r++)
            {
                grid.Rows.SetHeight(r, heightForCol);
            }
        }
Пример #31
0
        public GridRange?QueryFirst(GridRange queryArea)
        {
            var results = QueryInternal(queryArea, true);

            if (results.Count == 0)
            {
                return(null);
            }
            return(results[0]);
        }
Пример #32
0
        public static async Task<IGridData<string>> GetGridDataAsync(IRSession rSession, string expression, GridRange? gridRange, ISortOrder sortOrder = null) {
            await TaskUtilities.SwitchToBackgroundThread();

            string rows = gridRange?.Rows.ToRString();
            string columns = gridRange?.Columns.ToRString();
            string rowSelector = (sortOrder != null && !sortOrder.IsEmpty) ? sortOrder.GetRowSelector() : "";
            string expr = Invariant($"rtvs:::grid_data({expression}, {rows}, {columns}, {rowSelector})");

            try {
                return await rSession.EvaluateAsync<GridData>(expr, REvaluationKind.Normal);
            } catch (RException ex) {
                var message = Invariant($"Grid data evaluation failed:{Environment.NewLine}{ex.Message}");
                await VsAppShell.Current.Services.Log.WriteAsync(LogVerbosity.Normal, MessageCategory.Error, message);
                return null;
            }
        }
Пример #33
0
        public static async Task<IGridData<string>> GetGridDataAsync(string expression, GridRange gridRange, IRSession rSession = null) {
            await TaskUtilities.SwitchToBackgroundThread();

            if (rSession == null) {
                rSession = VsAppShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>().GetInteractiveWindowRSession();
                if (rSession == null) {
                    throw new InvalidOperationException(Invariant($"{nameof(IRSessionProvider)} failed to return RSession for {nameof(EvaluationWrapper)}"));
                }
            }

            string rows = gridRange.Rows.ToRString();
            string columns = gridRange.Columns.ToRString();

            REvaluationResult? result = null;
            using (var evaluator = await rSession.BeginEvaluationAsync(false)) {
                result = await evaluator.EvaluateAsync($"rtvs:::grid.dput(rtvs:::grid.data({expression}, {rows}, {columns}))", REvaluationKind.Normal);

                if (result.Value.ParseStatus != RParseStatus.OK || result.Value.Error != null) {
                    throw new InvalidOperationException($"Grid data evaluation failed:{result}");
                }
            }

            GridData data = null;

            if (result.HasValue) {
                data = GridParser.Parse(result.Value.StringResult.ToUnicodeQuotes());
                data.Range = gridRange;

                if ((data.ValidHeaderNames.HasFlag(GridData.HeaderNames.Row) && data.RowNames.Count != gridRange.Rows.Count)
                    || (data.ValidHeaderNames.HasFlag(GridData.HeaderNames.Column) && data.ColumnNames.Count != gridRange.Columns.Count)) {
                    throw new InvalidOperationException("Header names lengths are different from data's length");
                }
            }

            return data;
        }
Пример #34
0
        internal void MeasurePoints(IPoints points, GridRange newViewport, IGrid<string> data, bool refresh) {
            var orgGrid = _visualGrid;
            _visualGrid = new Grid<TextVisual>(
                newViewport,
                (r, c) => {
                    if (!refresh && _dataViewport.Contains(r, c)) {
                        return orgGrid[r, c];
                    }
                    var visual = new TextVisual();
                    visual.Row = r;
                    visual.Column = c;
                    visual.Text = data[r, c];
                    visual.Typeface = Typeface;
                    visual.FontSize = FontSize; // FontSize here is in device independent pixel, and Visual's FormattedText API uses the same unit
                    visual.Foreground = Foreground;
                    return visual;
                });

            _visualChildren.Clear();
            foreach (int c in newViewport.Columns.GetEnumerable()) {
                foreach (int r in newViewport.Rows.GetEnumerable()) {
                    var visual = _visualGrid[r, c];

                    visual.Draw();
                    points.Width[c] = visual.Size.Width + (visual.Margin * 2) + GridLineThickness;
                    points.Height[r] = visual.Size.Height + (visual.Margin * 2) + GridLineThickness;

                    _visualChildren.Add(_visualGrid[r, c]);
                }
            }

            _dataViewport = newViewport;
        }
Пример #35
0
 private void CreateGrid(GridRange newViewport, IGrid<string> data, GridUpdateType updateType) {
     var orgGrid = _visualGrid;
     if (Header) {
         _visualGrid = new Grid<TextVisual>(
                 newViewport,
                 (r, c) => {
                     if (updateType == GridUpdateType.Sort) {
                         return orgGrid[r, c];
                     }
                     if (updateType != GridUpdateType.Refresh && _dataViewport.Contains(r, c)) {
                         return orgGrid[r, c];
                     }
                     var visual = new HeaderTextVisual(c);
                     InitVisual(r, c, data, visual);
                     return visual;
                 });
     } else {
         _visualGrid = new Grid<TextVisual>(
             newViewport,
             (r, c) => {
                 if (updateType != GridUpdateType.Refresh && _dataViewport.Contains(r, c)) {
                     return orgGrid[r, c];
                 }
                 var visual = new TextVisual();
                 InitVisual(r, c, data, visual);
                 return visual;
             });
     }
 }
Пример #36
0
        internal void MeasurePoints(IPoints points, GridRange newViewport, IGrid<string> data, GridUpdateType updateType) {
            CreateGrid(newViewport, data, updateType);
            _visualChildren.Clear();

            foreach (int c in newViewport.Columns.GetEnumerable()) {
                foreach (int r in newViewport.Rows.GetEnumerable()) {
                    var visual = _visualGrid[r, c];

                    visual.Draw();
                    points.Width[c] = visual.Size.Width + (visual.Margin * 2) + GridLineThickness;
                    points.Height[r] = visual.Size.Height + (visual.Margin * 2) + GridLineThickness;

                    _visualChildren.Add(_visualGrid[r, c]);
                }
            }

            _dataViewport = newViewport;
        }
Пример #37
0
        private void DrawVisuals(
            GridRange dataViewport,
            IGridData<string> data,
            GridUpdateType updateType,
            Rect visualViewport,
            bool suppressNotification) {

            using (var deferal = Points.DeferChangeNotification(suppressNotification)) {
                // measure points
                ColumnHeader?.MeasurePoints(
                    Points.GetAccessToPoints(ColumnHeader.ScrollDirection),
                    new GridRange(new Range(0, 1), dataViewport.Columns),
                    new RangeToGrid<string>(dataViewport.Columns, data.ColumnHeader, true),
                    updateType);

                RowHeader?.MeasurePoints(
                    Points.GetAccessToPoints(RowHeader.ScrollDirection),
                    new GridRange(dataViewport.Rows, new Range(0, 1)),
                    new RangeToGrid<string>(dataViewport.Rows, data.RowHeader, false),
                    updateType == GridUpdateType.Sort ? GridUpdateType.Refresh : updateType);

                DataGrid?.MeasurePoints(
                    Points.GetAccessToPoints(DataGrid.ScrollDirection),
                    dataViewport,
                    data.Grid,
                    updateType == GridUpdateType.Sort ? GridUpdateType.Refresh : updateType);

                // adjust Offset in case of overflow
                if ((Points.HorizontalOffset + visualViewport.Width).GreaterThanOrClose(Points.HorizontalExtent)) {
                    Points.HorizontalOffset = Points.HorizontalExtent - visualViewport.Width;
                }
                if ((Points.VerticalOffset + visualViewport.Height).GreaterThanOrClose(Points.VerticalExtent)) {
                    Points.VerticalOffset = Points.VerticalExtent - visualViewport.Height;
                }

                // arrange and draw gridline
                ColumnHeader?.ArrangeVisuals(Points.GetAccessToPoints(ColumnHeader.ScrollDirection));
                RowHeader?.ArrangeVisuals(Points.GetAccessToPoints(RowHeader.ScrollDirection));
                DataGrid?.ArrangeVisuals(Points.GetAccessToPoints(DataGrid.ScrollDirection));

                Points.ViewportHeight = DataGrid.RenderSize.Height;
                Points.ViewportWidth = DataGrid.RenderSize.Width;
            }
        }
Пример #38
0
 public static Task<IGridData<string>> GetGridDataAsync(string expression, GridRange? gridRange, ISortOrder sortOrder = null) =>
     GetGridDataAsync(VsAppShell.Current.ExportProvider.GetExportedValue<IRInteractiveWorkflowProvider>().GetOrCreate().RSession, expression, gridRange, sortOrder);