$ cnpm install @thematic/core
This package contains the core theme parsing and transformation.
To load the default theme, you can call load
without any parameters:
import { load } from '@thematic/core'
const theme = load()
The Theme interface includes configuration objects for a wide variety of mark types and scales. Most of these follow a few basic format principles:
For example, to retrieve the configuration for rectangles on a chart (such as for a bar chart), it might look something like:
const bar = theme.rect()
const fill = bar.fill().hex() // get the hex code version of the fill color
The mark functions accept parameters ('MarkConfig') that allow for scale mappings, selection states, etc. The individual attr functions always accept a datum that can be used if scale mappings are provided.
For example:
import { scaleLinear } from 'd3-scale'
// get the selected bar config
const normalBar = theme.rect()
const selectedBar = theme.rect({ selectionState: SelectionState.Selected })
const normalFill = normalBar.fill().hex() // default color
const selectedFill = selectedBar.fill().hex() // darker color
// bind a scale
const scale = scaleLinear().range([1, 10])
const scaledCircle = theme.circle({
scaleBindings: {
radius: {
scale,
}
}
})
const r0 = scaledCircle.radius(0) // 1
const r1 = scaledCircle.radius(1) // 10
Copyright 2014 - 2017 © taobao.org |