Closed sc0ttj closed 2 years ago
A chart/graph making add-on.
Only 3.5kb minified & gzipped so far, also works standalone (Component not required).
Component
d3
TO DO
.dimensions()
{ x, y, h, w, margin, xRange, yRange, xScale, yScale, xDistance, yDistance }
xAxis()
yPos
yAxis()
xPos
.xAxis()
.yAxis()
tickLabels
start
end
rotation
circle()
.pie({ px, py, radius, slice, fill })
px
py
radius
slice
fill
pie()
innerRadius
stacked
bar()
.line({...})
setStyle()
Ctx
style
data.candle({ open, close, high, low, green, red, padding, style })
.colourScale('name', [min,max], scale, [startColour, endColour])
.colourScale('temperature', [0,100], 5, ['#eee','#c00'])
ctx.colours['temperature'](96) // returns '#c00'
sinebow
rainbow
turbo
Addons:
tweenState
springTo
Geo
useAudio
ctx.beginPath() .useData({ 'USA': [{}, // pad with an empty year.. just to create more space on chart { medals: 25 }, { medals: 15 }, { medals: 21 }, { medals: 42 }, { medals: 47 }, { medals: 21 }, { medals: 24 }, ], 'China': [{}, { medals: 10 }, { medals: 10 }, { medals: 25 }, { medals: 40 }, { medals: 32 }, { medals: 12 }, { medals: 21 }, ] }) // top, bottom, left, right .margin(50,60,120,40) .xAxis({ range: [1999,2006], scale: 1, // optional settings label: "Years", labelBelow: true, yPos: 0, tickLength: -3, tickCentered: true, tickLabelCentered: true, tickLabels: [], // can be func which receives each label, like `label => {...}` }) .yAxis({ range: [0,16], scale: 1, // optional settings label: "Gold medals", labelLeft: true, xPos: 0, tickLength: -3, tickCentered: false, tickLabels: [], // can be func which receives each label, like `label => {...}` }) .drawEach((country, key, i) => { // Now we can work with some "decorated" chart data, ${country}. // Use your top-level data here - to draw a legend, for example.. country.forEach(data => { // Note, ${data} has .bar(), .circle(), and .line() methods added, // which try to draw "ready-made" shapes, in the right place. // You should only define the attrs you want "joined" to your // data - and don't override any others. data.bar({ height: data.medals, stacked: false, padding: 24, style:{ fill: colors[i] }, }); data.circle({ cy: data.medals, radius: data.medals*2, start: 0, end: 360, rotate: 0, style: { fill: colors[i+2], lineWidth: 5, stroke: 'red' }, }); data.pie({ slice: data.medals, style: { fill: colors[n] }, }); data.arc({ slice: data.medals, radius: 80, innerRadius: 40, style: { fill: colors[n] }, }); data.line({ py: data.medals, stacked: true, style: { fill: colors[i], stroke: colors[i], lineWidth: 0, }, }); });
Outputs:
..easily flip swap the axes by changing a few lines of code:
..same chart, different settings:
Newer demo:
Charts
A chart/graph making add-on.
Only 3.5kb minified & gzipped so far, also works standalone (
Component
not required).d3
but simpler to useTO DO
.dimensions()
method:{ x, y, h, w, margin, xRange, yRange, xScale, yScale, xDistance, yDistance }
xAxis()
takes ayPos
param - a % value of the chart heightyAxis()
takes axPos
param - a % value of the chart width.xAxis()
and.yAxis()
:tickLabels
array, as the last paramtickLabels
to "hide" specific tick labelsstart
,end
androtation
(in degrees) tocircle()
.pie({ px, py, radius, slice, fill })
px
/py
to place itradius
is the width/size of itslice
is the slice width, in degrees,fill
to colour it inpie()
now takes an optionalinnerRadius
param, to create holes in the middle (doughnut charts)stacked
attr tobar()
fill
andstacked
attributes to.line({...})
methodfill
produces a "layered area chart",fill
andstacked
produces a "stacked area chart"setStyle()
fromCtx
)style
param to the drawing methodsdata.candle({ open, close, high, low, green, red, padding, style })
.colourScale('name', [min,max], scale, [startColour, endColour])
.colourScale('temperature', [0,100], 5, ['#eee','#c00'])
// creates 20 coloursctx.colours['temperature'](96) // returns '#c00'
sinebow
,rainbow
andturbo
from d3-scale-chromaticAddons:
tweenState
orspringTo
add-ons :)Ctx
add-on has a zoomable, pannable camera, and more shapes, plus save to video, image, etcGeo
add-onuseAudio
add-on, which can do audio visualisation stuffUsage:
Outputs:
..easily flip swap the axes by changing a few lines of code:
..same chart, different settings:
Newer demo: