Skip to content

Commit

Permalink
Merge pull request #47 from qlik-oss/hva/QB-21289
Browse files Browse the repository at this point in the history
fix: axis tick value formatting
  • Loading branch information
Donya-qlik authored Oct 26, 2023
2 parents 7a46276 + d33d726 commit bc46cff
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
33 changes: 28 additions & 5 deletions src/bridgepicassospec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ThemeManager from './theme';
import { interactionsSetup } from './interactions.js';

export default function (element, layout, direction, isInteractable) {
export default function (element, layout, direction, isInteractable, ds) {
let labels = {
startvalue: layout.labelsshow ? "Start Value" : layout.startName,
endvalue: layout.labelsshow ? "End Value" : layout.endName,
Expand Down Expand Up @@ -33,6 +33,26 @@ export default function (element, layout, direction, isInteractable) {
dockRight = 'left';
}

const shouldUseFormat = (measureInfo) => !measureInfo.isCustomFormatted && (measureInfo.qIsAutoFormat || measureInfo.qNumFormat.qType === 'U');

const setFormatCell = (cell, field) => {
const measureInfo = ds.field(field).raw();
const formatter = ds.field(field).formatter();
const useFormatter = shouldUseFormat(measureInfo);
const formatCell = (cell) => (cell.qNum === 'NaN' ? '-' : formatter(cell.qNum));
return (useFormatter ? formatCell(cell) : cell.qText);
};

const startLabelFn = (cell) => {
const field = 'qMeasureInfo/1';
return setFormatCell(cell, field);
};

const endLabelFn = (cell) => {
const field = 'qMeasureInfo/0';
return setFormatCell(cell, field);
};

return {
interactions: (!isInteractable ? [] : interactionsSetup()),
scales: {
Expand Down Expand Up @@ -165,18 +185,21 @@ export default function (element, layout, direction, isInteractable) {
layout: {
displayOrder: 1
},
data: {
data: {
extract: {
field: 'qDimensionInfo/0',
props: {
start: {
field: 'qMeasureInfo/0'
field: 'qMeasureInfo/0',
label: startLabelFn
},
end: {
field: 'qMeasureInfo/1'
field: 'qMeasureInfo/1',
label: endLabelFn
},
var: {
field: 'qMeasureInfo/2'
field: 'qMeasureInfo/2',
label: endLabelFn
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default ['$scope', '$element', function($scope, $element) {
$scope.updated = false;

$scope.app = qlik.currApp(this);

const localeInfo = $scope.app.model.layout.qLocaleInfo;

picasso.use(pq);
picasso.use(picassoHammer);

Expand All @@ -43,22 +44,29 @@ export default ['$scope', '$element', function($scope, $element) {
$scope.chartBrush
= enableSelectionOnFirstDimension($scope, $scope.chart, 'highlight', $scope.layout);
$scope.updatedData = async function(layout, isEditMode, dataUpdate) {
const data = {
type: 'q',
key: 'qHyperCube',
config: {
localeInfo,
},
data: await initVarianceCube($scope, layout)
};
const ds = picasso.data('q')(data);

let up = {};

if (dataUpdate) {
up.data = [{
type: 'q',
key: 'qHyperCube',
data: await initVarianceCube($scope, layout)
}];
up.data = [data];
}

if (isEditMode || typeof $scope.chart.settings === 'undefined') {
up.settings = bridgepicassospec(
$scope.chart.element,
layout,
$scope.$parent.options.direction,
!isEditMode && !$scope.backendApi.isSnapshot && !layout.qHyperCube.qDimensionInfo[0].qLocked);
!isEditMode && !$scope.backendApi.isSnapshot && !layout.qHyperCube.qDimensionInfo[0].qLocked,
ds);
}

$scope.chart.update(up);
Expand Down
1 change: 1 addition & 0 deletions src/converthypercube.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class ConvertHypercube {
qAttrExprInfo: mesInfo.qAttrExprInfo.map(i => i),
qCardinal: mesInfo.qCardinal,
qFallbackTitle: mesInfo.qFallbackTitle,
qIsAutoFormat: mesInfo.qIsAutoFormat,
qMax: max, //mesInfo.qMax,
qMin: min, //mesInfo.qMin,
qSortIndicator: mesInfo.qSortIndicator,
Expand Down

0 comments on commit bc46cff

Please sign in to comment.