forked from perspective-dev/perspective
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharea.js
More file actions
86 lines (75 loc) · 2.7 KB
/
area.js
File metadata and controls
86 lines (75 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
import * as fc from "d3fc";
import * as crossAxis from "../axis/crossAxis";
import * as mainAxis from "../axis/mainAxis";
import {areaSeries} from "../series/areaSeries";
import {seriesColors} from "../series/seriesColors";
import {splitAndBaseData} from "../data/splitAndBaseData";
import {colorLegend} from "../legend/legend";
import {filterData} from "../legend/filter";
import {withGridLines} from "../gridlines/gridlines";
import {hardLimitZeroPadding} from "../d3fc/padding/hardLimitZero";
import zoomableChart from "../zoom/zoomableChart";
import nearbyTip from "../tooltip/nearbyTip";
function areaChart(container, settings) {
const data = splitAndBaseData(settings, filterData(settings));
const color = seriesColors(settings);
const legend = colorLegend()
.settings(settings)
.scale(color);
const series = fc.seriesSvgRepeat().series(areaSeries(settings, color).orient("vertical"));
const xDomain = crossAxis.domain(settings)(data);
const xScale = crossAxis.scale(settings);
const yScale = mainAxis.scale(settings);
const xAxis = crossAxis.axisFactory(settings).domain(xDomain)();
const chart = fc
.chartSvgCartesian({
xScale,
yScale,
xAxis
})
.xDomain(xDomain)
.xLabel(crossAxis.label(settings))
.xAxisHeight(xAxis.size)
.xDecorate(xAxis.decorate)
.yDomain(
mainAxis
.domain(settings)
.include([0])
.paddingStrategy(hardLimitZeroPadding())(data)
)
.yLabel(crossAxis.label(settings))
.yOrient("left")
.yLabel(mainAxis.label(settings))
.yNice()
.plotArea(withGridLines(series).orient("vertical"));
chart.xPaddingInner && chart.xPaddingInner(1);
chart.xPaddingOuter && chart.xPaddingOuter(0.5);
const zoomChart = zoomableChart()
.chart(chart)
.settings(settings)
.xScale(xScale);
const toolTip = nearbyTip()
.settings(settings)
.xScale(xScale)
.yScale(yScale)
.color(color)
.data(data);
// render
container.datum(data).call(zoomChart);
container.call(toolTip);
container.call(legend);
}
areaChart.plugin = {
type: "d3_y_area",
name: "[d3fc] Y Area Chart",
max_size: 25000
};
export default areaChart;