| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918 |
- using MuchInfo.Chart.Data.EnumTypes;
- using MuchInfo.Chart.Data.Interfaces;
- using MuchInfo.Chart.Data.Models;
- using MuchInfo.Chart.Infrastructure.Data;
- using MuchInfo.Chart.Infrastructure.EventArgs;
- using MuchInfo.Chart.Infrastructure.Helpers;
- using MuchInfo.Chart.Infrastructure.Utilities;
- using MuchInfo.Chart.Utilities.Enums;
- using MuchInfo.Chart.WPF.Helpers;
- using MuchInfo.Chart.WPF.Primitives.Interfaces;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Shapes;
- namespace MuchInfo.Chart.WPF.Primitives
- {
- #region Delegates
- public delegate void PlotStyleChangedEventHandler();
- #endregion Delegates
- public class LinePlot : PlotBase
- {
- #region Fields
- protected Color mAreaFillColorDarkBG;
- protected Color mAreaFillColorLightBG;
- protected double mAreaFillOpacity;
- protected Color mPlotColorDarkBG;
- protected Color mPlotColorLightBG;
- protected Color mPlotNegColorDarkBG;
- protected Color mPlotNegColorLightBG;
- private readonly Color c_YestodayColor;
- private readonly Color c_TodayOpenColor;
- protected OutputDataWrapper mOutputData;
- //protected bool mPlotNegValsDiffColor;
- private DashStyleType _dashStyleType;
- private DoubleCollection _doubleCollection;
- private bool _isDark;
- private static Random _random = new Random(18000); // 没设置颜色时使用随机颜色,
- private double _lineThickness;
- #endregion Fields
- #region Constructors
- public LinePlot()
- {
- c_YestodayColor = Colors.Gold;
- c_TodayOpenColor = Colors.Chocolate;
- this.mPlotColorDarkBG = Colors.Cyan;
- this.mPlotColorLightBG = ColorHelper.DarkBlue;
- this.mPlotNegColorDarkBG = Colors.Red;
- this.mPlotNegColorLightBG = ColorHelper.DarkRed;
- //this.mPlotNegValsDiffColor = false;
- this._isDark = true;
- // this.mPlotType = LinePlotType.OHLC;
- this._dashStyleType = DashStyleType.Solid;
- this._lineThickness = 1.2;
- this.mAreaFillColorDarkBG = Colors.Gray;
- this.mAreaFillColorLightBG = ColorHelper.Gray;
- this.mAreaFillOpacity = 0.5;
- }
- public LinePlot(IndicatorModel indeicator, Chart chart)
- : base(indeicator, chart)
- {
- var OutputData = new OutputDataWrapper()
- {
- mDat = new ChartDataSet(indeicator.CalculateDataPoints),
- };
- this.mOutputData = OutputData;
- c_YestodayColor = Colors.Gold;
- c_TodayOpenColor = Colors.Chocolate;
- this.mPlotColorDarkBG = Colors.Cyan;
- this.mPlotColorLightBG = ColorHelper.DarkBlue;
- this.mPlotNegColorDarkBG = Colors.Red;
- this.mPlotNegColorLightBG = ColorHelper.DarkRed;
- this._isDark = true;
- this._dashStyleType = DashStyleType.Solid;
- this._lineThickness = 1.2;
- this.mAreaFillColorDarkBG = Colors.Gray;
- this.mAreaFillColorLightBG = ColorHelper.Gray;
- this.mAreaFillOpacity = 0.5;
- this.Calculate();
- InitAsNew();
- }
- #endregion Constructors
- #region Events
- public event PlotStyleChangedEventHandler PlotStyleChanged;
- #endregion Events
- #region Properties
- #region Public Properties
- public DashStyleType DashStyle
- {
- get
- {
- return this._dashStyleType;
- }
- set
- {
- this._dashStyleType = value;
- switch (this._dashStyleType)
- {
- case DashStyleType.Solid:
- this._doubleCollection = null;
- break;
- case DashStyleType.Dashed:
- this._doubleCollection = new DoubleCollection { 10.0, 5.0 };
- break;
- case DashStyleType.Dotted:
- this._doubleCollection = new DoubleCollection { 3.0, 3.0 };
- break;
- case DashStyleType.LongDashes:
- this._doubleCollection = new DoubleCollection { 25.0, 10.0 };
- break;
- }
- }
- }
- //public bool PlotNegValsDiffColor
- //{
- // get
- // {
- // return this.mPlotNegValsDiffColor;
- // }
- // set
- // {
- // bool flag = value != this.mPlotNegValsDiffColor;
- // if (flag)
- // {
- // this.mPlotNegValsDiffColor = value;
- // flag = (this.mChart != null);
- // if (flag)
- // {
- // this.mChart.Refresh();
- // }
- // }
- // }
- //}
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Public Methods
- #region 获取公式中各个图的颜色
- #endregion
- //public override void FromXML(XElement node)
- //{
- // Color? color = default(Color?);
- // bool flag = node.Attribute("PlotColor") != null;
- // if (flag)
- // {
- // this.mPlotColorDarkBG = ColorHelper.ColorFromString(node.Attribute("PlotColor").Value);
- // }
- // flag = (node.Attribute("PlotColorL") != null);
- // if (flag)
- // {
- // color = ColorHelper.ColorFromString(node.Attribute("PlotColorL").Value);
- // }
- // flag = (node.Attribute("PlotNegValsDiffColor") != null);
- // if (flag)
- // {
- // this.mPlotNegValsDiffColor = bool.Parse(node.Attribute("PlotNegValsDiffColor").Value);
- // }
- // flag = (node.Attribute("NegPlotColor") != null);
- // if (flag)
- // {
- // this.mPlotNegColorDarkBG = ColorHelper.ColorFromString(node.Attribute("NegPlotColor").Value);
- // }
- // flag = (node.Attribute("NegPlotColorL") != null);
- // if (flag)
- // {
- // this.mPlotNegColorLightBG = ColorHelper.ColorFromString(node.Attribute("NegPlotColorL").Value);
- // }
- // flag = (node.Attribute("AreaColor") != null);
- // if (flag)
- // {
- // this.mAreaFillColorDarkBG = ColorHelper.ColorFromString(node.Attribute("AreaColor").Value);
- // }
- // flag = (node.Attribute("AreaColorL") != null);
- // if (flag)
- // {
- // this.mAreaFillColorLightBG = ColorHelper.ColorFromString(node.Attribute("AreaColorL").Value);
- // }
- // flag = (node.Attribute("Thickness") != null);
- // if (flag)
- // {
- // this.LinePlot_1593 = XmlHelper.ParseDouble(node.Attribute("Thickness").Value);
- // }
- // flag = (node.Attribute("DashPattern") != null);
- // if (flag)
- // {
- // string value = node.Attribute("DashPattern").Value;
- // string text = value;
- // flag = (Operators.CompareString(text, DashStyleType.Solid.ToString(), false) == 0);
- // if (flag)
- // {
- // this.DashStyle = DashStyleType.Solid;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text, DashStyleType.Dashed.ToString(), false) == 0);
- // if (flag)
- // {
- // this.DashStyle = DashStyleType.Dashed;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text, DashStyleType.Dotted.ToString(), false) == 0);
- // if (flag)
- // {
- // this.DashStyle = DashStyleType.Dotted;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text, DashStyleType.LongDashes.ToString(), false) == 0);
- // if (flag)
- // {
- // this.DashStyle = DashStyleType.LongDashes;
- // }
- // }
- // }
- // }
- // }
- // flag = (node.Attribute("PlotStyle") != null);
- // if (flag)
- // {
- // string value2 = node.Attribute("PlotStyle").Value;
- // string text2 = value2.ToLower();
- // flag = (Operators.CompareString(text2, "eline", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.Line;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text2, "ehlc", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.HLC;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text2, "eohlc", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.OHLC;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text2, "ecandle", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.Candle;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text2, "ebar", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.Bar;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text2, "edot", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.Dot;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text2, "earea", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.Area;
- // }
- // else
- // {
- // flag = (Operators.CompareString(text2, "eheikenashi", false) == 0);
- // if (flag)
- // {
- // this.mPlotStyle = LinePlotType.HeikenAshi;
- // }
- // }
- // }
- // }
- // }
- // }
- // }
- // }
- // }
- // flag = (node.Attribute("OutputDataGUID") != null);
- // if (flag)
- // {
- // OutputDataWrapper arg_501_0 = this.mOutputData;
- // Guid value3 = new Guid(node.Attribute("OutputDataGUID").Value);
- // arg_501_0.DataGUID = value3;
- // }
- // flag = (node.Attribute("SourceID") != null);
- // if (flag)
- // {
- // this.mPendingSourceUID = (string)node.Attribute("SourceID");
- // }
- // try
- // {
- // IEnumerator<XElement> enumerator = node.Elements().GetEnumerator();
- // while (enumerator.MoveNext())
- // {
- // XElement current = enumerator.Current;
- // flag = !(current.Name == "PLOTADDITIONS");
- // if (flag)
- // {
- // var iXMLSavable = XmlTypeCreator.MakeElement(current);
- // flag = (iXMLSavable != null && iXMLSavable is ILineCalc);
- // if (flag)
- // {
- // this.mCalculation = (ILineCalc)iXMLSavable;
- // }
- // }
- // }
- // }
- // finally
- // {
- // //IEnumerator<XElement> enumerator;
- // //flag = (enumerator != null);
- // //if (flag)
- // //{
- // // enumerator.Dispose();
- // //}
- // }
- // flag = !color.HasValue;
- // if (flag)
- // {
- // bool flag2 = this.mCalculation != null;
- // if (flag2)
- // {
- // this.mPlotColorLightBG = this.mCalculation.DefaultColorForLightBG();
- // }
- // }
- // else
- // {
- // this.mPlotColorLightBG = color.Value;
- // }
- // base.ReadFromXML(node);
- //}
- //public override string GetXMLForDefault()
- //{
- // List<object> list = new List<object>();
- // list.Add("SAVEDEF");
- // return this.ToXML(list).ToString();
- //}
- public override void InitAsNew()
- {
- //this.mPlotType = ((ILineCalculation)this.PlotCalculation).DefaultPlotType;
- //this.mPlotColorDarkBG = this.PlotCalculation.DefaultColorForDarkBG();
- //this.mPlotColorLightBG = this.PlotCalculation.DefaultColorForLightBG();
- }
- public override void ReInstanceSources()
- {
- this.mOutputData.DataGUID = Guid.NewGuid();
- }
- public override void SourceDataChange(object change)
- {
- bool flag = change is DataChangedArgs;
- if (flag)
- {
- var dChange = (DataChangedArgs)change;
- //flag = this.mOutputData != null && this.mOutputData.DataPoints != null && this.mOutputData.DataPoints.Any();
- //if (flag)
- //{
- // flag = mOutputData.IsIncludeOHLCDataPoint(dChange);
- // if (flag)
- // {
- // return;
- // }
- //}
- }
- //调用公司计算
- this.Calculate();
- }
- #endregion Public Methods
- #region Internal Methods
- internal override List<FrameworkElement> BuildPlot(Chart owner, ScaleLayer aScale, IDateScaler dateScale,
- IValueScaler ValScale, Rect aRect)
- {
- //bool flag = this._isDark != owner.IsDarkBackground;
- //if (flag)
- //{
- // this._isDark = owner.IsDarkBackground;
- // //flag = (this.PlotCalculation != null && this.PlotCalculation is IBackGroundAwareCalculation);
- // if (flag)
- // {
- // }
- //}
- this.mChart = owner;
- this.mScale = aScale;
- bool flag = false; // (this.mCalculation != null && this.mCalculation is ISelfPlottingLineCalc);
- var result = new List<FrameworkElement>();
- //创建指标图形
- if (this.Indicator == null) return result;
- DashStyle = Indicator.DashStyleType;
- var painter = new PlotPainter(aRect, this._doubleCollection, Indicator.LineWidth);
- var eLinePlotType = Indicator.LinePlotType;
- switch (eLinePlotType)
- {
- case LinePlotType.Line:
- this.BuildAreaLine(painter, dateScale, ValScale, aRect, Indicator);
- break;
- case LinePlotType.HLC:
- flag = this.HasOHLC();
- if (flag)
- {
- this.BuildHLCPoints(painter, dateScale, ValScale, aRect, Indicator);
- }
- else
- {
- this.BuildAreaLine(painter, dateScale, ValScale, aRect, Indicator);
- }
- break;
- case LinePlotType.OHLC:
- flag = this.HasOHLC();
- if (flag)
- {
- this.BuildOHLCPoints(painter, dateScale, ValScale, aRect, Indicator);
- }
- else
- {
- this.BuildAreaLine(painter, dateScale, ValScale, aRect, Indicator);
- }
- break;
- case LinePlotType.Candlestick:
- flag = this.HasOHLC();
- if (flag)
- {
- this.BuildCandlestickPoints(painter, dateScale, ValScale, aRect, Indicator);
- }
- else
- {
- this.BuildAreaLine(painter, dateScale, ValScale, aRect, Indicator);
- }
- break;
- case LinePlotType.Bar:
- this.BuildBarPoints(painter, dateScale, ValScale, aRect, Indicator);
- break;
- case LinePlotType.Dot:
- this.BuildDotPoints(painter, dateScale, ValScale, aRect, Indicator, true);
- break;
- case LinePlotType.CIRCLEDOT:
- this.BuildDotPoints(painter, dateScale, ValScale, aRect, Indicator, false);
- break;
- case LinePlotType.CROSSDOT:
- this.BuildCROSSDOTPoints(painter, dateScale, ValScale, aRect, Indicator);
- break;
- case LinePlotType.Area:
- this.BuildAreaLine(painter, dateScale, ValScale, aRect, Indicator);
- this.BuildAreaPolyLine(painter, dateScale, ValScale, aRect, Indicator);
- break;
- case LinePlotType.FillRGN:
- result.AddRange(this.BuildArea(dateScale, ValScale, aRect, Indicator));
- break;
- //case LinePlotType.HeikenAshi:
- // flag = this.LinePlot_4886();
- // if (flag)
- // {
- // this.LinePlot_4892(painter, dateScale, ValScale, aRect,indicatorModel);
- // }
- // else
- // {
- // this.LinePlot_4891(painter, dateScale, ValScale, aRect,indicatorModel);
- // }
- // break;
- }
- #region 暂时不使用
- //flag = (this.Indicator.ParentFormula.IsMain && this.mChart != null &&
- // this.mChart.CurrentTimeFrame.TotalDays < 1.0 && (this.Indicator.IsShowYestodayLines));
- //if (flag)
- //{
- // this.BuildYesterdaysCloseLine(painter, dateScale, ValScale, aRect, this.Indicator);
- //}
- //flag = (this.Indicator.ParentFormula.IsMain && this.mChart != null && this.mChart.CurrentTimeFrame.TotalDays < 1.0 );
- //if (flag)
- //{
- // this.BuildTodaysOpenLine(painter, dateScale, ValScale, aRect, this.Indicator);
- //}
- #endregion
- result.AddRange(painter.GetGraph());
- try
- {
- List<FrameworkElement>.Enumerator enumerator3 = result.GetEnumerator();
- while (enumerator3.MoveNext())
- {
- FrameworkElement current3 = enumerator3.Current;
- current3.IsHitTestVisible = (false);
- }
- }
- finally
- {
- //List<FrameworkElement>.Enumerator enumerator3;
- //enumerator3.Dispose();
- }
- return result;
- }
- /// <summary>
- /// Calculates this instance.
- /// </summary>
- internal override void Calculate()
- {
- // bool flag = this.PlotCalculation is IBackGroundAwareCalculation;
- // if (flag)
- // {
- // ((IBackGroundAwareCalculation)this.PlotCalculation).SetCurrentBackground(this._isDark);
- // }
- // //flag = (this.mCalculation != null && this.mCalculation is PriceHistoryCalculation);
- // //if (flag)
- // //{
- // // ((PriceHistoryCalculation)this.mCalculation).isHeikenAshi = (this.mPlotType == LinePlotType.HeikenAshi);
- // //}
- // ////线状图设为一单色
- // //var cal = this.mCalculation as PriceHistoryCalculation;
- // //if (cal != null && this.mChart != null)
- // //{
- // // cal.ColorMode = this.mChart.LinePlotType == LinePlotType.Line || this.mChart.LinePlotType == LinePlotType.Area ?
- // // PriceColorType.OneColor : PriceColorType.CloseUpDown;
- // //}
- // this.mOutputData.OnDataSetDataChanged(((ILineCalculation)this.PlotCalculation).Calculate(this.mSource, this.CurrentPlotColor()));
- }
- internal override Color GetColor()
- {
- return this.CurrentPlotColor();
- }
- /// <summary>
- /// 检测画图面板中的图例,并返回它们在aDate日期下的数据面板
- /// </summary>
- /// <param name="aDate"></param>
- /// <param name="isDarkBackground"></param>
- /// <param name="isForex"></param>
- /// <returns></returns>
- internal override List<ControlPair> GetControlPairs(DateTime aDate, bool isDarkBackground, bool isForex)
- {
- var digits = isForex ? 4 : 2;
- var list = GetControlPairs(aDate, isDarkBackground, digits);
- return list;
- }
- /// <summary>
- /// Gets the control pairs.
- /// </summary>
- /// <param name="aDate">A date.</param>
- /// <param name="isDarkBackground">if set to <c>true</c> [is dark background].</param>
- /// <param name="digits">The digits.</param>
- /// <returns>List{ControlPair}.</returns>
- internal override List<ControlPair> GetControlPairs(DateTime aDate, bool isDarkBackground, int digits)
- {
- var list = new List<ControlPair>();
- checked
- {
- bool flag2 = this.Indicator.ParentFormula.IsMain;
- #region 显示当前的主图数据到面板中
- if (flag2)
- {
- if (this.OutputSource == null || this.OutputSource.CalculateDataPoints == null) return list;
- var datapoint = this.OutputSource.CalculateDataPoints.FirstOrDefault((point) => DateTime.Compare(point.Date, aDate) == 0);
- if (datapoint == null) return list;
- var iOHLCDataPoint = (IBarDataPoint)datapoint;
- list.Add(
- this.BuildQuoteControlPair(
- LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_Open),
- iOHLCDataPoint.Open, isDarkBackground, digits, false));
- list.Add(
- this.BuildQuoteControlPair(
- LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_High),
- iOHLCDataPoint.High, isDarkBackground, digits, false));
- list.Add(
- this.BuildQuoteControlPair(
- LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_Low), iOHLCDataPoint.Low,
- isDarkBackground, digits, false));
- list.Add(
- this.BuildQuoteControlPair(
- LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_Close),
- iOHLCDataPoint.Close, isDarkBackground, digits, false));
- var increase = GetIncrease(iOHLCDataPoint);
- list.Add(
- this.BuildQuoteControlPair(
- LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_Increase),
- increase.ToString("P2"), isDarkBackground));
- var increaseValue = GetIncreaseValue(iOHLCDataPoint);
- list.Add(this.BuildQuoteControlPair(LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_AmountChanges),
- increaseValue, isDarkBackground, 2, true));
- list.Add(
- this.BuildQuoteControlPair(
- LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_Turnover),
- iOHLCDataPoint.Turnover, isDarkBackground, 2, true));
- //期货才有持仓量
- if (this.mChart != null && this.mChart.CurrentGoods != null &&
- mChart.CurrentGoods.GoodsType == GoodsType.Futures)
- {
- list.Add(
- this.BuildQuoteControlPair(
- LanguageManager.FindResource(LanguageConst.Indicator_QuoteBoard_HoldVolume),
- iOHLCDataPoint.HoldVolume, isDarkBackground, 2, true));
- }
- }
- #endregion
- else
- {
- if (this.Indicator.LinePlotType != LinePlotType.FillRGN && this.Indicator.LinePlotType != LinePlotType.Area)
- {
- list.AddRange(this.GetPointControlPairs(aDate, digits, true));
- }
- }
- }
- return list;
- }
- /// <summary>
- /// Gets the increase.
- /// </summary>
- /// <param name="dataPoint">The data point.</param>
- /// <returns>System.Single.</returns>
- private float GetIncrease(IBarDataPoint dataPoint)
- {
- if (mChart == null || mChart.DataSet == null || mChart.DataSet.DataPoints == null || dataPoint == null) return 0;
- var dataPoints = mChart.DataSet.DataPoints;
- var item = dataPoints.FirstOrDefault(z => z.Date == dataPoint.Date);
- if (item == null) return 0;
- var index = dataPoints.IndexOf(item);
- if (index == 0)
- {
- return dataPoint.Open.Equals(0) ? 0f : (dataPoint.Close - dataPoint.Open) / dataPoint.Open;
- }
- else
- {
- var last = dataPoints[index - 1] as IOHLCDataPoint;
- if (last == null || last.Close == 0) return dataPoint.Open.Equals(0) ? 0f : (dataPoint.Close - dataPoint.Open) / dataPoint.Open;
- return last.Close.Equals(0) ? 0f : (dataPoint.Close - last.Close) / last.Close;
- }
- return 0;
- }
- /// <summary>
- /// Gets the increase.
- /// </summary>
- /// <param name="dataPoint">The data point.</param>
- /// <returns>System.Single.</returns>
- private float GetIncreaseValue(IBarDataPoint dataPoint)
- {
- if (mChart == null || mChart.DataSet == null || mChart.DataSet.DataPoints == null || dataPoint == null) return 0;
- var dataPoints = mChart.DataSet.DataPoints;
- var item = dataPoints.FirstOrDefault(z => z.Date == dataPoint.Date);
- if (item == null) return 0;
- var index = dataPoints.IndexOf(item);
- if (index == 0)
- {
- return dataPoint.Open.Equals(0) ? 0f : (dataPoint.Close - dataPoint.Open);
- }
- else
- {
- var last = dataPoints[index - 1] as IOHLCDataPoint;
- if (last == null || last.Close == 0) return dataPoint.Open.Equals(0) ? 0f : (dataPoint.Close - dataPoint.Open);
- return last.Close.Equals(0) ? 0f : (dataPoint.Close - last.Close);
- }
- return 0;
- }
- /// <summary>
- /// 应用公式计算的值
- /// </summary>
- /// <returns></returns>
- //internal ILineDataSet GetDataSet()
- //{
- // // return this.mOutputData;
- // return this.OutputSource;
- //}
- internal ILineDataSetWithUid LinePlot_4866()
- {
- return this.mOutputData;
- }
- /// <summary>
- /// 应用公司计算的值
- /// </summary>
- /// <returns></returns>
- internal IndicatorModel GetDataSet()
- {
- // return this.mOutputData;
- return this.OutputSource;
- }
- /// <summary>
- /// Gets the color of the plot.
- /// </summary>
- /// <returns>Color.</returns>
- internal override Color GetPlotColor()
- {
- if (this.Indicator != null) return this.Indicator.UpBrush;
- return Colors.White;
- }
- internal override void ShowPlotEdit(FrameworkElement relativeTo)
- {
- bool flag = this.mChart == null;
- if (!flag)
- {
- //LinePlotEditor linePlotEditor = new LinePlotEditor(this, this.mChart);
- //linePlotEditor.Show(relativeTo);
- }
- }
- #endregion Internal Methods
- #region Protected Methods
- internal Color CurrentPlotColor()
- {
- return _isDark ? this.mPlotColorDarkBG : this.mPlotColorLightBG;
- }
- /// <summary>
- /// 04月08日
- /// </summary>
- protected override void DeleteData()
- {
- //bool flag = this.mOutputData != null;
- //if (flag)
- //{
- // this.mOutputData.OnDelete();
- // //this.mOutputData.OnDataSetDataChanged();
- //}
- }
- /// <summary>
- /// 添加其他指标数据到面板
- /// </summary>
- private List<ControlPair> GetPointControlPairs(DateTime aDate, bool isForex, bool allowAbbreviate)
- {
- var digits = isForex ? 4 : 2;
- return GetPointControlPairs(aDate, digits, allowAbbreviate);
- }
- /// <summary>
- /// 添加其他指标数据到面板
- /// </summary>
- /// <param name="aDate">A date.</param>
- /// <param name="digits">The digits.</param>
- /// <param name="allowAbbreviate">if set to <c>true</c> [allow abbreviate].</param>
- /// <returns>List{ControlPair}.</returns>
- private List<ControlPair> GetPointControlPairs(DateTime aDate, int digits, bool allowAbbreviate)
- {
- var pairList = new List<ControlPair>();
- if (this.Indicator == null || this.Indicator.CalculateDataPoints == null) return pairList;
- ILineDataPoint dataPoint = null;
- if (this.mChart != null && this.mChart.CycleType == CycleType.TimeSharing)
- {
- dataPoint = this.Indicator.CalculateDataPoints.FirstOrDefault(z => z.Date.Date == aDate.Date && z.Date.Hour == aDate.Hour && z.Date.Minute == aDate.Minute);
- }
- else
- {
- dataPoint = this.Indicator.CalculateDataPoints.FirstOrDefault(
- (point) => DateTime.Compare(point.Date, aDate) == 0);
- }
- if (dataPoint == null) return pairList;
- if (float.IsNaN(dataPoint.Value)) return pairList;
- var leftTextBlock = new TextBlock
- {
- Text = this.Indicator.LineName,
- Foreground = new SolidColorBrush(Indicator.UpBrush),
- Padding = new Thickness(10.0, 0.0, 10.0, 0.0),
- };
- var rightTextBlock = new TextBlock
- {
- Text = TextFormatting.FormatNumber(dataPoint.Value, digits, allowAbbreviate),
- Foreground = leftTextBlock.Foreground,
- HorizontalAlignment = HorizontalAlignment.Right,
- Padding = new Thickness(5.0, 0.0, 0.0, 0.0)
- };
- pairList.Add(new ControlPair
- {
- ControlLeft = leftTextBlock,
- ControlRight = rightTextBlock
- });
- return pairList;
- }
- protected ControlPair GetPointerPair(string desc, Color descColor, float aVal, bool indent, bool isForex, bool allowAbbreviate)
- {
- var digits = isForex ? 4 : 2;
- return GetPointerPair(desc, descColor, aVal, indent, digits, allowAbbreviate);
- }
- protected ControlPair GetPointerPair(string desc, Color descColor, float aVal, bool indent, int digits, bool allowAbbreviate)
- {
- var foreground = new SolidColorBrush(descColor);
- var textBlock = new TextBlock
- {
- Text = desc,
- Foreground = (foreground),
- Margin = indent ? new Thickness(15.0, 3.0, 0.0, 0.0) : new Thickness(0.0, 3.0, 0.0, 0.0)
- };
- var textBlock2 = new TextBlock
- {
- Text = TextFormatting.FormatNumber(aVal, digits, allowAbbreviate),
- Foreground = (foreground),
- HorizontalAlignment = HorizontalAlignment.Right,
- Margin = new Thickness(5.0, 3.0, 0.0, 0.0)
- };
- return new ControlPair
- {
- ControlLeft = textBlock,
- ControlRight = textBlock2
- };
- }
- #endregion Protected Methods
- #region Private Methods
- private void BuildAreaLine(PlotPainter painter, IDateScaler dateScale, IValueScaler valScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- var upbrush = indicatorModel.UpBrush;
- bool flag = list != null;
- checked
- {
- if (flag)
- {
- bool flag2 = this.NotHasColoredDataPoint();
- if (flag2)
- {
- int num = dateScale.FirstVisibleIndexFromData(list);
- num--;
- num = Math.Max(0, num);
- int upper = list.Count;
- for (int i = num; i < upper; i++)
- {
- if (dateScale.DateVisible(list[i].Date))
- {
- float x = dateScale.XforDate(list[i].Date);
- if (!float.IsNaN(list[i].Value))
- {
- var point = new Point((double)x, (double)valScale.ScaledY(list[i].Value, aRect));
- painter.AddPoint(point, upbrush);
- }
- }
- }
- }
- else
- {
- int num = dateScale.FirstVisibleIndexFromData(list);
- //线从第2个点开始,第1个点忽略.
- num = Math.Max(1, num);
- var upper = list.Count;
- for (int i = num; i < upper; i++)
- {
- var start = list[i - 1];
- var end = list[i];
- flag2 = (dateScale.DateVisible(start.Date) || dateScale.DateVisible(end.Date));
- if (flag2)
- {
- float startX = dateScale.XforDate(start.Date);
- float endX = dateScale.XforDate(end.Date);
- if (!float.IsNaN(startX) && float.IsNaN(endX))
- {
- var lineGeometry = new LineGeometry()
- {
- StartPoint =
- new Point((double)startX, (double)valScale.ScaledY(start.Value, aRect)),
- EndPoint = new Point((double)endX, (double)valScale.ScaledY(end.Value, aRect))
- };
- painter.AddLine(lineGeometry, upbrush);
- }
- }
- }
- }
- }
- }
- }
- private void BuildAreaPolyLine(PlotPainter painter, IDateScaler dateScale, IValueScaler valScale, Rect aRect,
- IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- bool flag = list != null;
- checked
- {
- if (flag)
- {
- int num = dateScale.FirstVisibleIndexFromData(list);
- flag = (num < 0);
- if (flag)
- {
- num = 0;
- }
- int num2 = (int)Math.Round(unchecked(this.mAreaFillOpacity * 255.0));
- flag = (num2 < 0);
- if (flag)
- {
- num2 = 0;
- }
- flag = (num2 > 255);
- if (flag)
- {
- num2 = 255;
- }
- var solidBrush = indicatorModel.AreaBrush;
- Color aColor = Colors.Transparent;
- if (!ColorHelper.IsEmptyColor(solidBrush))
- {
- aColor = Color.FromArgb((byte)num2, solidBrush.R, solidBrush.G, solidBrush.B);
- }
- var pathGeometry = new PathGeometry();
- var pathFigure = new PathFigure();
- pathGeometry.Figures.Add(pathFigure);
- var arg_FC_0 = pathFigure;
- Point point = new Point(aRect.Left, (double)valScale.ScaledY(0f, aRect));
- arg_FC_0.StartPoint = (point);
- var polyLineSegment = new PolyLineSegment();
- pathFigure.Segments.Add(polyLineSegment);
- int arg_124_0 = num;
- int num3 = list.Count - 1;
- int num4 = arg_124_0;
- float num6 = 0f;
- while (true)
- {
- int arg_194_0 = num4;
- int num5 = num3;
- if (arg_194_0 > num5)
- {
- break;
- }
- flag = dateScale.DateVisible(list[num4].Date);
- if (flag)
- {
- num6 = dateScale.XforDate(list[num4].Date);
- var arg_17E_0 = polyLineSegment.Points;
- point = new Point((double)num6, (double)valScale.ScaledY(list[num4].Value, aRect));
- arg_17E_0.Add(point);
- }
- num4++;
- }
- var arg_1B7_0 = polyLineSegment.Points;
- point = new Point((double)num6, (double)valScale.ScaledY(0f, aRect));
- arg_1B7_0.Add(point);
- var arg_1E3_0 = polyLineSegment.Points;
- point = new Point(aRect.Left, (double)valScale.ScaledY(0f, aRect));
- arg_1E3_0.Add(point);
- painter.AddShape(pathGeometry, aColor);
- }
- }
- }
- private void BuildBarPoints(PlotPainter Painter, IDateScaler dateScale, IValueScaler ValScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- var width = (float)checked((int)Math.Round((double)dateScale.DistanceBetweenDates()) - 4);
- bool flag = width > 10f;
- if (flag)
- {
- width -= 4f;
- }
- checked
- {
- var num2 = (int)Math.Round((double)(width / 2f));
- flag = (list != null);
- if (flag)
- {
- int startIndex = dateScale.FirstVisibleIndexFromData(list);
- int endIndex = list.Count;
- for (int i = startIndex; i < endIndex; i++)
- {
- flag = dateScale.DateVisible(list[i].Date);
- if (flag)
- {
- Color aColor = Colors.White;
- if (indicatorModel.VolBar)
- {
- aColor = this.GetPointColor(list[i]);
- }
- else
- {
- var upColorBrush = indicatorModel.UpBrush;
- if (!ColorHelper.IsEmptyColor(upColorBrush))
- {
- aColor = upColorBrush;
- }
- else
- {
- indicatorModel.UpBrush = (Colors.White);
- }
- }
- flag = (indicatorModel.PlotNegValsDiffColor && list[i].Value < 0f);
- if (flag)
- {
- var solidColorBrush = indicatorModel.DownBrush;
- if (!ColorHelper.IsEmptyColor(solidColorBrush))
- {
- aColor = solidColorBrush;
- }
- }
- var num7 = (float)((int)Math.Round((double)dateScale.XforDate(list[i].Date)));
- flag = (width > 1f);
- unchecked
- {
- if (flag)
- {
- var rectangleGeometry = new RectangleGeometry();
- Rect rect = default(Rect);
- double num8 = (double)ValScale.ScaledY(list[i].Value, aRect) - 0.5;
- double num9 = (double)ValScale.ScaledY(0f, aRect) - 0.5;
- flag = (num8 > num9);
- if (flag)
- {
- double num10 = num8;
- num8 = num9;
- num9 = num10;
- }
- rect.X = ((double)(num7 - (float)num2) + 0.5);
- rect.Y = (num8);
- rect.Width = ((double)width);
- rect.Height = (Math.Max(-0.5, num9 - rect.Top));
- rectangleGeometry.Rect = (rect);
- Painter.AddShape(rectangleGeometry, aColor);
- }
- else
- {
- var lineGeometry = new LineGeometry
- {
- StartPoint = new Point((double)num7 + 0.5, (double)ValScale.ScaledY(list[i].Value, aRect)),
- EndPoint = new Point((double)num7 + 0.5, (double)ValScale.ScaledY(0f, aRect))
- };
- Painter.AddLine(lineGeometry, aColor);
- }
- }
- }
- }
- }
- }
- }
- private void BuildCandlestickPoints(PlotPainter painter, IDateScaler dateScale, IValueScaler valScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- if (list == null || !list.Any()) return;
- var num = (float)((int)Math.Round(unchecked(0.3 * (double)dateScale.DistanceBetweenDates())));
- #region 未知作用
- bool upFilled = true;
- bool downFilled = true;
- var fillModel = PriceColorType.BarUpDown;
- //var price = this.PlotCalculation as PriceHistoryCalculation;
- //if (price != null)
- //{
- // upFilled = price.UpFilled;
- // downFilled = price.DownFilled;
- // fillModel = price.FillMode;
- //}
- #endregion
- var start = dateScale.FirstVisibleIndexFromData(list);
- var length = list.Count;
- for (var i = start; i < length; i++)
- {
- var current = list[i];
- var visible = dateScale.DateVisible(current.Date);
- if (!visible) continue;
- var ohlcDataPoint = current as IOHLCDataPoint;
- if (ohlcDataPoint == null) continue;
- var dateX = (float)((int)Math.Round((double)dateScale.XforDate(ohlcDataPoint.Date)));
- var color = this.GetPointColor(ohlcDataPoint);
- var isFill = false;
- var isRising = false;
- var isDeclining = false;
- if (ohlcDataPoint.Close > ohlcDataPoint.Open)
- {
- isRising = true;
- isFill = upFilled;
- }
- else if (ohlcDataPoint.Close < ohlcDataPoint.Open)
- {
- isDeclining = true;
- isFill = downFilled;
- }
- if (i > 0 && fillModel == PriceColorType.CloseUpDown)
- {
- if (ohlcDataPoint.Close > ohlcDataPoint.Value)
- {
- isFill = upFilled;
- }
- else if (ohlcDataPoint.Close < ohlcDataPoint.Value)
- {
- isFill = downFilled;
- }
- }
- var rect = new Rect();
- if (!isRising && !isDeclining)
- {
- //相等画直线
- rect = new Rect(dateX - num + 0.5, 0.5 + valScale.ScaledY(ohlcDataPoint.Open, aRect), 2f * num, 0);
- painter.AddLine(new LineGeometry
- {
- StartPoint = new Point(rect.X - 0.5, rect.Y),
- EndPoint = new Point(rect.Right + 0.5, rect.Y)
- }, color);
- }
- else if (isRising)
- {
- rect = new Rect(dateX - num + 0.5, 0.5 + (double)valScale.ScaledY(ohlcDataPoint.Close, aRect), 2f * num, 0);
- rect.Height = (0.5 + (double)valScale.ScaledY(ohlcDataPoint.Open, aRect) - rect.Top);
- var rectangleGeometry = new RectangleGeometry { Rect = rect };
- if (isFill)
- {
- painter.AddShape(rectangleGeometry, color);
- }
- else
- {
- painter.AddLine(rectangleGeometry, color);
- }
- }
- else
- {
- rect = new Rect(dateX - num + 0.5, 0.5 + (double)valScale.ScaledY(ohlcDataPoint.Open, aRect), 2f * num, 0);
- rect.Height = (0.5 + (double)valScale.ScaledY(ohlcDataPoint.Close, aRect) - rect.Top);
- var rectangleGeometry = new RectangleGeometry { Rect = (rect) };
- if (isFill)
- {
- painter.AddShape(rectangleGeometry, color);
- }
- else
- {
- painter.AddLine(rectangleGeometry, color);
- }
- }
- painter.AddLine(new LineGeometry
- {
- StartPoint = new Point(dateX + 0.5, (double)valScale.ScaledY(ohlcDataPoint.High, aRect)),
- EndPoint = new Point((double)dateX + 0.5, rect.Top)
- }, color);
- painter.AddLine(new LineGeometry
- {
- StartPoint = new Point(dateX + 0.5, (double)valScale.ScaledY(ohlcDataPoint.Low, aRect)),
- EndPoint = new Point(dateX + 0.5, rect.Bottom)
- }, color);
- }
- }
- private void BuildDotPoints(PlotPainter Painter, IDateScaler dateScale, IValueScaler ValScale,
- Rect aRect, IndicatorModel indicatorModel, bool IsfillPoint)
- {
- var list = indicatorModel.CalculateDataPoints;
- checked
- {
- float num = (float)((int)Math.Round(unchecked(0.35 * (double)dateScale.DistanceBetweenDates())));
- bool flag = num <= 1f;
- if (flag)
- {
- num = 1.01f;
- }
- flag = ((double)num > 3.5);
- if (flag)
- {
- num = 3.5f;
- }
- flag = (list != null);
- if (flag)
- {
- int num2 = dateScale.FirstVisibleIndexFromData(list);
- int arg_90_0 = num2;
- int num3 = list.Count - 1;
- int num4 = arg_90_0;
- while (true)
- {
- int arg_1EA_0 = num4;
- int num5 = num3;
- if (arg_1EA_0 > num5)
- {
- break;
- }
- flag = dateScale.DateVisible(list[num4].Date);
- if (flag)
- {
- // Color aColor = this.GetPointColor(list[num4]);
- Color aColor = Colors.White; // this.GetPointColor(list[num4]);
- var upColorBrush = indicatorModel.UpBrush;
- if (!ColorHelper.IsEmptyColor(upColorBrush))
- {
- aColor = upColorBrush;
- }
- else
- {
- indicatorModel.UpBrush = (Colors.White);
- }
- var scalefloat = dateScale.XforDate(list[num4].Date);
- if (float.IsNaN(scalefloat))
- {
- float num6 = (float)((int)Math.Round((double)scalefloat));
- flag = (num > 1f);
- unchecked
- {
- if (flag)
- {
- EllipseGeometry ellipseGeometry = new EllipseGeometry();
- double num7 = (double)ValScale.ScaledY(list[num4].Value, aRect) - 0.5;
- EllipseGeometry arg_123_0 = ellipseGeometry;
- Point point = new Point((double)num6, num7);
- arg_123_0.Center = (point);
- ellipseGeometry.RadiusX = ((double)num);
- ellipseGeometry.RadiusY = ((double)num);
- Painter.AddShape(ellipseGeometry, aColor, IsfillPoint);
- }
- else
- {
- LineGeometry lineGeometry = new LineGeometry();
- Painter.AddLine(lineGeometry, aColor);
- LineGeometry arg_198_0 = lineGeometry;
- Point point = new Point((double)num6 + 0.5,
- (double)ValScale.ScaledY(list[num4].Value, aRect) - 0.5);
- arg_198_0.StartPoint = (point);
- LineGeometry arg_1D6_0 = lineGeometry;
- point = new Point((double)num6 + 0.5,
- (double)ValScale.ScaledY(list[num4].Value, aRect) + 0.5);
- arg_1D6_0.EndPoint = (point);
- }
- }
- }
- }
- num4++;
- }
- }
- }
- }
- private void BuildCROSSDOTPoints(PlotPainter Painter, IDateScaler dateScale, IValueScaler ValScale,
- Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- checked
- {
- float num = (float)((int)Math.Round(unchecked(0.35 * (double)dateScale.DistanceBetweenDates())));
- bool flag = num <= 1f;
- if (flag)
- {
- num = 1.01f;
- }
- flag = ((double)num > 3.5);
- if (flag)
- {
- num = 3.5f;
- }
- flag = (list != null);
- if (flag)
- {
- int num2 = dateScale.FirstVisibleIndexFromData(list);
- int arg_90_0 = num2;
- int num3 = list.Count - 1;
- int num4 = arg_90_0;
- while (true)
- {
- int arg_1EA_0 = num4;
- int num5 = num3;
- if (arg_1EA_0 > num5)
- {
- break;
- }
- flag = dateScale.DateVisible(list[num4].Date);
- if (flag)
- {
- Color aColor = Colors.White; // this.GetPointColor(list[num4]);
- var upColorBrush = (indicatorModel.UpBrush);
- if (!ColorHelper.IsEmptyColor(upColorBrush))
- {
- aColor = upColorBrush;
- }
- else
- {
- indicatorModel.UpBrush = (Colors.White);
- }
- var scalefloat = dateScale.XforDate(list[num4].Date);
- if (float.IsNaN(scalefloat))
- {
- float num6 = (float)((int)Math.Round(scalefloat));
- flag = (num > 1f);
- unchecked
- {
- if (flag)
- {
- PathGeometry pathGeometry = new PathGeometry();
- double num7 = (double)ValScale.ScaledY(list[num4].Value, aRect) - 0.5;
- LineGeometry line1 = new LineGeometry(new Point(num6 - num, num7 - num),
- new Point(num6 + num, num7 + num));
- LineGeometry line2 = new LineGeometry(new Point(num6 - num, num7 + num),
- new Point(num6 + num, num7 - num));
- pathGeometry.AddGeometry(line1);
- pathGeometry.AddGeometry(line2);
- Painter.AddShape(pathGeometry, aColor);
- }
- else
- {
- LineGeometry lineGeometry = new LineGeometry();
- Painter.AddLine(lineGeometry, aColor);
- LineGeometry arg_198_0 = lineGeometry;
- Point point = new Point((double)num6 + 0.5,
- (double)ValScale.ScaledY(list[num4].Value, aRect) - 0.5);
- arg_198_0.StartPoint = (point);
- LineGeometry arg_1D6_0 = lineGeometry;
- point = new Point((double)num6 + 0.5,
- (double)ValScale.ScaledY(list[num4].Value, aRect) + 0.5);
- arg_1D6_0.EndPoint = (point);
- }
- }
- }
- }
- num4++;
- }
- }
- }
- }
- private void BuildHLCPoints(PlotPainter painter, IDateScaler dateScale, IValueScaler valScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- checked
- {
- float num = (float)((int)Math.Round(unchecked(0.3 * (double)dateScale.DistanceBetweenDates())));
- bool flag = list != null;
- if (flag)
- {
- int num2 = dateScale.FirstVisibleIndexFromData(list);
- int arg_60_0 = num2;
- int num3 = list.Count - 1;
- int num4 = arg_60_0;
- while (true)
- {
- int arg_1B5_0 = num4;
- int num5 = num3;
- if (arg_1B5_0 > num5)
- {
- break;
- }
- flag = dateScale.DateVisible(list[num4].Date);
- if (flag)
- {
- Color aColor = this.GetPointColor(list[num4]);
- float num6 = (float)((int)Math.Round((double)dateScale.XforDate(list[num4].Date)));
- IOHLCDataPoint iOHLCDataPoint = (IOHLCDataPoint)list[num4];
- LineGeometry lineGeometry = new LineGeometry();
- painter.AddLine(lineGeometry, aColor);
- LineGeometry arg_F5_0 = lineGeometry;
- unchecked
- {
- Point point = new Point((double)num6 + 0.5, (double)valScale.ScaledY(iOHLCDataPoint.High, aRect));
- arg_F5_0.StartPoint = (point);
- LineGeometry arg_12A_0 = lineGeometry;
- point = new Point((double)num6 + 0.5, (double)(1f + valScale.ScaledY(iOHLCDataPoint.Low, aRect)));
- arg_12A_0.EndPoint = (point);
- lineGeometry = new LineGeometry();
- painter.AddLine(lineGeometry, aColor);
- LineGeometry arg_173_0 = lineGeometry;
- point = new Point((double)(num6 + num + 1f), 0.5 + (double)valScale.ScaledY(iOHLCDataPoint.Close, aRect));
- arg_173_0.StartPoint = (point);
- LineGeometry arg_1A2_0 = lineGeometry;
- point = new Point((double)num6, 0.5 + (double)valScale.ScaledY(iOHLCDataPoint.Close, aRect));
- arg_1A2_0.EndPoint = (point);
- }
- }
- num4++;
- }
- }
- }
- }
- private void BuildOHLCPoints(PlotPainter painter, IDateScaler dateScale, IValueScaler valScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- checked
- {
- float num = (float)((int)Math.Round(unchecked(0.3 * (double)dateScale.DistanceBetweenDates())));
- bool flag = list != null;
- if (flag)
- {
- int num2 = dateScale.FirstVisibleIndexFromData(list);
- int num3 = list.Count - 1;
- while (true)
- {
- if (num2 > num3)
- {
- break;
- }
- flag = dateScale.DateVisible(list[num2].Date);
- if (flag)
- {
- Color aColor = this.GetPointColor(list[num2]);
- float num6 = (float)((int)Math.Round((double)dateScale.XforDate(list[num2].Date)));
- var iOHLCDataPoint = (IOHLCDataPoint)list[num2];
- var lineGeometry = new LineGeometry();
- painter.AddLine(lineGeometry, this.GetPointColor(list[num2]));
- unchecked
- {
- Point point =
- lineGeometry.StartPoint = new Point((double)num6 + 0.5, (double)valScale.ScaledY(iOHLCDataPoint.High, aRect));
- lineGeometry.EndPoint = new Point((double)num6 + 0.5, (double)(1f + valScale.ScaledY(iOHLCDataPoint.Low, aRect)));
- lineGeometry = new LineGeometry();
- painter.AddLine(lineGeometry, aColor);
- lineGeometry.StartPoint = new Point((double)(num6 - num), 0.5 + (double)valScale.ScaledY(iOHLCDataPoint.Open, aRect));
- lineGeometry.EndPoint = new Point((double)(num6 + 1f), 0.5 + (double)valScale.ScaledY(iOHLCDataPoint.Open, aRect));
- lineGeometry = new LineGeometry();
- painter.AddLine(lineGeometry, aColor);
- lineGeometry.StartPoint = new Point((double)(num6 + num + 1f), 0.5 + (double)valScale.ScaledY(iOHLCDataPoint.Close, aRect));
- lineGeometry.EndPoint = new Point((double)num6, 0.5 + (double)valScale.ScaledY(iOHLCDataPoint.Close, aRect));
- }
- }
- num2++;
- }
- }
- }
- }
- /// <summary>
- /// 返回光标处的弹出菜单元素
- /// </summary>
- /// <param name="desc">The desc.</param>
- /// <param name="aVal">A value.</param>
- /// <param name="isDarkBackground">if set to <c>true</c> [is dark background].</param>
- /// <param name="digits">The digits.</param>
- /// <param name="allowAbbreviate">if set to <c>true</c> [allow abbreviate].</param>
- /// <returns>ControlPair.</returns>
- private ControlPair BuildQuoteControlPair(string desc, float aVal, bool isDarkBackground, int digits, bool allowAbbreviate)
- {
- var foreground = isDarkBackground ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black);
- var leftTextBlock = new TextBlock
- {
- Text = desc,
- Foreground = foreground,
- Padding = new Thickness(10.0, 0.0, 10.0, 0.0),
- };
- var rightTextBlock = new TextBlock
- {
- Text = TextFormatting.FormatNumber(aVal, digits, allowAbbreviate),
- Foreground = foreground,
- HorizontalAlignment = HorizontalAlignment.Right,
- Padding = new Thickness(5.0, 0.0, 0.0, 0.0)
- };
- return new ControlPair
- {
- ControlLeft = leftTextBlock,
- ControlRight = rightTextBlock
- };
- }
- /// <summary>
- /// Builds the quote control pair.
- /// </summary>
- /// <param name="desc">The desc.</param>
- /// <param name="valueString">The value string.</param>
- /// <param name="isDarkBackground">if set to <c>true</c> [is dark background].</param>
- /// <returns>ControlPair.</returns>
- private ControlPair BuildQuoteControlPair(string desc, string valueString, bool isDarkBackground)
- {
- var foreground = isDarkBackground ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black);
- var leftTextBlock = new TextBlock
- {
- Text = desc,
- Foreground = foreground,
- Padding = new Thickness(10.0, 0.0, 10.0, 0.0),
- };
- var rightTextBlock = new TextBlock
- {
- Text = valueString,
- Foreground = foreground,
- HorizontalAlignment = HorizontalAlignment.Right,
- Padding = new Thickness(5.0, 0.0, 0.0, 0.0)
- };
- return new ControlPair
- {
- ControlLeft = leftTextBlock,
- ControlRight = rightTextBlock
- };
- }
- /// <summary>
- /// 创建区域图
- /// </summary>
- /// <param name="dateScale"></param>
- /// <param name="valScale"></param>
- /// <param name="aRect"></param>
- /// <returns></returns>
- private List<FrameworkElement> BuildArea(IDateScaler dateScale, IValueScaler valScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = new List<FrameworkElement>();
- var path = new Path();
- var rectangleGeometry = new RectangleGeometry();
- rectangleGeometry.Rect = (aRect);
- path.Clip = (rectangleGeometry);
- path.UseLayoutRounding = (true);
- var solidColorBrush = new SolidColorBrush((this.Indicator.AreaBrush));
- solidColorBrush.Opacity = ((double)this.Indicator.Alpha / 256);
- path.StrokeThickness = indicatorModel.LineWidth < 1 ? 1 : indicatorModel.LineWidth;
- path.Fill = (solidColorBrush);
- var pathGeometry = new PathGeometry();
- path.Data = (pathGeometry);
- var pathFigure = new PathFigure();
- pathGeometry.Figures.Add(pathFigure);
- var list2 = indicatorModel.SubData[indicatorModel.FillRNGKey] as List<ILineDataPoint>;
- var doubleCond = indicatorModel.SubData[indicatorModel.CondKey] as double[];
- bool flag = false;
- bool flag2 = list2 != null && doubleCond != null;
- checked
- {
- bool flag3;
- if (flag2)
- {
- int num = list2.Count - 1;
- int num2 = 0;
- while (true)
- {
- int arg_1BF_0 = num2;
- int num3 = num;
- if (arg_1BF_0 > num3)
- {
- break;
- }
- bool arg_125_0 = (dateScale.DateVisible(list2[num2].Date)
- || (num2 < list2.Count - 1 && dateScale.DateVisible(list2[num2 + 1].Date))) ||
- (num2 > 0 && dateScale.DateVisible(list2[num2 - 1].Date));
- flag3 = arg_125_0 && Convert.ToBoolean(doubleCond[num2]);
- if (flag3)
- {
- float num4 = valScale.ScaledY(list2[num2].Value, aRect);
- float num5 = dateScale.XforDate(list2[num2].Date);
- flag3 = !flag;
- if (flag3)
- {
- var arg_175_0 = pathFigure;
- Point startPoint = new Point((double)num5, (double)num4);
- arg_175_0.StartPoint = (startPoint);
- flag = true;
- }
- else
- {
- var lineSegment = new LineSegment();
- var arg_19A_0 = lineSegment;
- Point startPoint = new Point((double)num5, (double)num4);
- arg_19A_0.Point = (startPoint);
- pathFigure.Segments.Add(lineSegment);
- }
- }
- num2++;
- }
- }
- list2 = this.Indicator.CalculateDataPoints;
- flag3 = (list2 != null) && doubleCond != null; ;
- if (flag3)
- {
- int num6 = list2.Count - 1;
- while (true)
- {
- int arg_2E3_0 = num6;
- int num3 = 0;
- if (arg_2E3_0 < num3)
- {
- break;
- }
- bool arg_24A_0 = (dateScale.DateVisible(list2[num6].Date)
- || (num6 < list2.Count - 1 && dateScale.DateVisible(list2[num6 + 1].Date))) ||
- (num6 > 0 && dateScale.DateVisible(list2[num6 - 1].Date));
- flag2 = arg_24A_0 && Convert.ToBoolean(doubleCond[num6]); ;
- if (flag2)
- {
- float num7 = valScale.ScaledY(list2[num6].Value, aRect);
- float num8 = dateScale.XforDate(list2[num6].Date);
- flag3 = !flag;
- if (flag3)
- {
- PathFigure arg_29A_0 = pathFigure;
- Point startPoint = new Point((double)num8, (double)num7);
- arg_29A_0.StartPoint = (startPoint);
- flag = true;
- }
- else
- {
- LineSegment lineSegment = new LineSegment();
- LineSegment arg_2BF_0 = lineSegment;
- Point startPoint = new Point((double)num8, (double)num7);
- arg_2BF_0.Point = (startPoint);
- pathFigure.Segments.Add(lineSegment);
- }
- }
- num6 += -1;
- }
- }
- flag3 = flag;
- if (flag3)
- {
- LineSegment lineSegment = new LineSegment();
- LineSegment arg_322_0 = lineSegment;
- Point startPoint = pathFigure.StartPoint;
- Point point = new Point(startPoint.X, pathFigure.StartPoint.Y);
- arg_322_0.Point = (point);
- pathFigure.Segments.Add(lineSegment);
- }
- list.Add(path);
- return list;
- }
- }
- #region 暂时未用到
- private void BuildTodaysOpenLine(PlotPainter painter, IDateScaler dateScale, IValueScaler valScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- bool flag = list != null && list.Count > 1;
- checked
- {
- if (flag)
- {
- DateTime aDate = list[list.Count - 1].Date;
- int num = list.Count - 1;
- while (true)
- {
- if (num < 0)
- {
- return;
- }
- flag = (DateTime.Compare(list[num].Date.Date, aDate.Date) < 0);
- if (flag)
- {
- break;
- }
- num += -1;
- }
- bool flag2 = num < list.Count - 1;
- if (flag2)
- {
- float num3 = dateScale.XforDate(list[num + 1].Date);
- float num4 = dateScale.XforDate(aDate);
- var lineGeometry = new LineGeometry();
- float aVal = list[num + 1].Value;
- flag2 = (list[num + 1] is IOHLCDataPoint);
- if (flag2)
- {
- aVal = ((IOHLCDataPoint)list[num + 1]).Open;
- }
- painter.AddLine(lineGeometry, c_TodayOpenColor);
- unchecked
- {
- lineGeometry.StartPoint = new Point((double)num4, 0.5 + (double)valScale.ScaledY(aVal, aRect));
- lineGeometry.EndPoint = new Point((double)num3, 0.5 + (double)valScale.ScaledY(aVal, aRect));
- }
- }
- }
- }
- }
- private void BuildYesterdaysCloseLine(PlotPainter painter, IDateScaler dateScale, IValueScaler valScale, Rect aRect, IndicatorModel indicatorModel)
- {
- var list = indicatorModel.CalculateDataPoints;
- bool flag = list != null && list.Count > 1;
- if (flag)
- {
- int num;
- float num3;
- float num4;
- LineGeometry lineGeometry;
- LineGeometry arg_F7_0;
- checked
- {
- DateTime aDate = list[list.Count - 1].Date;
- num = list.Count - 1;
- while (true)
- {
- int arg_13F_0 = num;
- int num2 = 0;
- if (arg_13F_0 < num2)
- {
- return;
- }
- flag = (DateTime.Compare(list[num].Date.Date, aDate.Date) < 0);
- if (flag)
- {
- break;
- }
- num += -1;
- }
- num3 = dateScale.XforDate(list[num].Date);
- num4 = dateScale.XforDate(aDate);
- lineGeometry = new LineGeometry();
- painter.AddLine(lineGeometry, c_YestodayColor);
- arg_F7_0 = lineGeometry;
- }
- Point point = new Point((double)num4, 0.5 + (double)valScale.ScaledY(list[num].Value, aRect));
- arg_F7_0.StartPoint = (point);
- LineGeometry arg_12A_0 = lineGeometry;
- point = new Point((double)num3, 0.5 + (double)valScale.ScaledY(list[num].Value, aRect));
- arg_12A_0.EndPoint = (point);
- }
- }
- #endregion
- private Color GetPointColor(ILineDataPoint aPoint)
- {
- bool flag = aPoint is IColoredDataPoint;
- Color result;
- if (flag)
- {
- result = ((IColoredDataPoint)aPoint).Color;
- }
- else
- {
- result = this.CurrentPlotColor();
- }
- return result;
- }
- private bool HasOHLC()
- {
- //bool flag = this.mOutputData == null || this.mOutputData.DataPoints == null;
- //checked
- //{
- // if (!flag)
- // {
- // var list = this.mOutputData.DataPoints;
- // int num = list.Count - 1;
- // int num2 = 0;
- // while (true)
- // {
- // int num3 = num;
- // if (num2 > num3)
- // {
- // return false;
- // }
- // flag = (list[num2] is IOHLCDataPoint);
- // if (flag)
- // {
- // break;
- // }
- // num2++;
- // }
- // return true;
- // }
- // return false;
- //}
- return true;
- }
- private bool NotHasColoredDataPoint()
- {
- //if (this.mOutputData == null || this.mOutputData.DataPoints == null) return true;
- //return !this.mOutputData.DataPoints.OfType<IColoredDataPoint>().Any();
- return true;
- }
- private void OnPlotStyleChanged()
- {
- if (PlotStyleChanged != null)
- {
- PlotStyleChanged();
- }
- }
- #endregion Private Methods
- #endregion Methods
- #region Other
- //public override XElement ToXML(List<object> args)
- //{
- // XElement xElement = new XElement(this.RootName());
- // xElement.Add(new XAttribute("PlotColor", this.mPlotColorDarkBG.ToString()));
- // xElement.Add(new XAttribute("PlotColorL", this.mPlotColorLightBG.ToString()));
- // bool flag = this.mPlotNegValsDiffColor;
- // if (flag)
- // {
- // xElement.Add(new XAttribute("PlotNegValsDiffColor", true.ToString()));
- // }
- // xElement.Add(new XAttribute("NegPlotColor", this.mPlotNegColorDarkBG.ToString()));
- // xElement.Add(new XAttribute("NegPlotColorL", this.mPlotNegColorLightBG.ToString()));
- // xElement.Add(new XAttribute("AreaColor", this.mAreaFillColorDarkBG.ToString()));
- // xElement.Add(new XAttribute("AreaColorL", this.mAreaFillColorLightBG.ToString()));
- // xElement.Add(new XAttribute("PlotStyle", this.mPlotStyle.ToString()));
- // xElement.Add(new XAttribute("Thickness", this.LinePlot_1593.ToString()));
- // xElement.Add(new XAttribute("DashPattern", this.LinePlot_1591.ToString()));
- // xElement.Add(new XAttribute("OutputDataGUID", this.mOutputData.DataGUID.ToString()));
- // flag = (this.mSource != null && (args == null || !args.Contains("NOSAVEINDSOURCE")));
- // if (flag)
- // {
- // xElement.Add(new XAttribute("SourceID", this.mSource.UID()));
- // }
- // xElement.Add(this.mCalculation.ToXML(args));
- // base.AddToXML(xElement, args);
- // return xElement;
- //}
- #endregion Other
- }
- }
|