<commit_before>/*
 * Copyright (c) 2015 IBM Corporation and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.brunel.build.util;

import org.brunel.data.Data;
import org.brunel.data.Field;
import org.brunel.data.auto.Auto;
import org.brunel.data.util.Range;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * Stores util on an axis
 */
public class AxisDetails {

    /* Estimate the space needed to show all text categories */
    public static int maxCategoryWidth(Field... fields) {
        if (fields.length == 0) return 0;
        int maxCharCount = 1;
        for (Field f : fields) {
            if (f.preferCategorical()) {
                for (Object s : f.categories()) {
                    int length = f.format(s).length();
                    if (s instanceof Range) length++;                       // The ellipsis is often rather long
                    maxCharCount = Math.max(maxCharCount, length);
                }
            } else {
                // If we have numeric data, we use our scaling to guess the divisions needed
                Object[] sampleTicks = Auto.makeNumericScale(f, true, new double[]{0,0}, 0, 5, false).divisions;
                for (Object s : sampleTicks)
                    maxCharCount = Math.max(maxCharCount, f.format(s).length());
                // Always allow room for three characters. We need this because D3 often
                // adds fractions to what should be integer scales
                maxCharCount = Math.max(maxCharCount, 3);
            }
        }
        return (int) (maxCharCount * 6.5);      // Assume a font with about this character width
    }

    private final Field[] fields;                      // Fields used in this axis
    public final String title;                         // Title for the axis
    public final String scale;                         // Name for the scale to use for this axis
    private final boolean categorical;                 // True if the axis is categorical<commit_msg>Several small defects fixed and added new transform methods 'top', 'bottom', 'inner', 'outer'<commit_after>/*
 * Copyright (c) 2015 IBM Corporation and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.brunel.build.util;

import org.brunel.data.Data;
import org.brunel.data.Field;
import org.brunel.data.auto.Auto;
import org.brunel.data.util.Range;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * Calculates information on how to display axes
 */
public class AxisDetails {

    /* Estimate the space needed to show all text categories */
    public static int maxCategoryWidth(Field... fields) {
        if (fields.length == 0) return 0;
        int maxCharCount = 1;
        for (Field f : fields) {
            if (f.preferCategorical()) {
                for (Object s : f.categories()) {
                    int length = f.format(s).length();
                    if (s instanceof Range) length++;                       // The ellipsis is often rather long
                    maxCharCount = Math.max(maxCharCount, length);
                }
            } else {
                // If we have numeric data, we use our scaling to guess the divisions needed
                Object[] sampleTicks = Auto.makeNumericScale(f, true, new double[]{0,0}, 0, 5, false).divisions;
                for (Object s : sampleTicks)
                    maxCharCount = Math.max(maxCharCount, f.format(s).length());
                // Always allow room for three characters. We need this because D3 often
                // adds fractions to what should be integer scales
                maxCharCount = Math.max(maxCharCount, 3);
            }
        }
        return (int) (maxCharCount * 6.5);      // Assume a font with about this character width
    }

    private final Field[] fields;                      // Fields used in this axis
    public final String title;                         // Title for the axis
    public final String scale;                         // Name for the scale to use for this axis
    private final boolean categorical;                 // True if the axis is categorical
{'fraction_non_alphanumeric': 0.08594194649971543, 'fraction_numerical': 0.007209258205274142, 'mean_word_length': 2.0993533215755438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1084372', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1308, 'n_words': 547}