Skip to content

Commit

Permalink
Merge pull request #56 from qlik-oss/hva/QB-21289-3
Browse files Browse the repository at this point in the history
fix: formatting issues for axis, bar and tooltip
  • Loading branch information
Donya-qlik authored Nov 16, 2023
2 parents aa664fa + 3339243 commit 4319cf1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
22 changes: 20 additions & 2 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,21 @@ 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 labelFn = (cell) => {
const field = 'qMeasureInfo/0';
return setFormatCell(cell, field);
};

return {
interactions: (!isInteractable ? [] : interactionsSetup()),
scales: {
Expand Down Expand Up @@ -171,12 +186,15 @@ export default function (element, layout, direction, isInteractable) {
props: {
start: {
field: 'qMeasureInfo/0',
label: labelFn
},
end: {
field: 'qMeasureInfo/1',
label: labelFn
},
var: {
field: 'qMeasureInfo/2',
label: labelFn
}
}
}
Expand Down Expand Up @@ -324,7 +342,7 @@ export default function (element, layout, direction, isInteractable) {
label({
data
}) {
return data ? data.end.label : '';
return data ? data.var.label : '';
},
placements: [ // label placements in prio order. Label will be placed in the first place it fits into
{
Expand Down
20 changes: 14 additions & 6 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +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 @@ -42,22 +44,28 @@ 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
2 changes: 1 addition & 1 deletion src/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function initVarianceCube(component, layout) {

const measures = hyperCubeDef.qMeasures;
let expression;
if (JSON.stringify(measures[0].qDef.qNumFormat) === JSON.stringify(measures[1].qDef.qNumFormat) && measures[0].qDef.qNumFormat) {
if (measures[0].qDef.qNumFormat) {
let formatter;
switch (measures[0].qDef.qNumFormat.qType) {
case "D":
Expand Down

0 comments on commit 4319cf1

Please sign in to comment.