use of lecho.lib.hellocharts.model.AxisValue in project CoCoin by Nightonke.
the class TagViewRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
switch(getItemViewType(position)) {
case TYPE_HEADER:
if (IS_EMPTY) {
holder.sum.setText(mContext.getResources().getString(R.string.tag_empty));
holder.sum.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
holder.from.setVisibility(View.INVISIBLE);
holder.to.setVisibility(View.INVISIBLE);
} else {
holder.from.setText(mContext.getResources().getString(R.string.from) + " " + startYear + " " + CoCoinUtil.GetMonthShort(startMonth));
holder.sum.setText(CoCoinUtil.GetInMoney((int) Sum));
holder.to.setText(mContext.getResources().getString(R.string.to) + " " + endYear + " " + CoCoinUtil.GetMonthShort(endMonth));
holder.to.setTypeface(CoCoinUtil.GetTypeface());
holder.from.setTypeface(CoCoinUtil.GetTypeface());
}
holder.sum.setTypeface(CoCoinUtil.typefaceLatoLight);
break;
case TYPE_CELL:
int year = contents.get(position - 1).get(0).getCalendar().get(Calendar.YEAR);
int month = contents.get(position - 1).get(0).getCalendar().get(Calendar.MONTH) + 1;
PieChartData pieChartData;
List<SubcolumnValue> subcolumnValues;
final List<Column> columns;
ColumnChartData columnChartData;
final List<SliceValue> sliceValues;
holder.date.setTypeface(CoCoinUtil.GetTypeface());
holder.expanse.setTypeface(CoCoinUtil.GetTypeface());
switch(chartType) {
case PIE:
sliceValues = new ArrayList<>();
for (Map.Entry<Integer, Double> entry : AllTagExpanse.get(position - 1).entrySet()) {
if (entry.getValue() >= 1) {
SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), mContext.getResources().getColor(CoCoinUtil.GetTagColorResource(entry.getKey())));
sliceValue.setLabel(String.valueOf(entry.getKey()));
sliceValues.add(sliceValue);
}
}
pieChartData = new PieChartData(sliceValues);
pieChartData.setHasLabels(false);
pieChartData.setHasLabelsOnlyForSelected(false);
pieChartData.setHasLabelsOutside(false);
pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
holder.pie.setPieChartData(pieChartData);
holder.pie.setOnValueTouchListener(new PieValueTouchListener(position - 1));
holder.pie.setChartRotationEnabled(false);
if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
} else {
holder.date.setText(year + " ");
}
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SelectedPosition[position] = (SelectedPosition[position] + 1) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SelectedPosition[position] = (SelectedPosition[position] - 1 + sliceValues.size()) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
break;
case SUM_HISTOGRAM:
columns = new ArrayList<>();
if (type.get(position - 1).equals(SHOW_IN_YEAR)) {
int numColumns = 12;
for (int i = 0; i < numColumns; i++) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue(MonthExpanseSum[(year - startYear) * 12 + i], CoCoinUtil.GetRandomColor());
value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + year);
subcolumnValues.add(value);
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < numColumns; i++) {
axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetMonthShort(i + 1)));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + "");
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
Calendar tempCal = new GregorianCalendar(year, month - 1, 1);
int daysInMonth = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
int numColumns = daysInMonth;
for (int i = 0; i < numColumns; ++i) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue((float) DayExpanseSum[(year - startYear) * 372 + (month - 1) * 31 + i], CoCoinUtil.GetRandomColor());
value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + (i + 1) + " " + year);
subcolumnValues.add(value);
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < daysInMonth; i++) {
axisValueList.add(new AxisValue(i).setLabel(i + 1 + ""));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] + 1) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.COLUMN);
holder.chart.selectValue(selectedValue);
}
});
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] - 1 + columns.size()) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.COLUMN);
holder.chart.selectValue(selectedValue);
}
});
break;
case HISTOGRAM:
columns = new ArrayList<>();
if (type.get(position - 1).equals(SHOW_IN_YEAR)) {
int numColumns = 12;
for (int i = 0; i < numColumns; i++) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue(MonthExpanseSum[(year - startYear) * 12 + i], CoCoinUtil.GetRandomColor());
value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + year);
subcolumnValues.add(value);
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < numColumns; i++) {
axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetMonthShort(i + 1)));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + "");
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
Calendar tempCal = Calendar.getInstance();
tempCal.set(year, month - 1, 1);
tempCal.add(Calendar.SECOND, 0);
int daysInMonth = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
int p = contents.get(position - 1).size() - 1;
int numColumns = daysInMonth;
for (int i = 0; i < numColumns; ++i) {
subcolumnValues = new ArrayList<>();
SubcolumnValue value = new SubcolumnValue(0, CoCoinUtil.GetRandomColor());
subcolumnValues.add(value);
while (p >= 0 && contents.get(position - 1).get(p).getCalendar().get(Calendar.DAY_OF_MONTH) == i + 1) {
subcolumnValues.get(0).setValue(subcolumnValues.get(0).getValue() + (float) contents.get(position - 1).get(p).getMoney());
subcolumnValues.get(0).setLabel(p + "");
p--;
}
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
columnChartData = new ColumnChartData(columns);
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < daysInMonth; i++) {
axisValueList.add(new AxisValue(i).setLabel(i + 1 + ""));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.chart.setColumnChartData(columnChartData);
holder.chart.setZoomEnabled(false);
holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
}
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] + 1) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.chart.selectValue(selectedValue);
}
});
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
SelectedPosition[position] = (SelectedPosition[position] - 1 + columns.size()) % columns.size();
} while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
holder.chart.selectValue(selectedValue);
}
});
break;
}
}
}
use of lecho.lib.hellocharts.model.AxisValue in project xDrip by NightscoutFoundation.
the class BgGraphBuilder method xAxis.
@NonNull
private Axis xAxis() {
List<AxisValue> axisValues = new ArrayList<AxisValue>();
final java.text.DateFormat timeFormat = hourFormat();
timeFormat.setTimeZone(TimeZone.getDefault());
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(start_time);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
if (calendar.getTimeInMillis() < start_time) {
calendar.add(Calendar.HOUR, 1);
}
while (calendar.getTimeInMillis() < end_time) {
axisValues.add(new AxisValue((calendar.getTimeInMillis() / FUZZER), (timeFormat.format(calendar.getTimeInMillis())).toCharArray()));
calendar.add(Calendar.HOUR, 1);
}
Axis axis = new Axis();
axis.setValues(axisValues);
axis.setHasLines(true);
return axis;
}
use of lecho.lib.hellocharts.model.AxisValue in project xDrip by NightscoutFoundation.
the class BgGraphBuilder method xAxis.
public Axis xAxis() {
// final boolean is24 = DateFormat.is24HourFormat(context);
Axis xAxis = new Axis();
xAxis.setAutoGenerated(false);
List<AxisValue> xAxisValues = new ArrayList<AxisValue>();
GregorianCalendar now = new GregorianCalendar();
GregorianCalendar today = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
SimpleDateFormat timeFormat = new SimpleDateFormat(is24 ? "HH" : "h a");
timeFormat.setTimeZone(TimeZone.getDefault());
double start_hour = today.getTime().getTime();
double timeNow = new Date().getTime();
for (int l = 0; l <= 24; l++) {
if ((start_hour + (60000 * 60 * (l))) < timeNow) {
if ((start_hour + (60000 * 60 * (l + 1))) >= timeNow) {
endHour = start_hour + (60000 * 60 * (l));
l = 25;
}
}
}
// Display current time on the graph
SimpleDateFormat longTimeFormat = new SimpleDateFormat(is24 ? "HH:mm" : "h:mm a");
xAxisValues.add(new AxisValue(fuzz(timeNow), (longTimeFormat.format(timeNow)).toCharArray()));
// Add whole hours to the axis (as long as they are more than 15 mins away from the current time)
for (int l = 0; l <= 24; l++) {
double timestamp = endHour - (60000 * 60 * l);
if ((timestamp - timeNow < 0) && (timestamp > start_time)) {
if (Math.abs(timestamp - timeNow) > (1000 * 60 * 8 * timespan)) {
xAxisValues.add(new AxisValue(fuzz(timestamp), (timeFormat.format(timestamp)).toCharArray()));
} else {
xAxisValues.add(new AxisValue(fuzz(timestamp), "".toCharArray()));
}
}
}
xAxis.setValues(xAxisValues);
xAxis.setTextSize(10);
xAxis.setHasLines(true);
return xAxis;
}
use of lecho.lib.hellocharts.model.AxisValue in project xDrip-plus by jamorham.
the class BgGraphBuilder method xAxis.
public Axis xAxis() {
// final boolean is24 = DateFormat.is24HourFormat(context);
Axis xAxis = new Axis();
xAxis.setAutoGenerated(false);
List<AxisValue> xAxisValues = new ArrayList<AxisValue>();
GregorianCalendar now = new GregorianCalendar();
GregorianCalendar today = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
SimpleDateFormat timeFormat = new SimpleDateFormat(is24 ? "HH" : "h a");
timeFormat.setTimeZone(TimeZone.getDefault());
double start_hour = today.getTime().getTime();
double timeNow = new Date().getTime();
for (int l = 0; l <= 24; l++) {
if ((start_hour + (60000 * 60 * (l))) < timeNow) {
if ((start_hour + (60000 * 60 * (l + 1))) >= timeNow) {
endHour = start_hour + (60000 * 60 * (l));
l = 25;
}
}
}
// Display current time on the graph
SimpleDateFormat longTimeFormat = new SimpleDateFormat(is24 ? "HH:mm" : "h:mm a");
xAxisValues.add(new AxisValue(fuzz(timeNow), (longTimeFormat.format(timeNow)).toCharArray()));
// Add whole hours to the axis (as long as they are more than 15 mins away from the current time)
for (int l = 0; l <= 24; l++) {
double timestamp = endHour - (60000 * 60 * l);
if ((timestamp - timeNow < 0) && (timestamp > start_time)) {
if (Math.abs(timestamp - timeNow) > (1000 * 60 * 8 * timespan)) {
xAxisValues.add(new AxisValue(fuzz(timestamp), (timeFormat.format(timestamp)).toCharArray()));
} else {
xAxisValues.add(new AxisValue(fuzz(timestamp), "".toCharArray()));
}
}
}
xAxis.setValues(xAxisValues);
xAxis.setTextSize(10);
xAxis.setHasLines(true);
return xAxis;
}
use of lecho.lib.hellocharts.model.AxisValue in project xDrip-plus by jamorham.
the class BgGraphBuilder method yAxis.
// ///////AXIS RELATED//////////////
public Axis yAxis() {
Axis yAxis = new Axis();
yAxis.setAutoGenerated(true);
List<AxisValue> axisValues = new ArrayList<AxisValue>();
yAxis.setValues(axisValues);
yAxis.setHasLines(false);
return yAxis;
}
Aggregations