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(); } }
private void Update(bool suppressRaiseEvents) { var scroller = _owner.Scroller; var oldVisibleRange = _visibleRange; _visibleRange = scroller?.DataViewport ?? new GridRange(new Range(0, 0), new Range(0, 0)); if (!oldVisibleRange.Contains(_visibleRange)) { ResetChildrenCache(); } foreach (var automationPeer in GetChildren()) { switch (automationPeer) { case MatrixViewCellAutomationPeer cellAutomationPeer when _visibleRange.Contains(cellAutomationPeer.Row, cellAutomationPeer.Column): cellAutomationPeer.SetValue(scroller?.Data.Grid[cellAutomationPeer.Row, cellAutomationPeer.Column], suppressRaiseEvents); break; case MatrixViewHeaderAutomationPeer headerAutomationPeer when _visibleRange.Contains(_visibleRange.Rows.Start, headerAutomationPeer.Column): headerAutomationPeer.SetValue(scroller?.Data.ColumnHeader[headerAutomationPeer.Column], suppressRaiseEvents); break; case MatrixViewItemAutomationPeer itemAutomationPeer: itemAutomationPeer.ClearValue(suppressRaiseEvents); break; } } }
private async Task DrawVisualsAsync(GridUpdateType updateType, bool suppressNotification, CancellationToken token, ISortOrder sortOrder) { Rect visualViewport = new Rect( Points.HorizontalOffset, Points.VerticalOffset, Points.ViewportWidth, Points.ViewportHeight); GridRange newViewport = Points.ComputeDataViewport(visualViewport); if (newViewport.Rows.Count < 1 || newViewport.Columns.Count < 1) { return; } // pull data from provider try { var data = await DataProvider.GetAsync(newViewport, sortOrder); if (!data.Grid.Range.Contains(newViewport) || !data.ColumnHeader.Range.Contains(newViewport.Columns) || !data.RowHeader.Range.Contains(newViewport.Rows)) { throw new InvalidOperationException("Couldn't acquire enough data"); } // actual drawing runs in UI thread await Task.Factory.StartNew( () => DrawVisuals(newViewport, data, updateType, visualViewport, suppressNotification), token, TaskCreationOptions.None, _ui); } catch (OperationCanceledException) { } }
private async Task DrawVisualsAsync(GridRange dataViewport, IGridData <string> data, GridUpdateType updateType, Rect visualViewport, bool suppressNotification, CancellationToken token) { await _services.MainThread().SwitchToAsync(token); DataGrid.SelectedIndex = new GridIndex(Math.Min(DataGrid.SelectedIndex.Row, DataProvider.RowCount - 1), Math.Min(DataGrid.SelectedIndex.Column, DataProvider.ColumnCount - 1)); var columnsData = new RangeToGrid <string>(dataViewport.Columns, data.ColumnHeader, true); var rowsData = new RangeToGrid <string>(dataViewport.Rows, data.RowHeader, false); var cellsData = data.Grid; using (Points.DeferChangeNotification(suppressNotification)) { // measure points ColumnHeader.MeasurePoints( Points.GetAccessToPoints(ColumnHeader.ScrollDirection), new GridRange(new Range(0, 1), dataViewport.Columns), columnsData, updateType); RowHeader.MeasurePoints( Points.GetAccessToPoints(RowHeader.ScrollDirection), new GridRange(dataViewport.Rows, new Range(0, 1)), rowsData, updateType == Sort ? Refresh : updateType); DataGrid.MeasurePoints( Points.GetAccessToPoints(DataGrid.ScrollDirection), dataViewport, cellsData, updateType == Sort ? Refresh : updateType); // adjust Offset in case of overflow if ((Points.HorizontalOffset + visualViewport.Width).GreaterOrCloseTo(Points.HorizontalExtent)) { Points.HorizontalOffset = Points.HorizontalExtent - visualViewport.Width; } if ((Points.VerticalOffset + visualViewport.Height).GreaterOrCloseTo(Points.VerticalExtent)) { Points.VerticalOffset = Points.VerticalExtent - visualViewport.Height; } if (updateType == ScrollIntoView) { AdjustFocusedCellOffset(visualViewport); } // 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; } DataViewport = dataViewport; Data = data; _owner.AutomationPeer?.Update(); }
public Grid(GridRange range, IList <T> list) { if (list.Count != range.Rows.Count * range.Columns.Count) { throw new ArgumentException("Length of the initialization vector doesn't match grid dimensions"); } Range = range; _list = list; }
public Grid(GridRange range, IList <T> list) { if (list.Count != range.Rows.Count * range.Columns.Count) { throw new ArgumentException("Number of initializing data doesn't match with grid's dimensions"); } Range = range; _list = list; }
public Task <IGridData <string> > GetAsync(GridRange gridRange, ISortOrder sortOrder = null) { var t = _session.GetGridDataAsync(_evaluation.Expression, gridRange, sortOrder); if (t == null) { // May happen when R host is not running Trace.Fail(Invariant($"{nameof(VariableViewModel)} returned null grid data")); return(Task.FromResult <IGridData <string> >(null)); } return(t); }
public Task <IGridData <string> > GetAsync(GridRange gridRange) { var t = GridDataSource.GetGridDataAsync(_evaluation.Expression, gridRange); if (t == null) { // May happen when R host is not running Trace.Fail(Invariant($"{nameof(EvaluationWrapper)} returned null grid data")); return(Task.FromResult <IGridData <string> >(null)); } return(t); }
public GridData( IList <string> rowNames, IList <string> columnNames, IList <string> values) { RowNames = rowNames; ColumnNames = columnNames; Values = values; if (rowNames != null && columnNames != null) { Range = new GridRange(new Range(0, rowNames.Count), new Range(0, columnNames.Count)); } }
public Grid(GridRange range, Func <int, int, T> createNew) { Range = range; _list = new List <T>(range.Rows.Count * range.Columns.Count); foreach (int c in range.Columns.GetEnumerable()) { foreach (int r in range.Rows.GetEnumerable()) { _list.Add(createNew(r, c)); } } }
private async Task DrawVisualsAsync( GridRange dataViewport, IGridData <string> data, GridUpdateType updateType, Rect visualViewport, bool suppressNotification, CancellationToken token) { await VsAppShell.Current.SwitchToMainThreadAsync(token); 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; } }
private void DrawVisuals( GridRange dataViewport, IGridData <string> data, bool refresh, 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), refresh); RowHeader?.MeasurePoints( Points.GetAccessToPoints(RowHeader.ScrollDirection), new GridRange(dataViewport.Rows, new Range(0, 1)), new RangeToGrid <string>(dataViewport.Rows, data.RowHeader, false), refresh); DataGrid?.MeasurePoints( Points.GetAccessToPoints(DataGrid.ScrollDirection), dataViewport, data.Grid, refresh); // 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; } }
public RangeToGrid(Range range, IRange <T> data, bool takeColumn) { if (takeColumn) { Range = new GridRange(new Range(0, 1), range); _getItemFunc = GetItemColumnMode; _setItemFunc = SetItemColumnMode; } else { Range = new GridRange(range, new Range(0, 1)); _getItemFunc = GetItemRowMode; _setItemFunc = SetItemRowMode; } _data = data; }
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; }
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; }
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); }); } }
public Task <IGridData <string> > GetAsync(GridRange gridRange, ISortOrder sortOrder = null) => _dataSource.GetGridDataAsync(_dataObject.Expression, gridRange, sortOrder);
public bool Contains(GridRange other) => Rows.Contains(other.Rows) && Columns.Contains(other.Columns);
public GridByList(GridRange range, List <List <T> > data) { Range = range; _data = data; }