com.jjoe64.graphview.GraphView Java Examples

The following examples show how to use com.jjoe64.graphview.GraphView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventPainter.java    From ssj with GNU General Public License v3.0 7 votes vote down vote up
private void createSeries(final GraphView view, final int spacing)
{
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(new Runnable()
    {
        public void run()
        {
            _series = new BarGraphSeries<>();
            _series.setColor(Color.parseColor(options.color.get()));
            _series.setDrawValuesOnTop(true);
            _series.setValuesOnTopColor(Color.BLACK);
            _series.setSpacing(spacing);

            view.addSeries(_series);
        }
    }, 1);
}
 
Example #2
Source File: GraphViewActivity.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
private void getSampleCode() {

        GraphViewSeries exampleSeries = new GraphViewSeries(new GraphView.GraphViewData[] {
                new GraphView.GraphViewData(1, 2.0d)
                , new GraphView.GraphViewData(2, 1.5d)
                , new GraphView.GraphViewData(3, 2.5d)
                , new GraphView.GraphViewData(4, 1.0d)
        });

        GraphView graphView = new LineGraphView(this, "GraphViewDemo");
        graphView.addSeries(exampleSeries);

        GraphView barGraphView = new BarGraphView(this, "BarGraphView");
        barGraphView.addSeries(exampleSeries);

        LinearLayout layout = (LinearLayout) findViewById(R.id.linear_layout);
        layout.addView(barGraphView);
    }
 
Example #3
Source File: TitleLineGraphSeries.java    From WiFiAnalyzer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void drawSelection(GraphView graphView, Canvas canvas, boolean b, DataPointInterface value) {
    double spanX = graphView.getViewport().getMaxX(false) - graphView.getViewport().getMinX(false);
    double spanXPixel = graphView.getGraphContentWidth();

    double spanY = graphView.getViewport().getMaxY(false) - graphView.getViewport().getMinY(false);
    double spanYPixel = graphView.getGraphContentHeight();

    double pointX = (value.getX() - graphView.getViewport().getMinX(false)) * spanXPixel / spanX;
    pointX += graphView.getGraphContentLeft();

    double pointY = (value.getY() - graphView.getViewport().getMinY(false)) * spanYPixel / spanY;
    pointY = graphView.getGraphContentTop() + spanYPixel - pointY;

    // border
    canvas.drawCircle((float) pointX, (float) pointY, 30f, mSelectionPaint);

    // fill
    Paint.Style prevStyle = mPaint.getStyle();
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawCircle((float) pointX, (float) pointY, 23f, mPaint);
    mPaint.setStyle(prevStyle);
}
 
Example #4
Source File: ChannelGraphView.java    From WiFiAnalyzer with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private GraphViewWrapper makeGraphViewWrapper() {
    MainContext mainContext = MainContext.INSTANCE;
    Settings settings = mainContext.getSettings();
    Configuration configuration = mainContext.getConfiguration();
    ThemeStyle themeStyle = settings.getThemeStyle();
    int graphMaximumY = settings.getGraphMaximumY();
    GraphView graphView = makeGraphView(mainContext, graphMaximumY, themeStyle);
    graphViewWrapper = new GraphViewWrapper(graphView, settings.getChannelGraphLegend(), themeStyle);
    configuration.setSize(graphViewWrapper.getSize(graphViewWrapper.calculateGraphType()));
    int minX = wiFiChannelPair.first.getFrequency() - WiFiChannels.FREQUENCY_OFFSET;
    int maxX = minX + (graphViewWrapper.getViewportCntX() * WiFiChannels.FREQUENCY_SPREAD);
    graphViewWrapper.setViewport(minX, maxX);
    graphViewWrapper.addSeries(makeDefaultSeries(wiFiChannelPair.second.getFrequency(), minX));
    return graphViewWrapper;
}
 
Example #5
Source File: MonthStatisticFragment.java    From privacy-friendly-food-tracker with GNU General Public License v3.0 5 votes vote down vote up
void UpdateGraph() {

        try {

            final Date startDate = getMonthByValue(-1);
            final Date endDate = getMonthByValue(0);
            List<ConsumedEntrieAndProductDao.DateCalories> consumedEntriesList = databaseFacade.getCaloriesPerDayinPeriod(startDate,endDate);
            List<ConsumedEntrieAndProductDao.DateCalories> calories = databaseFacade.getPeriodCalories(startDate,endDate);
            DataPoint[] dataPointInterfaces = new DataPoint[consumedEntriesList.size()];
            for (int i = 0; i < consumedEntriesList.size(); i++) {
                dataPointInterfaces[i] = (new DataPoint(consumedEntriesList.get(i).unique1.getTime(), consumedEntriesList.get(i).unique2/100));
            }
            if (calories.size() != 0) {

                Calendar startDateCalendar = Calendar.getInstance();
                startDateCalendar.setTime(startDate);
                Calendar endDateCalendar = Calendar.getInstance();
                endDateCalendar.setTime(endDate);
                float periodCalories = calories.get(0).unique2;
                float periodDays = daysBetween( endDateCalendar,startDateCalendar);
                float averageCalories = periodCalories/periodDays;
                BigDecimal averageCaloriesBigDecimal = round(averageCalories,0) ;
                textView.setText(averageCaloriesBigDecimal.toString());
            }
            GraphView graph = (GraphView) parentHolder.findViewById(R.id.graph);
            LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dataPointInterfaces);
            graph.addSeries(series);
            graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(referenceActivity));
            graph.getGridLabelRenderer().setHumanRounding(false, true);
            graph.getViewport().setMinX(startDate.getTime());
            graph.getViewport().setMaxX(endDate.getTime());
            graph.getViewport().setXAxisBoundsManual(true);
            graph.getGridLabelRenderer().setTextSize(40);
            graph.getViewport().setScrollable(true);
            graph.getGridLabelRenderer().setHorizontalLabelsAngle(135);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
        }
    }
 
Example #6
Source File: TimeGraphViewTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetGraphView() {
    // setup
    GraphView expected = mock(GraphView.class);
    when(graphViewWrapper.getGraphView()).thenReturn(expected);
    // execute
    GraphView actual = fixture.getGraphView();
    // validate
    assertEquals(expected, actual);
    verify(graphViewWrapper).getGraphView();
}
 
Example #7
Source File: TimeGraphAdapterTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetGraphViews() {
    // execute
    List<GraphView> graphViews = fixture.getGraphViews();
    // validate
    assertEquals(WiFiBand.values().length, graphViews.size());
}
 
Example #8
Source File: GraphAdapterTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetGraphViews() {
    // setup
    when(graphViewNotifier.getGraphView()).thenReturn(graphView);
    // execute
    List<GraphView> actual = fixture.getGraphViews();
    // validate
    assertEquals(1, actual.size());
    assertEquals(graphView, actual.get(0));
    verify(graphViewNotifier).getGraphView();
}
 
Example #9
Source File: ChannelGraphAdapterTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetGraphViews() {
    // setup
    int expected = expectedCount();
    // execute
    List<GraphView> graphViews = fixture.getGraphViews();
    // validate
    assertEquals(expected, graphViews.size());
}
 
Example #10
Source File: ChannelGraphViewTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetGraphView() {
    // setup
    GraphView expected = mock(GraphView.class);
    when(graphViewWrapper.getGraphView()).thenReturn(expected);
    // execute
    GraphView actual = fixture.getGraphView();
    // validate
    assertEquals(expected, actual);
    verify(graphViewWrapper).getGraphView();
}
 
Example #11
Source File: TimeGraphView.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private GraphViewWrapper makeGraphViewWrapper() {
    MainContext mainContext = MainContext.INSTANCE;
    Settings settings = mainContext.getSettings();
    ThemeStyle themeStyle = settings.getThemeStyle();
    int graphMaximumY = settings.getGraphMaximumY();
    Configuration configuration = mainContext.getConfiguration();
    GraphView graphView = makeGraphView(mainContext, graphMaximumY, themeStyle);
    graphViewWrapper = new GraphViewWrapper(graphView, settings.getTimeGraphLegend(), themeStyle);
    configuration.setSize(graphViewWrapper.getSize(graphViewWrapper.calculateGraphType()));
    graphViewWrapper.setViewport();
    return graphViewWrapper;
}
 
Example #12
Source File: TimeGraphView.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private GraphView makeGraphView(@NonNull MainContext mainContext, int graphMaximumY, @NonNull ThemeStyle themeStyle) {
    Resources resources = mainContext.getResources();
    return new GraphViewBuilder(mainContext.getContext(), NUM_X_TIME, graphMaximumY, themeStyle)
        .setLabelFormatter(new TimeAxisLabel())
        .setVerticalTitle(resources.getString(R.string.graph_axis_y))
        .setHorizontalTitle(resources.getString(R.string.graph_time_axis_x))
        .setHorizontalLabelsVisible(false)
        .build();
}
 
Example #13
Source File: GraphViewWrapper.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
public GraphViewWrapper(@NonNull GraphView graphView, @NonNull GraphLegend graphLegend, @NonNull ThemeStyle themeStyle) {
    this.graphView = graphView;
    this.graphLegend = graphLegend;
    this.themeStyle = themeStyle;
    setSeriesCache(new SeriesCache());
    setSeriesOptions(new SeriesOptions());
}
 
Example #14
Source File: GraphViewBuilder.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
void setGridLabelRenderer(@NonNull GraphView graphView) {
    GridLabelRenderer gridLabelRenderer = graphView.getGridLabelRenderer();
    gridLabelRenderer.setHumanRounding(false);
    gridLabelRenderer.setHighlightZeroLines(false);
    gridLabelRenderer.setNumVerticalLabels(getNumVerticalLabels());
    gridLabelRenderer.setNumHorizontalLabels(numHorizontalLabels);
    gridLabelRenderer.setVerticalLabelsVisible(true);
    gridLabelRenderer.setHorizontalLabelsVisible(horizontalLabelsVisible);
    gridLabelRenderer.setTextSize(gridLabelRenderer.getTextSize() * GraphConstants.TEXT_SIZE_ADJUSTMENT);

    gridLabelRenderer.reloadStyles();
    if (labelFormatter != null) {
        gridLabelRenderer.setLabelFormatter(labelFormatter);
    }
    if (verticalTitle != null) {
        gridLabelRenderer.setVerticalAxisTitle(verticalTitle);
        gridLabelRenderer.setVerticalAxisTitleTextSize(
            gridLabelRenderer.getVerticalAxisTitleTextSize() * GraphConstants.AXIS_TEXT_SIZE_ADJUSTMENT);
    }
    if (horizontalTitle != null) {
        gridLabelRenderer.setHorizontalAxisTitle(horizontalTitle);
        gridLabelRenderer.setHorizontalAxisTitleTextSize(
            gridLabelRenderer.getHorizontalAxisTitleTextSize() * GraphConstants.AXIS_TEXT_SIZE_ADJUSTMENT);
    }

    setGridLabelRenderColors(gridLabelRenderer);
}
 
Example #15
Source File: GraphViewBuilder.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
void setViewPortY(@NonNull GraphView graphView) {
    Viewport viewport = graphView.getViewport();
    viewport.setScrollable(true);
    viewport.setYAxisBoundsManual(true);
    viewport.setMinY(GraphConstants.MIN_Y);
    viewport.setMaxY(getMaximumY());
    viewport.setXAxisBoundsManual(true);
}
 
Example #16
Source File: GraphViewBuilder.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
public GraphView build() {
    GraphView graphView = new GraphView(context);
    setGraphView(graphView);
    setGridLabelRenderer(graphView);
    setViewPortY(graphView);
    return graphView;
}
 
Example #17
Source File: WeekStatisticFragment.java    From privacy-friendly-food-tracker with GNU General Public License v3.0 5 votes vote down vote up
void UpdateGraph() {
    List<ConsumedEntrieAndProductDao.DateCalories> consumedEntriesList = new ArrayList<>();
    List<ConsumedEntrieAndProductDao.DateCalories> calories = new ArrayList<>();
    try {

        Date startDate = getWeekByValue(-1);
        Date endDate = getWeekByValue(0);
        consumedEntriesList = databaseFacade.getCaloriesPerDayinPeriod(startDate,endDate);
        calories = databaseFacade.getPeriodCalories(startDate,endDate);
        DataPoint[] dataPointInterfaces = new DataPoint[consumedEntriesList.size()];
        for (int i = 0; i < consumedEntriesList.size(); i++) {
            dataPointInterfaces[i] = (new DataPoint(consumedEntriesList.get(i).unique1.getTime(), consumedEntriesList.get(i).unique2/100));
        }
        int weekdays = 8;

        float averageCalories = calories.get(0).unique2 / weekdays;

        BigDecimal averageCaloriesBigDecimal = round(averageCalories,0) ;

        if (calories.size() != 0) {
            textView.setText(averageCaloriesBigDecimal.toString());
        }
        GraphView graph = (GraphView) parentHolder.findViewById(R.id.graph);
        LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dataPointInterfaces);
        graph.addSeries(series);
        graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(referenceActivity));
        graph.getGridLabelRenderer().setHumanRounding(false, true);
        graph.getViewport().setMinX(startDate.getTime());
        graph.getViewport().setMaxX(endDate.getTime());
        graph.getViewport().setXAxisBoundsManual(true);

        graph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
        graph.getGridLabelRenderer().setTextSize(40);
        graph.getViewport().setScrollable(true);
        graph.getGridLabelRenderer().setHorizontalLabelsAngle(135);
    } catch (Exception e) {
        Log.e("Error", e.getMessage());
    }
}
 
Example #18
Source File: ChannelGraphView.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private GraphView makeGraphView(@NonNull MainContext mainContext, int graphMaximumY, @NonNull ThemeStyle themeStyle) {
    Resources resources = mainContext.getResources();
    return new GraphViewBuilder(mainContext.getContext(), getNumX(), graphMaximumY, themeStyle)
        .setLabelFormatter(new ChannelAxisLabel(wiFiBand, wiFiChannelPair))
        .setVerticalTitle(resources.getString(R.string.graph_axis_y))
        .setHorizontalTitle(resources.getString(R.string.graph_channel_axis_x))
        .build();
}
 
Example #19
Source File: GraphActivity.java    From Telephoto with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_graph);

        List<TimeStats> timeStatsList = PrefsController.instance.getPrefs().getTimeStatsList();
        if (!timeStatsList.isEmpty()) {
            // battery temperature graph
            List<Float> batteryTemperatureList = Converters.TIME_STATS_TO_TEMPERATURE_LIST.apply(timeStatsList);
            DataPoint[] batTempDataPoints = new DataPoint[batteryTemperatureList.size()];
            int i = 0;
            for (Float batteryTemperature : batteryTemperatureList) {
                batTempDataPoints[i++] = new DataPoint(i, batteryTemperature);
            }

            GraphView tempGraph = (GraphView) findViewById(R.id.temperature_graph);

            LineGraphSeries<DataPoint> batTempSeries = new LineGraphSeries<>(batTempDataPoints);
            batTempSeries.setDrawDataPoints(true);
            tempGraph.addSeries(batTempSeries);

            // battery level graph
//            List<Float> batteryLevelList = Converters.TIME_STATS_TO_BATTERY_LEVEL.apply(timeStatsList);
//            DataPoint[] batLevelDataPoints = new DataPoint[batteryLevelList.size()];
//            i = 0;
//            for (Float batteryLevel: batteryLevelList) {
//                batLevelDataPoints[i++] = new DataPoint(i, batteryLevel);
//            }
//            LineGraphSeries<DataPoint> batLevelSeries = new LineGraphSeries<>(batLevelDataPoints);
//            GraphView lvlGraph = (GraphView) findViewById(R.id.level_graph);
//            lvlGraph.addSeries(batLevelSeries);
        }

    }
 
Example #20
Source File: SettingsFragment.java    From BackPackTrackII with GNU General Public License v3.0 5 votes vote down vote up
public updateForecast(int type, Location location, boolean cache, View view) {
    this.type = type;
    this.context = view.getContext();
    this.progress = (ProgressBar) view.findViewById(R.id.pbWeatherForecast);
    this.graph = (GraphView) view.findViewById(R.id.gvForecast);
    this.header = (LinearLayout) view.findViewById(R.id.llHeader);
    this.list = (ListView) view.findViewById(R.id.lvWeatherForecast);
    this.time = (TextView) view.findViewById(R.id.tvTime);
    this.prefs = getPreferenceScreen().getSharedPreferences();
    this.apikey_fio = prefs.getString(PREF_WEATHER_APIKEY_FIO, null);
    this.location = location;
    this.cache = cache;
}
 
Example #21
Source File: PipelineRunner.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
public PipelineRunner(MainActivity a, GraphView[] graphs)
{
    _act = a;
    _graphs = graphs;

    if(Pipeline.isInstanced())
        Pipeline.getInstance().clear();
    _ssj = Pipeline.getInstance();
}
 
Example #22
Source File: MainActivity.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
public void onStartPressed(View v)
    {
        Button btn = (Button) findViewById(R.id.btn_start);
        btn.setAlpha(0.5f);
        btn.setEnabled(false);
        getCacheDir().getAbsolutePath();

        AssetManager am = getApplicationContext().getAssets();
        getAssets();
        TextView text = (TextView) findViewById(R.id.txt_ssj);

        if(_pipe == null || !_pipe.isRunning())
        {
            text.setText(_ssj_version + " - starting");



            GraphView graph = (GraphView) findViewById(R.id.graph);
            graph.removeAllSeries();
//            graph.getSecondScale().removeAllSeries(); //not implemented in GraphView 4.0.1
            GraphView graph2 = (GraphView) findViewById(R.id.graph2);
            graph2.removeAllSeries();
//            graph2.getSecondScale().removeAllSeries(); //not implemented in GraphView 4.0.1

            GraphView graphs[] = new GraphView[]{graph, graph2};

            _pipe = new PipelineRunner(this, graphs);
            _pipe.setExceptionHandler(this);
            _pipe.start();
        }
        else
        {
            text.setText(_ssj_version + " - stopping");
            _pipe.terminate();
        }
    }
 
Example #23
Source File: SignalPainter.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
private void createSeries(final GraphView view, final Stream[] stream_in)
{
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(new Runnable()
    {
        public void run()
        {
            for (int i = 0; i < stream_in.length; i++)
            {
                for (int j = 0; j < stream_in[i].dim; j++)
                {
                    LineGraphSeries<DataPoint> s = new LineGraphSeries<>();
                    s.setTitle(stream_in[i].desc[j]);
                    s.setColor(colors[color_id++ % colors.length]);

                    //define scale length
                    if(!options.renderMax.get())
                        _maxPoints[_series.size()] = (int)(options.size.get() * stream_in[i].sr) +1;
                    else
                        _maxPoints[_series.size()] = (int)(options.size.get() * (stream_in[i].sr / (double)stream_in[i].num)) +1;

                    _series.add(s);

                    if (options.secondScaleStream.get() == i && options.secondScaleDim.get() == j)
                    {
                        view.getSecondScale().setMinY(options.secondScaleMin.get());
                        view.getSecondScale().setMaxY(options.secondScaleMax.get());
                        view.getSecondScale().addSeries(s);
                    } else
                    {
                        _view.addSeries(s);
                    }
                }
            }
        }
    }, 1);
}
 
Example #24
Source File: Analytics.java    From PocketMaps with MIT License 4 votes vote down vote up
/**
 * init and setup Graph Contents
 */
private void initGraph() {
    hasNewPoint = false;
    maxXaxis = 0.1;
    maxY1axis = 10;
    maxY2axis = 0.4;
    graph = (GraphView) findViewById(R.id.analytics_graph);

    speedGraphSeries = new LineGraphSeries<>();
    graph.addSeries(speedGraphSeries);

    graph.getGridLabelRenderer().setVerticalLabelsColor(0xFF009688);
    graph.getViewport().setYAxisBoundsManual(true);
    resetGraphY1MaxValue();
    distanceGraphSeries = new LineGraphSeries<>();
    //        graph.getViewport().setXAxisBoundsManual(true);
    graph.getViewport().setScalable(true);
    graph.getViewport().setScrollable(true);

    graph.getViewport().setMinX(0);
    // set second scale
    graph.getSecondScale().addSeries(distanceGraphSeries);
    // the y bounds are always manual for second scale
    graph.getSecondScale().setMinY(0);
    resetGraphY2MaxValue();
    //        resetGraphXMaxValue();
    graph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(0xFFFF5722);
    // legend
    if (Variable.getVariable().isImperalUnit())
    {
      speedGraphSeries.setTitle("Speed mi/h");
      distanceGraphSeries.setTitle("Distance mi");
    }
    else
    {
      speedGraphSeries.setTitle("Speed km/h");
      distanceGraphSeries.setTitle("Distance km");
    }
    speedGraphSeries.setColor(0xFF009688);
    distanceGraphSeries.setColor(0xFFFF5722);
    graph.getLegendRenderer().setVisible(true);
    graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP);
}
 
Example #25
Source File: GraphViewActivity.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
private void sampleMultipleSeries() {
    String[] months = {
            "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
            "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
    };

    int[] index = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    int[] incomeA = {4000, 5500, 2300, 2100, 2500, 2900, 3200, 2400, 1800, 2100, 3500, 5900};
    int[] incomeB = {3600, 4500, 3200, 3600, 2800, 1800, 2100, 2900, 2200, 2500, 4000, 3500};
    int[] incomeC = {4300, 4000, 3000, 3200, 2400, 2500, 2600, 3400, 3900, 4500, 5000, 4500};


    int num = 100;
    GraphView.GraphViewData[] data = new GraphView.GraphViewData[index.length];
    for (int i = 0; i < index.length; i++) {
        data[i] = new GraphView.GraphViewData(i, incomeA[i]);
    }
    GraphViewSeries seriesA = new GraphViewSeries("Googla",
            new GraphViewSeries.GraphViewSeriesStyle(Color.RED, 5), data);

    data = new GraphView.GraphViewData[index.length];
    for (int i = 0; i < index.length; i++) {
        data[i] = new GraphView.GraphViewData(i, incomeB[i]);
    }
    GraphViewSeries seriesB = new GraphViewSeries("Microsa",
            new GraphViewSeries.GraphViewSeriesStyle(Color.BLUE, 5), data);

    data = new GraphView.GraphViewData[index.length];
    for (int i = 0; i < index.length; i++) {
        data[i] = new GraphView.GraphViewData(i, incomeC[i]);
    }
    GraphViewSeries seriesC = new GraphViewSeries("Appla",
            new GraphViewSeries.GraphViewSeriesStyle(Color.GREEN, 5), data);

    GraphView graphView = new LineGraphView(this, "Multiple Series");
    graphView.addSeries(seriesA);
    graphView.addSeries(seriesB);
    graphView.addSeries(seriesC);

    graphView.setShowLegend(true);
    graphView.getGraphViewStyle().setLegendWidth(200);

    LinearLayout layout = (LinearLayout) findViewById(R.id.linear_layout);
    layout.addView(graphView);

    graphView.setBackgroundColor(Color.WHITE);
}
 
Example #26
Source File: GraphUtil.java    From BlurTestAndroid with Apache License 2.0 4 votes vote down vote up
public static GraphViewSeries getStraightLine(int heightY, int maxX, String name, GraphViewSeries.GraphViewSeriesStyle seriesStyle) {
    GraphView.GraphViewData[] data = new GraphView.GraphViewData[2];
    data[0] = new GraphView.GraphViewData(0, heightY);
    data[1] = new GraphView.GraphViewData(maxX, heightY);
    return new GraphViewSeries(name, seriesStyle, data);
}
 
Example #27
Source File: BenchmarkDetailsDialog.java    From BlurTestAndroid with Apache License 2.0 4 votes vote down vote up
private GraphView createGraph(BenchmarkWrapper wrapper) {
    Resources res = getResources();
    int lineThicknessPx = (int) Math.ceil(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()));

    GraphView.GraphViewData[] data = new GraphView.GraphViewData[wrapper.getStatInfo().getBenchmarkData().size()];
    for (int j = 0; j < wrapper.getStatInfo().getBenchmarkData().size(); j++) {
        data[j] = new GraphView.GraphViewData(j, wrapper.getStatInfo().getBenchmarkData().get(j));
    }

    LineGraphView graphView = new LineGraphView(getActivity(), "");
    GraphViewSeries.GraphViewSeriesStyle seriesStyle = new GraphViewSeries.GraphViewSeriesStyle(res.getColor(R.color.graphBgGreen), lineThicknessPx);

    if (wrapper.getStatInfo().getAsAvg().getMin() <= IBlur.MS_THRESHOLD_FOR_SMOOTH) {
        graphView.addSeries(GraphUtil.getStraightLine(IBlur.MS_THRESHOLD_FOR_SMOOTH, wrapper.getStatInfo().getBenchmarkData().size() - 1, "16ms", new GraphViewSeries.GraphViewSeriesStyle(res.getColor(R.color.graphBgRed), lineThicknessPx)));
    }
    graphView.addSeries(GraphUtil.getStraightLine((int) wrapper.getStatInfo().getAsAvg().getAvg(), wrapper.getStatInfo().getBenchmarkData().size() - 1, "Avg", new GraphViewSeries.GraphViewSeriesStyle(res.getColor(R.color.graphBlue), lineThicknessPx)));
    graphView.addSeries(new GraphViewSeries("Blur", seriesStyle, data));
    graphView.setScrollable(true);
    graphView.setScalable(true);
    graphView.setManualYAxis(true);
    graphView.getGraphViewStyle().setGridColor(res.getColor(R.color.transparent));
    graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
        @Override
        public String formatLabel(double value, boolean isValueX) {
            if (!isValueX) {
                return Math.round(value) + "ms";
            } else {
                return null;
            }
        }
    });
    graphView.setManualYAxisBounds(wrapper.getStatInfo().getAsAvg().getMax(), Math.max(0, wrapper.getStatInfo().getAsAvg().getMin() - 3l));
    graphView.setDrawBackground(false);
    graphView.setShowLegend(true);

    graphView.getGraphViewStyle().setHorizontalLabelsColor(res.getColor(R.color.transparent));
    graphView.getGraphViewStyle().setNumHorizontalLabels(0);
    graphView.getGraphViewStyle().setVerticalLabelsColor(res.getColor(R.color.optionsTextColorDark));
    graphView.getGraphViewStyle().setNumVerticalLabels(4);
    graphView.getGraphViewStyle().setVerticalLabelsAlign(Paint.Align.CENTER);
    graphView.getGraphViewStyle().setVerticalLabelsWidth((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, res.getDisplayMetrics()));
    graphView.getGraphViewStyle().setTextSize((int) Math.ceil(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, res.getDisplayMetrics())));

    return graphView;
}
 
Example #28
Source File: StatsActivity.java    From 10000sentences with Apache License 2.0 4 votes vote down vote up
private void setupGraph(
        Map<String, List<StatsService.DataPoint>> dataPointsByCollectionId,
        GraphView graph,
        boolean yFromZero,
        final Formatter yAxisFormatter) {

    double minX = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(daysAgo) - TimeUnit.HOURS.toMillis(12);
    double maxX = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(12);
    double minY = 0;
    double maxY = 0;

    int colorNo = 0;
    for (String collectionId : dataPointsByCollectionId.keySet()) {
        List<StatsService.DataPoint> points = dataPointsByCollectionId.get(collectionId);

        BarGraphSeries series = new BarGraphSeries<>(points.toArray(new DataPointInterface[points.size()]));
        series.setColor(ContextCompat.getColor(this, graphColors[(colorNo ++) % graphColors.length]));
        series.setTitle(collectionId);

        graph.addSeries(series);

        if (minY == 0) {
            minY = series.getLowestValueY();
        }
        if (maxY == 0) {
            maxY = series.getHighestValueY();
        }

        maxY = Math.max(maxY, series.getHighestValueY());
        minY = Math.min(minY, series.getLowestValueY());
    }

    if (yFromZero) {
        minY = 0;
    }

    if (minY == maxY) {
        minY = 0;
        maxY = 1 + maxY * 1.5;
    }

    graph.getViewport().setMinX(minX);
    graph.getViewport().setMaxX(maxX);
    graph.getViewport().setXAxisBoundsManual(true);

    graph.getViewport().setMinY(minY);
    graph.getViewport().setMaxY(maxY);
    graph.getViewport().setYAxisBoundsManual(true);

    graph.getLegendRenderer().setFixedPosition(0, 0);
    graph.getLegendRenderer().setVisible(true);

    graph.getGridLabelRenderer().setLabelFormatter(new LabelFormatter() {
        public String lattestFormatted;
        Calendar cal = Calendar.getInstance();
        @Override
        public String formatLabel(double value, boolean isValueX) {
            if (isValueX) {
                cal.setTimeInMillis((long) value);
                String formatted = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
                if (formatted.equals(lattestFormatted)) {
                    this.lattestFormatted = formatted;
                    return "";
                }
                this.lattestFormatted = formatted;
                return formatted;
            }
            return yAxisFormatter.format(value);
        }

        @Override
        public void setViewport(Viewport viewport) {}
    });
    graph.getGridLabelRenderer().setGridColor(Color.GRAY);
    graph.getGridLabelRenderer().setNumHorizontalLabels(daysAgo);
}
 
Example #29
Source File: GraphData.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
public GraphData(GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) {
    units = ProfileFunctions.getSystemUnits();
    this.graph = graph;
    this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
}
 
Example #30
Source File: GraphAdapter.java    From WiFiAnalyzer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public GraphView transform(GraphViewNotifier input) {
    return input.getGraphView();
}