public AxisLineFormatGroup(IStreamReader reader) { // *4(AxisLine LineFormat) this.AxisLine = (AxisLine)BiffRecord.ReadRecord(reader); this.LineFormat = (LineFormat)BiffRecord.ReadRecord(reader); }
public AxisLine AxisLine() { if (axisLine == null) { axisLine = new AxisLine(); } return(axisLine); }
/// <summary> /// Updates this instance. /// </summary> internal void Update() { double desiredWidth = 0; CalculateAutoInterval(); GenerateLabels(); if (this.ActualHeight > 0 && this.ActualWidth > 0) { double yAxisHeightStep = this.ActualHeight / ((MIntervalCount > 0) ? MIntervalCount : 1); double yAxisHeightPosition = 0; Rect oldRect = new Rect(0, 0, 0, 0); AxisLine.X1 = this.ActualWidth; AxisLine.X2 = this.ActualWidth; AxisLine.Y1 = 0; AxisLine.Y2 = this.ActualHeight; Binding binding = new Binding(); binding.Path = new PropertyPath("AxisLineStyle"); binding.Source = this; AxisLine.SetBinding(Line.StyleProperty, binding); double labelSize = 0; int minorCount = 0; if (this.MLabels.Count == Labels.Count) { for (int i = this.MLabels.Count - 1; i >= 0; i--) { yAxisHeightPosition = this.DataToPoint(MLabelValues[i]); ContentControl label = Labels[i]; label.Content = MLabels[i]; label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); label.RenderTransform = labelRotation; Line tickLine = MajorTickLines[i]; double labelPadding = 0; tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); //tickLine.X1 = this.ActualWidth; tickLine.Y1 = yAxisHeightPosition; tickLine.Y2 = yAxisHeightPosition; //tickLine.X2 = tickLine.X1 - MajorLineSize; switch (MajorTicksPosition) { case TickPosition.Inside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 + MajorLineSize; if (this.ShowMajorTicks) { labelPadding = 0; desiredWidth = 0; } break; case TickPosition.Cross: tickLine.X1 = this.ActualWidth - (MajorLineSize / 2); tickLine.X2 = this.ActualWidth + (MajorLineSize / 2); if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize / 2; } break; case TickPosition.Outside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 - MajorLineSize; if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize; } break; default: break; } //desiredWidth = 0; if (i != 0) { double minorWidth = yAxisHeightStep; double minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = MinorTickLines[minorCount]; minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1)); minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1)); //minorLine.X1 = this.ActualWidth - (minorLine.StrokeThickness); // minorLine.X2 = minorLine.X1 - MinorLineSize; switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 + MinorLineSize; break; case TickPosition.Cross: minorLine.X1 = this.ActualWidth - (MinorLineSize / 2); minorLine.X2 = this.ActualWidth + (MinorLineSize / 2); break; case TickPosition.Outside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 - MinorLineSize; break; default: break; } minorCount++; } } if (this.LabelAngle == 0) { Canvas.SetLeft(label, this.ActualWidth - (label.DesiredSize.Width) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (label.DesiredSize.Height / 2)); labelSize = Math.Max(labelSize, label.DesiredSize.Width); } else { Canvas.SetLeft(label, this.ActualWidth - (rotatedRect.Width) - rotatedRect.X - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (rotatedRect.Height / 2) - rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Width); } } } else { if (this.MLabels.Count > Labels.Count) { int offset = this.MLabels.Count - Labels.Count; for (int j = 0; j < offset; j++) { ContentControl label = new ContentControl(); label.Content = MLabels[this.MLabels.Count - offset - 1]; //label.ContentTemplate = this.LabelTemplate; Binding labelTemplateBinding = new Binding(); labelTemplateBinding.Path = new PropertyPath("LabelTemplate"); labelTemplateBinding.Source = this; label.SetBinding(ContentControl.ContentTemplateProperty, labelTemplateBinding); label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); label.RenderTransform = labelRotation; Labels.Add(label); Line tickLine = new Line(); Binding styleBinding = new Binding(); styleBinding.Path = new PropertyPath("MajorLineStyle"); styleBinding.Source = this; tickLine.SetBinding(Line.StyleProperty, styleBinding); tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); tickLine.Y1 = yAxisHeightPosition; tickLine.Y2 = yAxisHeightPosition; //tickLine.X2 = tickLine.X1 - MajorLineSize; switch (MajorTicksPosition) { case TickPosition.Inside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 + MajorLineSize; break; case TickPosition.Cross: tickLine.X1 = this.ActualWidth - (MajorLineSize / 2); tickLine.X2 = this.ActualWidth + (MajorLineSize / 2); break; case TickPosition.Outside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 - MajorLineSize; break; default: break; } //Binding tickSizeBinding = new Binding(); //tickSizeBinding.Path = new PropertyPath("MajorLineSize"); //tickSizeBinding.Source = this; //tickSizeBinding.Converter = new MajorSizeThicknessConverter(); //tickSizeBinding.ConverterParameter = tickLine.X1; //tickLine.SetBinding(Line.X2Property, tickSizeBinding); Binding ticklineVisibilityBinding = new Binding(); ticklineVisibilityBinding.Path = new PropertyPath("ShowMajorTicks"); ticklineVisibilityBinding.Source = this; ticklineVisibilityBinding.Converter = new BooleanToVisibilityConverter(); tickLine.SetBinding(Line.VisibilityProperty, ticklineVisibilityBinding); double minorWidth = yAxisHeightStep; double minorstep = minorWidth / (MinorTicksCount + 1); for (int k = 0; k < this.MinorTicksCount; j++) { Line minorLine = new Line(); Binding minorstyleBinding = new Binding(); minorstyleBinding.Path = new PropertyPath("MinorLineStyle"); minorstyleBinding.Source = this; minorLine.SetBinding(Line.StyleProperty, minorstyleBinding); minorLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1)); minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1)); switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 + MinorLineSize; break; case TickPosition.Cross: minorLine.X1 = this.ActualWidth - (MinorLineSize / 2); minorLine.X2 = this.ActualWidth + (MinorLineSize / 2); break; case TickPosition.Outside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 - MinorLineSize; break; default: break; } MinorTickLines.Add(minorLine); this.Children.Add(minorLine); } this.Children.Add(label); MajorTickLines.Add(tickLine); this.Children.Add(tickLine); } } else { int offset = Labels.Count - this.MLabels.Count; for (int j = 0; j < offset; j++) { this.Children.Remove(Labels[Labels.Count - 1]); Labels.RemoveAt(Labels.Count - 1); for (int k = 0; k < this.MinorTicksCount; k++) { this.Children.Remove(MinorTickLines[MinorTickLines.Count - 1]); MinorTickLines.RemoveAt(MinorTickLines.Count - 1); } this.Children.Remove(MajorTickLines[MajorTickLines.Count - 1]); MajorTickLines.RemoveAt(MajorTickLines.Count - 1); } } for (int i = this.MLabels.Count - 1; i >= 0; i--) { ContentControl label = Labels[i]; label.Content = MLabels[i]; label.Measure(new Size(this.ActualHeight, this.ActualWidth)); RotateTransform labelRotation = new RotateTransform(); labelRotation.Angle = LabelAngle; Rect rotatedRect = GetRotatedRect(new Rect(0, 0, label.DesiredSize.Width, label.DesiredSize.Height), labelRotation); label.RenderTransform = labelRotation; Line tickLine = MajorTickLines[i]; double labelPadding = 0; tickLine.Y1 = yAxisHeightPosition; tickLine.Y2 = yAxisHeightPosition; switch (MajorTicksPosition) { case TickPosition.Inside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 + MajorLineSize; if (this.ShowMajorTicks) { labelPadding = 0; desiredWidth = 0; } break; case TickPosition.Cross: tickLine.X1 = this.ActualWidth - (MajorLineSize / 2); tickLine.X2 = this.ActualWidth + (MajorLineSize / 2); if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize / 2; } break; case TickPosition.Outside: tickLine.X1 = this.ActualWidth; tickLine.X2 = tickLine.X1 - MajorLineSize; if (this.ShowMajorTicks) { labelPadding = tickLine.X2; desiredWidth = this.MajorLineSize; } break; default: break; } tickLine.Measure(new Size(this.ActualHeight, this.ActualWidth)); //desiredWidth = 0; double minorstep = 0; if (!(i == 0)) { double minorWidth = yAxisHeightStep; minorstep = minorWidth / (MinorTicksCount + 1); for (int j = 0; j < this.MinorTicksCount; j++) { Line minorLine = MinorTickLines[minorCount]; minorLine.Y1 = (yAxisHeightPosition + minorstep * (j + 1)); minorLine.Y2 = (yAxisHeightPosition + minorstep * (j + 1)); //minorLine.X1 = this.ActualWidth - (minorLine.StrokeThickness); //minorLine.X2 = minorLine.X1 - MinorLineSize; switch (MinorTicksPosition) { case TickPosition.Inside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 + MinorLineSize; break; case TickPosition.Cross: minorLine.X1 = this.ActualWidth - (MinorLineSize / 2); minorLine.X2 = this.ActualWidth + (MinorLineSize / 2); break; case TickPosition.Outside: minorLine.X1 = this.ActualWidth; minorLine.X2 = minorLine.X1 - MinorLineSize; break; default: break; } minorCount++; } } if (this.LabelAngle == 0) { Canvas.SetLeft(label, this.ActualWidth - (label.DesiredSize.Width) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (label.DesiredSize.Height / 2)); labelSize = Math.Max(labelSize, label.DesiredSize.Width); } else { Canvas.SetLeft(label, this.ActualWidth - (rotatedRect.Width - rotatedRect.X) - desiredWidth - 1); Canvas.SetTop(label, yAxisHeightPosition - (rotatedRect.Height / 2) - rotatedRect.Y); labelSize = Math.Max(labelSize, rotatedRect.Width); } yAxisHeightPosition += yAxisHeightStep; //desiredWidth = desiredWidth + labelSize; } } header.Measure(new Size(this.ActualHeight, this.ActualWidth)); Canvas.SetLeft(header, this.ActualWidth - labelSize - header.DesiredSize.Height - this.MajorLineSize - 1); Canvas.SetTop(header, this.ActualHeight / 2); desiredWidth = desiredWidth + header.DesiredSize.Height + labelSize; } if (this.Chart.AxisWidth < desiredWidth) { this.Chart.AxisWidth = desiredWidth + 1; } }
public void Update(Boolean useTransition) { if (Equal(previousScale, Scale)) { UpdateWithSameScale(useTransition); return; } AxisLine.SetValue(linePrimary1, Scale.RangeStart); AxisLine.SetValue(linePrimary2, Scale.RangeEnd); AxisLine.SetValue(lineSecondary1, 0); AxisLine.SetValue(lineSecondary2, 0); List <TextBlock> previousTickLabels = tickLabels; List <Line> previousTickMarkers = tickMarkers; Int32 tickCount = Scale.TickCount; Storyboard axisStoryboard = new Storyboard() { //BeginTime = Const.AnimationDelay }; #region remove previous ticks if (previousTickLabels != null) { if (useTransition) { Int32 index = 0; List <Tick> ticks = previousScale.GetTicks(); foreach (TextBlock tickLabel in previousTickLabels) { Tick tick = ticks[index]; Line tickMarker = previousTickMarkers[index]; if (previousScale.GetType() == Scale.GetType() && !(Scale is Ordinal)) // 같고 ordinal이 아니어야 (linear)야 position animation 가능 { // text block animation axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickLabel, canvasPrimaryString, Scale.ClampedMap(tick.DomainValue) - (Double)tickLabel.GetValue(tickLabelSizeProperty) / 2) ); // tick marker animation 1 & 2 (for two Xs or Ys) axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickMarker, linePrimary1String, Scale.ClampedMap(tick.DomainValue), true) ); axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickMarker, linePrimary2String, Scale.ClampedMap(tick.DomainValue), true) ); } // make text block opacity 0 axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickLabel, "Opacity", 0) ); // make tick marker opacity 0 axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickMarker, "Opacity", 0) ); tickLabel.SetValue(canvasSecondary, Orientation == Orientations.Horizontal ? (24 - tickLabel.ActualHeight) / 2 : -tickLabel.ActualWidth - 10); index++; } } else { foreach (TextBlock tickLabel in previousTickLabels) { AxisCanvas.Children.Remove(tickLabel); } foreach (Line tickMarker in previousTickMarkers) { AxisCanvas.Children.Remove(tickMarker); } } } #endregion #region add new ticks tickLabels = new List <TextBlock>(); tickMarkers = new List <Line>(); var currentTicks = Scale.GetTicks(); foreach (Tick tick in currentTicks) { TextBlock tickLabel = new TextBlock() { Text = tick.Label, Style = Resources["TickLabelStyle"] as Style, Opacity = 0 }; Line tickMarker = new Line() { Style = Resources["TickMarkerStyle"] as Style, Opacity = 0 }; AxisCanvas.Children.Add(tickLabel); tickLabel.Measure(new Size(Double.MaxValue, Double.MaxValue)); if (Orientation == Orientations.Vertical) { if (tickLabel.ActualWidth > 28) { tickLabel.FontSize = tickLabel.FontSize * 28 / tickLabel.ActualWidth; tickLabel.Measure(new Size(Double.MaxValue, Double.MaxValue)); } tickLabel.Height = tickLabel.ActualHeight; } else if (Orientation == Orientations.Horizontal) { tickLabel.MaxWidth = Math.Abs(Scale.RangeEnd - Scale.RangeStart) / currentTicks.Count; tickLabel.Measure(new Size(Double.MaxValue, Double.MaxValue)); //tickLabel.Width = tickLabel.ActualWidth; } tickLabel.SetValue(canvasPrimary, previousScale.ClampedMap(tick.DomainValue) - (Double)tickLabel.GetValue(tickLabelSizeProperty) / 2); tickLabel.SetValue(canvasSecondary, Orientation == Orientations.Horizontal ? (24 - tickLabel.ActualHeight) / 2 : -tickLabel.ActualWidth - 10); AxisCanvas.Children.Add(tickMarker); tickMarker.SetValue(linePrimary1, previousScale.ClampedMap(tick.DomainValue)); tickMarker.SetValue(linePrimary2, previousScale.ClampedMap(tick.DomainValue)); tickMarker.SetValue(lineSecondary1, 0); tickMarker.SetValue(lineSecondary2, Orientation == Orientations.Horizontal ? 3 : -3); if (!useTransition || (previousScale.GetType() != Scale.GetType() || Scale is Ordinal)) // position animation disabled because two scales have different types { tickLabel.SetValue(canvasPrimary, tick.RangeValue - (Double)tickLabel.GetValue(tickLabelSizeProperty) / 2); tickMarker.SetValue(linePrimary1, tick.RangeValue); tickMarker.SetValue(linePrimary2, tick.RangeValue); } else { axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickLabel, canvasPrimaryString, tick.RangeValue - (Double)tickLabel.GetValue(tickLabelSizeProperty) / 2) ); axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickMarker, linePrimary1String, tick.RangeValue, true) ); axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickMarker, linePrimary2String, tick.RangeValue, true) ); } if (useTransition) { axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickLabel, "Opacity", LabelOpacityGetter == null ? 1 : LabelOpacityGetter(tick.DomainValue, 0, tickLabel)) ); axisStoryboard.Children.Add( Util.GenerateDoubleAnimation(tickMarker, "Opacity", 1) ); } else { tickLabel.Opacity = LabelOpacityGetter == null ? 1 : LabelOpacityGetter(tick.DomainValue, 0, tickLabel); tickMarker.Opacity = 1; } tickLabels.Add(tickLabel); tickMarkers.Add(tickMarker); } #endregion axisStoryboard.Completed += delegate { if (previousTickLabels != null) { foreach (TextBlock tickLabel in previousTickLabels) { AxisCanvas.Children.Remove(tickLabel); } foreach (Line tickMarker in previousTickMarkers) { AxisCanvas.Children.Remove(tickMarker); } } }; axisStoryboard.Begin(); previousScale = Scale.Clone(); }
public AxisLine AxisLine() { axisLine = new AxisLine(); return(axisLine); }
private void button1_Click(object sender, EventArgs e) { List <AxisLineParam> listAxisParam = new List <AxisLineParam>(); CanvasParam canvasparam = new CanvasParam(); Pen p = new Pen(Color.Blue, 1); BufferedGraphics myBuffer = currentContext.Allocate(panel1.CreateGraphics(), panel1.ClientRectangle); Graphics g = myBuffer.Graphics; g.Clear(this.BackColor); this.DoubleBuffered = true; canvasparam.ArrowLength = 6; canvasparam.g = g; canvasparam.OriginX = 43; canvasparam.OriginY = 355; canvasparam.VerticalLength = 350; canvasparam.HorizontalLength = 1000; canvasparam.BlankLegend = 30; canvasparam.ScaleLength = 5; canvasparam.ScalePadding = 0; AxisLineParam bHParam = new AxisLineParam(); bHParam.Direction = LineDirection.Horizontal; bHParam.MaxScale = 100000; bHParam.MinScale = 0; bHParam.CellScale = 10000; bHParam.showVirtualLine = ShowVirtualLine.Visible; bHParam.Caption = "时间(分)"; bHParam.Attributes = "Time"; BaseLine bH = new AxisLine(canvasparam, bHParam); bH.Draw(p); AxisLineParam bVParam = new AxisLineParam(); bVParam.Direction = LineDirection.Vertical; bVParam.showVirtualLine = ShowVirtualLine.Visible; bVParam.MaxScale = 40; bVParam.MinScale = -40; bVParam.CellScale = 10; bVParam.Caption = "温度/℃"; bVParam.Attributes = "Temp"; BaseLine bV = new AxisLine(canvasparam, bVParam); bV.Draw(p); AxisLineParam PowerParam = new AxisLineParam(); PowerParam.Direction = LineDirection.Vertical; PowerParam.showVirtualLine = ShowVirtualLine.Hide; PowerParam.lineLocation = LineLocation.Right; PowerParam.MaxScale = 500; PowerParam.MinScale = 0; PowerParam.CellScale = 100; PowerParam.Caption = "功率"; PowerParam.Attributes = "Power"; PowerParam.Index = 0; BaseLine bPower = new AxisLine(canvasparam, PowerParam); bPower.Draw(p); listAxisParam.Add(bVParam); listAxisParam.Add(bHParam); listAxisParam.Add(PowerParam); DataLine dl = new DataLine(canvasparam, listAxisParam, "Temp"); dl.lineWith = 2; dl.listData = CreateData(Convert.ToInt32(textBox1.Text)); dl.Draw(p); myBuffer.Render(); myBuffer.Dispose(); g.Dispose(); }
public void Dispose() { AxisLine?.Dispose(); AxisArrow?.Dispose(); AxisValueMarker?.Dispose(); }