<commit_before>{-# LANGUAGE TypeFamilies #-}

module Diagrams.Backend.Cairo.CmdLineSized where

import Diagrams.Prelude hiding ((<>), option, value)
import Diagrams.Backend.Cairo
import Diagrams.Backend.Cairo.CmdLine
import Diagrams.Backend.CmdLine
import Diagrams.BoundingBox

import Data.Maybe (fromMaybe)

import System.FilePath (splitExtension)

import Options.Applicative

data SizedOpts = SizedOpts
    { _scale   :: Maybe Double
    , _outp    :: String
    }

sizedOpts :: Parser SizedOpts
sizedOpts = SizedOpts
    <$> (optional . option)
            (long "scale" <> short 's'
             <> metavar "FACTOR"
             <> help "Desired scaling factor relative to default size")
    <*> strOption
            (long "output" <> short 'o'
             <> metavar "FILE"
             <> help "Desired output file")

instance Parseable SizedOpts where
    parser = sizedOpts

cmtopoint :: Double -> Double
cmtopoint = (* 28.3464567)

newtype M = M (Diagram Cairo R2)

instance Mainable M where
    type MainOpts M = SizedOpts

    mainRender opts (M x) = do
        let w = fst . unr2 . boxExtents . boundingBox $ x
            w' = (fromMaybe 1 (_scale opts)) * w
            (base, ext) = splitExtension (_outp opts)
            w'' = case ext of
                      ".png" -> round (40 * w')
                      _      -> round . cmtopoint $ w'
            dopts = DiagramOpts (Just w'') Nothing (_outp opts)
            lopts = DiagramLoopOpts False Nothing 0
        mainRender (dopts, lopts) x<commit_msg>ToResult for Mainable newtype wrapper<commit_after>{-# LANGUAGE TypeFamilies #-}

module Diagrams.Backend.Cairo.CmdLineSized where

import Diagrams.Prelude hiding ((<>), option, value)
import Diagrams.Backend.Cairo
import Diagrams.Backend.Cairo.CmdLine
import Diagrams.Backend.CmdLine
import Diagrams.BoundingBox

import Data.Maybe (fromMaybe)

import System.FilePath (splitExtension)

import Options.Applicative

data SizedOpts = SizedOpts
    { _scale   :: Maybe Double
    , _outp    :: String
    }

sizedOpts :: Parser SizedOpts
sizedOpts = SizedOpts
    <$> (optional . option)
            (long "scale" <> short 's'
             <> metavar "FACTOR"
             <> help "Desired scaling factor relative to default size")
    <*> strOption
            (long "output" <> short 'o'
             <> metavar "FILE"
             <> help "Desired output file")

instance Parseable SizedOpts where
    parser = sizedOpts

cmtopoint :: Double -> Double
cmtopoint = (* 28.3464567)

newtype M = M (Diagram Cairo R2)

instance Mainable M where
    type MainOpts M = SizedOpts

    mainRender opts (M x) = do
        let w = fst . unr2 . boxExtents . boundingBox $ x
            w' = (fromMaybe 1 (_scale opts)) * w
            (base, ext) = splitExtension (_outp opts)
            w'' = case ext of
                      ".png" -> round (40 * w')
                      _      -> round . cmtopoint $ w'
            dopts = DiagramOpts (Just w'') Nothing (_outp opts)
            lopts = DiagramLoopOpts False Nothing 0
        mainRender (dopts, lopts) x

instance ToResult M where
    type Args M = ()
    type ResultOf M = M

    toResult d _ = d
{'fraction_non_alphanumeric': 0.09696778269109287, 'fraction_numerical': 0.009475679090334808, 'mean_word_length': 2.2920997920997923, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '6804393', 'n_tokens_mistral': 1009, 'n_tokens_neox': 990, 'n_words': 301}