Skip to content

Commit

Permalink
Merge pull request #17078 from jiawulin001/issue#17077
Browse files Browse the repository at this point in the history
feat: barSeries.startValue added
  • Loading branch information
Ovilia committed May 21, 2024
2 parents 75dd430 + 0e862ce commit a4db0d4
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/chart/bar/BarSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export interface BarSeriesOption

showBackground?: boolean

startValue?: number

backgroundStyle?: ItemStyleOption & {
borderRadius?: number | number[]
}
Expand Down
1 change: 1 addition & 0 deletions src/coord/axisCommonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface AxisBaseOptionCommon extends ComponentOption,
* + null/undefined: auto decide max value (consider pretty look and boundaryGap).
*/
max?: ScaleDataValue | 'dataMax' | ((extent: {min: number, max: number}) => ScaleDataValue);
startValue?: number;

}

Expand Down
6 changes: 5 additions & 1 deletion src/coord/scaleRawExtentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ export class ScaleRawExtentInfo {
const isOrdinal = this._isOrdinal = scale.type === 'ordinal';
this._needCrossZero = scale.type === 'interval' && model.getNeedCrossZero && model.getNeedCrossZero();

const modelMinRaw = this._modelMinRaw = model.get('min', true);
let axisMinValue = model.get('min', true);
if (axisMinValue == null) {
axisMinValue = model.get('startValue', true);
}
const modelMinRaw = this._modelMinRaw = axisMinValue;
if (isFunction(modelMinRaw)) {
// This callback always provides users the full data extent (before data is filtered).
this._modelMinNum = parseAxisModelMinMax(scale, modelMinRaw({
Expand Down
19 changes: 13 additions & 6 deletions src/layout/barGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,13 @@ export function createProgressiveLayout(seriesType: string): StageHandler {
while ((dataIndex = params.next()) != null) {
const value = store.get(stacked ? stackedDimIdx : valueDimIdx, dataIndex);
const baseValue = store.get(baseDimIdx, dataIndex) as number;

let baseCoord = valueAxisStart;
let startValue;
let stackStartValue;

// Because of the barMinHeight, we can not use the value in
// stackResultDimension directly.
if (stacked) {
startValue = +value - (store.get(valueDimIdx, dataIndex) as number);
stackStartValue = +value - (store.get(valueDimIdx, dataIndex) as number);
}

let x;
Expand All @@ -530,7 +529,7 @@ export function createProgressiveLayout(seriesType: string): StageHandler {
if (isValueAxisH) {
const coord = cartesian.dataToPoint([value, baseValue]);
if (stacked) {
const startCoord = cartesian.dataToPoint([startValue, baseValue]);
const startCoord = cartesian.dataToPoint([stackStartValue, baseValue]);
baseCoord = startCoord[0];
}
x = baseCoord;
Expand All @@ -545,7 +544,7 @@ export function createProgressiveLayout(seriesType: string): StageHandler {
else {
const coord = cartesian.dataToPoint([baseValue, value]);
if (stacked) {
const startCoord = cartesian.dataToPoint([baseValue, startValue]);
const startCoord = cartesian.dataToPoint([baseValue, stackStartValue]);
baseCoord = startCoord[1];
}
x = coord[0] + columnOffset;
Expand Down Expand Up @@ -603,5 +602,13 @@ function isInLargeMode(seriesModel: BarSeriesModel) {

// See cases in `test/bar-start.html` and `#7412`, `#8747`.
function getValueAxisStart(baseAxis: Axis2D, valueAxis: Axis2D) {
return valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.type === 'log' ? 1 : 0));
let startValue = valueAxis.model.get('startValue');
if (!startValue) {
startValue = 0;
}
return valueAxis.toGlobalCoord(
valueAxis.dataToCoord(
valueAxis.type === 'log'
? (startValue > 0 ? startValue : 1)
: startValue));
}
6 changes: 5 additions & 1 deletion src/layout/barPolar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import RadiusAxis from '../coord/polar/RadiusAxis';
import GlobalModel from '../model/Global';
import ExtensionAPI from '../core/ExtensionAPI';
import { Dictionary } from '../util/types';
import { PolarAxisModel } from '../coord/polar/AxisModel';

type PolarAxis = AngleAxis | RadiusAxis;

Expand Down Expand Up @@ -104,7 +105,10 @@ function barLayoutPolar(seriesType: string, ecModel: GlobalModel, api: Extension
const clampLayout = baseAxis.dim !== 'radius'
|| !seriesModel.get('roundCap', true);

const valueAxisStart = valueAxis.dataToCoord(0);
const valueAxisModel = valueAxis.model as PolarAxisModel;
const startValue = valueAxisModel.get('startValue');
const valueAxisStart = valueAxis.dataToCoord(startValue || 0);

for (let idx = 0, len = data.count(); idx < len; idx++) {
const value = data.get(valueDim, idx) as number;
const baseValue = data.get(baseDim, idx) as number;
Expand Down
225 changes: 225 additions & 0 deletions test/bar-startValue.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a4db0d4

Please sign in to comment.