33// import { createChartJSConfig } from '../adapters/chartjs.js';
44import { getColor , categoricalColors } from '../utils/colors.js' ;
55import { formatValue } from '../utils/formatting.js' ;
6+ import { normalizeTitle } from '../utils/normalizeTitle.js' ;
67
78/**
89 * Creates a bar chart configuration
@@ -41,7 +42,7 @@ export function barChart(dataFrame, options = {}) {
4142 }
4243
4344 // Create Chart.js configuration
44- return {
45+ const config = {
4546 type : 'bar' ,
4647 data : {
4748 labels : data . map ( ( row ) => row [ xCol ] ) ,
@@ -66,12 +67,6 @@ export function barChart(dataFrame, options = {}) {
6667 options : {
6768 responsive : true ,
6869 maintainAspectRatio : false ,
69- plugins : {
70- title : {
71- display : ! ! options . chartOptions ?. title ,
72- text : options . chartOptions ?. title || 'Bar Chart' ,
73- } ,
74- } ,
7570 scales : {
7671 x : {
7772 title : {
@@ -92,6 +87,11 @@ export function barChart(dataFrame, options = {}) {
9287 ...options . chartOptions ,
9388 } ,
9489 } ;
90+
91+ // Normalize title configuration
92+ normalizeTitle ( config . options , options . chartOptions ?. title , 'Bar Chart' , false ) ;
93+
94+ return config ;
9595}
9696
9797/**
@@ -306,13 +306,18 @@ export function histogram(dataFrame, options) {
306306 // Convert DataFrame to array of objects for easier processing
307307 const data = dataFrame . toArray ( ) ;
308308
309- if ( ! options . column ) {
310- throw new Error ( 'Data column must be specified' ) ;
309+ const column = options . column || options . values ;
310+ if ( ! column ) {
311+ throw new Error ( 'Data column must be specified (column or values)' ) ;
311312 }
312313
313314 // Extract data
314315 const values = data
315- . map ( ( row ) => row [ options . column ] )
316+ . map ( ( row ) => {
317+ const val = row [ column ] ;
318+ // Преобразуем строки в числа, если возможно
319+ return typeof val === 'string' ? parseFloat ( val ) : val ;
320+ } )
316321 . filter ( ( val ) => typeof val === 'number' && ! isNaN ( val ) ) ;
317322
318323 if ( values . length === 0 ) {
@@ -351,13 +356,13 @@ export function histogram(dataFrame, options) {
351356 // Create chart configuration
352357 const color = options . chartOptions ?. color || getColor ( 0 ) ;
353358
354- return {
359+ const config = {
355360 type : 'bar' ,
356361 data : {
357362 labels : binLabels ,
358363 datasets : [
359364 {
360- label : options . chartOptions ?. label || options . column ,
365+ label : options . chartOptions ?. label || ` ${ column } Distribution` ,
361366 data : histogramData ,
362367 backgroundColor : color ,
363368 borderColor : color ,
@@ -370,8 +375,8 @@ export function histogram(dataFrame, options) {
370375 maintainAspectRatio : false ,
371376 plugins : {
372377 title : {
373- display : ! ! options . chartOptions ?. title ,
374- text : options . chartOptions ?. title || `Histogram of ${ options . column } ` ,
378+ display : true ,
379+ text : options . chartOptions ?. title || `Histogram of ${ column } ` ,
375380 } ,
376381 tooltip : {
377382 callbacks : {
@@ -388,7 +393,7 @@ export function histogram(dataFrame, options) {
388393 x : {
389394 title : {
390395 display : true ,
391- text : options . chartOptions ?. xLabel || options . column ,
396+ text : options . chartOptions ?. xLabel || column ,
392397 } ,
393398 } ,
394399 y : {
@@ -402,6 +407,11 @@ export function histogram(dataFrame, options) {
402407 ...options . chartOptions ,
403408 } ,
404409 } ;
410+
411+ // Normalize title configuration
412+ normalizeTitle ( config . options , options . chartOptions ?. title , `Histogram of ${ column } ` , true ) ;
413+
414+ return config ;
405415}
406416
407417/**
@@ -534,4 +544,6 @@ export function paretoChart(dataFrame, options) {
534544 ...options . chartOptions ,
535545 } ,
536546 } ;
547+
548+ return config ;
537549}
0 commit comments