Git Product home page Git Product logo

deck's Introduction

deck: A Go package for slide decks

Deck Intro

Deck is a library for clients to make scalable presentations, using a standard markup language. Clients read deck files into the Deck structure, and traverse the structure for display, publication, etc. Clients may be interactive or produce standard formats such as SVG or PDF.

Also included is a REST API for listing content, uploading, stopping, starting and removing decks, generating tables, and playing video.

The deck on Deck

Elements

  • deck: enclosing element
  • canvas: describe the dimensions of the drawing canvas, one per deck
  • metadata elements: title, creator, publisher, subject, description, date
  • slide: within a deck, any number of slides, specify the slide duration, background and text colors.

within slides any number of:

  • text: plain, textblock, or code
  • list: plain, bullet, number, centered
  • image: JPEG or PNG images
  • line: straight line
  • rect: rectangle
  • ellipse: ellipse
  • curve: quadraticd Bezier curve
  • arc: elliptical arc
  • polygon: filled polygon
  • polyline: closed polyline

Markup

Here is a sample deck in XML:

<deck>
	<title>Sample Deck</title>
	<canvas width="1024" height="768"/>
	<slide bg="maroon" fg="white" duration="1s">
		<image xp="20" yp="30" width="256" height="256" name="picture.png"/>
		<text xp="20" yp="80" sp="3" link="http://example.com/">Deck uses these elements</text>
		<line xp1="20" yp1="75" xp2="90" yp2="75" sp="0.3" color="rgb(127,127,127)"/>
		<list xp="20" yp="70" sp="1.5">
			<li>canvas</li>
			<li>slide</li>
			<li>text</li>
			<li>list</li>
			<li>image</li>
			<li>line</li>
			<li>rect</li>
			<li>ellipse</li>
			<li>curve</li>
			<li>arc</li>
		</list>
		<line    xp1="20" yp1="10" xp2="30" yp2="10"/>
		<rect    xp="35"  yp="10" wp="4" hp="3" color="rgb(127,0,0)"/>
		<ellipse xp="45"  yp="10" wp="4" hp="3" color="rgb(0,127,0)"/>
		<curve   xp1="60" yp1="10" xp2="75" yp2="20" xp3="70" yp3="10" />       
		<arc     xp="55"  yp="10" wp="4" hp="3" a1="0" a2="180" color="rgb(0,0,127)"/>
		<polygon xc="75 75 80" yc="8 12 10" color="rgb(0,0,127)"/>
	</slide>
</deck>

The list and text elements have common attributes:

xp: horizontal percentage
yp: vertical percentage
sp: font size percentage
lp: line spacing percentage
type: "bullet", "number" (list), "block", "code" (text)
align: "left", "middle", "end"
color: SVG names ("maroon"), RGB "rgb(127,0,0)" or hex ("#rrggbb")
font: "sans", "serif", "mono"
opacity: opacity percentage
rotation: (0-360 degrees)
link: url

See the example directory for example decks.

Layout

All layout in done in terms of percentages, using a coordinate system with the origin (0%, 0%) at the lower left. The x (horizontal) direction increases to the right, with the y (vertical) direction increasing to upwards. For example, to place an element in the middle of the canvas, specify xp="50" yp="50". To place an element one-third from the top, and one-third from the bottom: xp="66.6" yp="33.3".

The size of text is also scaled to the width of the canvas. For example sp="3" is a typical size for slide headings. The dimensions of graphical elements (width, height, stroke width) are also scaled to the canvas width.

The content of the slides are automatically scaled based on the specified canvas size (sane defaults are should be set the clients, if dimensions not specified)

deck's percent grid

Deck's percentage based layout

Clients

example client

package main

import (
	"fmt"
	"log"

	"github.com/ajstarks/deck"
)

func dotext(x, y, size float64, text deck.Text) {
	fmt.Println("\tText:", x, y, size, text.Tdata)
}

func dolist(x, y, size float64, list deck.List) {
	fmt.Println("\tList:", x, y, size)
	for i, l := range list.Li {
		fmt.Println("\t\titem", i, l)
	}
}
func main() {
	presentation, err := deck.Read("deck.xml", 1024, 768) // open the deck
	if err != nil {
		log.Fatal(err)
	}
	for slidenumber, slide := range presentation.Slide { // for every slide...
		fmt.Println("Processing slide", slidenumber)
		for _, t := range slide.Text { // process the text elements
			x, y, size := deck.Dimen(presentation.Canvas, t.Xp, t.Yp, t.Sp)
			dotext(x, y, size, t)
		}
		for _, l := range slide.List { // process the list elements
			x, y, size := deck.Dimen(presentation.Canvas, l.Xp, l.Yp, l.Sp)
			dolist(x, y, size, l)
		}
	}
}

Currently there are four clients: pdfdeck, pngdeck, svgdeck and vgdeck.

For PDF decks, install pdfdeck:

go install github.com/ajstarks/deck/cmd/pdfdeck@latest

pdfdeck produces decks in PDF corresponding to the input file:

pdfdeck deck.xml

produces deck.pdf

For SVG decks, install svgdeck:

go install github.com/ajstarks/deck/cmd/svgdeck@latest

This command:

svgdeck deck.xml

produces one slide per SVG file, with each slide linked to the next.

For png decks, install pngdeck:

go install github.com/ajstarks/deck/cmd/pngdeck@latest

This command:

pngdeck deck.xml

makes one image per slide, numbered like deck-00001.png

vgdeck is a program for showing presentations on the Raspberry Pi, using the openvg library. To install:

go get github.com/ajstarks/deck/cmd/vgdeck

To run vgdeck, specify one or more files (marked up in deck XML) on the command line, and each will be shown in turn.

vgdeck sales.xml program.xml architecture.xml

Here are the vgdeck commands:

  • Next slide: +, Ctrl-N, [Return]
  • Previous slide, -, Ctrl-P, [Backspace]
  • First slide: ^, Ctrl-A
  • Last slide: $, Ctrl-E
  • Reload: r, Ctrl-R
  • X-Ray: x, Ctrl-X
  • Search: /, Ctrl-F
  • Save: s, Ctrl-S
  • Quit: q

All commands are a single keystroke, acted on immediately (only the search command waits until you hit [Return] after entering your search text) To cycle through the deck, repeatedly tap [Return] key

DECKFONTS

pdfdeck and pngdeck use the DECKFONTS environment variable as the location of font files. Choose a directory for your fonts, say $HOME/deckfonts, and set the DECKFONTS environment variable to this directory. Note that the repository at github.com/ajstarks/deckfonts contains a set of fonts (Times, Helvetica, Courier, Zapf Dingbats, Charter, Fira, Go, IBM Plex, and Noto) for you to use:

export DECKFONTS=$HOME/deckfonts
cd $HOME
git clone https://github.com/ajstarks/deckfonts
...
pdfdeck foo.xml # (use helvetica as the default)
pdfdeck -sans NotoSans-Regular -serif NotoSerif-Regular -mono NotoMono-Regular foo.xml # specify fonts

Alternatively you can manually install fonts from the gofpdf package: (these instructions assume you installed gofpdf in your GOPATH.)

mkdir $HOME/deckfonts # make the DECKFONTS directory
export DECKFONTS=$HOME/deckfonts # you should make this permanent in your shell startup
cp $GOPATH/src/github.com/jung-kurt/gofpdf/font/*.json $DECKFONTS

In general you can place TrueType files obtained from anywhere in your DECKFONTS directory and then you can use them with pdfdeck: For example, the gofpdf package has DejaVu fonts:

cp $GOPATH/src/github.com/jung-kurt/gofpdf/font/DejaVu*.ttf $DECKFONTS
pdfdeck -sans DejaVuSansCondensed foo.xml

Also, to use the Go fonts:

cd $HOME
mkdir gofonts
cd gofonts
git clone https://go.googlesource.com/image
cp image/font/gofont/ttfs/*.ttf $DECKFONTS
...
pdfdeck -sans Go-Regular -mono Go-Mono foo.xml

you can also manually set the font directory via command line option:

pdfdeck -fontdir $GOPATH/src/github.com/jung-kurt/gofpdf/font foo.xml

API

The command deckd is a server program that provides an API for slide decks. The API supports deck start, stop, listing, upload, and remove. Responses are encoded in JSON.

To install:

go get github.com/ajstarks/deck/cmd/deckd

Command line options control the working directory and address:port

-port Address:port (default: localhost:1958)

-dir [name] working directory (default: ".")

-maxupload [bytes] upload limit

GET / lists the API

GET /deck lists information on content, (filename, metadata (number of slides or image dimensions), modification time) in JSON

GET /deck?filter=[type] filter content list by type (std, deck, image, video)

POST /deck/file.xml?cmd=[duration] starts up a deck; the deck, duration, and process id are returned in JSON

POST /deck/file.xml?slide=[number] start at the specified slide

POST /deck?cmd=stop stops the running deck

DELETE /deck/file.xml removes a deck

PUT or POST to /upload uploads the contents of the Deck: header to the server

POST /table with the content of a tab-separated list, creates a slide with a formatted table, the Deck: header specifies the resulting deck file

POST /table/?textsize=[size] -- specify the text size of the generated table

POST /media plays the media file specified in the Media: header

The command deck is a command line interface to the deck Web API. Install it like this:

go get github.com/ajstarks/deck/cmd/deck

$ deck
Usage:
	List:    deck list [image|deck|video]
	Play:    deck play file [duration] [start-slide]
	Stop:    deck stop
	Upload:  deck upload files...
	Remove:  deck remove files...
	Video:   deck video file
	Table:   deck table file [textsize]

The shell script version of the command is in deck.sh. This version uses gttp (go get github.com/dgryski/gttp) to make HTTP requests.

deck's People

Contributors

ajstarks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deck's Issues

makefont installation?

Greeting! I am trying out this package and having trouble figuring out how to install makefont

I tried installing gofpdf but that doesn't seem to help.

go version go1.13.5 darwin/amd64

Thank you!

Deckd

Are you still using it ?

I was thinking of extending it so users can have a web gui for interacting with deck.

I noticed the html code is not used …

A simple htmx pattern ( you can google it ) to make a html driven gui to talk to der kd basically , so that users can interact with the system .

fonts in many locations

Hey

I am needing to allow someone to be able to tell Deck multiply places to look for fonts, as well as guess where they typically are.

https://github.com/flopp/go-findfont works for me, and finds all fonts on the users system by searching in the standard paths per OS. It can also search for a particular font.

I am not sure of the best approach in terms of usability. I think that Deck could look into the standard system folders using go-findfont, and then allow the DECK_FONTS env variable to be an array, so that the user can hint for other non system folders
what do you think ?

Go module definitions, more package APIs

Hi, I'm super excited to have found this excellent project!

A couple of quick things:

  1. It would be great if both the base deck and generate packages had go module definitions.
  2. All of the command line tools (especially decksh, dchart and the export tools e.g. svgdeck) are excellent. I just wish they each had exported golang package APIs (with module definitions) so that it was possible to build on top of all of this great work you've done in a platform independent way without relying on external command line dependencies.

Specifically, I'd love to be able to go from data to writing (or serving) an SVG slide/chart in a self-contained statically-linked go program, without resorting to piping together exec.Command("dchart",...) type code (with the attendant brittleness of depending on those execs being correctly installed, in the path, etc.)

Item 1 above is easy. Item 2 is obviously more work, but doing it would also make it much easier to maintain those command line tools over time by abstracting the core functionality of each away from the command line processing parts.

Anyway, I'm sure you know all of this, but I can imagine so many uses for all of the hard work you've done here, if only it was a little easier to access from golang itself!

Deckd usage

Hey

i could not work out how to configure / deckd

any chance you can add a readme for newbies ?

partial rendering to increase perf.

We can increase perf by using partial rendering

At the moment a change to decksh produces all of the xml and then the GIO Rendering system renders with that xml.

What we can look at is doing on partials updates. Because there is a one to one mapping of a decksh line to xml its possible and not boiling the ocean. The GIO rendering engine would then update the screen of just the changed xml.

decksh and gcdeck and variables editing.

Hey

I was wondering if we can extend gcdeck with more gui to help designers work on their designed without having to know too much Deck markdown or .dsh

This is just an idea to help make it easier for graphics people to not have to edit .dsh directly.
The biomimicry people using this are non technical and i am trying to make it easier for them to use the gcdeck tool.

Here is one of your examples: https://speakerdeck.com/ajstarks/decksh-a-little-language-for-decks?slide=5

Its has a variable called "gy=10" that affects the elements placement.

How is the Layout --

Left Pane: Preview area of Deck
Right Upper Pane: Elements List
Right Lower Pane. Properties List

How is the description of each and how they interact.

The Elements list shows a representation of the elements in the .dsh file. It could be a tree or a list.
The Properties list shows properties.
If no element is selected it shows the global variables of the .dsh
If an element is selected it shows the elements properties in the Property List.

When they click on an element in that list , highlight it in the Preview pane with some sort of border. We can do that by just injecting into the rendering stream using a "HighlightFocus" context variable, so that it looks for the element passing through the buffer and injects the deck markup to put a border around it.
At the same time, show the properties of that element on a Property List . Just like the "HighlightFocus" this is just a global context listening for a variable called "PropertyFocus", so it knows what Element to show the properties for.

When they change the global .dsh variable like "gy=10", , the file updates and so then does the Preview Deck, and and hence the properties affected by it in the Properties List.

The idea with the HighlightFocus and PropertyFocus variables is so that GCDeck can be told what to render in its Panes. These variables are set globally. Once it knows the element its looking for it can look it up in the Deck Markup and pass the string along the context allows the Properties List to update.

Hope you get the gist of my explanation above. I imagine you have also thought about how to make things easier for designers who find it hard to deal with markup / dsl files too, so if you have some thought on this let me know.

If you want to have a video chat to discuss

upgrade to go 1.8 and use of go.mod files

I am having working on extending the code.

One reason is the fact that we are not using the go work functionality for golang 1.8.
It allows module overrides that are private. It also ensures that the go.mod does not need any replace directives.
here is a simple example : https://github.com/xmlking/go-workspace


Also 2nd thing is that deck/generate has its own go.mod. Having go.mods inside go.mods recursively like this screws up the gopls for vscode for me. vscode Workspaces does not help either.

vdeck support

Just tried to run vgdeck on a Mac but it has c dependencies

vgdeck % go run .
# github.com/ajstarks/openvg
/Users/apple/go/pkg/mod/github.com/ajstarks/[email protected]/openvg.go:7:10: fatal error: 'VG/openvg.h' file not found
#include "VG/openvg.h"
         ^~~~~~~~~~~~~
1 error generated.

Do we even want to both because gcdeck is its replacement in a way ?

Interaction

This issue follows on from the Maps Issue .

One aspect that I keep needing with Science decks is the ability for users to add interactions to a deck slide.

Typically this can be two types of higher level interaction.

1 Routing , where a slide has a wider ( like a button ) that navigates the user from the current slide to another slide in the same deck.

2 layers, where a slide has the ability to replace part of he slide with something else.

The overriding use case driving all this is that they want to be able to make decks where the end use is able to interact with the the finished deck in very simple ways so that the users can explore the visualisations.

So maybe we could add this concept to the Decksh ? Is it something others are I retested in ?

I have sone more in depth notes on my laptop about more precise aspects of this but I am away from it for another week.

pdfdeck: open times.json: no such file or directory

pdfdeck gives me an error. It seems that some font files missing, do I have to specify the fonts somewhere? Anyway .. sometimes helvetica is missing and sometimes courier ..

maigl@dreggnbox:~/devel/deck_test$ pdfdeck countdown.xml 
pdfdeck: open courier.json: no such file or directory
maigl@dreggnbox:~/devel/deck_test$ pdfdeck countdown.xml 
pdfdeck: open helvetica.json: no such file or directory

I pulled from master (commit e8d9980) and used your countdown example .. and with svgdeck I get the expected results ..

Eventhough pdfdeck fails, there is an empty result-file 'countdown.pdf' in my folder.

Runaway rendering in gcdeck

gcdeck test.xml # from the the decksh repo

after several pages. the rendering loops through the file at rapid speed with no user intervention.

i18n aspects

Lots a graphics people have a situation where they need to produce graphics with the text in different languages.

.dsp already supports text substitution, so the fundamentals are there.

I just wanted to write down my own thoughts on this:

  • I like to have a data file where i have the translation field, and the translation-override field. The translation is the machine translation, and the translation-override is the human checker overriding it. I actually model this in google sheets and set it up to do the translation, and then wrote a golang package to extract it as a csv from the google sheet. Its one way to approach this area.

  • https://github.com/cameronkinsella/manga-translator is pretty cool GIO proejct that does OCR on images, extracts the text, and translates it, and puts the text back into the image. I mention this because it's got some good code to help with talking to the google trans api and also setting up configs. I also reference this because its another way to do it as opposed to the google sheet approach i have used. I can dig out this code if needed ...

  • caching can really be useful here, because you get a translation memory, and so dont have to hit a Google sheet or the google trans api if you already have a translation for that "key" in your files.

  • i expect we might need a first class element in the .dsp DSL for trans, but not sure. Pluralisation i think will be the thing that forces the need for a first class element, as well the Data Format, etc.

  • Date Format, Currency Format are very often needed. There are a few light and simple golang packages out there that do this. It should be presumed that Time is always UTC when coming from any DB, and then converted to the User timezone format. Because Deck needs to output PDF, etc in many languages the "user timezone, locale" would be a config, not a runtime lookup. However for presentations with deckd, It would need to check the user runtime to determine the "user timezone, locale"

  • GIO is getting there with RTL and LTR support. So eventually that would also be an aspect.

Any plan to add a table support

Hello, I was experimenting this library, found useful, are you planning for any table support like list you provided, and whats the future roadmap on this library ? Is there any active development happening?

speed up xml

https://github.com/clbanning/mxj

this will also make it faster and remove any reflection.
it will also allow use to run the deck libs in a browser using wasm.

The current Generate command can then use this and all he golang structs will not have tags, ut instead use this lib to bind the xml to the structs and visa versa.

Let me know if you interested.

Maps

Been talking to the science users and one thing that is coming up is the ability to have basic poly line style maps at the global , country , city level .

The use case is that often they have csv data that relates to locations. For example Covid by geography.

Often they combine it with dcharts so that the end user can see the data via a bar chart ( or other ) and a map.

In the map there are a few ways they display the data representation:

Country poly line is filled with a colour that relates back to a legend.

Circle ( filled in ) in the centre of the country or state or city. The size ( and perhaps colour ) of the circle represents the quantity that relates back to a legend ( if also using colour ).

I was doing a little bit of research and it seems geojson is popular as a data format to describe maps so that might be a good data source.

I don’t know if this should be part of dcharts but I suspect it’s the right area.

Decksh could then compose a map chart and other charts ? I am presuming that decksh can make calls to the dcharts package to output deck markup, but have not checked.

There is another related requirement with this that I might as well bring up here. They are finding that sonetines they need to have the chart zoomable.

For example in a map you might want to zoom and pan. Or to click on a country and to then see the map chart for that country should the map chart of the states of that country. Then in a state the cities etc. Presume that the user can go back out also.

in addition when composing using decksh they would want to be able to layout slides with each country map on each slide. So to me the zoom feature is perhaps u der the hood in actual fact just navigating to different slides !! It would mean adding the ability to navigate decks via sone sort of data driven meta.

In a heat map chart ( do we even have these ) they want to click an area and god to the next level , and also go back out.

I know there are many different things to what I described above. I wanted to show a reasonable expansive use case to show all the aspects so that the technical aspects can be dissected out of the epic use case.

there may be a need in general for routing for example not just for maps but in general.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.