本文整理汇总了C#中System.Windows.Shapes.Rectangle.BeginAnimation方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.BeginAnimation方法的具体用法?C# Rectangle.BeginAnimation怎么用?C# Rectangle.BeginAnimation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Shapes.Rectangle
的用法示例。
在下文中一共展示了Rectangle.BeginAnimation方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: enlarge_shape
private void enlarge_shape()
{
Rectangle rect1 = new Rectangle();
rect1.Width = 200;
rect1.Height = 120;
rect1.StrokeThickness = 3;
rect1.Stroke = Brushes.Black;
Canvas.SetLeft(rect1, 30);
canvas1.Children.Add(rect1);
DoubleAnimation da = new DoubleAnimation();
da.From = 30;
da.To = 100;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
da.AutoReverse = true;
da.RepeatBehavior = RepeatBehavior.Forever;
//rect1.BeginAnimation(Rectangle.HeightProperty, da);
rect1.BeginAnimation(Rectangle.HeightProperty, da);
rect1.BeginAnimation(Rectangle.WidthProperty, da);
}
示例2: GetVisualFeedback
public UIElement GetVisualFeedback(UIElement draggedElt)
{
Rectangle rect = new Rectangle();
rect.Width = draggedElt.RenderSize.Width;
rect.Height = draggedElt.RenderSize.Height;
rect.Fill = new VisualBrush(draggedElt);
rect.Opacity = 0.5;
rect.IsHitTestVisible = false;
DoubleAnimation anim = new DoubleAnimation(0.75, new Duration(TimeSpan.FromMilliseconds(500)));
anim.From = 0.25;
anim.AutoReverse = true;
anim.RepeatBehavior = RepeatBehavior.Forever;
rect.BeginAnimation(UIElement.OpacityProperty, anim);
return rect;
}
示例3: SetGridBar
/// <summary>
/// Sets the grid's percentage bar
/// </summary>
/// <param name="strataValue">
/// The strata value to which this grid cell belongs; used to search the list of grids and
/// return the proper System.Windows.Controls.Grid for text insertion.
/// </param>
/// <param name="rowNumber">The row number of the grid to add the bar to</param>
/// <param name="pct">The percentage width of the bar</param>
private void SetGridBar(string strataValue, int rowNumber, double pct)
{
Grid grid = GetStrataGrid(strataValue);
Rectangle rctBar = new Rectangle();
rctBar.Width = 0.1;// pct * 100.0;
rctBar.Fill = this.Resources["frequencyPercentBarBrush"] as SolidColorBrush;
rctBar.HorizontalAlignment = HorizontalAlignment.Left;
rctBar.Margin = new Thickness(2,6,2,6); //.HorizontalAlignment = HorizontalAlignment.Left;
Grid.SetRow(rctBar, rowNumber);
Grid.SetColumn(rctBar, /*4*/6);
grid.Children.Add(rctBar);
DoubleAnimation daBar = new DoubleAnimation();
daBar.From = 1;
daBar.To = pct * 100.0;
daBar.Duration = new Duration(TimeSpan.FromSeconds(0.5));
rctBar.BeginAnimation(Rectangle.WidthProperty, daBar);
}
示例4: RenderFrequencyFooter
/// <summary>
/// Used to render the footer (last row) of a given frequency output grid
/// </summary>
/// <param name="strataValue">
/// The strata value to which this grid cell belongs; used to search the list of grids and
/// return the proper System.Windows.Controls.Grid for text insertion.
/// </param>
/// <param name="footerRowIndex">The row index of the footer</param>
/// <param name="totalRows">The total number of rows in this grid</param>
private void RenderFrequencyFooter(string strataValue, int footerRowIndex, int totalRows)
{
Grid grid = GetStrataGrid(strataValue);
RowDefinition rowDefTotals = new RowDefinition();
rowDefTotals.Height = new GridLength(26);
grid.RowDefinitions.Add(rowDefTotals);
TextBlock txtValTotals = new TextBlock();
txtValTotals.Text = SharedStrings.TOTAL;
txtValTotals.Margin = new Thickness(4, 0, 4, 0);
txtValTotals.VerticalAlignment = VerticalAlignment.Center;
txtValTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtValTotals, footerRowIndex);
Grid.SetColumn(txtValTotals, 0);
grid.Children.Add(txtValTotals);
TextBlock txtFreqTotals = new TextBlock();
txtFreqTotals.Text = totalRows.ToString();
txtFreqTotals.Margin = new Thickness(4, 0, 4, 0);
txtFreqTotals.VerticalAlignment = VerticalAlignment.Center;
txtFreqTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtFreqTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtFreqTotals, footerRowIndex);
Grid.SetColumn(txtFreqTotals, 1);
grid.Children.Add(txtFreqTotals);
TextBlock txtPctTotals = new TextBlock();
txtPctTotals.Text = (1).ToString("P");//SharedStrings.DASHBOARD_100_PERCENT_LABEL;
txtPctTotals.Margin = new Thickness(4, 0, 4, 0);
txtPctTotals.VerticalAlignment = VerticalAlignment.Center;
txtPctTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtPctTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtPctTotals, footerRowIndex);
Grid.SetColumn(txtPctTotals, 2);
grid.Children.Add(txtPctTotals);
TextBlock txtAccuTotals = new TextBlock();
txtAccuTotals.Text = (1).ToString("P");
txtAccuTotals.Margin = new Thickness(4, 0, 4, 0);
txtAccuTotals.VerticalAlignment = VerticalAlignment.Center;
txtAccuTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtAccuTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtAccuTotals, footerRowIndex);
Grid.SetColumn(txtAccuTotals, 3);
grid.Children.Add(txtAccuTotals);
TextBlock txtCILowerTotals = new TextBlock();
txtCILowerTotals.Text = StringLiterals.SPACE + StringLiterals.SPACE + StringLiterals.SPACE;
txtCILowerTotals.Margin = new Thickness(4, 0, 4, 0);
txtCILowerTotals.VerticalAlignment = VerticalAlignment.Center;
txtCILowerTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtCILowerTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtCILowerTotals, footerRowIndex);
Grid.SetColumn(txtCILowerTotals, 4);
grid.Children.Add(txtCILowerTotals);
TextBlock txtUpperTotals = new TextBlock();
txtUpperTotals.Text = StringLiterals.SPACE + StringLiterals.SPACE + StringLiterals.SPACE;
txtUpperTotals.Margin = new Thickness(4, 0, 4, 0);
txtUpperTotals.VerticalAlignment = VerticalAlignment.Center;
txtUpperTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtUpperTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtUpperTotals, footerRowIndex);
Grid.SetColumn(txtUpperTotals, 5);
grid.Children.Add(txtUpperTotals);
Rectangle rctTotalsBar = new Rectangle();
rctTotalsBar.Width = 0.1;// 100;
rctTotalsBar.Fill = this.Resources["frequencyPercentBarBrush"] as SolidColorBrush;
rctTotalsBar.Margin = new Thickness(2, 6, 2, 6);
rctTotalsBar.HorizontalAlignment = HorizontalAlignment.Left;
Grid.SetRow(rctTotalsBar, footerRowIndex);
Grid.SetColumn(rctTotalsBar, 6);
grid.Children.Add(rctTotalsBar);
DoubleAnimation daBar = new DoubleAnimation();
daBar.From = 1;
daBar.To = 100;
daBar.Duration = new Duration(TimeSpan.FromSeconds(0.5));
rctTotalsBar.BeginAnimation(Rectangle.WidthProperty, daBar);
}
示例5: PlotRow
private void PlotRow(bool animate)
{
var stackedChart = Chart as IStackedBar;
if (stackedChart == null) return;
var stackedSeries = Chart.Series.OfType<StackedBarSeries>().ToList();
var serieIndex = stackedSeries.IndexOf(this);
var unitW = ToPlotArea(Chart.Max.Y - 1, AxisTags.Y) - Chart.PlotArea.Y + 5;
var overflow = unitW - stackedChart.MaxColumnWidth > 0 ? unitW - stackedChart.MaxColumnWidth : 0;
unitW = unitW > stackedChart.MaxColumnWidth ? stackedChart.MaxColumnWidth : unitW;
var pointPadding = .1 * unitW;
const int seriesPadding = 2;
var h = unitW - 2 * pointPadding;
var f = Chart.GetFormatter(Chart.Invert ? Chart.AxisX : Chart.AxisY);
foreach (var point in Values.Points)
{
var t = new TranslateTransform();
var helper = stackedChart.IndexTotals[(int) point.Y];
var w = ToPlotArea(helper.Total, AxisTags.X) - ToPlotArea(Chart.Min.X, AxisTags.X);
var rh = w * (point.X / helper.Total);
if (double.IsNaN(rh)) return;
var stackedW = w * (helper.Stacked.ContainsKey(serieIndex) ? (helper.Stacked[serieIndex].Stacked / helper.Total) : 0);
var r = new Rectangle
{
StrokeThickness = StrokeThickness,
Stroke = Stroke,
Fill = Fill,
Width = 0,
Height = Math.Max(0, h - seriesPadding),
RenderTransform = t
};
var hr = new Rectangle
{
StrokeThickness = 0,
Fill = Brushes.Transparent,
Width = rh,
Height = Math.Max(0, h - seriesPadding)
};
Canvas.SetTop(r, ToPlotArea(point.Y, AxisTags.Y) + pointPadding + overflow / 2);
Canvas.SetTop(hr, ToPlotArea(point.Y, AxisTags.Y) + pointPadding + overflow / 2);
Canvas.SetLeft(hr, ToPlotArea(Chart.Min.X, AxisTags.X) + stackedW);
Panel.SetZIndex(hr, int.MaxValue);
Chart.Canvas.Children.Add(r);
Chart.Canvas.Children.Add(hr);
Shapes.Add(r);
Shapes.Add(hr);
var hAnim = new DoubleAnimation
{
To = rh,
Duration = TimeSpan.FromMilliseconds(500)
};
var rAnim = new DoubleAnimation
{
From = ToPlotArea(Chart.Min.X, AxisTags.X),
To = ToPlotArea(Chart.Min.X, AxisTags.X) + stackedW,
Duration = TimeSpan.FromMilliseconds(500)
};
if (DataLabels)
{
var tb = BuildATextBlock(0);
var te = f(Chart.Invert ? point.X : point.Y);
var ft = new FormattedText(
te,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize, Brushes.Black);
tb.Text = te;
Chart.Canvas.Children.Add(tb);
Chart.Shapes.Add(tb);
Canvas.SetLeft(tb, Canvas.GetLeft(hr) + hr.Width*.5 - ft.Width*.5);
Canvas.SetTop(tb, Canvas.GetTop(hr) + hr.Height*.5 - ft.Height*.5);
}
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
r.BeginAnimation(WidthProperty, hAnim);
t.BeginAnimation(TranslateTransform.XProperty, rAnim);
animated = true;
}
}
if (!animated)
{
r.Width = rh;
if (rAnim.To != null) t.X = (double)rAnim.To;
}
hr.MouseDown += Chart.DataMouseDown;
//.........这里部分代码省略.........
示例6: Plot
public override void Plot(bool animate = true)
{
var chart = Chart as IStackedBar;
if (chart == null) return;
var stackedSeries = Chart.Series.OfType<StackedBarSeries>().ToList();
var serieIndex = stackedSeries.IndexOf(this);
var unitW = ToPlotArea(1, AxisTags.X) - Chart.PlotArea.X + 5;
var overflow = unitW - chart.MaxColumnWidth > 0 ? unitW - chart.MaxColumnWidth : 0;
unitW = unitW > chart.MaxColumnWidth ? chart.MaxColumnWidth : unitW;
var pointPadding = .1 * unitW;
const int seriesPadding = 2;
var barW = unitW - 2 * pointPadding;
foreach (var point in Values.Points)
{
var t = new TranslateTransform();
var helper = chart.IndexTotals[(int) point.X];
var barH = ToPlotArea(Chart.Min.Y, AxisTags.Y) - ToPlotArea(helper.Total, AxisTags.Y);
var rh = barH * (point.Y / helper.Total);
if (double.IsNaN(rh)) return;
var stackedH = barH * (helper.Stacked.ContainsKey(serieIndex) ? (helper.Stacked[serieIndex].Stacked / helper.Total) : 0);
var r = new Rectangle
{
StrokeThickness = StrokeThickness,
Stroke = Stroke,
Fill = Fill,
Width = Math.Max(0, barW - seriesPadding),
Height = 0,
RenderTransform = t
};
var hr = new Rectangle
{
StrokeThickness = 0,
Fill = Brushes.Transparent,
Width = Math.Max(0, barW - seriesPadding),
Height = rh
};
Canvas.SetLeft(r, ToPlotArea(point.X, AxisTags.X) + pointPadding + overflow / 2);
Canvas.SetLeft(hr, ToPlotArea(point.X, AxisTags.X) + pointPadding + overflow / 2);
Canvas.SetTop(hr, ToPlotArea(Chart.Min.Y, AxisTags.Y) - rh - stackedH);
Panel.SetZIndex(hr, int.MaxValue);
Chart.Canvas.Children.Add(r);
Chart.Canvas.Children.Add(hr);
Shapes.Add(r);
Shapes.Add(hr);
var hAnim = new DoubleAnimation
{
To = rh,
Duration = TimeSpan.FromMilliseconds(500)
};
var rAnim = new DoubleAnimation
{
From = ToPlotArea(Chart.Min.Y, AxisTags.Y),
To = ToPlotArea(Chart.Min.Y, AxisTags.Y) - rh - stackedH,
Duration = TimeSpan.FromMilliseconds(500)
};
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
r.BeginAnimation(HeightProperty, hAnim);
t.BeginAnimation(TranslateTransform.YProperty, rAnim);
animated = true;
}
}
if (!animated)
{
r.Height = rh;
if (rAnim.To != null) t.Y = (double)rAnim.To;
}
if (!Chart.Hoverable) continue;
hr.MouseEnter += Chart.DataMouseEnter;
hr.MouseLeave += Chart.DataMouseLeave;
Chart.HoverableShapes.Add(new HoverableShape
{
Series = this,
Shape = hr,
Target = r,
Value = point
});
}
}
示例7: PlotRows
private void PlotRows(bool animate)
{
var chart = Chart as IBar;
if (chart == null) return;
var barSeries = Chart.Series.OfType<BarSeries>().ToList();
var pos = barSeries.IndexOf(this);
var count = barSeries.Count;
var unitW = ToPlotArea(Chart.Max.Y - 1, AxisTags.Y) - Chart.PlotArea.Y + 5;
var overflow = unitW - chart.MaxColumnWidth * 3 > 0 ? unitW - chart.MaxColumnWidth * 3 : 0;
unitW = unitW > chart.MaxColumnWidth * 3 ? chart.MaxColumnWidth * 3 : unitW;
var pointPadding = .1 * unitW;
const int seriesPadding = 2;
var barW = (unitW - 2 * pointPadding) / count;
var bothLimitsPositive = Chart.Max.X > 0 && Chart.Min.X > 0 - Chart.S.X * .01;
var bothLimitsNegative = Chart.Max.X < 0 + Chart.S.X * .01 && Chart.Min.X < 0;
foreach (var point in Values.Points)
{
var t = new TranslateTransform();
var r = new Rectangle
{
StrokeThickness = StrokeThickness,
Stroke = Stroke,
Fill = Fill,
Width = 0,
Height = Math.Max(0, barW - seriesPadding),
RenderTransform = t
};
var barStart = bothLimitsPositive
? Chart.Min.X
: (bothLimitsNegative ? Chart.Max.X : 0);
var direction = point.X > 0 ? 1 : -1;
var rw = bothLimitsNegative
? ToPlotArea(point.X, AxisTags.X)
: ToPlotArea(point.X*direction, AxisTags.X) - ToPlotArea(barStart, AxisTags.X);
var hr = new Rectangle
{
Fill = Brushes.Transparent,
StrokeThickness = 0,
Width = rw,
Height = Math.Max(0, barW - seriesPadding)
};
Canvas.SetTop(r, ToPlotArea(point.Y, AxisTags.Y) + barW * pos + pointPadding + overflow / 2);
Canvas.SetTop(hr, ToPlotArea(point.Y, AxisTags.Y) + barW * pos + pointPadding + overflow / 2);
var l = direction > 0 ? ToPlotArea(barStart, AxisTags.X) : ToPlotArea(barStart, AxisTags.X) - rw;
Canvas.SetLeft(hr, l);
Panel.SetZIndex(hr, int.MaxValue);
Chart.Canvas.Children.Add(r);
Chart.Canvas.Children.Add(hr);
Shapes.Add(r);
Shapes.Add(hr);
var hAnim = new DoubleAnimation
{
To = rw,
Duration = TimeSpan.FromMilliseconds(500)
};
var rAnim = new DoubleAnimation
{
From = ToPlotArea(barStart, AxisTags.X),
To = l,
Duration = TimeSpan.FromMilliseconds(500)
};
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
r.BeginAnimation(WidthProperty, hAnim);
t.BeginAnimation(TranslateTransform.XProperty, rAnim);
animated = true;
}
}
if (!animated)
{
r.Width = rw;
t.X = l;
}
hr.MouseDown += Chart.DataMouseDown;
hr.MouseEnter += Chart.DataMouseEnter;
hr.MouseLeave += Chart.DataMouseLeave;
Chart.HoverableShapes.Add(new HoverableShape
{
Series = this,
Shape = hr,
Target = r,
Value = point
//.........这里部分代码省略.........
示例8: SetGridBar
/// <summary>
/// Sets the grid's percentage bar
/// </summary>
/// <param name="strataValue">
/// The strata value to which this grid cell belongs; used to search the list of grids and
/// return the proper System.Windows.Controls.Grid for text insertion.
/// </param>
/// <param name="rowNumber">The row number of the grid to add the bar to</param>
/// <param name="pct">The percentage width of the bar</param>
private void SetGridBar(string strataValue, int rowNumber, double pct)
{
Grid grid = GetStrataGrid(strataValue);
Rectangle rctBar = new Rectangle();
rctBar.Width = 0.1;// pct * 100.0;
rctBar.Fill = this.Resources["frequencyPercentBarBrush"] as SolidColorBrush;
rctBar.HorizontalAlignment = HorizontalAlignment.Left;
rctBar.Margin = new Thickness(2,6,2,6); //.HorizontalAlignment = HorizontalAlignment.Left;
Grid.SetRow(rctBar, rowNumber);
Grid.SetColumn(rctBar, /*4*/6);
grid.Children.Add(rctBar);
int maxWidth = 100;
int.TryParse(txtBarWidth.Text, out maxWidth);
DoubleAnimation daBar = new DoubleAnimation();
daBar.From = 1;
daBar.To = pct * maxWidth;//100.0;
daBar.Duration = new Duration(TimeSpan.FromSeconds(0.5));
rctBar.BeginAnimation(Rectangle.WidthProperty, daBar);
if (cmbPercentBarMode.SelectedIndex > 0)
{
TextBlock tb = new TextBlock();
tb.Margin = new Thickness(pct * maxWidth + 5, 0, 0, 0);
tb.Foreground = this.Resources["cellForeground"] as SolidColorBrush;
tb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
tb.Text = pct.ToString("P0");
Grid.SetRow(tb, rowNumber);
Grid.SetColumn(tb, 6);
grid.Children.Add(tb);
}
}
示例9: RenderFrequencyFooter
//.........这里部分代码省略.........
grid.RowDefinitions.Add(rowDefTotals);
if (checkboxDrawFooter.IsChecked == false)
{
rowDefTotals.Height = new GridLength(0);
return;
}
TextBlock txtValTotals = new TextBlock();
txtValTotals.Text = SharedStrings.TOTAL;
txtValTotals.Margin = new Thickness(4, 0, 4, 0);
txtValTotals.VerticalAlignment = VerticalAlignment.Center;
txtValTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtValTotals, footerRowIndex);
Grid.SetColumn(txtValTotals, 0);
grid.Children.Add(txtValTotals);
TextBlock txtFreqTotals = new TextBlock();
txtFreqTotals.Text = totalRows.ToString();
txtFreqTotals.Margin = new Thickness(4, 0, 4, 0);
txtFreqTotals.VerticalAlignment = VerticalAlignment.Center;
txtFreqTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtFreqTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtFreqTotals, footerRowIndex);
Grid.SetColumn(txtFreqTotals, 1);
grid.Children.Add(txtFreqTotals);
TextBlock txtPctTotals = new TextBlock();
txtPctTotals.Text = (1).ToString("P");//SharedStrings.DASHBOARD_100_PERCENT_LABEL;
txtPctTotals.Margin = new Thickness(4, 0, 4, 0);
txtPctTotals.VerticalAlignment = VerticalAlignment.Center;
txtPctTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtPctTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtPctTotals, footerRowIndex);
Grid.SetColumn(txtPctTotals, 2);
grid.Children.Add(txtPctTotals);
TextBlock txtAccuTotals = new TextBlock();
txtAccuTotals.Text = (1).ToString("P");
txtAccuTotals.Margin = new Thickness(4, 0, 4, 0);
txtAccuTotals.VerticalAlignment = VerticalAlignment.Center;
txtAccuTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtAccuTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtAccuTotals, footerRowIndex);
Grid.SetColumn(txtAccuTotals, 3);
grid.Children.Add(txtAccuTotals);
TextBlock txtCILowerTotals = new TextBlock();
txtCILowerTotals.Text = StringLiterals.SPACE + StringLiterals.SPACE + StringLiterals.SPACE;
txtCILowerTotals.Margin = new Thickness(4, 0, 4, 0);
txtCILowerTotals.VerticalAlignment = VerticalAlignment.Center;
txtCILowerTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtCILowerTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtCILowerTotals, footerRowIndex);
Grid.SetColumn(txtCILowerTotals, 4);
grid.Children.Add(txtCILowerTotals);
TextBlock txtUpperTotals = new TextBlock();
txtUpperTotals.Text = StringLiterals.SPACE + StringLiterals.SPACE + StringLiterals.SPACE;
txtUpperTotals.Margin = new Thickness(4, 0, 4, 0);
txtUpperTotals.VerticalAlignment = VerticalAlignment.Center;
txtUpperTotals.HorizontalAlignment = HorizontalAlignment.Right;
txtUpperTotals.FontWeight = FontWeights.Bold;
Grid.SetRow(txtUpperTotals, footerRowIndex);
Grid.SetColumn(txtUpperTotals, 5);
grid.Children.Add(txtUpperTotals);
Rectangle rctTotalsBar = new Rectangle();
rctTotalsBar.Width = 0.1;// 100;
rctTotalsBar.Fill = this.Resources["frequencyPercentBarBrush"] as SolidColorBrush;
rctTotalsBar.Margin = new Thickness(2, 6, 2, 6);
rctTotalsBar.HorizontalAlignment = HorizontalAlignment.Left;
Grid.SetRow(rctTotalsBar, footerRowIndex);
Grid.SetColumn(rctTotalsBar, 6);
grid.Children.Add(rctTotalsBar);
DoubleAnimation daBar = new DoubleAnimation();
daBar.From = 1;
int maxWidth = 100;
int.TryParse(txtBarWidth.Text, out maxWidth);
daBar.To = maxWidth;
daBar.Duration = new Duration(TimeSpan.FromSeconds(0.5));
rctTotalsBar.BeginAnimation(Rectangle.WidthProperty, daBar);
if (cmbPercentBarMode.SelectedIndex > 0)
{
TextBlock tb = new TextBlock();
tb.Margin = new Thickness(maxWidth + 5, 0, 0, 0);
tb.Foreground = this.Resources["cellForeground"] as SolidColorBrush;
tb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
tb.Text = 1.ToString("P0");
Grid.SetRow(tb, footerRowIndex);
Grid.SetColumn(tb, 6);
grid.Children.Add(tb);
}
}
示例10: PlotColumns
private void PlotColumns(bool animate)
{
var chart = Chart as IBar;
if (chart == null) return;
var barSeries = Chart.Series.OfType<BarSeries>().ToList();
var pos = barSeries.IndexOf(this);
var count = barSeries.Count;
var unitW = ToPlotArea(1, AxisTags.X) - Chart.PlotArea.X + 5;
var overflow = unitW - chart.MaxColumnWidth * 3 > 0 ? unitW - chart.MaxColumnWidth * 3 : 0;
unitW = unitW > chart.MaxColumnWidth * 3 ? chart.MaxColumnWidth * 3 : unitW;
var pointPadding = .1 * unitW;
const int seriesPadding = 2;
var barW = (unitW - 2 * pointPadding) / count;
var bothLimitsPositive = Chart.Max.Y > 0 && Chart.Min.Y > 0 - Chart.S.Y * .01;
var bothLimitsNegative = Chart.Max.Y < 0 + Chart.S.Y * .01 && Chart.Min.Y < 0;
var f = Chart.GetFormatter(Chart.Invert ? Chart.AxisX : Chart.AxisY);
foreach (var point in Values.Points)
{
var t = new TranslateTransform();
var r = new Rectangle
{
StrokeThickness = StrokeThickness,
Stroke = Stroke,
Fill = Fill,
Width = Math.Max(0, barW - seriesPadding),
Height = 0,
RenderTransform = t
};
var barStart = bothLimitsPositive
? Chart.Min.Y
: (bothLimitsNegative ? Chart.Max.Y : 0);
var direction = point.Y > 0 ? 1 : -1;
var rh = bothLimitsNegative
? ToPlotArea(point.Y, AxisTags.Y)
: ToPlotArea(barStart, AxisTags.Y) - ToPlotArea(point.Y * direction, AxisTags.Y);
var hr = new Rectangle
{
Fill = Brushes.Transparent,
StrokeThickness = 0,
Width = Math.Max(0, barW - seriesPadding),
Height = rh
};
Canvas.SetLeft(r, ToPlotArea(point.X, AxisTags.X) + barW * pos + pointPadding + overflow / 2);
Canvas.SetLeft(hr, ToPlotArea(point.X, AxisTags.X) + barW * pos + pointPadding + overflow / 2);
var h = direction > 0 ? ToPlotArea(barStart, AxisTags.Y) - rh : ToPlotArea(barStart, AxisTags.Y);
Canvas.SetTop(hr, h);
Panel.SetZIndex(hr, int.MaxValue);
Chart.Canvas.Children.Add(r);
Chart.Canvas.Children.Add(hr);
Shapes.Add(r);
Shapes.Add(hr);
if (DataLabels)
{
var tb = BuildATextBlock(0);
var te = f(Chart.Invert ? point.X : point.Y);
var ft = new FormattedText(
te,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize, Brushes.Black);
tb.Text = te;
Chart.Canvas.Children.Add(tb);
Chart.Shapes.Add(tb);
Canvas.SetLeft(tb, Canvas.GetLeft(hr) + hr.Width*.5 - ft.Width*.5);
Canvas.SetTop(tb, direction > 0 ? Canvas.GetTop(hr) - ft.Height - 5 : Canvas.GetTop(hr) + hr.Height + 5);
}
var hAnim = new DoubleAnimation
{
To = rh,
Duration = TimeSpan.FromMilliseconds(500)
};
var rAnim = new DoubleAnimation
{
From = ToPlotArea(barStart, AxisTags.Y),
To = h,
Duration = TimeSpan.FromMilliseconds(500)
};
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
r.BeginAnimation(HeightProperty, hAnim);
t.BeginAnimation(TranslateTransform.YProperty, rAnim);
animated = true;
}
}
//.........这里部分代码省略.........
示例11: Plot
public override void Plot(bool animate = true)
{
var chart = Chart as BarChart;
if (chart == null) return;
var xCount = 0;
var pos = Chart.Series.IndexOf(this);
var count = Chart.Series.Count;
var unitW = ToPlotArea(1, AxisTags.X) - Chart.PlotArea.X + 5;
var overflow = unitW - chart.MaxColumnWidth*3 > 0 ? unitW - chart.MaxColumnWidth*3 : 0;
unitW = unitW > chart.MaxColumnWidth*3 ? chart.MaxColumnWidth*3 : unitW;
var pointPadding = .1*unitW;
const int seriesPadding = 2;
var barW = (unitW - 2*pointPadding)/count;
foreach (var d in PrimaryValues)
{
xCount ++;
var point = new Point(xCount -1, d);
var t = new TranslateTransform();
var r = new Rectangle
{
StrokeThickness = StrokeThickness,
Stroke = new SolidColorBrush{Color = Color},
Fill = new SolidColorBrush { Color = Color, Opacity = .8},
Width = barW - seriesPadding,
Height = 0,
RenderTransform = t
};
var rh = ToPlotArea(Chart.Min.Y, AxisTags.Y) - ToPlotArea(point.Y, AxisTags.Y);
Canvas.SetLeft(r, ToPlotArea(point.X, AxisTags.X) + barW*pos + pointPadding + overflow/2);
Chart.Canvas.Children.Add(r);
Shapes.Add(r);
var hAnim = new DoubleAnimation
{
To = rh,
Duration = TimeSpan.FromMilliseconds(300)
};
var rAnim = new DoubleAnimation
{
From = ToPlotArea(Chart.Min.Y, AxisTags.Y),
To = ToPlotArea(Chart.Min.Y, AxisTags.Y) - rh,
Duration = TimeSpan.FromMilliseconds(300)
};
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
r.BeginAnimation(FrameworkElement.HeightProperty, hAnim);
t.BeginAnimation(TranslateTransform.YProperty, rAnim);
animated = true;
}
}
if (!animated)
{
r.Height = rh;
t.Y = ToPlotArea(Chart.Min.Y, AxisTags.Y) - rh;
}
if (!Chart.Hoverable) continue;
r.MouseEnter += Chart.OnDataMouseEnter;
r.MouseLeave += Chart.OnDataMouseLeave;
Chart.HoverableShapes.Add(new HoverableShape
{
Serie = this,
Shape = r,
Target = r,
Value = point
});
}
}
示例12: Plot
public override void Plot(bool animate = true)
{
var chart = Chart as IBar;
if (chart == null) return;
var barSeries = Chart.Series.OfType<BarSeries>().ToList();
var pos = barSeries.IndexOf(this);
var count = barSeries.Count;
var unitW = ToPlotArea(1, AxisTags.X) - Chart.PlotArea.X + 5;
var overflow = unitW - chart.MaxColumnWidth*3 > 0 ? unitW - chart.MaxColumnWidth*3 : 0;
unitW = unitW > chart.MaxColumnWidth*3 ? chart.MaxColumnWidth*3 : unitW;
var pointPadding = .1*unitW;
const int seriesPadding = 2;
var barW = (unitW - 2*pointPadding)/count;
foreach (var point in ChartPoints)
{
var t = new TranslateTransform();
var r = new Rectangle
{
StrokeThickness = StrokeThickness,
Stroke = Stroke,
Fill = Fill,
Width = Math.Max(0, barW - seriesPadding),
Height = 0,
RenderTransform = t
};
var rh = ToPlotArea(Chart.Min.Y, AxisTags.Y) - ToPlotArea(point.Y, AxisTags.Y);
var hr = new Rectangle
{
Fill = Brushes.Transparent,
StrokeThickness = 0,
Width = Width = Math.Max(0, barW - seriesPadding),
Height = rh
};
Canvas.SetLeft(r, ToPlotArea(point.X, AxisTags.X) + barW*pos + pointPadding + overflow/2);
Canvas.SetLeft(hr, ToPlotArea(point.X, AxisTags.X) + barW * pos + pointPadding + overflow / 2);
Canvas.SetTop(hr, ToPlotArea(Chart.Min.Y, AxisTags.Y) - rh);
Panel.SetZIndex(hr, int.MaxValue);
Chart.Canvas.Children.Add(r);
Chart.Canvas.Children.Add(hr);
Shapes.Add(r);
Shapes.Add(hr);
var hAnim = new DoubleAnimation
{
To = rh,
Duration = TimeSpan.FromMilliseconds(300)
};
var rAnim = new DoubleAnimation
{
From = ToPlotArea(Chart.Min.Y, AxisTags.Y),
To = ToPlotArea(Chart.Min.Y, AxisTags.Y) - rh,
Duration = TimeSpan.FromMilliseconds(300)
};
var animated = false;
if (!Chart.DisableAnimation)
{
if (animate)
{
r.BeginAnimation(HeightProperty, hAnim);
t.BeginAnimation(TranslateTransform.YProperty, rAnim);
animated = true;
}
}
if (!animated)
{
r.Height = rh;
t.Y = ToPlotArea(Chart.Min.Y, AxisTags.Y) - rh;
}
if (!Chart.Hoverable) continue;
hr.MouseEnter += Chart.DataMouseEnter;
hr.MouseLeave += Chart.DataMouseLeave;
Chart.HoverableShapes.Add(new HoverableShape
{
Series = this,
Shape = hr,
Target = r,
Value = point
});
}
}