victory#VictoryVoronoiContainer JavaScript Examples
The following examples show how to use
victory#VictoryVoronoiContainer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CashFlowGraph.js From actual with MIT License | 5 votes |
function CashFlowGraph({ style, start, end, graphData, isConcise, compact }) {
return (
<Container>
{(width, height, portalHost) =>
graphData && (
<VictoryChart
scale={{ x: 'time' }}
theme={theme}
domainPadding={10}
width={width}
height={height}
containerComponent={
<VictoryVoronoiContainer voronoiDimension="x" />
}
>
<VictoryGroup>
<VictoryBar
data={graphData.expenses}
style={{ data: { fill: theme.colors.red } }}
/>
<VictoryBar data={graphData.income} />
</VictoryGroup>
<VictoryLine
data={graphData.balances}
labelComponent={<Tooltip portalHost={portalHost} />}
labels={x => x.premadeLabel}
style={{
data: { stroke: colors.n5 }
}}
/>
<VictoryAxis
tickFormat={x => d.format(x, isConcise ? "MMM ''yy" : 'MMM d')}
tickValues={graphData.balances.map(item => item.x)}
tickCount={Math.min(5, graphData.balances.length)}
offsetY={50}
/>
<VictoryAxis dependentAxis crossAxis={false} />
</VictoryChart>
)
}
</Container>
);
}
Example #2
Source File: NetWorthGraph.js From actual with MIT License | 5 votes |
function NetWorthGraph({ style, start, end, graphData, compact }) {
const Chart = compact ? VictoryGroup : VictoryChart;
return (
<Container style={[style, compact && { height: 'auto' }]}>
{(width, height, portalHost) =>
graphData && (
<Chart
scale={{ x: 'time' }}
theme={theme}
domainPadding={{ x: 0, y: 10 }}
width={width}
height={height}
containerComponent={
<VictoryVoronoiContainer voronoiDimension="x" />
}
padding={
compact && {
top: 0,
bottom: 0,
left: 0,
right: 0
}
}
>
<Area
start={graphData.start}
end={graphData.end}
data={graphData.data}
/>
{React.createElement(
graphData.data.length === 1 ? VictoryBar : VictoryArea,
{
data: graphData.data,
labelComponent: <Tooltip portalHost={portalHost} />,
labels: x => x.premadeLabel,
style: {
data:
graphData.data.length === 1
? { width: 50 }
: {
clipPath: 'url(#positive)',
fill: 'url(#positive-gradient)'
}
}
}
)}
{graphData.data.length > 1 && (
<VictoryArea
data={graphData.data}
style={{
data: {
clipPath: 'url(#negative)',
fill: 'url(#negative-gradient)',
stroke: theme.colors.red,
strokeLinejoin: 'round'
}
}}
/>
)}
{!compact && (
<VictoryAxis
tickFormat={x => d.format(x, "MMM ''yy")}
tickValues={graphData.data.map(item => item.x)}
tickCount={Math.min(5, graphData.data.length)}
offsetY={50}
/>
)}
{!compact && (
<VictoryAxis dependentAxis crossAxis={!graphData.hasNegative} />
)}
</Chart>
)
}
</Container>
);
}
Example #3
Source File: Rewards.js From testnets-cardano-org with MIT License | 5 votes |
RewardsGraph = ({ title, yLabel, currencySymbol, data, normalizeLargeNumber }) => (
<ChartContainer marginTop={8}>
<h4>{title}</h4>
<Theme.Consumer>
{({ theme }) => (
<VictoryChart
width={500}
height={300}
scale={{ x: 'linear' }}
padding={{ top: 75, bottom: 55, left: 100, right: 65 }}
containerComponent={
<VictoryVoronoiContainer
voronoiDimension='x'
labels={({ datum }) => `Epoch: ${datum.x}\n${currencySymbol} ${normalizeLargeNumber(datum.y, 6)}\n${currencySymbol} ${normalizeLargeNumber(datum.reward, 6)}`}
/>
}
>
<VictoryAxis
crossAxis={false}
label='Epoch'
style={{
tickLabels: { fill: theme.palette.text.primary },
axisLabel: { fill: theme.palette.text.primary, padding: 35 }
}}
/>
<VictoryAxis
dependentAxis
label={yLabel}
style={{
tickLabels: { fill: theme.palette.text.primary },
axisLabel: { fill: theme.palette.text.primary, padding: 70 }
}}
/>
<VictoryLine
style={{
data: { stroke: theme.palette.primary.light }
}}
data={data}
labelComponent={<VictoryTooltip />}
/>
</VictoryChart>
)}
</Theme.Consumer>
</ChartContainer>
)
Example #4
Source File: Overview.js From actual with MIT License | 4 votes |
function CashFlowCard() {
const end = monthUtils.currentDay();
const start = monthUtils.currentMonth() + '-01';
const data = useReport('cash_flow_simple', useArgsMemo(simpleCashFlow)(start, end));
if (!data) {
return null;
}
const { graphData } = data;
const expense = -(graphData.expense || 0);
const income = graphData.income || 0;
return (
<Card flex={1} to="/reports/cash-flow">
<View style={{ flex: 1 }}>
<View style={{ flexDirection: 'row', padding: 20 }}>
<View style={{ flex: 1 }}>
<Block
style={[styles.mediumText, { fontWeight: 500, marginBottom: 5 }]}
>
Cash Flow
</Block>
<DateRange start={start} end={end} />
</View>
<View style={{ textAlign: 'right' }}>
<Change
amount={income - expense}
style={{ color: colors.n6, fontWeight: 300 }}
/>
</View>
</View>
<Container style={{ height: 'auto', flex: 1 }}>
{(width, height, portalHost) => (
<VictoryGroup
colorScale={[theme.colors.blue, theme.colors.red]}
width={100}
height={height}
theme={theme}
domain={{
x: [0, 100],
y: [0, Math.max(income, expense, 100)]
}}
containerComponent={
<VictoryVoronoiContainer voronoiDimension="x" />
}
labelComponent={
<Tooltip
portalHost={portalHost}
offsetX={(width - 100) / 2}
offsetY={y => (y + 40 > height ? height - 40 : y)}
light={true}
forceActive={true}
style={{
padding: 0
}}
/>
}
padding={{
top: 0,
bottom: 0,
left: 0,
right: 0
}}
>
<VictoryBar
data={[
{
x: 30,
y: Math.max(income, 5),
width: 20,
premadeLabel: (
<div style={{ textAlign: 'right' }}>
<div>Income</div>
<div>{integerToCurrency(income)}</div>
</div>
),
labelPosition: 'left'
}
]}
labels={d => d.premadeLabel}
/>
<VictoryBar
data={[
{
x: 60,
y: Math.max(expense, 5),
width: 20,
premadeLabel: (
<div>
<div>Expenses</div>
<div>{integerToCurrency(expense)}</div>
</div>
),
labelPosition: 'right',
fill: theme.colors.red
}
]}
labels={d => d.premadeLabel}
/>
</VictoryGroup>
)}
</Container>
</View>
</Card>
);
}
Example #5
Source File: historyView.jsx From OpticQL with MIT License | 4 votes |
History = () => {
const { store } = useContext(Context);
// Declaring an empty array to store either the line chart, bar chart, or string (for no historical data)
let chartContainer = [];
// Container for line chart --> Used when there is more than ONE path
const containerLine = [
<VictoryChart
domainPadding={{ x: 10 }}
containerComponent={
<VictoryVoronoiContainer
voronoiDimension="x"
labels={({ datum }) =>
`Query: ${datum.t} ms,
Query String: ${datum.z}`
}
labelComponent={
<VictoryTooltip
cornerRadius={5}
flyoutStyle={{ fill: "#D4F1F4" }}
style={{ fontSize: 6 }}
constrainToVisibleArea
flyoutPadding={5}
/>
}
/>
}
>
<VictoryLine
style={{
data: { stroke: "#189AB4" },
}}
// Performance data inserted here
data={store.history}
/>
<VictoryAxis
label={"Query Database ID"}
style={{
tickLabels: { fontSize: 10, padding: 5, angle: -30, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 10, padding: 30, fill: "white" },
}}
/>
<VictoryAxis
label={"Response Duration (ms)"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 10, padding: 30, fill: "white" },
}}
dependentAxis
/>
</VictoryChart>,
];
// Container for bar chart --> Used when there is ONLY ONE path
const containerBar = [
<VictoryChart
domainPadding={{ x: 5 }}
>
<VictoryBar
style={{
data: { fill: "#189AB4" },
}}
// Performance data object inserted here
data={store.history}
labels={({ datum }) =>
`Query: ${datum.t} ms,
Query String: ${datum.z}`
}
barWidth={({ index }) => index * 5 + 20}
labelComponent={
<VictoryTooltip
cornerRadius={5}
flyoutStyle={{ fill: "#D4F1F4" }}
style={{ fontSize: 6 }}
constrainToVisibleArea
flyoutPadding={5}
/>
}
/>
<VictoryAxis
label={"Query Database ID"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 10, fill: "white" },
}}
/>
<VictoryAxis
label={"Response Duration (ms)"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 10, fill: "white" },
}}
dependentAxis
/>
</VictoryChart>,
];
// Conditional statement to assign chartContainer to charting (line or bar) if there is data, or else, a string indicating no data to render
if (store.history.length === 0) {
chartContainer = '(No historical query information to display)';
} else if (store.history.length === 1) {
chartContainer.push(containerBar);
} else {
chartContainer.push(containerLine);
}
const headerStr = 'Historical GraphQL Performance (Overall response duration in ms)'
const linkStyle = {
"color": "#05445E",
"textDecoration": "none",
}
return (
// <div>
<div className="historyViewContainer">
<img src="./logo2.png" />
<button className="quadrantButton">
<Link to="/" style={linkStyle}>Home</Link>
</button>
<h3 style={{ "color": "#ffffff" }}>{headerStr}</h3>
<div style={{ "width": "80%", "color": "#ffffff", "textAlign": "center", "marginTop": "50px" }}>
{chartContainer}
</div>
</div>
// </div>
);
}
Example #6
Source File: performanceData.jsx From OpticQL with MIT License | 4 votes |
PerfData = () => {
const { store } = useContext(Context);
// Local state to show or hide the pop-up window
const [showWindowPortal, setWindowPortal] = useState(false);
// Change state of showWindowPortal whenever Expand Performance Metrics button is clicked
function toggleWindowPortal () {
setWindowPortal(!showWindowPortal)
}
// To format the response metrics with commas if 4 digits or more
function numberWithCommas (x) {
return x.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
}
// Declaring variables to re-assign if store.query.extensions is not falsy
const data = [];
// Variable for rendering of the Summary Performance Metrics text in the upper right hand corner of lower left quadrant
const htmlContainer = [];
// Variable for rending of the main charting (bar or line Victory charts)
const chartContainer = [];
let overallResTime;
let startTime;
let endTime;
const performanceObj = {};
const perfAvg = {};
const anomaliesObj = {};
// If the request is valid (with an associated response), and it is not a mutation request
if (store.query.extensions && !store.mutationEvent) {
const topLevelQueryArr = [];
// Saving top-level request information --> formatting overall response time (in ms) to include commas before the decimal
overallResTime = numberWithCommas(
(store.query.extensions.tracing.duration / 1000000).toFixed(2)
);
// Saving the rest of the top-level (overall) request information
startTime = store.query.extensions.tracing.startTime;
endTime = store.query.extensions.tracing.endTime;
// Saving resolver-level information to a variable
const performanceDataArray = store.query.extensions.tracing.execution.resolvers;
// Resolver-level query information
for (let i = 0; i < performanceDataArray.length; i++) {
const currResolver = performanceDataArray[i];
// This captures 'parent' resolvers and associated duration
if (currResolver.path.length === 1) {
const pathStr = currResolver.path[0];
const pathDuration = currResolver.duration;
topLevelQueryArr.push([pathStr, pathDuration]);
} else {
// 'Children' resolvers and duration get stored in performanceObj
const pathStrJoined = currResolver.path.join(".");
const pathKey = currResolver.path.filter(function (curEl) {
return typeof curEl === "string";
});
const pathKeyJoined = pathKey.join(".");
if (performanceObj[pathKeyJoined]) {
performanceObj[pathKeyJoined].push([pathStrJoined, currResolver.duration]);
} else {
performanceObj[pathKeyJoined] = [[pathStrJoined, currResolver.duration]];
}
}
}
// Finding the average of all the 'children' resolvers duration time for each identified path
for (let perfQuery in performanceObj) {
let perfArr = performanceObj[perfQuery];
let average = 0;
for (let i = 0; i < perfArr.length; i++) {
average += perfArr[i][1];
}
const finalAvg = average / perfArr.length / 1000000;
perfAvg[perfQuery] = Number(finalAvg.toFixed(4));
}
// Isolating the 'children' resolvers where the duration time exceeds the average duration time for that identified path
for (const [pathName, avg] of Object.entries(perfAvg)) {
const anomaliesArr = [];
const arrayOfTimes = performanceObj[pathName];
arrayOfTimes.forEach((el) => {
const resTime = el[1] / 1000000;
if (resTime > avg) {
anomaliesArr.push(`${el[0]}: ${resTime} ms`);
}
});
anomaliesObj[pathName] = anomaliesArr;
}
// Declaring the performance data to be rendered in Victory chart
for (let queryKey in perfAvg) {
let queryKeyObj = {};
queryKeyObj.x = queryKey;
queryKeyObj.y = perfAvg[queryKey];
queryKeyObj.z = anomaliesObj[queryKey].length;
queryKeyObj.q = performanceObj[queryKey].length;
queryKeyObj.t = numberWithCommas(perfAvg[queryKey].toFixed(4));
data.push(queryKeyObj);
}
// Console logs for error-checking
// console.log("performanceObj ", performanceObj);
// console.log("topLevelQueryArr ", topLevelQueryArr);
// console.log("perfAvg:", perfAvg);
// console.log("anomaliesObj:", anomaliesObj);
// console.log("data: ", data);
// Container for line chart --> Used when there is MORE THAN ONE path
const containerLine = [
<VictoryChart
height={350}
padding={60}
domainPadding={{ x: 10 }}
containerComponent={
<VictoryVoronoiContainer
voronoiDimension="x"
labels={({ datum }) =>
`Avg. response time: ${datum.t} ms,
# total resolvers: ${datum.q},
# outlier resolvers: ${datum.z}`
}
labelComponent={
<VictoryTooltip
cornerRadius={5}
flyoutStyle={{ fill: "#D4F1F4" }}
style={{ fontSize: 9 }}
/>
}
/>
}
>
<VictoryLine
style={{
data: { stroke: "#189AB4" },
}}
// Performance data is inputted here
data={data}
/>
<VictoryAxis
label={"Path"}
style={{
tickLabels: { fontSize: 10, padding: 15, angle: -30, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white", padding: 45 },
}}
/>
<VictoryAxis
label={"Duration Time (ms)"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white", padding: 40 },
}}
dependentAxis
/>
</VictoryChart>,
];
// Container for bar chart --> Used when there is ONLY ONE path
const containerBar = [
<VictoryChart
height={350}
padding={60}
domainPadding={{ x: 5 }}
>
<VictoryBar
style={{
data: { fill: "#189AB4" },
}}
// Performance data is inputted here
data={data}
labels={({ datum }) =>
`Avg. response time: ${datum.t} ms,
# total resolvers: ${datum.q},
# outlier resolvers: ${datum.z}`
}
barWidth={({ index }) => index * 5 + 20}
labelComponent={
<VictoryTooltip
dy={0}
style={{ fontSize: 8 }}
constrainToVisibleArea
/>
}
/>
<VictoryAxis
label={"Path"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white" },
}}
/>
<VictoryAxis
label={"Duration Time (ms)"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white", padding: 40 },
}}
dependentAxis
/>
</VictoryChart>,
];
// Adding <p> tags with top-level query information to HTMLcontainer array
htmlContainer.push(
<p key={"overallPerfMetric: 0"} className="perfMetricPTag" className="perfMetricPTagTitle">Summary Metrics:</p>
);
htmlContainer.push(
<p key={"overallPerfMetric: 3"} className="perfMetricPTag">
▫ Overall response time: {overallResTime} ms
</p>
);
for (let i = 0; i < topLevelQueryArr.length; i++) {
let overallParentResTime = numberWithCommas(
(topLevelQueryArr[i][1] / 1000000).toFixed(2)
);
htmlContainer.push(
<p
key={`Time Elapsed to parent resolver-${i}`}
className="perfMetricPTag"
>{` ▫ Response time to ${topLevelQueryArr[i][0]} field: ${overallParentResTime} ms`}</p>
);
}
// Conditional statement to assign chartContainer to either the line or bar chart
if (data.length === 1) {
chartContainer.push(containerBar);
} else {
chartContainer.push(containerLine);
}
}
// If the request is valid (with an associated response), and it is a MUTATION request
if (store.query.extensions && store.mutationEvent) {
// Saving the overall duration time for the MUTATION request
const overallDurationTime = numberWithCommas(((store.query.extensions.tracing.duration) / 1000000).toFixed(4));
// Saving the resolvers array to a variable
const resolverArr = store.query.extensions.tracing.execution.resolvers;
// For loop to create a data object to be rendered inside Victory charts
for (let i = 0; i < resolverArr.length; i++) {
// If conditional to isolate where the resolver path is only one field (which indicates a mutation request vs. the callback fields requested)
if (resolverArr[i].path.length === 1) {
const resolverDuration = (resolverArr[i].duration) / 1000000;
const resolverName = resolverArr[i].path[0];
const mutationObj = {};
mutationObj.x = resolverName;
mutationObj.y = resolverDuration;
mutationObj.z = numberWithCommas(resolverDuration.toFixed(4));
data.push(mutationObj);
}
}
// Adding <p> tags with top-level query information to HTMLcontainer array
htmlContainer.push(
<p key={"overallPerfMetric: 0"} className="perfMetricPTag" className="perfMetricPTagTitle">Summary Performance Metrics:</p>
);
htmlContainer.push(
<p key={"overallPerfMetric: 3"} className="perfMetricPTag">
▫ Overall response time: {overallDurationTime} ms
</p>
);
// Container for line chart --> Used when there is MORE THAN ONE path
const containerLine = [
<VictoryChart
height={350}
padding={60}
domainPadding={{ x: 10 }}
containerComponent={
<VictoryVoronoiContainer
voronoiDimension="x"
labels={({ datum }) =>
`Response time: ${datum.z} ms`
}
labelComponent={
<VictoryTooltip
cornerRadius={5}
flyoutStyle={{ fill: "#D4F1F4" }}
style={{ fontSize: 9 }}
/>
}
/>
}
>
<VictoryLine
style={{
data: { stroke: "#189AB4" },
}}
// Performance data is inserted here
data={data}
/>
<VictoryAxis
label={"Path"}
style={{
tickLabels: { fontSize: 10, padding: 15, angle: -30, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white", padding: 45 },
}}
/>
<VictoryAxis
label={"Duration Time (ms)"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white", padding: 40 },
}}
dependentAxis
/>
</VictoryChart>,
];
// Container for bar chart --> Used when there is ONLY ONE path
const containerBar = [
<VictoryChart
height={350}
padding={60}
domainPadding={{ x: 5 }}
>
<VictoryBar
style={{
data: { fill: "#189AB4" },
}}
// Performance data is inserted here
data={data}
labels={({ datum }) =>
`Response time: ${datum.z} ms`
}
barWidth={({ index }) => index * 5 + 20}
labelComponent={
<VictoryTooltip
dy={0}
style={{ fontSize: 8 }}
constrainToVisibleArea
/>
}
/>
<VictoryAxis
label={"Path"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white" },
}}
/>
<VictoryAxis
label={"Duration Time (ms)"}
style={{
tickLabels: { fontSize: 10, padding: 5, fill: "white" },
axis: { stroke: "white" },
axisLabel: { fontSize: 12, fill: "white", padding: 40 },
}}
dependentAxis
/>
</VictoryChart>,
];
// Conditional statement to assign chartContainer to either the line or bar chart
if (data.length === 1) {
chartContainer.push(containerBar);
} else {
chartContainer.push(containerLine);
}
}
const linkStyle = {
"color": "#05445E",
"textDecoration": "none",
}
return (
<div>
{store.loading && <div className="loadingBox"><img className='loadingImg' src="./assets/loading.gif" /></div>}
{(!store.query.data && !store.loading) && <div id='queryPlaceholder'>No query results to display</div>}
{(store.query.data && !store.loading) &&
<div>
<div className="performanceMetricsButtonInfo">
<button onClick={toggleWindowPortal} className="performanceMetricsButton">
Expand Performance Metrics
</button>
<button className="performanceMetricsButton">
<Link to="/fullhistory" style={linkStyle}>View Historical Metrics</Link>
</button>
<ExpandPerfData key={'ExpandPerfData 1'} showWindow={showWindowPortal} performanceAvg={perfAvg} anomaliesObject={anomaliesObj} performance={performanceObj} />
<div>{htmlContainer}</div>
</div>
<div className="chartContainerDiv">{chartContainer}</div>
</div>
}
</div>
)
}