Skip to content

Commit

Permalink
Completed MVP for artistwork page.
Browse files Browse the repository at this point in the history
some clean up
POC for adding version info to application
  • Loading branch information
czf committed Jan 15, 2021
1 parent d9e6709 commit 892582b
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ public IEnumerable<ArtistWorkInfo> GetArtistWorks(char alphaFilter)
{
throw new NotImplementedException();
}

public async Task<ArtistWorkInfo> GetArtistWork(int id)
{
return await Task.FromResult(GetArtistWorks().First(x => x.Id == id));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public List<ItemCount> GetSongPlayedOverTime(AggregateTimeRange timeRange, int a

}

public List<ItemCount> GetSongPlayedAndOtherPlayed(AggregateTimeRange timeRange, int artistWorkId)
{
int multiplier = GetTimeRangeMultipler(timeRange);
List<ItemCount> result = new List<ItemCount>()
{
new ItemCount(){Count = 98 * multiplier, Name= "Other", ItemId = 0},
new ItemCount(){Count = 2 * multiplier, Name= GetOverTimeName(1, timeRange), ItemId = artistWorkId},
};
return result;
}

private string GetOverTimeName(int index, AggregateTimeRange aggregateTimeRange)
{
string result = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<CascadingValue Value="@HeaderButtonConfigs" Name="HeaderButtonConfigs">


<DashboardPieChartComponent @ref="Chart"
ChartTitle="@DashboardPieChartComponentTitle"
GenerateChartDatas="SongPercentageOfArtist"
SliceColorGenerator="SliceColorGenerator"
OnDashboardPieChartClick="OnDashboardPieChartClick"/>
</CascadingValue>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Blazorise.Charts;
using Microsoft.AspNetCore.Components;
using RadiocomDataViewApp.Clients;
using RadiocomDataViewApp.Interfaces;
using RadiocomDataViewApp.Objects;

namespace RadiocomDataViewApp.Components.ArtistWorkCharts
{
public partial class SongPercentageOfArtistPieChart : ComponentBase
{
private DashboardPieChartComponent Chart;
private List<HeaderButtonState> HeaderButtonConfigs { get; set; }

private AggregateTimeRange ChartDataTimeRange = AggregateTimeRange.SevenDays;

[Parameter]
public int ArtistWorkId { get; set; }
[Parameter]
public string ArtistName { get; set; }

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

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

public SongPercentageOfArtistPieChart()
{
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 UpdateChartDataTimeRange(AggregateTimeRange mostPlayedTimeRange)
{
ChartDataTimeRange = mostPlayedTimeRange;
Console.Write("djfoisajfiodsajfa\n\n\n");
Chart.RefreshChartData();
}
private IEnumerable<DashboardChartData> SongPercentageOfArtist()
{
List<ItemCount> radioComData = RadiocomDataAggregateDataClient.GetSongPlayedAndOtherPlayed(ChartDataTimeRange, ArtistWorkId);
return radioComData.Select(x => new DashboardChartData() { Label = x.Name, Value = x.Count, DataId = x.ItemId });

}

private ChartColor SliceColorGenerator(int indx)
{
ChartColor color;
if (indx == 0)
{
color = OtherSongsPieChartColor;
}
else
{
color = ViewedSongPieChartColor;
}
return color;
}
private void OnDashboardPieChartClick()
{
NavManager.NavigateTo($"/artist/{ArtistId}/artistworks");
}
private static readonly ChartColor ViewedSongPieChartColor = ChartColor.FromRgba(255, 255, 255, 1);//white
private static readonly ChartColor OtherSongsPieChartColor = ChartColor.FromRgba(104, 104, 103, 1);//grey

private string DashboardPieChartComponentTitle => $" Comparison with Other Songs Played by {ArtistName}";

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<CascadingValue Value="@HeaderButtonConfigs" Name="HeaderButtonConfigs">


<DashboardLineGraphChartComponent @ref="Chart"
ChartTitle="Song Played Over Time"
XAxisLabel="XLabel"
GenerateChartDatas="SongPlayedOverTime" />
</CascadingValue>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.ArtistWorkCharts
{
public partial class SongPlayedOverTimeChart : ComponentBase
{
private DashboardLineGraphChartComponent Chart;
private List<HeaderButtonState> HeaderButtonConfigs { get; set; }

private AggregateTimeRange ChartDataTimeRange = AggregateTimeRange.SevenDays;

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

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

public SongPlayedOverTimeChart()
{
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 UpdateChartDataTimeRange(AggregateTimeRange mostPlayedTimeRange)
{
ChartDataTimeRange = mostPlayedTimeRange;
Chart.RefreshChartData();
}
private IEnumerable<DashboardChartData> SongPlayedOverTime()
{
List<ItemCount> radioComData = RadiocomDataAggregateDataClient.GetSongPlayedOverTime(ChartDataTimeRange, ArtistWorkId);
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 @@ -26,7 +26,7 @@ public partial class DashboardHorizontalBarChartComponent : ComponentBase
};

public readonly object ChartOptionsObj;
public readonly ChartOptions chartOptions;
//public readonly ChartOptions chartOptions;

[Parameter]
public string YAxisLabel { get; set; }
Expand Down Expand Up @@ -133,14 +133,14 @@ public DashboardHorizontalBarChartComponent()
};


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" } } },
}
};
//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

}
Expand Down
19 changes: 19 additions & 0 deletions RadiocomDataViewApp/Components/DashboardPieChartComponent.razor
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 />



<PieChart @ref="Chart" TItem="int" OptionsObject="@ChartOptionsObj" Clicked="OnPieChartClick" />
</CardBody>

</Card>
137 changes: 137 additions & 0 deletions RadiocomDataViewApp/Components/DashboardPieChartComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise.Charts;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using RadiocomDataViewApp.Objects;

namespace RadiocomDataViewApp.Components
{
public partial class DashboardPieChartComponent : ComponentBase
{
private const string DEFAULT_SLICE_COLOR = "#FFF";

private PieChart<int> Chart;
public readonly object ChartOptionsObj;



[Parameter]
public string ChartTitle { get; set; }
[Parameter]
public Func<IEnumerable<DashboardChartData>> GenerateChartDatas { get; set; }
[Parameter]
public Func<int, ChartColor> SliceColorGenerator { get; set; }

/// <summary>
/// event for clicking specfically on the PieChart
/// </summary>
[Parameter]
public EventCallback<DashboardChartMouseEventArgs> OnDashboardPieChartClick { get; set; }

public DashboardPieChartComponent()
{
#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

};
#endregion chartOptions
}

public void RefreshChartData()
{
Console.WriteLine("refresh picharet");
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 sliceColor = SliceColorGenerator?.Invoke(i);
if (!string.IsNullOrWhiteSpace(sliceColor))
{
colors.Add(sliceColor);
}
else
{
colors.Add(DEFAULT_SLICE_COLOR);
}
}

PieChartDataset<int> newChartDataset = new PieChartDataset<int>()
{
Data = newDatas.Select(x => x.Value).ToList(),
BackgroundColor = colors,
BorderColor = colors
};
newChartDataset.HoverBackgroundColor.Clear();
newChartDataset.HoverBorderColor.Clear();
CurrentDataset = newChartDataset;
Chart.AddDataSet(newChartDataset);
Chart.Update();
}

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (firstRender)
{
Console.Write("ridnejejf");
RefreshChartData();
}
}

//private async Task OnSliceElementClickedHandler(ChartMouseEventArgs args)
//{

// DashboardChartMouseEventArgs chartMouseEventArgs = new DashboardChartMouseEventArgs(args.DatasetIndex, args.Index, args.Model);
// chartMouseEventArgs.DatasetElement = CurrentDataset.Data[args.Index];
// await OnDashboardChartElementClick.InvokeAsync(chartMouseEventArgs);
//}

private async Task OnPieChartClick(ChartMouseEventArgs args)
{
DashboardChartMouseEventArgs chartMouseEventArgs = new DashboardChartMouseEventArgs(args.DatasetIndex, args.Index, args.Model);
chartMouseEventArgs.DatasetElement = CurrentDataset.Data[chartMouseEventArgs.Index];
await OnDashboardPieChartClick.InvokeAsync(chartMouseEventArgs);
}

protected PieChartDataset<int> CurrentDataset { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public partial class DashboardSingleIntegerMetricComponent : ComponentBase
public void RefreshChartData()
{
_integerMetricValue = (GenerateSingleDataMetric).Invoke();
Console.WriteLine("singleInt: " + _integerMetricValue);
}

protected override void OnParametersSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace RadiocomDataViewApp.Interfaces
{
public interface IRadiocomArtistWorkRepository
{
public IEnumerable<ArtistWorkInfo> GetArtistWorks();
public IEnumerable<ArtistWorkInfo> GetArtistWorks(char alphaFilter);
IEnumerable<ArtistWorkInfo> GetArtistWorks();
IEnumerable<ArtistWorkInfo> GetArtistWorks(char alphaFilter);
Task<ArtistWorkInfo> GetArtistWork(int id);

}
}
Loading

0 comments on commit 892582b

Please sign in to comment.