forked from holtzy/The-Python-Graph-Gallery
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChartImage.js
More file actions
66 lines (58 loc) · 1.48 KB
/
ChartImage.js
File metadata and controls
66 lines (58 loc) · 1.48 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
import "./chartImage.css";
import React from "react";
import { useStaticQuery, graphql } from "gatsby";
import Img from "gatsby-image";
const allGifs = ["animated_chart", "animated_gapminder.gif", "animated_volcano.gif"]
// This component displays a logo representing a chart type of the gallery. Example: bar chart
// Logo has a different size depending on the window size.
export default function ChartImage({ imgName, caption }) {
if (allGifs.includes(imgName)) {
return (
<p>TODO</p>)
}
const data = useStaticQuery(graphql`
query MyQuery {
allFile(filter: { relativeDirectory: { eq: "graph" } }) {
edges {
node {
id
name
childImageSharp {
fluid {
aspectRatio
base64
sizes
src
srcWebp
srcSet
}
}
}
}
}
}
`);
const image = data.allFile.edges.find((n) => {
return n.node.name.includes(imgName);
});
if (!image) {
return null;
}
// Note: alt tag looks to be ignored?
return (
<>
<div className="chartImageContainer">
<Img
alt={caption}
fluid={image.node.childImageSharp.fluid}
className="chartImageImg"
/>
<div className="chartImageOverlay">
<div className="chartImageOverlayText">
<p>{caption}</p>
</div>
</div>
</div>
</>
);
}