use of com.jjoe64.graphview.GraphViewSeries in project WordPress-Android by wordpress-mobile.
the class StatsVisitorsAndViewsFragment method updateUI.
protected void updateUI() {
if (!isAdded()) {
return;
}
if (mVisitsData == null) {
setupNoResultsUI(false);
return;
}
final VisitModel[] dataToShowOnGraph = getDataToShowOnGraph(mVisitsData);
if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
setupNoResultsUI(false);
return;
}
// Hide the "no-activity this period" message
mNoActivtyThisPeriodContainer.setVisibility(View.GONE);
// Read the selected Tab in the UI
OverviewLabel selectedStatsType = overviewItems[mSelectedOverviewItemIndex];
// Update the Legend and enable/disable the visitors checkboxes
mLegendContainer.setVisibility(View.VISIBLE);
mLegendLabel.setText(StringUtils.capitalize(selectedStatsType.getLabel().toLowerCase()));
switch(selectedStatsType) {
case VIEWS:
mVisitorsCheckboxContainer.setVisibility(View.VISIBLE);
mVisitorsCheckbox.setEnabled(true);
mVisitorsCheckbox.setChecked(mIsCheckboxChecked);
break;
default:
mVisitorsCheckboxContainer.setVisibility(View.GONE);
break;
}
// Setting Up labels and prepare variables that hold series
final String[] horLabels = new String[dataToShowOnGraph.length];
mStatsDate = new String[dataToShowOnGraph.length];
GraphView.GraphViewData[] mainSeriesItems = new GraphView.GraphViewData[dataToShowOnGraph.length];
GraphView.GraphViewData[] secondarySeriesItems = null;
if (mIsCheckboxChecked && selectedStatsType == OverviewLabel.VIEWS) {
secondarySeriesItems = new GraphView.GraphViewData[dataToShowOnGraph.length];
}
// index of days that should be XXX on the graph
final boolean[] weekendDays;
if (getTimeframe() == StatsTimeframe.DAY) {
weekendDays = new boolean[dataToShowOnGraph.length];
} else {
weekendDays = null;
}
// Check we have at least one result in the current section.
boolean atLeastOneResultIsAvailable = false;
// Fill series variables with data
for (int i = 0; i < dataToShowOnGraph.length; i++) {
int currentItemValue = 0;
switch(selectedStatsType) {
case VIEWS:
currentItemValue = dataToShowOnGraph[i].getViews();
break;
case VISITORS:
currentItemValue = dataToShowOnGraph[i].getVisitors();
break;
case LIKES:
currentItemValue = dataToShowOnGraph[i].getLikes();
break;
case COMMENTS:
currentItemValue = dataToShowOnGraph[i].getComments();
break;
}
mainSeriesItems[i] = new GraphView.GraphViewData(i, currentItemValue);
if (currentItemValue > 0) {
atLeastOneResultIsAvailable = true;
}
if (mIsCheckboxChecked && secondarySeriesItems != null) {
secondarySeriesItems[i] = new GraphView.GraphViewData(i, dataToShowOnGraph[i].getVisitors());
}
String currentItemStatsDate = dataToShowOnGraph[i].getPeriod();
horLabels[i] = getDateLabelForBarInGraph(currentItemStatsDate);
mStatsDate[i] = currentItemStatsDate;
if (weekendDays != null) {
SimpleDateFormat from = new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT);
try {
Date date = from.parse(currentItemStatsDate);
Calendar c = Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTimeInMillis(date.getTime());
weekendDays[i] = c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
} catch (ParseException e) {
weekendDays[i] = false;
AppLog.e(AppLog.T.STATS, e);
}
}
}
if (mGraphContainer.getChildCount() >= 1 && mGraphContainer.getChildAt(0) instanceof GraphView) {
mGraphView = (StatsBarGraph) mGraphContainer.getChildAt(0);
} else {
mGraphContainer.removeAllViews();
mGraphView = new StatsBarGraph(getActivity());
mGraphContainer.addView(mGraphView);
}
mGraphView.removeAllSeries();
GraphViewSeries mainSeriesOnScreen = new GraphViewSeries(mainSeriesItems);
mainSeriesOnScreen.getStyle().color = getResources().getColor(R.color.stats_bar_graph_main_series);
mainSeriesOnScreen.getStyle().outerColor = getResources().getColor(R.color.grey_lighten_30_translucent_50);
mainSeriesOnScreen.getStyle().highlightColor = getResources().getColor(R.color.stats_bar_graph_main_series_highlight);
mainSeriesOnScreen.getStyle().outerhighlightColor = getResources().getColor(R.color.stats_bar_graph_outer_highlight);
mainSeriesOnScreen.getStyle().padding = DisplayUtils.dpToPx(getActivity(), 5);
mGraphView.addSeries(mainSeriesOnScreen);
// Add the Visitors series if it's checked in the legend
if (mIsCheckboxChecked && secondarySeriesItems != null && selectedStatsType == OverviewLabel.VIEWS) {
GraphViewSeries secondarySeries = new GraphViewSeries(secondarySeriesItems);
secondarySeries.getStyle().padding = DisplayUtils.dpToPx(getActivity(), 10);
secondarySeries.getStyle().color = getResources().getColor(R.color.stats_bar_graph_secondary_series);
secondarySeries.getStyle().highlightColor = getResources().getColor(R.color.orange_fire);
mGraphView.addSeries(secondarySeries);
}
// the purpose of making these bars visually easily to compare.
switch(selectedStatsType) {
case VISITORS:
double maxYValue = getMaxYValueForVisitorsAndView(dataToShowOnGraph);
mGraphView.setManualYAxisBounds(maxYValue, 0d);
break;
default:
mGraphView.setManualYAxis(false);
break;
}
// Set the Graph Style
mGraphView.getGraphViewStyle().setNumHorizontalLabels(dataToShowOnGraph.length);
// Set the maximum size a column can get on the screen in PX
mGraphView.getGraphViewStyle().setMaxColumnWidth(DisplayUtils.dpToPx(getActivity(), StatsConstants.STATS_GRAPH_BAR_MAX_COLUMN_WIDTH_DP));
mGraphView.setHorizontalLabels(horLabels);
mGraphView.setGestureListener(this);
// If zero results in the current section disable clicks on the graph and show the dialog.
mNoActivtyThisPeriodContainer.setVisibility(atLeastOneResultIsAvailable ? View.GONE : View.VISIBLE);
mGraphView.setClickable(atLeastOneResultIsAvailable);
// Draw the background on weekend days
mGraphView.setWeekendDays(weekendDays);
// Only happens on 720DP tablets
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphBarIndex = -1;
mPrevNumberOfBarsGraph = dataToShowOnGraph.length;
onBarTapped(dataToShowOnGraph.length - 1);
mGraphView.highlightBar(dataToShowOnGraph.length - 1);
return;
}
mPrevNumberOfBarsGraph = dataToShowOnGraph.length;
int barSelectedOnGraph;
if (mSelectedBarGraphBarIndex == -1) {
// No previous bar was highlighted, highlight the most recent one
barSelectedOnGraph = dataToShowOnGraph.length - 1;
} else if (mSelectedBarGraphBarIndex < dataToShowOnGraph.length) {
barSelectedOnGraph = mSelectedBarGraphBarIndex;
} else {
// A previous bar was highlighted, but it's out of the screen now. This should never happen atm.
barSelectedOnGraph = dataToShowOnGraph.length - 1;
mSelectedBarGraphBarIndex = barSelectedOnGraph;
}
updateUIBelowTheGraph(barSelectedOnGraph);
mGraphView.highlightBar(barSelectedOnGraph);
}
use of com.jjoe64.graphview.GraphViewSeries in project WordPress-Android by wordpress-mobile.
the class StatsSingleItemDetailsActivity method updateUI.
private void updateUI() {
if (isFinishing()) {
return;
}
final VisitModel[] dataToShowOnGraph = getDataToShowOnGraph();
if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
setupEmptyUI();
return;
}
final String[] horLabels = new String[dataToShowOnGraph.length];
String[] mStatsDate = new String[dataToShowOnGraph.length];
GraphView.GraphViewData[] views = new GraphView.GraphViewData[dataToShowOnGraph.length];
for (int i = 0; i < dataToShowOnGraph.length; i++) {
int currentItemValue = dataToShowOnGraph[i].getViews();
views[i] = new GraphView.GraphViewData(i, currentItemValue);
String currentItemStatsDate = dataToShowOnGraph[i].getPeriod();
horLabels[i] = StatsUtils.parseDate(currentItemStatsDate, StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_SHORT_DAY_SHORT_FORMAT);
mStatsDate[i] = currentItemStatsDate;
}
GraphViewSeries mCurrentSeriesOnScreen = new GraphViewSeries(views);
mCurrentSeriesOnScreen.getStyle().color = getResources().getColor(R.color.stats_bar_graph_main_series);
mCurrentSeriesOnScreen.getStyle().highlightColor = getResources().getColor(R.color.stats_bar_graph_main_series_highlight);
mCurrentSeriesOnScreen.getStyle().outerhighlightColor = getResources().getColor(R.color.stats_bar_graph_outer_highlight);
mCurrentSeriesOnScreen.getStyle().padding = DisplayUtils.dpToPx(this, 5);
StatsBarGraph mGraphView;
if (mGraphContainer.getChildCount() >= 1 && mGraphContainer.getChildAt(0) instanceof GraphView) {
mGraphView = (StatsBarGraph) mGraphContainer.getChildAt(0);
} else {
mGraphContainer.removeAllViews();
mGraphView = new StatsBarGraph(this);
mGraphContainer.addView(mGraphView);
}
mGraphView.removeAllSeries();
mGraphView.addSeries(mCurrentSeriesOnScreen);
//mGraphView.getGraphViewStyle().setNumHorizontalLabels(getNumOfHorizontalLabels(dataToShowOnGraph.length));
mGraphView.getGraphViewStyle().setNumHorizontalLabels(dataToShowOnGraph.length);
mGraphView.getGraphViewStyle().setMaxColumnWidth(DisplayUtils.dpToPx(this, StatsConstants.STATS_GRAPH_BAR_MAX_COLUMN_WIDTH_DP));
mGraphView.setHorizontalLabels(horLabels);
mGraphView.setGestureListener(this);
// Only happens on 720DP tablets
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphIndex = dataToShowOnGraph.length - 1;
} else {
mSelectedBarGraphIndex = (mSelectedBarGraphIndex != -1) ? mSelectedBarGraphIndex : dataToShowOnGraph.length - 1;
}
mGraphView.highlightBar(mSelectedBarGraphIndex);
mPrevNumberOfBarsGraph = dataToShowOnGraph.length;
setMainViewsLabel(StatsUtils.parseDate(mStatsDate[mSelectedBarGraphIndex], StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_LONG_DAY_SHORT_FORMAT), dataToShowOnGraph[mSelectedBarGraphIndex].getViews());
showHideEmptyModulesIndicator(false);
mMonthsAndYearsList.setVisibility(View.VISIBLE);
List<PostViewsModel.Year> years = mRestResponseParsed.getYears();
MonthsAndYearsListAdapter monthsAndYearsListAdapter = new MonthsAndYearsListAdapter(this, years, mRestResponseParsed.getHighestMonth());
StatsUIHelper.reloadGroupViews(this, monthsAndYearsListAdapter, mYearsIdToExpandedMap, mMonthsAndYearsList);
mAveragesList.setVisibility(View.VISIBLE);
List<PostViewsModel.Year> averages = mRestResponseParsed.getAverages();
MonthsAndYearsListAdapter averagesListAdapter = new MonthsAndYearsListAdapter(this, averages, mRestResponseParsed.getHighestDayAverage());
StatsUIHelper.reloadGroupViews(this, averagesListAdapter, mAveragesIdToExpandedMap, mAveragesList);
mRecentWeeksList.setVisibility(View.VISIBLE);
List<PostViewsModel.Week> recentWeeks = mRestResponseParsed.getWeeks();
RecentWeeksListAdapter recentWeeksListAdapter = new RecentWeeksListAdapter(this, recentWeeks, mRestResponseParsed.getHighestWeekAverage());
StatsUIHelper.reloadGroupViews(this, recentWeeksListAdapter, mRecentWeeksIdToExpandedMap, mRecentWeeksList);
}
Aggregations