double x = 0;
double y = 0;
boolean gap = false;
for (int i = 0; i < store.size(); i++) {
PrecisePoint point = coordinates.get(i);
if (point != null) {
x = point.getX();
y = point.getY();
} else {
x = y = Double.NaN;
}
if (!Double.isNaN(x) && !Double.isNaN(y)) {
if (onbreak) {
onbreak = false;
}
if (lineCommands.size() > 0 && !gap) {
lineCommands.add(new LineTo(x, y));
} else {
lineCommands.add(new MoveTo(x, y));
gap = false;
}
gapPosition.put(String.valueOf(lineCommands.size() - 1), i);
} else if (!gapless) {
gap = true;
}
if (Double.isNaN(firstY) && !Double.isNaN(y)) {
firstY = y;
}
}
List<PathCommand> renderCommands;
if (smooth && lineCommands.size() > 0) {
PathSprite smooth = new PathSprite();
smooth.setCommands(lineCommands);
renderCommands = smooth.copy().toSmooth(segments).getCommands();
} else {
renderCommands = PathSprite.copyCommands(lineCommands);
}
// Correct path if we're animating timeAxis intervals
if (markerIndex > 0 && previousCommands != null && previousCommands.size() > 1) {
previousCommands.remove(1);
line.setCommands(previousCommands);
if (chart.hasShadows()) {
for (int i = 0; i < lineShadows.size(); i++) {
PathSprite shadow = lineShadows.get(i);
shadow.setCommands(previousCommands);
}
}
}
List<PathCommand> dummyCommands = new ArrayList<PathCommand>();
dummyCommands.add(new MoveTo(bbox.getX(), bbox.getY() + bbox.getHeight() / 2.0));
for (int k = 1; k < lineCommands.size(); k++) {
dummyCommands.add(new LineTo(bbox.getX() + bbox.getWidth() / k, bbox.getY() + bbox.getHeight() / 2.0));
}
// Only create a line if one doesn't exist.
if (line == null) {
line = new PathSprite();
line.setStroke(stroke);
chart.addSprite(line);
line.setCommands(dummyCommands);
if (chart.hasShadows()) {
// create shadows
for (int i = 0; i < shadowGroups.size(); i++) {
PathSprite shadow = new PathSprite();
Sprite shadowAttr = shadowAttributes.get(i);
shadow.setStrokeWidth(shadowAttr.getStrokeWidth());
shadow.setStrokeOpacity(shadowAttr.getStrokeOpacity());
shadow.setStroke(shadowAttr.getStroke());
shadow.setTranslation(new Translation(shadowAttr.getTranslation()));
shadow.setFill(Color.NONE);
shadow.setCommands(line.getCommands());
chart.addSprite(shadow);
lineShadows.add(shadow);
}
}
}
if (stroke != null) {
line.setStroke(stroke);
}
if (!Double.isNaN(strokeWidth)) {
line.setStrokeWidth(strokeWidth);
}
line.setFill(Color.NONE);
if (chart.isAnimated() && line.size() > 0) {
if (markerIndex > 0) {
if (smooth) {
renderCommands.remove(1);
} else {
MoveTo move = (MoveTo) renderCommands.get(0);
renderCommands.add(1, new LineTo(move.getX(), move.getY()));
}
previousCommands = renderCommands;
}
DrawFx.createCommandsAnimator(line, renderCommands).run(500);
} else {
line.setCommands(renderCommands);
line.redraw();
}
if (lineRenderer != null) {
lineRenderer.spriteRenderer(line, 0, chart.getStore());
}
if (fill != Color.NONE && fill != null) {
fillCommands.addAll(renderCommands);
fillCommands.add(new LineTo(x, bbox.getY() + bbox.getHeight()));
fillCommands.add(new LineTo(bbox.getX(), bbox.getY() + bbox.getHeight()));
fillCommands.add(new LineTo(bbox.getX(), firstY));
if (fillSprite == null) {
fillSprite = new PathSprite();
fillSprite.setOpacity(0.3);
fillSprite.setFill(fill);
fillSprite.setCommands(dummyCommands);
chart.addSprite(fillSprite);
}
if (chart.isAnimated() && fillSprite.size() > 0) {
DrawFx.createCommandsAnimator(fillSprite, fillCommands).run(chart.getAnimationDuration(),
chart.getAnimationEasing());
} else {
fillSprite.setCommands(fillCommands);
fillSprite.redraw();
}
if (fillRenderer != null) {
fillRenderer.spriteRenderer(fillSprite, 0, chart.getStore());
}
}
if (chart.hasShadows()) {
for (int i = 0; i < lineShadows.size(); i++) {
PathSprite shadow = lineShadows.get(i);
if (!hidden) {
shadow.setHidden(false);
}
if (chart.isAnimated()) {
DrawFx.createCommandsAnimator(shadow, renderCommands).run(chart.getAnimationDuration(),
chart.getAnimationEasing());
} else {
shadow.setCommands(renderCommands);
shadow.redraw();
}
if (shadowRenderer != null) {
shadowRenderer.spriteRenderer(shadow, i, chart.getCurrentStore());
}
}
shadowed = true;
} else {
hideShadows();
}
if (showMarkers) {
for (int i = 0; i < lineCommands.size(); i++) {
int index = i;
PrecisePoint point = getPointFromCommand(lineCommands.get(index));
if (index < sprites.size()) {
marker = sprites.get(index);
marker.setHidden(false);
} else {
marker = markerConfig.copy();
if (i == 0) {
marker.setTranslation(bbox.getX(), bbox.getY() + bbox.getHeight() / 2.0);
} else {
marker.setTranslation(bbox.getX() + bbox.getWidth() / i, bbox.getY() + bbox.getHeight() / 2.0);
}
sprites.add(marker);
chart.addSprite(marker);
}
if (hidden) {
marker.setHidden(true);
}
if (chart.isAnimated() && marker.getTranslation() != null
&& ((markerIndex <= 0) || (markerIndex > 0 && index != sprites.size() - 1))) {
DrawFx.createTranslationAnimator(marker, point.getX(), point.getY()).run(chart.getAnimationDuration(),
chart.getAnimationEasing());
} else {
marker.setTranslation(point.getX(), point.getY());
marker.redraw();
}
if (renderer != null) {
renderer.spriteRenderer(marker, index, store);
}