use of lecho.lib.hellocharts.model.Axis 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.Axis in project dobby-android by InceptAi.
the class RtGraphViewHolder method setupLineChart.
private void setupLineChart() {
List<Line> lineList = new ArrayList<>(1);
List<Float> rawPoints = graphData.getData();
List<PointValue> pointList = new ArrayList<>(rawPoints.size());
for (int i = 0; i < rawPoints.size(); i++) {
pointList.add(new PointValue(i, rawPoints.get(i)));
}
Line line = new Line(pointList);
line.setColor(ChartUtils.COLOR_ORANGE);
line.setHasPoints(false);
lineList.add(line);
lineChartData.setLines(lineList);
Axis axisX = new Axis();
axisX.setLineColor(ChartUtils.COLOR_GREEN);
axisX.setName("Time");
Axis axisY = new Axis();
axisY.setLineColor(ChartUtils.COLOR_GREEN);
axisY.setName("Bandwidth");
lineChartData.setAxisYLeft(axisY);
lineChartData.setAxisXBottom(axisX);
lineChartView.setLineChartData(lineChartData);
resetViewport();
}
use of lecho.lib.hellocharts.model.Axis 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.Axis in project xDrip by NightscoutFoundation.
the class BgSparklineBuilder method build.
public Bitmap build() {
List<Line> lines = new ArrayList<>();
// simple mode
bgGraphBuilder.defaultLines(true);
lines.add(bgGraphBuilder.inRangeValuesLine());
lines.add(bgGraphBuilder.lowValuesLine());
lines.add(bgGraphBuilder.highValuesLine());
if (showFiltered) {
for (Line line : bgGraphBuilder.filteredLines()) {
line.setHasPoints(false);
lines.add(line);
}
}
if (showLowLine) {
if (height <= SCALE_TRIGGER) {
Line line = bgGraphBuilder.lowLine();
line.setFilled(false);
lines.add(line);
} else {
lines.add(bgGraphBuilder.lowLine());
}
}
if (showHighLine)
lines.add(bgGraphBuilder.highLine());
if (useSmallDots) {
for (Line line : lines) line.setPointRadius(2);
}
if (useTinyDots) {
for (Line line : lines) line.setPointRadius(1);
}
LineChartData lineData = new LineChartData(lines);
if (showAxes) {
if (height <= SCALE_TRIGGER) {
Axis xaxis = bgGraphBuilder.chartXAxis();
xaxis.setTextSize(4);
} else {
Axis yaxis = bgGraphBuilder.yAxis();
yaxis.setTextSize(6);
lineData.setAxisYLeft(yaxis);
Axis xaxis = bgGraphBuilder.chartXAxis();
xaxis.setTextSize(6);
lineData.setAxisXBottom(xaxis);
}
}
// lines.add(bgGraphBuilder.rawInterpretedLine());
chart.setBackgroundColor(backgroundColor);
chart.setLineChartData(lineData);
Viewport viewport = chart.getMaximumViewport();
viewport.left = start;
viewport.right = end;
if (height <= SCALE_TRIGGER) {
// for pebble classic we always want the lowest mark to be in the same place on the image
viewport.bottom = (float) (bgGraphBuilder.doMgdl ? 2 * Constants.MMOLL_TO_MGDL : 2);
viewport.top = (float) (bgGraphBuilder.doMgdl ? 16 * Constants.MMOLL_TO_MGDL : 16);
}
chart.setViewportCalculationEnabled(false);
chart.setInteractive(false);
chart.setCurrentViewport(viewport);
chart.setPadding(0, 0, 0, 0);
chart.setLeft(0);
chart.setTop(0);
if (height > SCALE_TRIGGER) {
chart.setRight(width);
chart.setBottom(height);
} else {
chart.setRight(width * 2);
chart.setBottom(height * 2);
}
Log.d(TAG, "pebble debug: w:" + width + " h:" + height + " start:" + start + " end:" + end + " ");
if (height > SCALE_TRIGGER) {
return getViewBitmap(chart);
} else {
return getResizedBitmap(getViewBitmap(chart), width, height);
}
}
use of lecho.lib.hellocharts.model.Axis 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;
}
Aggregations