@massimo-cassandro/minimo 1.31.0 → 1.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/charts/src/bars.js +6 -4
- package/charts/src/goal.js +4 -3
- package/charts/src/hbars.js +6 -4
- package/charts/src/helpers/chart-utils.js +47 -0
- package/charts/src/lines.js +6 -3
- package/package.json +1 -1
package/charts/src/bars.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseStdAxisOpts } from './helpers/parse-std-axis-opts.js';
|
|
2
|
-
import { parseContainer } from './helpers/chart-utils.js';
|
|
2
|
+
import { parseContainer, waitForContainerSize } from './helpers/chart-utils.js';
|
|
3
3
|
import { cartesianAxis } from './helpers/cartesian-axis.js';
|
|
4
4
|
import { legenda } from './helpers/legenda.js';
|
|
5
5
|
|
|
@@ -185,13 +185,15 @@ export async function bars(params) {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
// container
|
|
188
|
-
|
|
188
|
+
let containerElement;
|
|
189
|
+
[containerElement, params.width, params.height] = parseContainer({ container: params.container, width: params.width, height: params.height });
|
|
189
190
|
|
|
190
|
-
|
|
191
|
-
if(!params.width || !params.height) {
|
|
191
|
+
if(!containerElement && (!params.width || !params.height)) {
|
|
192
192
|
throw `width e/o height mancanti: width: ${params.width}, height: ${params.height}`;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
({ width: params.width, height: params.height } = await waitForContainerSize(containerElement, { width: params.width, height: params.height }, params.debug));
|
|
196
|
+
|
|
195
197
|
// =>> legenda
|
|
196
198
|
// costruzione delle opzioni per la legenda
|
|
197
199
|
const legenda_params = {
|
package/charts/src/goal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// mostra un triangolo rettangolo disposto orizzontalmente che mostra
|
|
2
2
|
// la porzione di raggiungimento di un obiettivo
|
|
3
3
|
|
|
4
|
-
import { parseContainer, getElementFromContainer } from './helpers/chart-utils.js';
|
|
4
|
+
import { parseContainer, getElementFromContainer, waitForContainerSize } from './helpers/chart-utils.js';
|
|
5
5
|
import { createTextEl } from './helpers/create-text-element.js';
|
|
6
6
|
|
|
7
7
|
export async function goal({
|
|
@@ -158,11 +158,12 @@ export async function goal({
|
|
|
158
158
|
// calcolo width
|
|
159
159
|
[, width] = parseContainer({ container: container, width: width, height: height });
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
if(!width || !height) {
|
|
161
|
+
if(!container && (!width || !height)) {
|
|
163
162
|
throw `width e/o height mancanti: width: ${width}, height: ${height} (chartHeight: ${chartHeight})`;
|
|
164
163
|
}
|
|
165
164
|
|
|
165
|
+
({ width, height } = await waitForContainerSize(container, { width, height }, debug));
|
|
166
|
+
|
|
166
167
|
// larghezza iniziale grafico
|
|
167
168
|
// al netto del padding orizzontale pari a 1/2 cursore, in modo che sia visibile interamente
|
|
168
169
|
// quando posizionato agli estremi (anche in presenta di etichetta laterale, nel caso quest'ultima sia più alta del grafico)
|
package/charts/src/hbars.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// categorie sull'asse verticale (a sinistra), valori sull'asse orizzontale (in basso)
|
|
3
3
|
|
|
4
4
|
import { parseStdAxisOpts } from './helpers/parse-std-axis-opts.js';
|
|
5
|
-
import { parseContainer } from './helpers/chart-utils.js';
|
|
5
|
+
import { parseContainer, waitForContainerSize } from './helpers/chart-utils.js';
|
|
6
6
|
import { cartesianAxis } from './helpers/cartesian-axis.js';
|
|
7
7
|
import { legenda } from './helpers/legenda.js';
|
|
8
8
|
|
|
@@ -186,13 +186,15 @@ export async function hbars(params) {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
// container
|
|
189
|
-
|
|
189
|
+
let containerElement;
|
|
190
|
+
[containerElement, params.width, params.height] = parseContainer({ container: params.container, width: params.width, height: params.height });
|
|
190
191
|
|
|
191
|
-
|
|
192
|
-
if(!params.width || !params.height) {
|
|
192
|
+
if(!containerElement && (!params.width || !params.height)) {
|
|
193
193
|
throw `width e/o height mancanti: width: ${params.width}, height: ${params.height}`;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
({ width: params.width, height: params.height } = await waitForContainerSize(containerElement, { width: params.width, height: params.height }, params.debug));
|
|
197
|
+
|
|
196
198
|
// =>> legenda
|
|
197
199
|
// costruzione delle opzioni per la legenda
|
|
198
200
|
const legenda_params = {
|
|
@@ -155,3 +155,50 @@ export function parseContainer({ container = null, width = null, height = null }
|
|
|
155
155
|
|
|
156
156
|
return [containerElement, width, height];
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Attende che il container abbia dimensioni valide, utile quando è temporaneamente
|
|
161
|
+
* nascosto (es. `display: none` dentro un tab o un pannello non ancora attivo) al
|
|
162
|
+
* momento della creazione del grafico. Se `width`/`height` sono già entrambe valide
|
|
163
|
+
* risolve immediatamente, altrimenti osserva il container con un `ResizeObserver` ed
|
|
164
|
+
* attende che torni visibile. Non ha timeout: se il container non torna mai visibile
|
|
165
|
+
* la promise resta in sospeso.
|
|
166
|
+
* @param {Element|null} containerElement - L'elemento container (può essere null).
|
|
167
|
+
* @param {Object} size - Dimensioni già note.
|
|
168
|
+
* @param {number|null} size.width - Larghezza già nota (se valida, non si attende il container).
|
|
169
|
+
* @param {number|null} size.height - Altezza già nota (se valida, non si attende il container).
|
|
170
|
+
* @param {boolean} [debug=false] - Se true, logga in console quando l'attesa ha inizio. (default: false)
|
|
171
|
+
* @returns {Promise<{width: number, height: number}>} Le dimensioni effettive una volta disponibili.
|
|
172
|
+
*/
|
|
173
|
+
export function waitForContainerSize(containerElement, { width = null, height = null } = {}, debug = false) {
|
|
174
|
+
if (width && height) {
|
|
175
|
+
return Promise.resolve({ width, height });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!containerElement) {
|
|
179
|
+
return Promise.resolve({ width, height });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return new Promise(resolve => {
|
|
183
|
+
|
|
184
|
+
if (debug) {
|
|
185
|
+
// eslint-disable-next-line no-console
|
|
186
|
+
console.warn('MinimoCharts → in attesa che il container ottenga dimensioni valide (es. tab/pannello nascosto)', containerElement);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const observer = new ResizeObserver(entries => {
|
|
190
|
+
for (const entry of entries) {
|
|
191
|
+
const observedWidth = width || entry.contentRect.width;
|
|
192
|
+
const observedHeight = height || entry.contentRect.height;
|
|
193
|
+
|
|
194
|
+
if (observedWidth && observedHeight) {
|
|
195
|
+
observer.disconnect();
|
|
196
|
+
resolve({ width: observedWidth, height: observedHeight });
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
observer.observe(containerElement);
|
|
203
|
+
});
|
|
204
|
+
}
|
package/charts/src/lines.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseStdAxisOpts } from './helpers/parse-std-axis-opts.js';
|
|
2
|
-
import { parseContainer } from './helpers/chart-utils.js';
|
|
2
|
+
import { parseContainer, waitForContainerSize } from './helpers/chart-utils.js';
|
|
3
3
|
import { cartesianAxis } from './helpers/cartesian-axis.js';
|
|
4
4
|
import { legenda } from './helpers/legenda.js';
|
|
5
5
|
|
|
@@ -196,12 +196,15 @@ export async function lines(params) {
|
|
|
196
196
|
|
|
197
197
|
|
|
198
198
|
// container
|
|
199
|
-
|
|
199
|
+
let containerElement;
|
|
200
|
+
[containerElement, params.width, params.height] = parseContainer({ container: params.container, width: params.width, height: params.height });
|
|
200
201
|
|
|
201
|
-
if(!params.width || !params.height) {
|
|
202
|
+
if(!containerElement && (!params.width || !params.height)) {
|
|
202
203
|
throw `width e/o height mancanti: width: ${params.width}, height: ${params.height}`;
|
|
203
204
|
}
|
|
204
205
|
|
|
206
|
+
({ width: params.width, height: params.height } = await waitForContainerSize(containerElement, { width: params.width, height: params.height }, params.debug));
|
|
207
|
+
|
|
205
208
|
// =>> ricalcolo data_lines_attrs (utilizzato anche per le linee della legenda)
|
|
206
209
|
const default_line_width = params.data_lines_attrs['stroke-width']?? 1;
|
|
207
210
|
|