Skip to content

Support for svg in React code. #31

@ColeTownsend

Description

@ColeTownsend

Issuehunt badges

Supporting inline SVG

React by default can support inline svg code. Because NodeGUI does not render to a browser window though, we can't use that.

Possible Solutions
One solution might be to bridge QTSvg albeit I am not savvy enough to do this.

Sample code that triggered error

import React from 'react';
import { letterFrequency } from '@vx/mock-data';
import { Group } from '@vx/group';
import { Bar } from '@vx/shape';
import { scaleLinear, scaleBand } from '@vx/scale';

const data = letterFrequency;

const width = 500;
const height = 500;
const margin = { top: 20, bottom: 20, left: 20, right: 20 };

const xMax = width - margin.left - margin.right;
const yMax = height - margin.top - margin.bottom;

const x = (d: any) => d.letter;
const y = (d: any) => +d.frequency * 100;

const xScale = scaleBand({
  rangeRound: [0, xMax],
  domain: data.map(x),
  padding: 0.4,
});
const yScale = scaleLinear({
  rangeRound: [yMax, 0],
  domain: [0, Math.max(...data.map(y))],
});

const compose = (scale: any, accessor: any) => (data: any) => scale(accessor(data));
const xPoint = compose(
  xScale,
  x,
);
const yPoint = compose(
  yScale,
  y,
);

function BarGraph() {
  return (
    <svg width={width} height={height}>
      {data.map((d: any, i: any) => {
        const barHeight = yMax - yPoint(d);
        return (
          <Group key={`bar-${i}`}>
            <Bar x={xPoint(d)} y={yMax - barHeight} height={barHeight} width={xScale.bandwidth()} fill="#fc2e1c" />
          </Group>
        );
      })}
    </svg>
  );
}
export default BarGraph;
``


<!-- Issuehunt content -->

---

<details>
<summary>
<b>IssueHunt Summary</b>
</summary>


### Backers (Total: $20.00)

- $20.00 have been anonymously funded.

#### [Become a backer now!](https://issuehunt.io/r/nodegui/react-nodegui/issues/31)
#### [Or submit a pull request to get the deposits!](https://issuehunt.io/r/nodegui/react-nodegui/issues/31)
### Tips

- Checkout the [Issuehunt explorer](https://issuehunt.io/r/nodegui/react-nodegui/) to discover more funded issues.
- Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.
---
IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
</details>
<!-- /Issuehunt content-->

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions