// Methods // Method that fetch the latest bank transactions //and updates user's carbon footprint public void UpdateFootprint() { // TODO, only dummy data at this point // 1500 NOK as example of montly fuel purchase, 3 x 500 NOK IEmission fuelEmissions = new Fuel(User.Vehicle); fuelEmissions.CalculateCO2(1500); IEmission flightEmissions = new Flight(); // 2500 NOK as example of montly air travel expenses flightEmissions.CalculateCO2(2500); IEmission householdEmissions = new Household(); // 1000 NOK as example of montly electricity bill householdEmissions.CalculateCO2(1000); Emissions = new IEmission[] { fuelEmissions, flightEmissions, householdEmissions }; Flight = flightEmissions.KgCO2; Fuel = fuelEmissions.KgCO2; Household = householdEmissions.KgCO2; }
// Calculate angle to rotate the cake orientation so that it aligns // the selected emission icon on on the top arc of the cake. // Sets the currently selected emission. public float UpdateOrientation(IEmission Selected) { // Reset first (avoid accumulating huge sums in startAngle) //InitializeCake(); bool add = false; float newStartAngleOffset = 0; // Calculate the amount to offset foreach (PieceOfCake Slice in PiecesOfCake) { if (add) { newStartAngleOffset += Slice.ArcAngle; } if (Slice.Emission.Equals(Selected)) { CurrentlySelected = Slice; newStartAngleOffset += (Slice.ArcAngle / 2) - 90; add = true; } } OffsetDifference = newStartAngleOffset - OldOffset; OldOffset = newStartAngleOffset; return(OffsetDifference); }
public EmissionHighlightView(IEmission emission) { InitializeComponent(); this.emission = emission; YetiRankImage.Source = "YetiPrince"; //HighlightedEmissionValueLabel.Text = (int)emission.KgCO2 + " kg CO2."; }
// Use this for initialization public virtual void Start() { switch (Type) { case EmissionType.Directional: emission = new DirectionalEmission(); break; } lastEmissionTime = Time.time - Interval; }
public EmissionDetailsPage(IEmission emission) { InitializeComponent(); ToolbarItems.Add(new ToolbarItem("Statistikk", "graph_icon.png", async() => { var page = new ContentPage(); var result = await page.DisplayAlert("Title", "Message", "Accept", "Cancel"); System.Diagnostics.Debug.WriteLine("success: {0}", result); })); DataSourceListView.ItemsSource = dataSourceList; Title = CakeUtil.GetTitle(emission) + "utslipp"; dataSourceList.Add(new DataSource(DateTime.Now, "Some datasource", 23.98, EmissionType.Flight)); dataSourceList.Add(new DataSource(DateTime.Now, "Some other datasource", 89.43, EmissionType.Flight)); dataSourceList.Add(new DataSource(DateTime.Now, "Some third datasource", 219.91, EmissionType.Flight)); }
public Icon(IEmission emission, SKPoint cakeCenter, float radius, float offset, SKPoint center) { Radius = radius; Offset = offset; Center = center; SVG = CakeUtil.GetSVGPath(emission); Color = CakeUtil.GetColor(emission); DropShadow = SKImageFilter.CreateDropShadow(-(Center.X - cakeCenter.X) / 12, -(Center.Y - cakeCenter.Y) / 12, 9, 9, SKColors.Black.WithAlpha(50), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground); ScaleSVGPath(); CenterSVGPath(); }
public PieceOfCake(IEmission emission, SKPoint cakeCenter, float startAngle, float sweepAngle, float cakeRadius, float iconSpacing, float iconRadius) { Emission = emission; StartAngle = startAngle; EndAngle = startAngle + sweepAngle; ArcAngle = EndAngle - StartAngle; Color = CakeUtil.GetColor(emission); CakeCenter = cakeCenter; // Calculate coordinates for icons float offsetAngle = StartAngle + (sweepAngle / 2); float offsetX = (cakeRadius + iconSpacing) * (float)Math.Cos(offsetAngle * Math.PI * 2 / 360); float offsetY = (cakeRadius + iconSpacing) * (float)Math.Sin(offsetAngle * Math.PI * 2 / 360); SKPoint IconCenter = new SKPoint(cakeCenter.X + offsetX, cakeCenter.Y + offsetY); Icon = new Icon(emission, cakeCenter, iconRadius, iconSpacing, IconCenter); }
public static SKColor GetColor(IEmission emission) { switch (emission.Type) { case EmissionType.Flight: return(SKColor.Parse(ConfigurationManager.AppSettings["FlightCakeColor"])); case EmissionType.Fuel: return(SKColor.Parse(ConfigurationManager.AppSettings["FuelCakeColor"])); case EmissionType.Household: return(SKColor.Parse(ConfigurationManager.AppSettings["HouseholdCakeColor"])); default: return(SKColors.Transparent); } }
public static SKPath GetSVGPath(IEmission emission) { switch (emission.Type) { case EmissionType.Flight: return(SKPath.ParseSvgPathData(ConfigurationManager.AppSettings["FlightIconSVG"])); case EmissionType.Fuel: return(SKPath.ParseSvgPathData(ConfigurationManager.AppSettings["FuelIconSVG"])); case EmissionType.Household: return(SKPath.ParseSvgPathData(ConfigurationManager.AppSettings["HouseholdIconSVG"])); default: return(SKPath.ParseSvgPathData("")); } }
public static string GetTitle(IEmission emission) { switch (emission.Type) { case EmissionType.Flight: return(ConfigurationManager.AppSettings["FlightTitleText"]); case EmissionType.Fuel: return(ConfigurationManager.AppSettings["FuelTitleText"]); case EmissionType.Household: return(ConfigurationManager.AppSettings["HouseholdTitleText"]); default: return(""); } }
public void SetOrientation(float offset) { for (int i = 0; i < PiecesOfCake.Length; i++) { IEmission emission = PiecesOfCake[i].Emission; float startAngle = PiecesOfCake[i].StartAngle += offset; float arcAngle = PiecesOfCake[i].ArcAngle; float iconRadius = IconRadius; float iconOffset = IconOffset; bool isSelected = PiecesOfCake[i].Emission.Equals(CurrentlySelected); // Make icon of selected category bigger if (isSelected) { float factor = 1f; iconRadius = IconRadius * factor; //iconOffset = iconRadius / 2 + IconOffset; } PiecesOfCake[i] = new PieceOfCake(emission, Center, startAngle, arcAngle, Radius, iconOffset, iconRadius); } }
public async Task AnimateSelection(IEmission Select, float millis) { float offset = UpdateOrientation(Select); float i = 0; // These two values constitute the animation speed // angleInterval is the resolution of animation float angleInterval = Math.Abs(offset) > 220 ? offset / 22 : offset / 12; // ms is the frame rate. Acts unexpectedly for vaues below 10. int ms = 8; IsAnimating = true; PopOver.Factor = 0; if (offset < 0) { while (i > offset - angleInterval) { SetOrientation(angleInterval); CanvasView.InvalidateSurface(); await Task.Delay(TimeSpan.FromMilliseconds(ms)); i += angleInterval; //System.Diagnostics.Debug.WriteLine("i: " + i); if (i < offset * 0.1) { float remaining = offset * 0.9f / angleInterval; PopOver.Factor += 1f / remaining; } CanvasView.InvalidateSurface(); } SetOrientation(offset - i); PopOver.Factor = 1; await Task.Delay(TimeSpan.FromMilliseconds(ms)); CanvasView.InvalidateSurface(); } else { while (i < offset - angleInterval) { SetOrientation(angleInterval); CanvasView.InvalidateSurface(); await Task.Delay(TimeSpan.FromMilliseconds(ms)); i += angleInterval; //System.Diagnostics.Debug.WriteLine("i: " + i); if (i > offset * 0.1) { float remaining = offset * 0.9f / angleInterval; PopOver.Factor += 1f / remaining; } CanvasView.InvalidateSurface(); } SetOrientation(offset - i); PopOver.Factor = 1; await Task.Delay(TimeSpan.FromMilliseconds(ms)); CanvasView.InvalidateSurface(); } //System.Diagnostics.Debug.WriteLine("offset: " + offset); IsAnimating = false; }