Beispiel #1
0
        static public async Task <Bitmap> CreateHistogram(HistogramAttributes attributes)
        {
            await FlaskApi.PutRequest(ApiEndpointConfigurations.histogramPlotterApiEndPoint, attributes.PlotToKeyAndArguments());



            Dictionary <string, object> result = await FlaskApi.GetRequest(ApiEndpointConfigurations.histogramPlotterApiEndPoint, printResponse : false);



            string imageDataInString      = result[ApiEndpointConfigurations.plotImageData_key] as string;
            string imageDimensionInString = result[ApiEndpointConfigurations.plotImageShape_key] as string;

            #region getting image Shape
            //(height,width ,3)
            int[] imageShape = DataStructureConverter.ConvertArrayInStringToArrayOfInt(imageDimensionInString);
            int   height     = imageShape[0];
            int   width      = imageShape[1];

            #endregion

            #region getting bitmap

            byte[] imageData = DataStructureConverter.ConvertArrayInStringToArrayOfByte(imageDataInString);

            //make bitmap
            Bitmap bitmap = MyImageLibrary.CreateImageFromRGB(width, height, imageData);
            #endregion


            return(bitmap);
        }
Beispiel #2
0
        static public async Task <Bitmap> CreateHistogram(HistogramAttributes attributes)
        {
            await FlaskApi.PutRequest(ApiEndpointConfigurations.histogramPlotterApiEndPoint, new Dictionary <string, string>
            {
                { "xColumnName", attributes.XColumnName },
                { "plotName", attributes.PlotName },
                { "xLabel", attributes.XLabel },
                { "xAxisLabelColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.XAxisLabelColor)) },
                { "barColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.BarColor)) },
                { "yLabel", attributes.YLabel },
                { "yAxisLabelColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.YAxisLabelColor)) },
                { "plotNameColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.PlotNameColor)) },

                { "bottomSpineColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.BottomSpineColor)) },
                { "topSpineColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.TopSpineColor)) },
                { "leftSpineColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.LeftSpineColor)) },
                { "rightSpineColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.RightSpineColor)) },

                { "figureBackgroundColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.FigureBackgroundColor)) },
                { "axesBackgroundColor", JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.AxesBackgroundColor)) },
                //{"titleColorTest",JsonConvert.SerializeObject(MyImageLibrary.ConvertColorToRGBA(attributes.ColorTest))}
            });

            Dictionary <string, object> result = await FlaskApi.GetRequest(ApiEndpointConfigurations.histogramPlotterApiEndPoint, printResponse : false);



            string imageDataInString      = result[ApiEndpointConfigurations.plotImageData_key] as string;
            string imageDimensionInString = result[ApiEndpointConfigurations.plotImageShape_key] as string;

            #region getting image Shape
            //(height,width ,3)
            int[] imageShape = DataStructureConverter.ConvertArrayInStringToArrayOfInt(imageDimensionInString);
            int   height     = imageShape[0];
            int   width      = imageShape[1];

            #endregion

            #region getting bitmap

            byte[] imageData = DataStructureConverter.ConvertArrayInStringToArrayOfByte(imageDataInString);

            //make bitmap
            Bitmap bitmap = MyImageLibrary.CreateImageFromRGB(width, height, imageData);
            #endregion


            return(bitmap);
        }
        /// <summary>
        /// Start plotting
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnPlotGraph_Click(object sender, EventArgs e)
        {
            //draw respective plot
            string exceptionMessage = "";

            switch (this.plotType)
            {
            case CsvPlotter.PlotTypes.Histogram:
            {
                HistogramAttributes attributes = this.pgPlotProperty.SelectedObject as HistogramAttributes;
                if (attributes.ColumnsNamesAreValid(ref exceptionMessage))
                {
                    Bitmap image = await CsvPlotter.CreateHistogram(attributes);

                    using (ShowPlotForm showPlotForm = new ShowPlotForm(image))
                    {
                        showPlotForm.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show(exceptionMessage, "Exception Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            break;

            case CsvPlotter.PlotTypes.Scatter:
            {
                ScatterAttributes attributes = this.pgPlotProperty.SelectedObject as ScatterAttributes;
                if (attributes.ColumnsNamesAreValid(ref exceptionMessage))
                {
                    Bitmap image = await CsvPlotter.CreateScatterPlot(attributes);

                    using (ShowPlotForm showPlotForm = new ShowPlotForm(image))
                    {
                        showPlotForm.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show(exceptionMessage, "Exception Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            break;
            }
        }