Skip to content

Commit

Permalink
fix: support DataSet “setFillShader” for all charts
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Mar 18, 2021
1 parent 8fb538f commit 90591f9
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 75 deletions.
50 changes: 16 additions & 34 deletions src/charting/data/BaseDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {

private mColorDefault = '#8CEAFF';

protected mGradientColor = null;

protected mGradientColors: GradientColor[] = null;

/**
* List representing all colors that are used for drawing the actual values for this DataSet
*/
Expand Down Expand Up @@ -172,17 +168,6 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
return this.mColors[Math.floor(index) % this.mColors.length];
}

public getGradientColors() {
return this.mGradientColors;
}

public getGradientColor(index?: number) {
if (!this.mGradientColors || index === undefined) {
return this.mGradientColor;
}
return this.mGradientColors[index % this.mGradientColors.length];
}

// /**
// * Sets the colors that should be used fore this DataSet. Colors are reused
// * as soon as the number of Entries the DataSet represents is higher than
Expand All @@ -206,25 +191,6 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
this.mColors.push(value);
}

/**
* Sets the start and end color for gradient color, ONLY color that should be used for this DataSet.
*
* @param startColor
* @param endColor
*/
public setGradientColor(startColor, endColor) {
this.mGradientColor = new GradientColor(startColor, endColor);
}

/**
* Sets the start and end color for gradient colors, ONLY color that should be used for this DataSet.
*
* @param gradientColors
*/
public setGradientColors(gradientColors: GradientColor[]) {
this.mGradientColors = gradientColors;
}

/**
* Sets a color with a specific alpha value.
*
Expand Down Expand Up @@ -406,6 +372,22 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
this.mAxisDependency = dependency;
}

/**
* the shader to be used for filling the line surface
*/
protected mFillShader;
/**
* Sets the shader that is used for filling the area below the line
*
* @param shader
*/
public setFillShader(shader) {
this.mFillShader = shader;
}
public getFillShader() {
return this.mFillShader;
}

/**
* ###### ###### DATA RELATED METHODS ###### ######
*/
Expand Down
2 changes: 1 addition & 1 deletion src/charting/data/DataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Utils } from '../utils/Utils';
export enum Rounding {
UP,
DOWN,
CLOSEST,
CLOSEST
}
/**
* The DataSet class represents one group or type of entries (Entry) in the
Expand Down
17 changes: 0 additions & 17 deletions src/charting/data/LineRadarDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
*/
protected mFillDrawable: ImageSource;

/**
* the shader to be used for filling the line surface
*/
protected mFillShader;

/**
* transparency used for filling line surface
*/
Expand Down Expand Up @@ -55,18 +50,6 @@ export abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
this.mFillColor = color;
this.mFillDrawable = null;
}
/**
* Sets the shader that is used for filling the area below the line
*
* @param shader
*/
public setFillShader(shader) {
this.mFillShader = shader;
}
public getFillShader() {
return this.mFillShader;
}


public getFillDrawable() {
return this.mFillDrawable;
Expand Down
2 changes: 1 addition & 1 deletion src/charting/data/LineScatterCandleRadarDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export abstract class LineScatterCandleRadarDataSet<T extends Entry> extends Bar
* @param phase offset, in degrees (normally, use 0)
*/
public enableDashedHighlightLine(lineLength, spaceLength, phase) {
this.mHighlightDashPathEffect = new DashPathEffect([lineLength,spaceLength],phase);
this.mHighlightDashPathEffect = new DashPathEffect([lineLength, spaceLength], phase);
}

/**
Expand Down
22 changes: 7 additions & 15 deletions src/charting/interfaces/datasets/IDataSet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,6 @@ export interface IDataSet<T extends Entry> {
*/
getColors(): (string | Color)[];

/**
* Returns the Gradient colors
*
* @return
*/
getGradientColors(): GradientColor[];

/**
* Returns the Gradient colors
*
* @param index
* @return
*/
getGradientColor(index?: number): GradientColor;

/**
* Returns the color at the given index of the DataSet's color array.
* Performs a IndexOutOfBounds check by modulus.
Expand Down Expand Up @@ -504,4 +489,11 @@ export interface IDataSet<T extends Entry> {
* @return
*/
isVisible(): boolean;

/**
* Returns the shader used for filling the area below the line.
*
* @return
*/
getFillShader();
}
6 changes: 0 additions & 6 deletions src/charting/interfaces/datasets/ILineRadarDataSet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export interface ILineRadarDataSet<T extends Entry> extends ILineScatterCandleRa
* @return
*/
getFillDrawable(): ImageSource;
/**
* Returns the shader used for filling the area below the line.
*
* @return
*/
getFillShader();

/**
* Returns the alpha value that is used for filling the line surface,
Expand Down
8 changes: 7 additions & 1 deletion src/charting/renderer/BarChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ export class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
trans.pointValuesToPixel(buffer.buffer);

const isSingleColor = dataSet.getColors().length === 1;
const isInverted = this.mChart.isInverted(dataSet.getAxisDependency());
// const isInverted = this.mChart.isInverted(dataSet.getAxisDependency());
const renderPaint = this.renderPaint;
const previousShader = renderPaint.getShader();
const shader = dataSet.getFillShader();
if (shader) {
renderPaint.setShader(shader);
}
if (isSingleColor) {
renderPaint.setColor(dataSet.getColor());
}
Expand Down Expand Up @@ -192,6 +197,7 @@ export class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
}
}
}
renderPaint.setShader(previousShader);

return true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/charting/renderer/BubbleChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
const maxSize = dataSet.getMaxSize();
const customRender = this.mChart.getCustomRenderer();
const renderPaint = this.renderPaint;
const previousShader = renderPaint.getShader();
const shader = dataSet.getFillShader();
if (shader) {
renderPaint.setShader(shader);
}
for (let j = this.mXBounds.min; j <= this.mXBounds.range + this.mXBounds.min; j++) {
const entry = dataSet.getEntryForIndex(j);
const xValue = getEntryXValue(entry, xKey, j);
Expand All @@ -104,6 +109,7 @@ export class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
c.drawCircle(this.pointBuffer[0], this.pointBuffer[1], shapeHalf, renderPaint);
}
}
renderPaint.setShader(previousShader);
}

public drawValues(c: Canvas) {
Expand Down
6 changes: 6 additions & 0 deletions src/charting/renderer/HorizontalBarChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export class HorizontalBarChartRenderer extends BarChartRenderer {
const isSingleColor = dataSet.getColors().length === 1;
const isInverted = this.mChart.isInverted(dataSet.getAxisDependency());
const renderPaint = this.renderPaint;
const previousShader = renderPaint.getShader();
const shader = dataSet.getFillShader();
if (shader) {
renderPaint.setShader(shader);
}

if (isSingleColor) {
renderPaint.setColor(dataSet.getColor());
Expand Down Expand Up @@ -130,6 +135,7 @@ export class HorizontalBarChartRenderer extends BarChartRenderer {
}
}
}
renderPaint.setShader(previousShader);

return true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/charting/renderer/PieChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ export class PieChartRenderer extends DataRenderer {
const customRender = this.mChart.getCustomRenderer();
const renderPaint = this.renderPaint;
const pathBuffer = this.pathBuffer;
const previousShader = renderPaint.getShader();
const shader = dataSet.getFillShader();
if (shader) {
renderPaint.setShader(shader);
}
for (let j = 0; j < entryCount; j++) {
const sliceAngle = drawAngles[j];
let innerRadius = userInnerRadius;
Expand Down Expand Up @@ -380,6 +385,7 @@ export class PieChartRenderer extends DataRenderer {

angle += sliceAngle * phaseX;
}
renderPaint.setShader(previousShader);

return result;
}
Expand Down
7 changes: 7 additions & 0 deletions src/charting/renderer/RadarChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,19 @@ export class RadarChartRenderer extends LineRadarRenderer {
// surface.close();

if (dataSet.isDrawFilledEnabled()) {
const renderPaint = this.renderPaint;
const previousShader = renderPaint.getShader();
const shader = dataSet.getFillShader();
if (shader) {
renderPaint.setShader(shader);
}
const drawable = dataSet.getFillDrawable();
if (drawable != null) {
this.drawFilledPathBitmap(c, surface, drawable, dataSet.getFillShader());
} else {
this.drawFilledPath(c, surface, dataSet.getFillColor(), dataSet.getFillAlpha());
}
renderPaint.setShader(previousShader);
}

// draw the line (only if filled is disabled or alpha is below 255)
Expand Down
6 changes: 6 additions & 0 deletions src/charting/renderer/ScatterChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
const customRender = this.mChart.getCustomRenderer();
const renderPaint = this.renderPaint;
const pixelBuffer = this.pixelBuffer;
const previousShader = renderPaint.getShader();
const shader = dataSet.getFillShader();
if (shader) {
renderPaint.setShader(shader);
}
for (let i = 0; i < max; i++) {
const e = dataSet.getEntryForIndex(i);

Expand All @@ -80,6 +85,7 @@ export class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
renderer.renderShape(c, dataSet, this.mViewPortHandler, pixelBuffer[0], pixelBuffer[1], renderPaint);
}
}
renderPaint.setShader(previousShader);
}

public drawValues(c: Canvas) {
Expand Down

0 comments on commit 90591f9

Please sign in to comment.