<commit_before>#include "QDataAnalysisView.h"

#include "QAction"
#include "QHeaderView"
#include <algorithm>
#include "xo/utility/color.h"
#include "xo/system/log.h"
#include "xo/xo_types.h"
#include "qtfx.h"
#include <array>
#include "xo/system/log.h"
#include "xo/container/sorted_vector.h"
#include "xo/numerical/constants.h"
#include "qt_convert.h"
#include "xo/numerical/compare.h"
#include "xo/numerical/math.h"
#include "xo/container/container_tools.h"
#include "qcustomplot/qcustomplot.h"

QDataAnalysisView::QDataAnalysisView( QDataAnalysisModel* m, QWidget* parent ) :
	QWidget( parent ),
	currentUpdateIdx( 0 ),
	model( m )
{
	filter = new QLineEdit( this );
	filter->setPlaceholderText( "Filter channels" );
	connect( filter, &QLineEdit::textChanged, this, &QDataAnalysisView::filterChanged );

	selectBox = new QCheckBox( this );
	connect( selectBox, &QCheckBox::stateChanged, this, &QDataAnalysisView::select );

	auto* header = new QHGroup( this, 0, 4 );
	*header << filter << selectBox;

	itemList = new QTreeWidget( this );
	itemList->setRootIsDecorated( false );
	itemList->setColumnCount( 2 );
	itemList->header()->close();
	itemList->resize( 100, 100 );
	QStringList headerLabels;
	headerLabels << "Variable" << "Value";
	itemList->setHeaderLabels( headerLabels );

	itemGroup = new QVGroup( this, 0, 4 );
	itemGroup->setContentsMargins( 0, 0, 0, 0 );
	*itemGroup << header << itemList;
	connect( itemList, &QTreeWidget::itemChanged, this, &QDataAnalysisView::itemChanged );

	splitter = new QSplitter( this );
	splitter->setContentsMargins( 0, 0, 0, 0 );
	splitter->setObjectName( "Analysis.Splitter" );
	splitter->addWidget( itemGroup );

	QVBoxLayout* layout = new QVBoxLayout( this );
	setLayout( layout );
	layout->setContentsMargins( 0, 0, 0, 0 );
	layout->setSpacing( 4 );
	layout->addWidget( splitter );

	for ( int i = 0; i < maxSeriesCount; ++i )
		freeColors.insert( i );

	customPlot = new QCustomPlot();
	customPlot->setInteraction( QCP::iRangeZoom, true );
	customPlot->setInteraction( QCP::iRangeDrag, true );
	customPlot->axisRect()->setRangeDrag( Qt::Horizontal );
	customPlot->axisRect()->setRangeZoom( Qt::Horizontal );
	customPlot->legend->setVisible( true );
	customPlot->legend->setFont( itemList->font() );
	customPlot->legend->setRowSpacing( -6 );
	customPlotLine = new QCPItemLine( customPlot );
	customPlotLine->setHead( QCPLineEnding( QCPLineEnding::esDiamond, 9, 9, true ) );
	customPlotLine->setTail( QCPLineEnding( QCPLineEnding::esDiamond, 9, 9, true ) );
	customPlot->addItem( customPlotLine );
	splitter->addWidget( customPlot );
	connect( customPlot, &QCustomPlot::mousePress, this, &QDataAnalysisView::mouseEvent );
	connect( customPlot, &QCustomPlot::mouseMove, this, &QDataAnalysisView::mouseEvent );
	connect( customPlot->xAxis, SIGNAL( rangeChanged( const QCPRange&, const QCPRange& ) ), this, SLOT( rangeChanged( const QCPRange&, const QCPRange& ) ) );

	splitter->setSizes( QList< int >{ 100, 300 } );
	reset();
}

int QDataAnalysisView::decimalPoints( double v )
{
	if ( v != 0 && xo::less_than_or_equal( abs( v ), 0.05 ) )
		return 6;
	else return 3;
}

void QDataAnalysisView::refresh( double time, bool refreshAll )
{
	if ( itemList->topLevelItemCount() != model->seriesCount() )
		return reset();

	if ( model->seriesCount() == 0 )
		return;

	// update state
	currentTime = time;

	// draw stuff if visible
	if ( isVisible() )
	{
		int itemCount = refreshAll ? int( model->seriesCount() ) : std::min<int>( smallRefreshItemCount, int( model->seriesCount() ) );
		itemList->setUpdatesEnabled( false );<commit_msg>U*: QDataAnalysisView now shows 6 decimals when value < 0.1 instead of <= 0.05<commit_after>#include "QDataAnalysisView.h"

#include "QAction"
#include "QHeaderView"
#include <algorithm>
#include "xo/utility/color.h"
#include "xo/system/log.h"
#include "xo/xo_types.h"
#include "qtfx.h"
#include <array>
#include "xo/system/log.h"
#include "xo/container/sorted_vector.h"
#include "xo/numerical/constants.h"
#include "qt_convert.h"
#include "xo/numerical/compare.h"
#include "xo/numerical/math.h"
#include "xo/container/container_tools.h"
#include "qcustomplot/qcustomplot.h"

QDataAnalysisView::QDataAnalysisView( QDataAnalysisModel* m, QWidget* parent ) :
	QWidget( parent ),
	currentUpdateIdx( 0 ),
	model( m )
{
	filter = new QLineEdit( this );
	filter->setPlaceholderText( "Filter channels" );
	connect( filter, &QLineEdit::textChanged, this, &QDataAnalysisView::filterChanged );

	selectBox = new QCheckBox( this );
	connect( selectBox, &QCheckBox::stateChanged, this, &QDataAnalysisView::select );

	auto* header = new QHGroup( this, 0, 4 );
	*header << filter << selectBox;

	itemList = new QTreeWidget( this );
	itemList->setRootIsDecorated( false );
	itemList->setColumnCount( 2 );
	itemList->header()->close();
	itemList->resize( 100, 100 );
	QStringList headerLabels;
	headerLabels << "Variable" << "Value";
	itemList->setHeaderLabels( headerLabels );

	itemGroup = new QVGroup( this, 0, 4 );
	itemGroup->setContentsMargins( 0, 0, 0, 0 );
	*itemGroup << header << itemList;
	connect( itemList, &QTreeWidget::itemChanged, this, &QDataAnalysisView::itemChanged );

	splitter = new QSplitter( this );
	splitter->setContentsMargins( 0, 0, 0, 0 );
	splitter->setObjectName( "Analysis.Splitter" );
	splitter->addWidget( itemGroup );

	QVBoxLayout* layout = new QVBoxLayout( this );
	setLayout( layout );
	layout->setContentsMargins( 0, 0, 0, 0 );
	layout->setSpacing( 4 );
	layout->addWidget( splitter );

	for ( int i = 0; i < maxSeriesCount; ++i )
		freeColors.insert( i );

	customPlot = new QCustomPlot();
	customPlot->setInteraction( QCP::iRangeZoom, true );
	customPlot->setInteraction( QCP::iRangeDrag, true );
	customPlot->axisRect()->setRangeDrag( Qt::Horizontal );
	customPlot->axisRect()->setRangeZoom( Qt::Horizontal );
	customPlot->legend->setVisible( true );
	customPlot->legend->setFont( itemList->font() );
	customPlot->legend->setRowSpacing( -6 );
	customPlotLine = new QCPItemLine( customPlot );
	customPlotLine->setHead( QCPLineEnding( QCPLineEnding::esDiamond, 9, 9, true ) );
	customPlotLine->setTail( QCPLineEnding( QCPLineEnding::esDiamond, 9, 9, true ) );
	customPlot->addItem( customPlotLine );
	splitter->addWidget( customPlot );
	connect( customPlot, &QCustomPlot::mousePress, this, &QDataAnalysisView::mouseEvent );
	connect( customPlot, &QCustomPlot::mouseMove, this, &QDataAnalysisView::mouseEvent );
	connect( customPlot->xAxis, SIGNAL( rangeChanged( const QCPRange&, const QCPRange& ) ), this, SLOT( rangeChanged( const QCPRange&, const QCPRange& ) ) );

	splitter->setSizes( QList< int >{ 100, 300 } );
	reset();
}

int QDataAnalysisView::decimalPoints( double v )
{
	if ( v != 0 && abs( v ) < 0.1 ) 
		return 6;
	else return 3;
}

void QDataAnalysisView::refresh( double time, bool refreshAll )
{
	if ( itemList->topLevelItemCount() != model->seriesCount() )
		return reset();

	if ( model->seriesCount() == 0 )
		return;

	// update state
	currentTime = time;

	// draw stuff if visible
	if ( isVisible() )
	{
		int itemCount = refreshAll ? int( model->seriesCount() ) : std::min<int>( smallRefreshItemCount, int( model->seriesCount() ) );
		itemList->setUpdatesEnabled( false );
{'fraction_non_alphanumeric': 0.1532370102806335, 'fraction_numerical': 0.012920255626562934, 'mean_word_length': 5.544545454545455, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4908110', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2463, 'n_words': 558}