android - AndroidPlot customize joints -
android - AndroidPlot customize joints -
i tried create plot this:
but not know how customize point have black stroke around orange fill, points "glued" lines.
or, @ to the lowest degree how create (outer circle of same color line).
any help?
i believe bottom image uses custom lineandpointrenderer, need utilize reproduce topmost image.
here's quick , dirty illustration of how this. first create custom formatter hold new formatting values needed:
/** * lineandpointformatter add-on of paint used "stroke" vertices. */ class mylineandpointformatter extends lineandpointformatter{ private paint strokepaint; /** * quick , dirty hard-coded params */ public mylineandpointformatter() { super(color.red, color.red, null, null); strokepaint = new paint(); strokepaint.setcolor(color.black); strokepaint.setstrokewidth(pixelutils.dptopix(2)); strokepaint.setstyle(paint.style.stroke); strokepaint.setantialias(true); } public paint getstrokepaint() { homecoming strokepaint; } @override public class<? extends seriesrenderer> getrendererclass() { homecoming mylineandpointrenderer.class; } @override public seriesrenderer getrendererinstance(xyplot plot) { homecoming new mylineandpointrenderer(plot); } }
next, custom renderer:
/** * lineandpointrenderer can stroke vertices. */ class mylineandpointrenderer extends lineandpointrenderer<mylineandpointformatter> { public mylineandpointrenderer(xyplot plot) { super(plot); } /** * overridden draw method "vertex stroke" effect. 99% of copy/pasted * super class' implementation. * @param canvas * @param plotarea * @param series * @param formatter */ @override protected void drawseries(canvas canvas, rectf plotarea, xyseries series, lineandpointformatter formatter) { pointf thispoint; pointf lastpoint = null; pointf firstpoint = null; paint linepaint = formatter.getlinepaint(); path path = null; arraylist<pair<pointf, integer>> points = new arraylist<pair<pointf, integer>>(series.size()); (int = 0; < series.size(); i++) { number y = series.gety(i); number x = series.getx(i); if (y != null && x != null) { thispoint = valpixconverter.valtopix( x, y, plotarea, getplot().getcalculatedminx(), getplot().getcalculatedmaxx(), getplot().getcalculatedminy(), getplot().getcalculatedmaxy()); points.add(new pair<pointf, integer>(thispoint, i)); } else { thispoint = null; } if(linepaint != null && thispoint != null) { // record first point of new path if(firstpoint == null) { path = new path(); firstpoint = thispoint; // create our first point @ bottom/x position filling // path.moveto(firstpoint.x, firstpoint.y); } if(lastpoint != null) { appendtopath(path, thispoint, lastpoint); } lastpoint = thispoint; } else { if(lastpoint != null) { renderpath(canvas, plotarea, path, firstpoint, lastpoint, formatter); } firstpoint = null; lastpoint = null; } } if(linepaint != null && firstpoint != null) { renderpath(canvas, plotarea, path, firstpoint, lastpoint, formatter); } paint vertexpaint = formatter.getvertexpaint(); paint strokepaint = ((mylineandpointformatter)formatter).getstrokepaint(); pointlabelformatter plf = formatter.getpointlabelformatter(); if (vertexpaint != null || plf != null) { (pair<pointf, integer> p : points) { pointlabeler pointlabeler = formatter.getpointlabeler(); // if vertexpaint available, draw vertex: if(vertexpaint != null) { canvas.drawpoint(p.first.x, p.first.y, vertexpaint); } // if stroke available, draw stroke: if(strokepaint != null) { // you'll want create radius configurable parameter // instead of hard-coded here. canvas.drawcircle(p.first.x, p.first.y, 4, strokepaint); } // if textpaint , pointlabeler available, draw point's text label: if(plf != null && pointlabeler != null) { canvas.drawtext(pointlabeler.getlabel(series, p.second), p.first.x + plf.hoffset, p.first.y + plf.voffset, plf.gettextpaint()); } } } } }
and finally, utilize these new pieces in activity:
mylineandpointformatter format = new mylineandpointformatter(); plot.addseries(series, format);
here's looks when used simplexyplot example:
it prettier thickening lines, picking improve background color etc, idea.
android androidplot
Comments
Post a Comment