Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated PDF/PNG are Broken But DOT Format Works #355

Open
pacarvalho opened this issue Jun 9, 2020 · 2 comments
Open

Generated PDF/PNG are Broken But DOT Format Works #355

pacarvalho opened this issue Jun 9, 2020 · 2 comments

Comments

@pacarvalho
Copy link

Whenever I opt for a format that is not DOT such as PDF and PNG I end up with something that looks like the image below:

erd

I am running my code with the following Dockerfile:

FROM ruby:2.5-alpine AS installer

# Expose port
EXPOSE 3000

# set some rails env vars
ENV RAILS_ENV production
ENV PORT 3000

# set the app directory var
ENV APP_HOME /app
RUN mkdir -p ${APP_HOME}
WORKDIR ${APP_HOME}

# Install necessary packanges
RUN apk add --no-cache \
    build-base curl libressl-dev zlib-dev git \
    mariadb-dev tzdata imagemagick libxslt-dev \
    bash nodejs graphviz

# Copy gemfiles to be able to bundle install
COPY Gemfile* ./

Using the ERD configuration below:

attributes:
  - content
  - foreign_key
  - inheritance
disconnected: true
filename: erd
filetype: png
indirect: true
inheritance: false
markup: true
notation: simple
orientation: horizontal
polymorphism: false
sort: true
warn: true
title: sample title
exclude: null
only: null
only_recursion_depth: null
prepend_primary: false
cluster: false
splines: spline

And running the command bundle exec erd inside the running container. The DOT format works as expected. Any ideas what could be causing this?

@johnsaltarelli
Copy link

johnsaltarelli commented Mar 22, 2021

@pacarvalho I was experiencing the same issue. The core of the problem is that the font specified by the RailsERD gem is "Arial" and this font is not available within the ruby Alpine image being used in your Dockerfile. Additionally, you cannot override this font through the standard RailsERD config options.

There is a way to install Arial into the Ruby Alpine Docker image. However, I have not been able to get this to work using the msttcorefonts-installer Alpine package (suggested by numerous SO questions). Because of this, I opted to install an alternate font into Alpine and then configure RailsERD to use this font instead.

I solved this by monkey patching the RailsERD gem via an initializer. I override the method returning the Arial font names. I opted to installed the NOTO font package (I believe any font would work).

Dockerfile


# Install Graphviz & Fonts
RUN apk add graphviz
RUN apk add font-noto
RUN apk add fontconfig 
RUN fc-cache -f

./config/initalizers/rails_erd.rb


module RailsERD
    class Config
        def self.font_names_based_on_os
            { 
                normal: "Noto Sans",
                bold:   "Noto Sans Bold",
                italic: "Noto Sans Italic",
            }
        end
    end
end

I am running 6.1.3 and was able to successfully generate a PDF diagram using this method. @voormedia It would be great if we could pass in font names when generating diagrams or as a YAML configuration option in .erdconfig

@kerrizor
Copy link
Collaborator

It would be great if we could pass in font names when generating diagrams or as a YAML configuration option in .erdconfig

I don't see why we couldn't add that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants