-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathvertical-bar-basic.hbs
113 lines (111 loc) · 3.54 KB
/
vertical-bar-basic.hbs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
}}
<div class="lineal-chart" data-test-chart={{or @chartTitle "vertical bar chart"}}>
<Lineal::Fluid as |width|>
{{#let
(scale-band domain=this.xDomain range=(array 0 width) padding=0.1)
(scale-linear range=(array this.chartHeight 0) domain=this.yDomain)
(scale-linear range=(array 0 this.chartHeight) domain=this.yDomain)
as |xScale yScale hScale|
}}
<svg width={{width}} height={{this.chartHeight}}>
<title>{{@chartTitle}}</title>
{{#if (and xScale.isValid yScale.isValid)}}
<Lineal::Axis
@scale={{yScale}}
@tickCount="4"
@tickPadding={{10}}
@tickSizeInner={{concat "-" width}}
@tickFormat={{this.formatTicksY}}
@orientation="left"
@includeDomain={{false}}
class="lineal-axis"
data-test-y-axis
/>
<Lineal::Axis
@scale={{xScale}}
@orientation="bottom"
transform="translate(0,{{yScale.range.min}})"
@includeDomain={{false}}
@tickSize="0"
@tickPadding={{10}}
class="lineal-axis"
data-test-x-axis
/>
{{/if}}
<Lineal::Bars
@data={{this.chartData}}
@x="x"
@y="y"
@height="y"
@width={{this.barWidth}}
@xScale={{xScale}}
@yScale={{yScale}}
@heightScale={{hScale}}
transform="translate({{this.barOffset xScale.bandwidth}},0)"
fill="transparent"
stroke="transparent"
class="lineal-chart-bar"
data-test-vertical-bar
/>
{{#if (and xScale.isValid yScale.isValid)}}
{{#each this.chartData as |d|}}
<rect
role="button"
aria-label="Show exact counts for {{d.legendX}}"
x="0"
y="0"
height={{this.chartHeight}}
width={{xScale.bandwidth}}
fill="transparent"
stroke="transparent"
transform="translate({{xScale.compute d.x}})"
{{on "mouseover" (fn (mut this.activeDatum) d)}}
{{on "mouseout" (fn (mut this.activeDatum) null)}}
data-test-interactive-area={{d.x}}
/>
{{/each}}
{{/if}}
</svg>
{{#if this.activeDatum}}
<div
class="lineal-tooltip-position chart-tooltip"
role="status"
{{style
--x=(this.tooltipX (xScale.compute this.activeDatum.x) xScale.bandwidth)
--y=(this.tooltipY (hScale.compute this.activeDatum.y))
}}
>
<div data-test-tooltip>
<p class="bold" data-test-tooltip-month>{{this.activeDatum.legendX}}</p>
<p data-test-tooltip-count>{{this.activeDatum.tooltip}}</p>
</div>
<div class="chart-tooltip-arrow"></div>
</div>
{{/if}}
{{/let}}
</Lineal::Fluid>
</div>
{{#if @showTable}}
<details data-test-underlying-data>
<summary>Underlying data</summary>
<Hds::Table @caption="Underlying data">
<:head as |H|>
<H.Tr>
<H.Th>Month</H.Th>
<H.Th>{{if @dataKey (humanize @dataKey)}} Count</H.Th>
</H.Tr>
</:head>
<:body as |B|>
{{#each this.chartData as |row|}}
<B.Tr>
<B.Td>{{row.legendX}}</B.Td>
<B.Td>{{row.legendY}}</B.Td>
</B.Tr>
{{/each}}
</:body>
</Hds::Table>
</details>
{{/if}}