How do I draw a line between two points in React Native? - reactjs

how to develop this kind of activity in react-native ?.
activity image
<img src="https://i.stack.imgur.com/9vTTb.png" >

The react-native SVG library might be useful for this, can refer to it here

The element is an SVG basic shape, used to create a line connecting two points.
<Svg height="100" width="100">
<Line x1="0" y1="0" x2="100" y2="100" stroke="red" strokeWidth="2" />
</Svg>
For more refer here.

Related

WPF Show part of drawing path

I have a drawing with <Path> element. It contains dificult Data attribute so how I can show part of this path.
There are certainly several ways to do this. A very easy one would be to put the Path in a Canvas, set its position inside the Canvas and clip it by the Canvas' bounds:
<Canvas Width="80" Height="60" ClipToBounds="True">
<Path Canvas.Left="-10" Canvas.Top="-10" Data="M0,0 L100,0 100,100 Z"
Stroke="Black" StrokeThickness="2" Fill="AliceBlue"/>
</Canvas>
make use of Blend tool for this where if you copy the data attribute for the path, you could see how it is generated.
It would make your job easier to modify the path as well see the data generation at the same time.

Control for rendering SVG graphics?

I need a control for rendering SVG graphics. The data is coming in the in the form of a StreamReader object. What's the easiest way to render such an image?
At present, I'm using PNGs:
But I'd like something higher resolution. SVGs would be perfect for this.
Sample SVG:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.28.0 (20110507.0327)
-->
<!-- Title: G Pages: 1 -->
<svg width="262pt" height="216pt"
viewBox="0.00 0.00 262.00 216.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph1" class="graph" transform="scale(1 1) rotate(0) translate(4 212)">
<title>G</title>
<polygon fill="white" stroke="white" points="-4,5 -4,-212 259,-212 259,5 -4,5"/>
<!-- a -->
<g id="node1" class="node"><title>a</title>
<polygon fill="purple" stroke="purple" points="159.618,-186.523 133,-198.872 106.382,-186.523 116.549,-166.541 149.451,-166.541 159.618,-186.523"/>
<polygon fill="none" stroke="purple" points="165.003,-188.397 133,-203.245 100.997,-188.397 114.139,-162.57 151.861,-162.57 165.003,-188.397"/>
<polygon fill="none" stroke="purple" points="170.387,-190.272 133,-207.617 95.6126,-190.272 111.729,-158.598 154.271,-158.598 170.387,-190.272"/>
<text text-anchor="middle" x="133" y="-177.3" font-family="Times New Roman,serif" font-size="14.00">a</text>
</g>
<!-- b -->
<g id="node3" class="node"><title>b</title>
<ellipse fill="none" stroke="black" cx="133" cy="-100" rx="27" ry="18"/>
<text text-anchor="middle" x="133" y="-96.3" font-family="Times New Roman,serif" font-size="14.00">b</text>
</g>
<!-- a->b -->
<g id="edge2" class="edge"><title>a->b</title>
<path fill="none" stroke="black" d="M133,-158.413C133,-149.086 133,-138.069 133,-128.192"/>
<polygon fill="black" stroke="black" points="136.5,-128.057 133,-118.057 129.5,-128.057 136.5,-128.057"/>
</g>
<!-- c -->
<g id="node4" class="node"><title>c</title>
<polygon fill="none" stroke="black" points="144.42,-41 22.2639,-41 -0.419833,-5 121.736,-5 144.42,-41"/>
<text text-anchor="middle" x="72" y="-19.3" font-family="Times New Roman,serif" font-size="14.00">hello world</text>
</g>
<!-- b->c -->
<g id="edge3" class="edge"><title>b->c</title>
<path fill="none" stroke="black" d="M120.656,-83.8226C112.588,-73.903 101.855,-60.7069 92.5226,-49.2327"/>
<polygon fill="black" stroke="black" points="95.0581,-46.8031 86.0329,-41.2536 89.6275,-51.22 95.0581,-46.8031"/>
</g>
<!-- d -->
<g id="node6" class="node"><title>d</title>
<polygon fill="none" stroke="black" points="194,-3.55271e-015 225.296,-34.5 162.704,-34.5 194,-3.55271e-015"/>
<text text-anchor="middle" x="194" y="-19.3" font-family="Times New Roman,serif" font-size="14.00">d</text>
</g>
<!-- b->d -->
<g id="edge5" class="edge"><title>b->d</title>
<path fill="none" stroke="black" d="M145.344,-83.8226C154.961,-71.9983 168.365,-55.5183 178.67,-42.8489"/>
<polygon fill="black" stroke="black" points="181.629,-44.757 185.224,-34.7906 176.199,-40.3401 181.629,-44.757"/>
</g>
<!-- e -->
<g id="node7" class="node"><title>e</title>
<polygon fill="none" stroke="black" points="254.137,-199 189.863,-199 208.407,-163 235.593,-163 254.137,-199"/>
<text text-anchor="middle" x="222" y="-177.3" font-family="Times New Roman,serif" font-size="14.00">e</text>
</g>
</g>
</svg>
When I had looked into using SVGs in my WPF applications, I found there were a couple packages that could be added in to provide this functionality, but in the end went with using SVGs that I converted to XAML, which will be able to scale in WPF applications the same way an SVG image is able to scale on browsers and such. If you have access to the SVG code (which it looks like you do), then this may be a good solution for you.
These are the steps I use to achieve this:
Converting SVG to XAML
I prefer to use Inkscape for the following steps.
Open the SVG in a image editor (e.g. Inkscape). The editor must support opening an SVG and saving the SVG as a XAML file.
From the editor, save the file as a XAML. The file should be saved as Silverlight compatible if given the choice. Close the image editor.
If any color changes are desired, open the file in a text editor (e.g. Notepad++, Visual Studio) and find any paths with a color value (look for something like 'fill=“#000000”') and change it to the desired hex color value. Save the file and close the text editor when finished.
Using a XAML image in a WPF project
Right click the resources folder the image should be kept in (e.g. \Resources\Images), pick the option to add an exisitng file.
Make sure the file selection type includes XAML files. Navigate to the file to use and add it.
Open the Properties pane in Visual Studio (right click the file and click the 'Properties' option). Under the 'Advanced' section in the Properties pane, set 'Build Action' to 'Resource' and Copy to Output Directory' to 'Do not copy'.
The image can now be used by setting the source of an item to display the image (e.g. a Frame) to the resource path (e.g. “/resources/images/.xaml”). This can be set either directly or through binding.
Example WPF/XAML code for displaying a XAML image
The following code shows an example of how to display a XAML image added using the above steps. This code will scale the image to fill the container it is added to. The source for the image is supplied through the binding used for the Frame element's source. This can be replaced with a string of the image's path (which is what is be provided through the binding value).
<Viewbox Stretch="Uniform"
Margin="4,4"
VerticalAlignment="Center">
<Frame Source="{Binding ImageSource}"
NavigationUIVisibility="Hidden"/>
</Viewbox>
An example of the path string is:
/resources/images/<file-name>.xaml
If the image is located in a DLL and is used in the same DLL, the path string will need to include more information using the following format:
/<AssemblyName>;component/resources/images/<file-name>.xaml
You can also consider a web render control, like WebView2, to display the SVG file.
Another idea is to render the SVG file to an image, ie. using Svg.Skia, and display the rendered image.

Drawing a rounded triangle in Blend

I am looking to draw an equilateral triangle with rounded corners in Expression Blend, kind of like the radius of the rectangle behaves.
I am thinking along the lines of drawing a circle/arc at each end-point and clipping, but this is cumbersome.
Is there a shape that can do this or do you have any other ideas on how to do this?
Thanks
It may be a little late, but just in case someone is trying to do the same...
I was trying to do the same, struggling with the lines in blen... I got discouraged and finally did it in Adobe Illustrator, then import my illustrator file in blend... IT WORKED! :D.
Here is a basic Rounded Triangle you can use and resize as you need with the width and height
<Grid x:Name="Root">
<Path Data="M42.6987,213C26.1987,213,19.5187,201.349,27.8537,187.109L115.1947,37.891C123.5307,23.651,137.1687,23.651,145.5047,37.891L232.8457,187.109C241.1807,201.349,234.4997,213,217.9997,213L42.6987,213z" Fill="White" Canvas.Left="-0.5" StrokeStartLineCap="Flat" Stretch="Fill" StrokeEndLineCap="Flat" Stroke="Black" StrokeThickness="3" StrokeMiterLimit="10" StrokeLineJoin="Miter" Canvas.Top="-0.5" Width="45" Height="30" RenderTransformOrigin="0.5, 0.5" />
</Grid>
Draw a line with an arc at each end point. You can then group all these three shapes and play along from there.

Fit XAML path into view

I have the following path. The data is from some data file:
<Path StrokeThickness="5" Stroke="Black" Fill="Yellow" Data="M 30330.8847248349,-37724.909002528 L 28556.3829935257,-37596.5557453925 28031.7660050946,-38008.0608378072 27746.4689258268,-38895.6687979239 27655.7148993139,-39397.1764657993 27718.5888966473,-39755.4955438608 27628.0246979519,-40621.440862981 28514.7500540091,-41208.8847446069 29093.8320242864,-40459.5872073251 29768.3831435369,-40107.7166927063 30092.4525793664,-39483.6045857995 30784.2658266352,-38627.7070622611 30811.846313938,-38537.1499823241 30358.6906348136,-37734.2759127391 30330.8847248349,-37724.909002528" />
I like to know what this looks like, so I want to render it in Kaxaml or XamlPad. Is there an easy way to resize this path so it will render nicely centered on the screen?
Just set the path's stretch attribute to Uniform to maitain the apsect ratio and you should be able to see it in KaXaml
<Path Stretch="Uniform" StrokeThickness="5" Stroke="Black" Fill="Yellow" Data="M 30330.8847248349,-37724.909002528 L 28556.3829935257,-37596.5557453925 28031.7660050946,-38008.0608378072 27746.4689258268,-38895.6687979239 27655.7148993139,-39397.1764657993 27718.5888966473,-39755.4955438608 27628.0246979519,-40621.440862981 28514.7500540091,-41208.8847446069 29093.8320242864,-40459.5872073251 29768.3831435369,-40107.7166927063 30092.4525793664,-39483.6045857995 30784.2658266352,-38627.7070622611 30811.846313938,-38537.1499823241 30358.6906348136,-37734.2759127391 30330.8847248349,-37724.909002528" />

WPF - Create buttons with up and down arrows using standard buttons

I want to create some up and down buttons using the standard button
background but with black arrows.
What is the best way to accomplish this with WPF??
Malcolm
I find Marlett (a font built into Windows) handy for that sort of thing.
<Button FontFamily="Marlett" FontSize="20" Content="5"/>
<Button FontFamily="Marlett" FontSize="20" Content="6"/>
Output:
No discussion on this subject would be complete without mentioning the geometry mini-language (or Path Markup Syntax) for a more compact shape definition:-
<Button>
<Path Fill="Black" Data="M 0 6 L 12 6 L 6 0 Z"/>
</Button>
<Button>
<Path Fill="Black" Data="M 0 0 L 6 6 L 12 0 Z"/>
</Button>
The first describes a Move to 0,6 Line to 12,6 Line to 6,0 and then close the shape (Z).
There is also a curve syntax.
The preferred way to do this now is using Segoe UI Symbol. It replaces Marlett and provides many useful glyphs.
Up and down would be
<Button FontFamily="Segoe UI Symbol" Content=""/>
<Button FontFamily="Segoe UI Symbol" Content=""/>
Which renders as:
This font is pre-installed on all versions of Windows 7 and 8.
As of the release of Windows 10, the Segoe UI Symbol font is considered a legacy resource and should be replaced by Segoe MDL2 Assets in all new projects as outlined here.
You can create a Polygon which represents your up and down triangles and then set them to be the content of the buttons:
<Button>
<Polygon
Points="300,200 450,200 375,300 300,200"
Stroke="Black">
<Polygon.Fill>
<SolidColorBrush Color="Black" />
</Polygon.Fill>
</Polygon>
</Button>
You can tweak these to draw different figured, but that's generally the XAML you would use for basic geometry.
If you would like to have an arrow with base rectangle you can use this sample...
<Button >
<Polygon Stretch="Fill" Fill="Black" Points="0,0 0,30 0,10 30,10 30,-10 45,10 30,30 30,20 0,20 0,0 30,0 30,10 0,10" />
</Button>

Resources