Ejemplo n.º 1
0
        /// <summary>
        /// Removes a country object from the list of all data
        /// </summary>
        /// <param name="toRemove"></param>
        public void RemoveCountryData(CountryObj toRemove)
        {
            //loops through all the data
            for (int i = allData.Count() - 1; i >= 0; i--)
            {
                //checks if the current country data is the one to remove
                if (allData[i].CountryData == toRemove)
                {
                    //loops through each of the textboxes
                    for (int j = 0; j < countryTitle_pnl.Controls.Count; j++)
                    {
                        //checks if the text box's text was the same as the country to remove's name
                        if (countryTitle_pnl.Controls[j].Text == toRemove.Country)
                        {
                            //removes the text box from the text box list and the controls list
                            Controls.Remove(countryTitle_pnl.Controls[j]);
                            countryTitle_pnl.Controls.Remove(countryTitle_pnl.Controls[j]);
                            RealignCountryLabels();
                        }
                    }

                    //removes the country data
                    allData.Remove(allData[i]);

                    //refinds the biggest values
                    Data.FindBiggestValues(allData);

                    //redraws the graph
                    graph.Invalidate();

                    //stops the search
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Turns the input country into a checkbox
        /// </summary>
        /// <param name="country">The country to convert</param>
        void LoadCountryAsCheckBox(CountryObj country)
        {
            //a checkbox to work with
            CheckBox c = new CheckBox();

            //sets the checkbox's text to the country name of the input
            c.Text        = country.Country;
            c.MaximumSize = new Size(0, 0);
            c.AutoSize    = true;
            c.FlatStyle   = FlatStyle.Flat;

            //checks if the country was already being shown in the main window
            if (Selected(country))
            {
                //sets the check status to ticked
                c.Checked = true;

                //loops through each dataset in the main window
                foreach (Data d in mainWindow.allData)
                {
                    //checks if the data's country is the same as the input country
                    if (d.CountryData.Country == country.Country)
                    {
                        //sets the checkbox font color to be the same as the graph color
                        c.ForeColor = d.GraphColor;

                        //stops searching
                        break;
                    }
                }
            }
            else
            {
                //sets the checkbox to unticked
                c.Checked = false;

                //sets the default color to black;
                c.ForeColor = Color.Black;
            }

            //sets the location of the checkbox under the last one
            c.Location = new Point(10, allCountries_pnl.Controls.Count * verticalSpacing);

            //sets up what method to call on click
            c.CheckedChanged += CheckChange;

            //adds the checkbox to the panel
            allCountries_pnl.Controls.Add(c);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if a country is selected in the main window
        /// </summary>
        /// <param name="toCheck"></param>
        /// <returns></returns>
        bool Selected(CountryObj toCheck)
        {
            //loops through each of the data from the main window
            foreach (Data d in mainWindow.allData)
            {
                //checks if the current data's country is the same as the one being checked against
                if (d.CountryData.Country == toCheck.Country)
                {
                    //returns that this country is selected
                    return(true);
                }
            }

            //returns that the country was not found
            return(false);
        }
Ejemplo n.º 4
0
        public Data(CountryObj _country, CasesObj[] _cases, Color _color)
        {
            CountryData    = _country;
            DailyCasesData = _cases;
            GraphColor     = _color;

            //checks if the new array is longers than the current longest array
            if (_cases.Length > longestArray)
            {
                //updates what the longest array is
                longestArray = _cases.Length;
            }

            //checks if the number of cases in the final day is bigger than the current biggest number of cases
            if (_cases[_cases.Length - 1].Cases > biggestCase)
            {
                //updates what the biggest number of cases is
                biggestCase = _cases[_cases.Length - 1].Cases;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Event for a checkbox status changing
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        void CheckChange(Object source, EventArgs e)
        {
            //turns the source back into a checkbox object
            CheckBox c = source as CheckBox;

            //gets the country object from the name of the clicked checkbox
            CountryObj country = ReturnCountryObj(c.Text, countries);

            //selects or deselectes based on the check status of the checkbox
            if (c.Checked)
            {
                Select(country, graphColor);

                c.ForeColor = graphColor;
            }
            else
            {
                DeSelect(country);

                c.ForeColor = Color.Black;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Pulls data about the entered country
        /// </summary>
        /// <param name="slug">The slug (country-identifier) for the wanted country</param>
        /// <param name="_countryName">The name of the country</param>
        /// <param name="graphColor">The color of the countries graph points</param>
        /// <param name="lastTxtLoc">The point to base the next textbox location on</param>
        /// <returns></returns>
        public async Task PullData(CountryObj countryObj, Color graphColor)
        {
            //the tobe location of the new
            Point location = new Point(0, 0);

            //checks if this is not the first label
            if (countryTitle_pnl.Controls.Count != 0)
            {
                //adds the label under the last label
                location.Y = countryTitle_pnl.Controls[countryTitle_pnl.Controls.Count - 1].Location.Y + countryTitle_pnl.Controls[countryTitle_pnl.Controls.Count - 1].Height + 30;
            }

            CasesObj[] pulledCases;
            Label      t = new Label();

            //pulls the entered country data
            pulledCases = await DataPuller.PullConfirmedData(countryObj.Slug);

            //checks to see if the pulled country data had any data
            if (pulledCases.Length > 0)
            {
                //adds the newly pulled data into the list of all datas
                allData.Add(new Data(countryObj, pulledCases, graphColor));

                //creates and sets up a new text box with the country name and color
                t.Location    = location;
                t.Text        = countryObj.Country;
                t.Font        = new Font(t.Font.FontFamily, 12);
                t.ForeColor   = graphColor;
                t.Anchor      = AnchorStyles.Top | AnchorStyles.Right;
                t.AutoSize    = true;
                t.MaximumSize = new Size(normalise_btn.Width, 0);
                countryTitle_pnl.Controls.Add(t);

                //draws the graph
                graph.Invalidate();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Tells the main window to remove a country's data
 /// </summary>
 /// <param name="toRemove">The country whos data to remove</param>
 void DeSelect(CountryObj toRemove)
 {
     mainWindow.RemoveCountryData(toRemove);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Selects the country in the main window
 /// </summary>
 /// <param name="toPullData"></param>
 async void Select(CountryObj toPullData, Color graphColor)
 {
     //tells the main window to add the new country's data
     await mainWindow.PullData(toPullData, graphColor);
 }