use of com.jjoe64.graphview.GraphView 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.GraphView 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);
}
use of com.jjoe64.graphview.GraphView in project Weather-Station by Kresshy.
the class GraphViewFragment method createViewForWindSpeedGraph.
private void createViewForWindSpeedGraph(LinearLayout container) {
Timber.d("Creating GraphView For WindSpeed");
windSpeedGraph = new LineGraphView(getActivity().getApplicationContext(), "Wind Speed");
windSpeedGraph.setScrollable(true);
// windSpeedGraph.setScalable(true);
windSpeedGraph.setViewPort(0, numberOfSamples);
windSpeedGraph.setGraphViewStyle(getGraphViewStyle());
windSpeedGraph.setHorizontalLabels(getHorizontalLabelsForGraph(numberOfSamples));
GraphViewData[] windSpeedData = new GraphViewData[1];
windSpeedData[0] = new GraphViewData(0, 0);
windSpeedDataList.add(windSpeedData);
GraphViewSeries windSpeedSeries = new GraphViewSeries("Wind Speed", new GraphViewSeries.GraphViewSeriesStyle(Color.BLUE, getLineWidthByNode(0)), windSpeedData);
windSpeedSeriesList.add(windSpeedSeries);
windSpeedGraph.addSeries(windSpeedSeries);
Timber.d("Adding GraphView For WindSpeed to LayoutContainer");
container.addView(windSpeedGraph);
}
use of com.jjoe64.graphview.GraphView in project Weather-Station by Kresshy.
the class GraphViewFragment method createViewForTemperatureGraph.
private void createViewForTemperatureGraph(LinearLayout container) {
Timber.d("Creating GraphView For Temperature");
temperatureGraph = new LineGraphView(getActivity().getApplicationContext(), "Temperature");
temperatureGraph.setScrollable(true);
// temperatureGraph.setScalable(true);
temperatureGraph.setViewPort(0, numberOfSamples);
temperatureGraph.setGraphViewStyle(getGraphViewStyle());
temperatureGraph.setHorizontalLabels(getHorizontalLabelsForGraph(numberOfSamples));
temperatureGraph.setShowHorizontalLabels(false);
GraphViewData[] temperatureData = new GraphViewData[1];
temperatureData[0] = new GraphViewData(0, 0);
temperatureDataList.add(temperatureData);
GraphViewSeries temperatureSeries = new GraphViewSeries("Temperature", new GraphViewSeries.GraphViewSeriesStyle(Color.RED, getLineWidthByNode(0)), temperatureData);
temperatureSeriesList.add(temperatureSeries);
temperatureGraph.addSeries(temperatureSeries);
Timber.d("Adding GraphView For Temperature to LayoutContainer");
container.addView(temperatureGraph);
}
use of com.jjoe64.graphview.GraphView in project Weather-Station by Kresshy.
the class GraphViewFragment method handleFirstIncomingMeasurement.
private void handleFirstIncomingMeasurement(Measurement measurement) {
Timber.d("Handling the (1st) first incoming message");
previousMeasurement = measurement;
Timber.d("Cleaning the graphViews");
windSpeedGraph.removeAllSeries();
temperatureGraph.removeAllSeries();
windSpeedDataList = new ArrayList<>();
temperatureDataList = new ArrayList<>();
windSpeedSeriesList = new ArrayList<>();
temperatureSeriesList = new ArrayList<>();
for (int i = 0; i < measurement.getNumberOfNodes(); i++) {
GraphViewData[] windSpeedData = new GraphViewData[1];
GraphViewData[] temperatureData = new GraphViewData[1];
if (i > 0) {
windSpeedData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getWindSpeed() + correctionWind);
temperatureData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getTemperature() + correctionTemp);
} else {
windSpeedData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getWindSpeed());
temperatureData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getTemperature());
}
try {
windSpeedData = windSpeedDataList.get(i);
} catch (IndexOutOfBoundsException e) {
Timber.d("Cannot find windSpeedData for nodeId: " + i + " creating new GraphViewDataArray");
windSpeedDataList.add(i, windSpeedData);
}
try {
temperatureData = temperatureDataList.get(i);
} catch (IndexOutOfBoundsException e) {
Timber.d("Cannot find temperatureData for nodeId: " + i + " creating new GraphViewDataArray");
temperatureDataList.add(i, temperatureData);
}
GraphViewSeries windSpeedSeries;
GraphViewSeries temperatureSeries;
windSpeedSeries = new GraphViewSeries("Wind Speed", new GraphViewSeries.GraphViewSeriesStyle(getColorForWindSpeedByNode(i), getLineWidthByNode(i)), windSpeedDataList.get(i));
temperatureSeries = new GraphViewSeries("Temperature", new GraphViewSeries.GraphViewSeriesStyle(getColorForTemperatureByNode(i), getLineWidthByNode(i)), temperatureDataList.get(i));
try {
windSpeedSeries = windSpeedSeriesList.get(i);
} catch (IndexOutOfBoundsException e) {
Timber.d("Cannot find windSpeedSeries for nodeId: " + i + " creating new GraphViewSeries");
windSpeedSeriesList.add(i, windSpeedSeries);
}
try {
temperatureSeries = temperatureSeriesList.get(i);
} catch (IndexOutOfBoundsException e) {
Timber.d("Cannot find temperatureSeries for nodeId: " + i + " creating new GraphViewSeries");
temperatureSeriesList.add(i, temperatureSeries);
}
Timber.d("Reset data in new Series for nodeId: " + i);
windSpeedSeriesList.get(i).resetData(windSpeedDataList.get(i));
temperatureSeriesList.get(i).resetData(temperatureDataList.get(i));
Timber.d("Adding Series for GraphView for nodeId: " + i);
windSpeedGraph.addSeries(windSpeedSeriesList.get(i));
temperatureGraph.addSeries(temperatureSeriesList.get(i));
}
lastMeasurementsList.add(measurement);
measurementCount++;
}
Aggregations