Skip to content

Commit

Permalink
Starting Artist and ArtistWork pages with mocked data.
Browse files Browse the repository at this point in the history
creating new dashboard chart for line graph
some clean up
  • Loading branch information
czf committed Jan 11, 2021
1 parent 1b33fd2 commit d9e6709
Show file tree
Hide file tree
Showing 27 changed files with 440 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ private static int GetTimeRangeMultipler(AggregateTimeRange timeRange)
break;
default:
throw new NotSupportedException("Value: " + timeRange.ToString());
break;
}

return multiplier;
Expand Down Expand Up @@ -77,5 +76,61 @@ public int GetTotalUniqueArtists(AggregateTimeRange timeRange)

return multiplier * _random.Next(300, 350);
}

public List<ItemCount> GetMostPlayedSongs(AggregateTimeRange timeRange, int artistId)
{
return GetMostPlayedSongs(timeRange);

}

public List<ItemCount> GetSongPlayedOverTime(AggregateTimeRange timeRange, int artistWorkId)
{
int multiplier = GetTimeRangeMultipler(timeRange);

List<ItemCount> result = new List<ItemCount>()
{
new ItemCount(){Count = 10 * multiplier, Name= GetOverTimeName(0, timeRange), ItemId = artistWorkId},
new ItemCount(){Count = 2 * multiplier, Name= GetOverTimeName(1, timeRange), ItemId = artistWorkId},
new ItemCount(){Count = 7 * multiplier, Name= GetOverTimeName(2, timeRange), ItemId = artistWorkId},
new ItemCount(){Count = 2 * multiplier, Name= GetOverTimeName(3, timeRange), ItemId = artistWorkId},
new ItemCount(){Count = 2 * multiplier, Name= GetOverTimeName(4, timeRange), ItemId = artistWorkId},
new ItemCount(){Count = 1 * multiplier, Name= GetOverTimeName(5, timeRange), ItemId = artistWorkId},
new ItemCount(){Count = 0 * multiplier, Name= GetOverTimeName(6, timeRange), ItemId = artistWorkId},
};
if(timeRange == AggregateTimeRange.ThreeMonths || timeRange == AggregateTimeRange.AllTime)
{
result.Add(new ItemCount() { Count = 10 * multiplier, Name = GetOverTimeName(7, timeRange), ItemId = artistWorkId });
result.Add(new ItemCount() { Count = 2 * multiplier, Name = GetOverTimeName(8, timeRange), ItemId = artistWorkId } );
result.Add(new ItemCount() { Count = 7 * multiplier, Name = GetOverTimeName(9, timeRange), ItemId = artistWorkId } );
result.Add(new ItemCount() { Count = 2 * multiplier, Name = GetOverTimeName(10, timeRange), ItemId = artistWorkId });
result.Add(new ItemCount() { Count = 2 * multiplier, Name = GetOverTimeName(11, timeRange), ItemId = artistWorkId });
}
result.Reverse();
return result;

}

private string GetOverTimeName(int index, AggregateTimeRange aggregateTimeRange)
{
string result = string.Empty;
switch (aggregateTimeRange)
{
case AggregateTimeRange.None:
throw new InvalidEnumArgumentException("Must specify time range value other than None");
case AggregateTimeRange.SevenDays:
result = DateTime.Now.AddDays(index * -1).DayOfWeek.ToString();
break;
case AggregateTimeRange.ThreeMonths:
result = DateTime.Now.AddDays(index * -7).ToShortDateString();
break;
case AggregateTimeRange.AllTime:
result = DateTime.Now.AddMonths(index * -1).ToShortDateString();
break;
default:
throw new NotSupportedException("Value: " + aggregateTimeRange.ToString());

}
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<CascadingValue Value="@HeaderButtonConfigs" Name="HeaderButtonConfigs">
<DashboardHorizontalBarChartComponent @ref="Chart"
YAxisLabel="YLabel"
GenerateChartDatas="TopPlayedArtistSongs"
ChartTitle="Top Played Songs"
OnDashboardChartElementClick="NavigateToArtistArtistsWorkRouteOnBarClick" />
</CascadingValue>


Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Microsoft.AspNetCore.Components;
using RadiocomDataViewApp.Clients;
using RadiocomDataViewApp.Interfaces;
using RadiocomDataViewApp.Objects;

namespace RadiocomDataViewApp.Components.ArtistCharts
{
public partial class TopPlayedArtistSongsChart : ComponentBase
{
private List<HeaderButtonState> HeaderButtonConfigs;
private AggregateTimeRange ChartDataTimeRange;
private DashboardHorizontalBarChartComponent Chart;

[Parameter]
public int ArtistId { get; set; }

[Inject]
public NavigationManager NavManager { get; set; }
[Inject]
public IRadiocomDataAggregateDataClient RadiocomDataAggregateDataClient { get; set; }



public TopPlayedArtistSongsChart()
{
HeaderButtonConfigs = new List<HeaderButtonState>()
{
new HeaderButtonState(){Text = "7 Days",ButtonColor=Color.Secondary,Active=true, ButtonClickCallback = EventCallback.Factory.Create(this, () => UpdateChartDataTimeRange(AggregateTimeRange.SevenDays)) } ,
new HeaderButtonState(){Text = "3 Months", ButtonClickCallback = EventCallback.Factory.Create(this, () => UpdateChartDataTimeRange(AggregateTimeRange.ThreeMonths)) } ,
new HeaderButtonState(){Text = "All Time", ButtonClickCallback = EventCallback.Factory.Create(this, () => UpdateChartDataTimeRange(AggregateTimeRange.AllTime)) }
};
ChartDataTimeRange = AggregateTimeRange.SevenDays;

}


private void NavigateToArtistArtistsWorkRouteOnBarClick(DashboardChartMouseEventArgs args)
{
BarChartDatasetXValue element = (BarChartDatasetXValue)args.DatasetElement;
NavManager.NavigateTo($"artist/{element.DataId}/works");
}

private void UpdateChartDataTimeRange(AggregateTimeRange mostPlayedTimeRange)
{
ChartDataTimeRange = mostPlayedTimeRange;
Chart.RefreshChartData();
}

private IEnumerable<DashboardChartData> TopPlayedArtistSongs()
{
List<ItemCount> radioComData = RadiocomDataAggregateDataClient.GetMostPlayedSongs(ChartDataTimeRange, ArtistId);
return radioComData.Select(x => new DashboardChartData() { Label = x.Name, Value = x.Count, DataId = x.ItemId });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@

namespace RadiocomDataViewApp.Components
{
public partial class DashboardChartComponent : ComponentBase
public partial class DashboardHorizontalBarChartComponent : ComponentBase
{
private const string DEFAULT_BAR_COLOR = "#FFF";

private Object StandardTicks = new
private object StandardTicks = new
{
FontColor = "#fff",
BeginAtZero = true
};



//[Inject]
//public IJSRuntime JSRuntime { get; set; }
//[Inject]
//public NavigationManager NavManager { get; set; }

public readonly Object ChartOptionsObj;
public readonly object ChartOptionsObj;
public readonly ChartOptions chartOptions;

[Parameter]
Expand All @@ -47,14 +40,14 @@ public partial class DashboardChartComponent : ComponentBase
public Func<int, ChartColor> BarColorGenerator { get; set; }
[Parameter]
public string ScaleLabelFontColor { get; set; }
[Parameter]
public string AxisTicksFontColor { get; set; }
[Parameter]
public Dictionary<string, EventCallback<MouseEventArgs>> ChartTimeFrames { get; set; }
//[Parameter]
//public string AxisTicksFontColor { get; set; }
//[Parameter]
//public Dictionary<string, EventCallback<MouseEventArgs>> ChartTimeFrames { get; set; }
[Parameter]
public EventCallback<DashboardChartMouseEventArgs> OnDashboardChartElementClick { get; set; }

private EventCallback<ChartMouseEventArgs> OnBarElementClick { get; set;}
//private EventCallback<ChartMouseEventArgs> OnBarElementClick { get; set;}
private async Task OnBarElementClickedHandler(ChartMouseEventArgs args)
{

Expand Down Expand Up @@ -99,7 +92,7 @@ public void RefreshChartData()
}

private HorizontalBarChart<BarChartDatasetXValue> Chart;
public DashboardChartComponent()
public DashboardHorizontalBarChartComponent()
{
#region chartOptions
ChartOptionsObj = new
Expand Down Expand Up @@ -154,7 +147,7 @@ public DashboardChartComponent()

protected override bool ShouldRender()
{
Console.WriteLine("should render:" + Chart.Data != null && (Chart.Data.Datasets?.Any(x => x.Data?.Any() ?? false) ?? false) && base.ShouldRender());
//Console.WriteLine("should render:" + Chart.Data != null && (Chart.Data.Datasets?.Any(x => x.Data?.Any() ?? false) ?? false) && base.ShouldRender());
return Chart.Data != null && (Chart.Data.Datasets?.Any(x => x.Data?.Any() ?? false) ?? false) && base.ShouldRender();
}
private string GetScaleFontColor()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Card>
<CardHeader>
@if (!String.IsNullOrEmpty(ChartTitle))
{
<Container Fluid="true" Style="text-align:center">
<Heading Size="HeadingSize.Is5" Alignment="TextAlignment.None">@ChartTitle</Heading>
</Container>
}
</CardHeader>
<CardBody>

<ChartComponentHeaderButtons />



<LineChart @ref="Chart" TItem="DashboardChartDatasetYValue" OptionsObject="@ChartOptionsObj" />
</CardBody>

</Card>
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise.Charts;
using Microsoft.AspNetCore.Components;
using RadiocomDataViewApp.Objects;

namespace RadiocomDataViewApp.Components
{
public partial class DashboardLineGraphChartComponent : ComponentBase
{
private const string DEFAULT_POINT_COLOR = "#FFF";
private const string DEFAULT_FILL_COLOR = "#555FAF";

private Object StandardTicks = new
{
FontColor = "#fff",
BeginAtZero = true
};
public readonly ChartOptions chartOptions;
public readonly object ChartOptionsObj;

private LineChart<DashboardChartDatasetYValue> Chart;

[Parameter]
public string FillColor { get; set; }

[Parameter]
public string YAxisLabel { get; set; }
[Parameter]
public string XAxisLabel { get; set; }
[Parameter]
public string ChartTitle { get; set; }
[Parameter]
public Func<int, ChartColor> PointColorGenerator { get; set; }
[Parameter]
public Func<IEnumerable<DashboardChartData>> GenerateChartDatas { get; set; }
[Parameter]
public string ScaleLabelFontColor { get; set; }
public DashboardLineGraphChartComponent()
{
#region chartOptions
ChartOptionsObj = new
{
Legend = new { Display = false },
Scales = new
{
YAxes = new object[]
{
new
{
ScaleLabel = new
{
FontColor = GetScaleFontColor(),
Display = true,
LabelString = YAxisLabel ?? string.Empty
},
Ticks = StandardTicks

}
},
XAxes = new object[]
{
new
{
ScaleLabel = new
{
FontColor = GetScaleFontColor(),
Display = true,
LabelString = XAxisLabel ?? string.Empty
},
Ticks = StandardTicks
}
}
},
AspectRatio = 1.5

};


chartOptions = new ChartOptions()
{
Scales = new Scales()
{
YAxes = new List<Axis>() { new Axis() { Ticks = new AxisTicks() { FontColor = "#fff" }, ScaleLabel = new AxisScaleLabel() { FontColor = "#fff", Display = true, LabelString = "valueObj" } } },
XAxes = new List<Axis>() { new Axis() { Ticks = new AxisTicks() { FontColor = "#fff" }, ScaleLabel = new AxisScaleLabel() { FontColor = "#fff", Display = true, LabelString = "dimension" } } },
},
};
#endregion

}

public void RefreshChartData()
{
IEnumerable<DashboardChartData> newDatas = GenerateChartDatas?.Invoke();
Chart.Clear();
Chart.AddLabels(newDatas.Select(x => x.Label).ToArray());

List<string> colors = new List<string>();
for (int i = 0; i < newDatas.Count(); i++)
{
string lineColor = PointColorGenerator?.Invoke(i);
if (!string.IsNullOrWhiteSpace(lineColor))
{
colors.Add(lineColor);
}
else
{
colors.Add(DEFAULT_POINT_COLOR);
}
}

LineChartDataset<DashboardChartDatasetYValue> newChartDataset = new LineChartDataset<DashboardChartDatasetYValue>()
{
Data = newDatas.Select(x => new DashboardChartDatasetYValue() { Y = x.Value, DataId = x.DataId }).ToList(),
Fill = true,
BackgroundColor = DEFAULT_FILL_COLOR,
PointBackgroundColor = colors,
PointBorderColor = colors,
PointRadius = 3.5f
};
//newChartDataset.HoverBorderColor.Clear();
CurrentDataset = newChartDataset;
Chart.AddDataSet(newChartDataset);
Chart.Update();
}
protected LineChartDataset<DashboardChartDatasetYValue> CurrentDataset { get; set; }

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (firstRender)
{
RefreshChartData();
}
}

private string GetScaleFontColor()
=> string.IsNullOrWhiteSpace(ScaleLabelFontColor) ? "#fff" : ScaleLabelFontColor;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<CascadingValue Value="@HeaderButtonConfigs" Name="HeaderButtonConfigs">
<DashboardChartComponent @ref="Chart"
<DashboardHorizontalBarChartComponent @ref="Chart"
YAxisLabel="YLabel"
GenerateChartDatas="TopPlayedArtists"
ChartTitle="Top Played Artists"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public TopPlayedArtistsChart()

private List<HeaderButtonState> HeaderButtonConfigs;
private AggregateTimeRange ChartDataTimeRange;
private DashboardChartComponent Chart;
private DashboardHorizontalBarChartComponent Chart;
private IEnumerable<DashboardChartData> TopPlayedArtists()
{
List<ItemCount> radioComData = RadiocomDataAggregateDataClient.GetMostPlayedArtists(ChartDataTimeRange);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<CascadingValue Value="@HeaderButtonConfigs" Name="HeaderButtonConfigs">
<DashboardChartComponent @ref="Chart"
<DashboardHorizontalBarChartComponent @ref="Chart"
YAxisLabel="YLabel"
GenerateChartDatas="TopPlayedSongs"
ChartTitle="Top Played Songs"
Expand Down
Loading

0 comments on commit d9e6709

Please sign in to comment.