<commit_before>/*  Copyright (C) 2011  <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package gui;


import java.awt.Color;
import java.awt.Graphics;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

import javax.swing.JPanel;

public class DataGraph extends JPanel {
	/**
	 * Shows data over time
	 */
	private static final long serialVersionUID = 1L;
	private int updateInterval = 1;		// in Seconds
	private int noOfColums = 20;
	private int columWidth = 2;
	private Timer updater = null;


	LinkedList<Integer> graphData = new LinkedList<Integer>();
	AtomicInteger currentCount = new AtomicInteger(0);

	public DataGraph(int hight, int width, int cNum, int cWidth, int interval){
		
		this.setSize(width , hight);
		this.noOfColums = cNum;
		this.columWidth = cWidth;
		this.updateInterval = interval;

		initGraphData();
	}
	
	private void initGraphData(){
		synchronized (graphData) {
			for (int i=0; i<noOfColums; i++){
				graphData.add(0);
			}
		}
	}

	public void add(int delta){
		currentCount.addAndGet(delta);
	}

	public void start(){
		if (updater == null){
			updater = new Timer("DataGraph updater");
			updater.scheduleAtFixedRate(new Updater(), updateInterval*1000, updateInterval*1000);
		}
	}

	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor(Color.BLUE);
		synchronized(graphData){
			

			int i = 0;
			for(int currval : graphData){
				g.fillRect(i*columWidth, this.getHeight()-currval, columWidth, currval);
				i++;
			}
		}
	}
	
	class Updater extends TimerTask{

		@Override
		public void run(){
			synchronized (graphData) {
				graphData.removeLast();
				graphData.addFirst(currentCount.getAndSet(0));
			}
			repaint();
		}
	}
}<commit_msg>added auto scale function to DataGraph. closes #3<commit_after>/*  Copyright (C) 2011  <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package gui;


import java.awt.Color;
import java.awt.Graphics;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

import javax.swing.JPanel;

public class DataGraph extends JPanel {
	/**
	 * Shows data over time
	 */
	private static final long serialVersionUID = 1L;
	private int updateInterval = 1;		// in Seconds
	private int noOfColums = 20;
	private int columWidth = 2;
	private Timer updater = null;
	private boolean autoscale;
	private double scaleFactor = 1;

	LinkedList<Integer> graphData = new LinkedList<Integer>();
	AtomicInteger currentCount = new AtomicInteger(0);

	public DataGraph(int hight, int width, int cNum, int cWidth, int interval,boolean autoscale){
		this.setSize(width , hight);
		this.noOfColums = cNum;
		this.columWidth = cWidth;
		this.updateInterval = interval;
		this.autoscale = autoscale;

		initGraphData();
	}
	
	public DataGraph(int hight, int width, int cNum, int cWidth, int interval){
		
		this.setSize(width , hight);
		this.noOfColums = cNum;
		this.columWidth = cWidth;
		this.updateInterval = interval;

		initGraphData();
	}
	
	private void initGraphData(){
		synchronized (graphData) {
			for (int i=0; i<noOfColums; i++){
				graphData.add(0);
			}
		}
	}

	public void add(int delta){
		currentCount.addAndGet(delta);
	}

	public void start(){
		if (updater == null){
			updater = new Timer("DataGraph updater");
			updater.scheduleAtFixedRate(new Updater(), updateInterval*1000, updateInterval*1000);
		}
	}

	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor(Color.BLUE);
		
		synchronized(graphData){
			int i = 0;
			for(int currval : graphData){
				currval=(int)(currval/scaleFactor);
				g.fillRect(i*columWidth, this.getHeight()-currval, columWidth, currval);
				i++;
			}
		}
	}
	
	private void calcScale(){
		int max = 0;
		
		for(int i : graphData){
			max = Math.max(max, i);
		}
		
		if(max > this.getHeight()){
			scaleFactor = max / this.getHeight();
		}else{
			scaleFactor = 1;
		}
	}
	
	class Updater extends TimerTask{

		@Override
		public void run(){
			synchronized (graphData) {
				graphData.removeLast();
				graphData.addFirst(currentCount.getAndSet(0));
			}
			calcScale();
			repaint();
		}
	}
}
{'fraction_non_alphanumeric': 0.10086033315028373, 'fraction_numerical': 0.009152480322167308, 'mean_word_length': 3.6941580756013748, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7520926', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1706, 'n_words': 545}