diff --git a/src/bridgepicassospec.js b/src/bridgepicassospec.js index 7203618..bc9b3d3 100644 --- a/src/bridgepicassospec.js +++ b/src/bridgepicassospec.js @@ -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, @@ -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: { @@ -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 } } } @@ -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 { diff --git a/src/controller.js b/src/controller.js index 1c030d6..19b7f38 100644 --- a/src/controller.js +++ b/src/controller.js @@ -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); @@ -42,14 +44,20 @@ 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') { @@ -57,7 +65,7 @@ export default ['$scope', '$element', function($scope, $element) { $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); diff --git a/src/converthypercube.js b/src/converthypercube.js index 51955f3..a4edb77 100644 --- a/src/converthypercube.js +++ b/src/converthypercube.js @@ -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, diff --git a/src/dataset.js b/src/dataset.js index 17473f0..8c14a24 100644 --- a/src/dataset.js +++ b/src/dataset.js @@ -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":