private void loadChart() { CurveChartTemplate defaultTemplate = null; var data = new List <DataRepository>(); if (_simulation.Results != null) { data.Add(_simulation.Results); } if (_simulation.Chart == null) { _simulation.Chart = _chartFactory.Create <CurveChart>().WithAxes(); _chartTask.SetOriginText(_simulation.Name, _simulation.Chart); } // Whether or not the chart is new, if it has no curves // we apply the simulation default template if (_simulation.Chart.Curves.Count == 0) { defaultTemplate = _simulation.DefaultChartTemplate; } addObservedDataRepositories(data, _simulation.Chart.Curves); _chartPresenter.Show(_simulation.Chart, data, defaultTemplate); }
private T createChartAnalysisFor <T>(ParameterIdentification parameterIdentification) where T : CurveChart, ISimulationAnalysis { var chart = _chartFactory.Create <T>(); AddSimulationAnalysisTo(parameterIdentification, chart); return(chart); }
public void ShowData(IReadOnlyList <DataRepository> data) { var chart = _chartFactory.Create <CurveChart>().WithAxes(); chart.Id = ShortGuid.NewGuid(); chart.Name = getChartName(data); addChartToProject(chart); ShowChart(chart, data); }
public IActionResult Get(ImageFormat imageFormat, int width, int height, double x0, double xn, double y0, double yn, string equation) { var equations = new[] { equation }; var decodedEquations = equations.ToArray(); var calculationsMode = CalculationsMode.Error; foreach (var eq in decodedEquations) { var mode = _modeDeterminer.DetermineMode(eq); if (mode == CalculationsMode.Complex) { calculationsMode = CalculationsMode.Complex; } else if (mode == CalculationsMode.Fxy && calculationsMode != CalculationsMode.Complex) { calculationsMode = CalculationsMode.Fxy; } else if (mode == CalculationsMode.Real && calculationsMode != CalculationsMode.Complex && calculationsMode != CalculationsMode.Fxy) { calculationsMode = CalculationsMode.Real; } } var chart = _chartFactory.Create(calculationsMode); foreach (var eq in decodedEquations) { var func = _functionsProvider.GetFunction(eq, calculationsMode, ""); chart.AddFunction(func); } chart.XMax = xn; chart.XMin = x0; chart.YMin = y0; chart.YMax = yn; chart.Visible = true; Image img = chart.GetImage(width, height); using (MemoryStream ms = new MemoryStream()) { img.Save(ms, imageFormat); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new ByteArrayContent(ms.ToArray()); result.Content.Headers.ContentType = new MediaTypeHeaderValue($"image/{imageFormat.ToString().ToLowerInvariant()}"); //return result; return(File(ms.ToArray(), $"image/{imageFormat.ToString().ToLowerInvariant()}")); } }
protected override void Context() { _view = A.Fake <ISimpleChartView>(); _chartFactory = A.Fake <IChartFactory>(); _chartDisplayPresenter = A.Fake <IChartDisplayPresenter>(); _eventPublisher = A.Fake <IEventPublisher>(); _dimensionFactory = A.Fake <IDimensionFactory>(); _presentationUserSettings = A.Fake <IPresentationUserSettings>(); sut = new SimpleChartPresenter(_view, _chartDisplayPresenter, _chartFactory, _eventPublisher, _presentationUserSettings, _dimensionFactory); _presentationUserSettings.DefaultChartYScaling = Scalings.Log; A.CallTo(() => _chartFactory.Create <CurveChart>()).ReturnsLazily(() => new CurveChart { DefaultYAxisScaling = _presentationUserSettings.DefaultChartYScaling }); }
private void Form1_Click(object sender, EventArgs e) { //string AssemblyName = "工厂方法模式_简易图表_工厂方法版";//直接指定当前程序集名称 string AssemblyName = Assembly.GetExecutingAssembly().GetName().Name; //得到当前程序集名称 Graphics g = this.CreateGraphics(); var p = new Pen(Color.Maroon); g.Clear(Color.LightBlue); IChartFactory chartFactory = null; //利用swich语句,选择要创建的工厂类对象 //switch (this.comboBox1.Text) //{ // case "Pie": // chartFactory = new PieChartFactory(); // break; // case "Bar": // chartFactory = new BarChartFactory(); // break; // case "Line": // chartFactory = new LineChartFactory(); // break; //} string className = AssemblyName + "." + comboBox1.Text + "ChartFactory"; //组装出需要的工厂类的类名 chartFactory = (IChartFactory)Assembly.Load(AssemblyName).CreateInstance(className); //利用反射,创建指定类名的实例 Chart chart = chartFactory.Create(g, p); //chart.Data = new int[]{100,400,300,500,200}; //chart.Data = new int[] { 300, 200, 400, 500, 100 }; string[] content = this.textBox1.Text.Split(','); chart.Data = new int[content.Length]; //创建需要的长度的int数组 for (int i = 0; i < content.Length; i++) { chart.Data[i] = Convert.ToInt32(content[i]); } //将字符串数组中各字符串转换为整型 chart.Display(); }