@@ -4,7 +4,8 @@ import { useConfig } from "../useConfig";
44import {
55 adaptColorToBackground ,
66 applyDataLabel ,
7- calculateNiceScale ,
7+ calculateNiceScale ,
8+ calculateNiceScaleWithExactExtremes ,
89 convertColorToHex ,
910 convertCustomPalette ,
1011 createCsvContent ,
@@ -14,6 +15,7 @@ import {
1415 error ,
1516 functionReturnsString ,
1617 getMissingDatasetAttributes ,
18+ hasDeepProperty ,
1719 isFunction ,
1820 lightenHexColor ,
1921 objectIsEmpty ,
@@ -112,17 +114,36 @@ const FINAL_CONFIG = computed(() => {
112114 userConfig: props .config ,
113115 defaultConfig: DEFAULT_CONFIG ,
114116 });
117+ let finalConfig = {};
115118 if (mergedConfig .theme ) {
116- return {
119+ finalConfig = {
117120 ... useNestedProp ({
118121 userConfig: themes .vue_ui_stackbar [mergedConfig .theme ] || props .config ,
119122 defaultConfig: mergedConfig
120123 }),
121124 customPalette: themePalettes[mergedConfig .theme ] || palette
122125 }
123126 } else {
124- return mergedConfig;
127+ finalConfig = mergedConfig;
128+ }
129+
130+ // ------------------------------ OVERRIDES -----------------------------------
131+
132+ if (props .config && hasDeepProperty (props .config , ' style.chart.grid.scale.scaleMin' )) {
133+ finalConfig .style .chart .grid .scale .scaleMin = props .config .style .chart .grid .scale .scaleMin ;
134+ } else {
135+ finalConfig .style .chart .grid .scale .scaleMin = null ;
125136 }
137+
138+ if (props .config && hasDeepProperty (props .config , ' style.chart.grid.scale.scaleMax' )) {
139+ finalConfig .style .chart .grid .scale .scaleMax = props .config .style .chart .grid .scale .scaleMax ;
140+ } else {
141+ finalConfig .style .chart .grid .scale .scaleMax = null ;
142+ }
143+
144+ // ----------------------------------------------------------------------------
145+
146+ return finalConfig;
126147});
127148
128149const mutableConfig = ref ({
@@ -281,10 +302,11 @@ const datasetSignedTotals = computed(() => {
281302});
282303
283304const yLabels = computed (() => {
284- const MAX = Math .max (... datasetSignedTotals .value .positive );
305+ const MAX = ( FINAL_CONFIG . value . style . chart . grid . scale . scaleMax !== null && ! FINAL_CONFIG . value . style . chart . bars . distributed ) ? FINAL_CONFIG . value . style . chart . grid . scale . scaleMax : Math .max (... datasetSignedTotals .value .positive );
285306 const workingMin = Math .min (... datasetSignedTotals .value .negative );
286- const MIN = [- Infinity , Infinity , NaN , undefined , null ].includes (workingMin) ? 0 : workingMin;
287- const scale = calculateNiceScale ((MIN > 0 ? 0 : MIN ), MAX < 0 ? 0 : MAX , FINAL_CONFIG .value .style .chart .grid .scale .ticks );
307+ const MIN = (FINAL_CONFIG .value .style .chart .grid .scale .scaleMin !== null && ! FINAL_CONFIG .value .style .chart .bars .distributed ) ? FINAL_CONFIG .value .style .chart .grid .scale .scaleMin : [- Infinity , Infinity , NaN , undefined , null ].includes (workingMin) ? 0 : workingMin;
308+
309+ const scale = (! FINAL_CONFIG .value .style .chart .bars .distributed && (FINAL_CONFIG .value .style .chart .grid .scale .scaleMax !== null || FINAL_CONFIG .value .style .chart .grid .scale .scaleMin !== null )) ? calculateNiceScaleWithExactExtremes ((MIN > 0 ? 0 : MIN ), MAX < 0 ? 0 : MAX , FINAL_CONFIG .value .style .chart .grid .scale .ticks ) : calculateNiceScale ((MIN > 0 ? 0 : MIN ), MAX < 0 ? 0 : MAX , FINAL_CONFIG .value .style .chart .grid .scale .ticks );
288310 return scale .ticks .map (t => {
289311 return {
290312 zero: drawingArea .value .bottom - (drawingArea .value .height * ((Math .abs (scale .min )) / (scale .max + Math .abs (scale .min )))),
@@ -315,7 +337,7 @@ const formattedDataset = computed(() => {
315337 const workingMin = Math .min (... datasetSignedTotals .value .negative );
316338 const premin = [- Infinity , Infinity , NaN , undefined , null ].includes (workingMin) ? 0 : workingMin;
317339
318- const scale = calculateNiceScale ((premin > 0 ? 0 : premin), premax < 0 ? 0 : premax, FINAL_CONFIG .value .style .chart .grid .scale .ticks );
340+ const scale = ( ! FINAL_CONFIG . value . style . chart . bars . distributed && ( FINAL_CONFIG . value . style . chart . grid . scale . scaleMax !== null || FINAL_CONFIG . value . style . chart . grid . scale . scaleMin !== null )) ? calculateNiceScaleWithExactExtremes ( FINAL_CONFIG . value . style . chart . grid . scale . scaleMin !== null ? FINAL_CONFIG . value . style . chart . grid . scale . scaleMin : (premin > 0 ? 0 : premin), FINAL_CONFIG . value . style . chart . grid . scale . scaleMax !== null ? FINAL_CONFIG . value . style . chart . grid . scale . scaleMax : premax < 0 ? 0 : premax, FINAL_CONFIG . value . style . chart . grid . scale . ticks ) : calculateNiceScale (FINAL_CONFIG . value . style . chart . grid . scale . scaleMin !== null ? FINAL_CONFIG . value . style . chart . grid . scale . scaleMin : (premin > 0 ? 0 : premin), FINAL_CONFIG . value . style . chart . grid . scale . scaleMax !== null ? FINAL_CONFIG . value . style . chart . grid . scale . scaleMax : premax < 0 ? 0 : premax, FINAL_CONFIG .value .style .chart .grid .scale .ticks );
319341 const { min: MIN , max: MAX } = scale;
320342
321343 const maxTotal = (MAX + (MIN >= 0 ? 0 : Math .abs (MIN ))) || 1
0 commit comments