ft-interactive/g-xaxisOrdinal

Name: g-xaxisOrdinal

Owner: FT Interactive News

Description: null

Created: 2017-06-15 11:21:37.0

Updated: 2017-06-15 11:30:54.0

Pushed: 2017-06-15 15:49:47.0

Homepage: null

Size: 49

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

xaxisOrdinal

Pre styled ordinal x-axis for use with the FT's g-chartframe architecture as part of the Visual Vocabulary. As the name suggests it creates an ordinal y-axis that can be appended to the .plot obejct in the g-chartframe hopefully eliminating the need to code another standard y-axis.

A centralised axis component for easy maintenance of styles accross the full Visual Vocabulary. The axis component also appends the correct script tags for use with the FT Pre-Flight script in Adobe Illustrator.

Will also work with other builds where the axis is called into an svg.

Prerequisites

The FT axis styles—add the folowwing link in your index file header

The d3 library is already installed in the build

Before starting

Note The .range() of the x-axis should be determind in part by the .labelWidth() of the y-axis, so it is advisable to ad your y-axis first. See the secton on positioning at yaxisLinear.

Installing
Manually install

Add the following line to the header of you index.html file.

ipt src="to come"> </script>
NPM install

Not yet deployed

Getting started

Note All examples shown are from the web frame style

Add the following code to your index.js to append a default x-axis to the .plot object (grey here but is not normally visible). Bye default there are no tick on an ordinal x-axis, these are set to zero.

t myXAxis = gAxis.xaxisOrdinal()
entFrame.plot()
.call(myXAxis);

alt tag

Set the .rangeRound() and the .offset() to the current frame width and height to make the axis correctly fit in the .plot object.

t myXAxis = gAxis.xaxisOrdinal()

xis
.rangeRound([0,currentFrame.dimension().width])
.offset(currentFrame.dimension().height);

entFrame.plot()
.call(myXAxis);

alt tag

Specify your the .domain in the same way that would in any other d3 axis

t myXAxis = gAxis.xaxisOrdinal()

xis
.rangeRound([0,currentFrame.dimension().width])
.offset(currentFrame.dimension().height);
.domain(myCatagories)

entFrame.plot()
.call(myXAxis);

alt tag

API reference

myAxis.domain([Array]) defines the axis domain in the same way as you would when creating a normal d3.scaleOrdinal(). If no .domain() is defined the default is [“Oranges”, “Lemons”, “Apples”, “Pears”]

myAxis.rangeRound([Array]) defines the axis bands in the same way as you would when creating a normal d3.scaleOrdinal(), would usually be set to the left margin and width of the .plot() object. If no .range() is defined the default is [40, 300].

myAxis.tickSize([Number]) Hardly ever used on an ordinal scale as usually no tck are required so set by default to zero.

myAxis.offset([Number]) The distance from the axis is positioned from the top of the .plot() container. Most ordinal scales on the x-axis are alligned to the bottom so this is usually set to the current frame height.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.