Skip to content

Commit

Permalink
Added options property disableNiceOnlyForScale for createScale (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
savvinsergey authored and ignatvilesov committed Jun 23, 2017
1 parent 918b701 commit 5342bb2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 1.2.0
* Added 'disableNiceOnlyForScale' to 'CreateAxisOptions' interface
and added verification with this property to createAxis func

## 1.1.0
* Removed `lodash`
* Updated dependencies

## 1.0.1
* Update ChartUtils to use SVG utils version 1.0.0
* Add CHANGELOG
* Add CHANGELOG
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ declare module powerbi.extensibility.utils.chart.axis {
shouldClamp?: boolean;
/** (optional) Disable "niceing" for numeric axis. It means that if max value is 172 the axis will show 172 but not rounded to upper value 180 */
disableNice?: boolean;
/** (optional) Disable "niceing" for numeric axis. Disabling nice will be applid only when creating scale obj (bestTickCount will be applied to 'ticks' method) */
disableNiceOnlyForScale?: boolean;
}
enum AxisOrientation {
top = 0,
Expand Down
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ var powerbi;
return 1;
}
function createScale(options) {
var pixelSpan = options.pixelSpan, dataDomain = options.dataDomain, metaDataColumn = options.metaDataColumn, outerPadding = options.outerPadding || 0, isScalar = !!options.isScalar, isVertical = !!options.isVertical, forcedTickCount = options.forcedTickCount, categoryThickness = options.categoryThickness, shouldClamp = !!options.shouldClamp, maxTickCount = options.maxTickCount, disableNice = options.disableNice;
var pixelSpan = options.pixelSpan, dataDomain = options.dataDomain, metaDataColumn = options.metaDataColumn, outerPadding = options.outerPadding || 0, isScalar = !!options.isScalar, isVertical = !!options.isVertical, forcedTickCount = options.forcedTickCount, categoryThickness = options.categoryThickness, shouldClamp = !!options.shouldClamp, maxTickCount = options.maxTickCount, disableNice = options.disableNice, disableNiceOnlyForScale = options.disableNiceOnlyForScale;
var dataType = getCategoryValueType(metaDataColumn, isScalar);
var maxTicks = isVertical ? getRecommendedNumberOfTicksForYAxis(pixelSpan) : getRecommendedNumberOfTicksForXAxis(pixelSpan);
if (maxTickCount &&
Expand Down Expand Up @@ -818,7 +818,11 @@ var powerbi;
scalarDomain[0] = options.zeroScalarDomain[0];
scalarDomain[1] = options.zeroScalarDomain[1];
}
scale = createNumericalScale(options.scaleType, pixelSpan, scalarDomain, dataType, outerPadding, bestTickCount, shouldClamp);
var bestTickCountForNumericalScale = bestTickCount;
if (disableNiceOnlyForScale) {
bestTickCountForNumericalScale = null;
}
scale = createNumericalScale(options.scaleType, pixelSpan, scalarDomain, dataType, outerPadding, bestTickCountForNumericalScale, shouldClamp);
}
else if (isScalar && dataType.dateTime) {
// Use of a linear scale, instead of a D3.time.scale, is intentional since we want
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-visuals-utils-chartutils",
"version": "1.1.0",
"version": "1.2.0",
"description": "ChartUtils",
"main": "lib/index.js",
"repository": {
Expand Down
10 changes: 8 additions & 2 deletions src/axis/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ module powerbi.extensibility.utils.chart.axis {
categoryThickness = options.categoryThickness,
shouldClamp = !!options.shouldClamp,
maxTickCount = options.maxTickCount,
disableNice = options.disableNice;
disableNice = options.disableNice,
disableNiceOnlyForScale = options.disableNiceOnlyForScale;

let dataType: ValueType = getCategoryValueType(metaDataColumn, isScalar);

Expand Down Expand Up @@ -808,7 +809,12 @@ module powerbi.extensibility.utils.chart.axis {
scalarDomain[1] = options.zeroScalarDomain[1];
}

scale = createNumericalScale(options.scaleType, pixelSpan, scalarDomain, dataType, outerPadding, bestTickCount, shouldClamp);
let bestTickCountForNumericalScale = bestTickCount;
if (disableNiceOnlyForScale) {
bestTickCountForNumericalScale = null;
}

scale = createNumericalScale(options.scaleType, pixelSpan, scalarDomain, dataType, outerPadding, bestTickCountForNumericalScale, shouldClamp);
}
else if (isScalar && dataType.dateTime) {
// Use of a linear scale, instead of a D3.time.scale, is intentional since we want
Expand Down
2 changes: 2 additions & 0 deletions src/axis/axisInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ module powerbi.extensibility.utils.chart.axis {
shouldClamp?: boolean;
/** (optional) Disable "niceing" for numeric axis. It means that if max value is 172 the axis will show 172 but not rounded to upper value 180 */
disableNice?: boolean;
/** (optional) Disable "niceing" for numeric axis. Disabling nice will be applid only when creating scale obj (bestTickCount will be applied to 'ticks' method) */
disableNiceOnlyForScale?: boolean;
}

export enum AxisOrientation {
Expand Down

0 comments on commit 5342bb2

Please sign in to comment.