<commit_before>/*******************************************************************************
 * (C) Copyright 2015 <NAME>
 *
 * 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 smile.plot

import java.awt.{Dimension, Color}
import javax.swing.{JFrame, WindowConstants}
import smile.stat.distribution.{Distribution, DiscreteDistribution}
import smile.math.matrix.SparseMatrix

/** Data visualization operators.
  *
  * @author <NAME>
  */
trait Operators {

  private val windowCount = new java.util.concurrent.atomic.AtomicInteger

  /** Create a plot window. */
  def window(title: String = ""): JFrame = {
    val t = if (title.isEmpty) { "Smile Plot " + windowCount.addAndGet(1) } else title
    val frame = new JFrame(t)
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
    frame.setSize(new Dimension(1000, 1000))
    frame.setLocationRelativeTo(null)
    frame.setVisible(true)
    frame
  }

  /** Scatter plot.
    *
    * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points.
    * @param color the color used to draw points.
    * @param legend the legend used to draw points.
    *               - . : dot
    *               - + : +
    *               - - : -
    *               - | : |
    *               - * : star
    *               - x : x
    *               - o : circle
    *               - O : large circle
    *               - @ : solid circle
    *               - # : large solid circle
    *               - s : square
    *               - S : large square
    *               - q : solid square
    *               - Q : large solid square
    *               - others : dot
    *
    * @return a tuple of window frame and plot canvas which can be added other shapes.
    */
  def plot(data: Array[Array[Double]], legend: Char = '*', color: Color = Color.BLACK): (JFrame, PlotCanvas) = {
    val canvas = ScatterPlot.plot(data, legend, color)

    val win = window()
    win.add(canvas)

    (win, canvas)
  }

  /** Scatter plot.
    *
    * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points.
    * @param labels labels of points.
    *
    * @return a tuple of window frame and plot canvas which can be added other shapes.
    */
  def plot(data: Array[Array[Double]], labels: Array[String]): (JFrame, PlotCanvas) = {
    val canvas = ScatterPlot.plot(data, labels)

    val win = window()
    win.add(canvas)

    (win, canvas)
  }

  /** Scatter plot.
    *
    * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points.
    * @param label the class labels of data.
    * @param legend the legend for each class.
    * @param palette the colors for each class.
    *
    * @return a tuple of window frame and plot canvas which can be added other shapes.
    */
  def plot(data: Array[Array[Double]], label: Array[Int], legend: Array[Char], palette: Array[Color]): (JFrame, PlotCanvas) = {
    val canvas = ScatterPlot.plot(data, label, legend, palette)

    val win = window()
    win.add(canvas)

    (win, canvas)
  }<commit_msg>add plot with labels but only one legend<commit_after>/*******************************************************************************
 * (C) Copyright 2015 <NAME>
 *
 * 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 smile.plot

import java.awt.{Dimension, Color}
import javax.swing.{JFrame, WindowConstants}
import smile.stat.distribution.{Distribution, DiscreteDistribution}
import smile.math.matrix.SparseMatrix

/** Data visualization operators.
  *
  * @author <NAME>
  */
trait Operators {

  private val windowCount = new java.util.concurrent.atomic.AtomicInteger

  /** Create a plot window. */
  def window(title: String = ""): JFrame = {
    val t = if (title.isEmpty) { "Smile Plot " + windowCount.addAndGet(1) } else title
    val frame = new JFrame(t)
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
    frame.setSize(new Dimension(1000, 1000))
    frame.setLocationRelativeTo(null)
    frame.setVisible(true)
    frame
  }

  /** Scatter plot.
    *
    * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points.
    * @param color the color used to draw points.
    * @param legend the legend used to draw points.
    *               - . : dot
    *               - + : +
    *               - - : -
    *               - | : |
    *               - * : star
    *               - x : x
    *               - o : circle
    *               - O : large circle
    *               - @ : solid circle
    *               - # : large solid circle
    *               - s : square
    *               - S : large square
    *               - q : solid square
    *               - Q : large solid square
    *               - others : dot
    *
    * @return a tuple of window frame and plot canvas which can be added other shapes.
    */
  def plot(data: Array[Array[Double]], legend: Char = '*', color: Color = Color.BLACK): (JFrame, PlotCanvas) = {
    val canvas = ScatterPlot.plot(data, legend, color)

    val win = window()
    win.add(canvas)

    (win, canvas)
  }

  /** Scatter plot.
    *
    * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points.
    * @param labels labels of points.
    *
    * @return a tuple of window frame and plot canvas which can be added other shapes.
    */
  def plot(data: Array[Array[Double]], labels: Array[String]): (JFrame, PlotCanvas) = {
    val canvas = ScatterPlot.plot(data, labels)

    val win = window()
    win.add(canvas)

    (win, canvas)
  }

  /** Scatter plot.
    *
    * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points.
    * @param label the class labels of data.
    * @param legend the legend for all classes.
    * @param palette the colors for each class.
    *
    * @return a tuple of window frame and plot canvas which can be added other shapes.
    */
  def plot(data: Array[Array[Double]], label: Array[Int], legend: Char, palette: Array[Color]): (JFrame, PlotCanvas) = {
    val canvas = ScatterPlot.plot(data, label, legend, palette)

    val win = window()
    win.add(canvas)

    (win, canvas)
  }

  /** Scatter plot.
    *
    * @param data a n-by-2 or n-by-3 matrix that describes coordinates of points.
    * @param label the class labels of data.
    * @param legend the legend for each class.
    * @param palette the colors for each class.
    *
    * @return a tuple of window frame and plot canvas which can be added other shapes.
    */
  def plot(data: Array[Array[Double]], label: Array[Int], legend: Array[Char], palette: Array[Color]): (JFrame, PlotCanvas) = {
    val canvas = ScatterPlot.plot(data, label, legend, palette)

    val win = window()
    win.add(canvas)

    (win, canvas)
  }
{'fraction_non_alphanumeric': 0.14163198385672846, 'fraction_numerical': 0.006053726825576996, 'mean_word_length': 2.418103448275862, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2643487', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2185, 'n_words': 788}