<commit_before>(* <NAME>
 * 
 * Copyright (C) 2012 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library 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 file
 * license.txt for more details.
 *)
open Common2
open Common
(* floats are the norm in graphics *)
open Common2.ArithFloatInfix

open Figures

open Model3
module M = Model3
module Ctl = Controller3

module E = Database_code
module DM = Dependencies_matrix_code

module CairoH = Cairo_helpers3

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

(*****************************************************************************)
(* Helpers *)
(*****************************************************************************)

(* less: have a draw_labels.ml ? *) 

(* similar to highlight_code.ml *)
let color_of_node (_, kind) =
  match kind with
  | E.Function -> "gold"
  | E.Prototype -> "gold4"
  (* less: different color for interfaces and traits? *)
  | E.Class -> "coral"
  | E.Module -> "chocolate"
  | E.Package -> "chocolate"
  | E.Type -> "YellowGreen"
  | E.Constant -> "pink"
  | E.Global -> "cyan"
  | E.GlobalExtern -> "cyan4"
  | E.Macro -> "pink1"
  | E.Exception -> "orchid"
  | E.TopStmts -> "black"

  | E.Method -> "gold3"
  | E.Field -> "MediumPurple1"
  | E.ClassConstant -> "pink3"
  | E.Constructor -> "pink3"

  | E.Other _s -> "white"

  | E.Dir -> "SteelBlue2"
  | E.MultiDirs -> "SteelBlue3"
  | E.File -> "wheat"

(* we often keep fully qualified names in the graph_code to avoid
 * ambiguities between entities, but in code_graph we prefer to
 * display short names as the parents already contain the
 * information.
 *)
let txt_of_node (s, kind) = 
  match kind with
  | E.Dir | E.File | E.MultiDirs -> Common2.basename s
  | E.Package | E.Module
  | E.Class 
  | E.Field | E.Constructor | E.Method | E.ClassConstant
  | E.Function | E.Type | E.Constant | E.Global
  | E.Exception 
    -> Graph_code.shortname_of_node (s, kind)
  | _ -> s

(* todo: style/font_of_node_kind? so put in bold directories *)

let line_width_of_depth l d =
  let h = l.height_cell in
  match d with
  | 0 -> h / 8.
  | 1 -> h / 20.
  | 2 -> h / 40.
  | _ -> h / 80.

let line_color_of_depth d =
  match d with
  | 0 -> "wheat"
  | 1 -> "grey80"
  | 2 -> "grey65"
  | 3 -> "grey50"
  | _ -> "grey30"

(*****************************************************************************)
(* Matrix Coord -> XY Coord  *)
(*****************************************************************************)

let rect_of_cell i j l =
  (* the matrix is accessed as matrix.(row).(col), but here y corresponds
   * to the row, and x to the column, hence the association of j to x
   * and i to y.
   *)<commit_msg>* code_graph/view_matrix.ml:<commit_after>(* <NAME>
 * 
 * Copyright (C) 2012 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library 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 file
 * license.txt for more details.
 *)
open Common2
open Common
(* floats are the norm in graphics *)
open Common2.ArithFloatInfix

open Figures

open Model3
module M = Model3
module Ctl = Controller3

module E = Database_code
module DM = Dependencies_matrix_code

module CairoH = Cairo_helpers3

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

(*****************************************************************************)
(* Helpers *)
(*****************************************************************************)

(* less: have a draw_labels.ml ? *) 

(* similar to highlight_code.ml *)
let color_of_node (_, kind) =
  match kind with
  | E.Function -> "gold"
  | E.Prototype -> "gold4"
  (* less: different color for interfaces and traits? *)
  | E.Class -> "coral"
  | E.Module -> "chocolate"
  | E.Package -> "chocolate"
  | E.Type -> "YellowGreen"
  | E.Constant -> "pink"
  | E.Global -> "cyan"
  | E.GlobalExtern -> "cyan4"
  | E.Macro -> "pink1"
  | E.Exception -> "orchid"
  | E.TopStmts -> "black"

  | E.Method -> "gold3"
  | E.Field -> "MediumPurple1"
  | E.ClassConstant -> "pink3"
  | E.Constructor -> "pink3"

  | E.Other _s -> "white"

  | E.Dir -> "SteelBlue2"
  | E.MultiDirs -> "SteelBlue3"
  | E.File -> "wheat"

(* we often keep fully qualified names in the graph_code to avoid
 * ambiguities between entities, but in code_graph we prefer to
 * display short names as the parents already contain the
 * information.
 *)
let txt_of_node (s, kind) = 
  match kind with
  | E.Dir | E.File | E.MultiDirs -> 
      Common2.basename s
  | E.Package | E.Module
  | E.Class 
  | E.Field | E.Constructor | E.Method | E.ClassConstant
  | E.Function | E.Type | E.Constant | E.Global | E.Macro
  | E.Exception 
    -> Graph_code.shortname_of_node (s, kind)
  | _ -> s

(* todo: style/font_of_node_kind? so put in bold directories *)

let line_width_of_depth l d =
  let h = l.height_cell in
  match d with
  | 0 -> h / 8.
  | 1 -> h / 20.
  | 2 -> h / 40.
  | _ -> h / 80.

let line_color_of_depth d =
  match d with
  | 0 -> "wheat"
  | 1 -> "grey80"
  | 2 -> "grey65"
  | 3 -> "grey50"
  | _ -> "grey30"

(*****************************************************************************)
(* Matrix Coord -> XY Coord  *)
(*****************************************************************************)

let rect_of_cell i j l =
  (* the matrix is accessed as matrix.(row).(col), but here y corresponds
   * to the row, and x to the column, hence the association of j to x
   * and i to y.
   *)
{'fraction_non_alphanumeric': 0.25322428436615285, 'fraction_numerical': 0.01384083044982699, 'mean_word_length': 3.5421428571428573, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4593278', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1885, 'n_words': 636}