React Polar Map Example

Demonstrates how to create a Polar Map Example using our PolarTriangleRenderableSeries class, along with a triangulation alorithm.

Fullscreen

Edit

 Edit

Docs

drawExample.ts

index.tsx

constrainedDelaunayTriangulation.ts

Copy to clipboard
Minimise
Fullscreen
1import {
2    NumberRange,
3    XyDataSeries,
4    ETriangleSeriesDrawMode,
5    PolarPanModifier,
6    PolarZoomExtentsModifier,
7    PolarMouseWheelZoomModifier,
8    PolarTriangleRenderableSeries,
9    PolarNumericAxis,
10    EPolarAxisMode,
11    EAxisAlignment,
12    SciChartPolarSurface,
13} from "scichart";
14
15import constrainedDelaunayTriangulation from "./constrainedDelaunayTriangulation";
16
17export const drawExample = async (rootElement: string | HTMLDivElement) => {
18    // Create a SciChartSurface
19    const { wasmContext, sciChartSurface } = await SciChartPolarSurface.create(rootElement);
20
21    sciChartSurface.debugRendering = false;
22
23    let showFromSouthPole = false;
24
25    const setView = (positionFromSPole: boolean) => {
26        showFromSouthPole = positionFromSPole;
27
28        sciChartSurface.xAxes.clear();
29        sciChartSurface.yAxes.clear();
30        sciChartSurface.renderableSeries.clear(true);
31
32        const xAxis = new PolarNumericAxis(wasmContext, {
33            polarAxisMode: EPolarAxisMode.Angular,
34            visibleRange: new NumberRange(-180, 180), // longitude
35            flippedCoordinates: showFromSouthPole ? true : false,
36            axisAlignment: EAxisAlignment.Bottom,
37            useNativeText: true,
38            drawMajorBands: false,
39            drawMajorGridLines: false,
40            drawMajorTickLines: false,
41            drawMinorGridLines: false,
42            drawMinorTickLines: false,
43            labelPrecision: 0
44        });
45        sciChartSurface.xAxes.add(xAxis);
46
47        const yAxis = new PolarNumericAxis(wasmContext, {
48            polarAxisMode: EPolarAxisMode.Radial,
49            visibleRange: new NumberRange(-90, 90), // latitude
50            axisAlignment: EAxisAlignment.Left,
51            flippedCoordinates: showFromSouthPole ? false : true,
52            useNativeText: true,
53            drawMajorBands: false,
54            drawMajorGridLines: false,
55            drawMajorTickLines: false,
56            drawMinorGridLines: false,
57            drawMinorTickLines: false,
58            labelPrecision: 0
59        });
60        sciChartSurface.yAxes.add(yAxis);
61    };
62
63    setView(true);
64
65    const [min, max] = [140, 1379302771]; // population min max
66
67    function interpolateColor(min: number, max: number, value: number) {
68        // Clamp value between min and max
69        value = Math.max(min, Math.min(max, value));
70        // Normalize to [0,1]
71        let t = (value - min) / (max - min);
72
73        // Parse hex colors to RGB
74        function hexToRgb(hex: string) {
75            hex = hex.replace(/^#/, "");
76            if (hex.length === 3)
77                hex = hex
78                    .split("")
79                    .map((x) => x + x)
80                    .join("");
81            const num = parseInt(hex, 16);
82            return [num >> 16, (num >> 8) & 255, num & 255];
83        }
84
85        // Interpolate between two RGB colors
86        function lerp(a: number, b: number, t: number) {
87            return Math.round(a + (b - a) * t);
88        }
89
90        const colorA = hexToRgb("#ffffff");
91        const colorB = hexToRgb("#1e3489");
92        const r = lerp(colorA[0], colorB[0], t);
93        const g = lerp(colorA[1], colorB[1], t);
94        const b = lerp(colorA[2], colorB[2], t);
95
96        // Convert back to hex
97        return "#" + [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
98    }
99
100    let dataArray: { name: string; gdp: number; population: number; areaData: number[][] }[] = [];
101
102    const setMapJson = (mapData: { features: any[] }) => {
103        dataArray = [];
104
105        mapData?.features.forEach((state, i) => {
106            if (state.geometry.type === "Polygon") {
107                let area = state.geometry.coordinates[0];
108                area.pop();
109                let areaData = [].concat(...constrainedDelaunayTriangulation(area));
110
111                dataArray.push({
112                    name: state.properties.NAME,
113                    gdp: +state.properties.GDP_MD_EST,
114                    population: +state.properties.POP_EST,
115                    areaData,
116                });
117            } else {
118                let polyArea = state.geometry.coordinates;
119
120                if (state.properties.SOVEREIGNT === "Antarctica" && showFromSouthPole === false) {
121                    return;
122                }
123
124                polyArea.forEach((a: any[]) => {
125                    let area = a[0];
126
127                    area.pop();
128                    let areaData = [].concat(...constrainedDelaunayTriangulation(area));
129
130                    dataArray.push({
131                        name: state.properties.NAME,
132                        gdp: +state.properties.GDP_MD_EST,
133                        population: +state.properties.POP_EST,
134                        areaData,
135                    });
136                });
137            }
138        });
139    };
140
141    const setMap = () => {
142        sciChartSurface.renderableSeries.clear(true);
143
144        const series = dataArray.map((d, i) => {
145            const dataSeries = new XyDataSeries(wasmContext, {
146                xValues: d.areaData.map((p) => p[0]),
147                yValues: d.areaData.map((p) => p[1]),
148            });
149
150            const triangleSeries = new PolarTriangleRenderableSeries(wasmContext, {
151                dataSeries: dataSeries,
152                drawMode: ETriangleSeriesDrawMode.List,
153                fill: interpolateColor(min, max, d.population),
154                opacity: 0.9,
155            });
156
157            return triangleSeries;
158        });
159
160        sciChartSurface.renderableSeries.add(...series);
161    };
162
163    sciChartSurface.chartModifiers.add(new PolarPanModifier());
164    sciChartSurface.chartModifiers.add(new PolarZoomExtentsModifier());
165    sciChartSurface.chartModifiers.add(new PolarMouseWheelZoomModifier());
166    return { sciChartSurface, wasmContext, setMapJson, setMap, setView };
167};
168

Polar Map Example - React

Overview

This React implementation showcases a polar map visualization using SciChart's SciChart React component. The example displays geographic data as color-coded triangles on a polar coordinate system with view switching capabilities.

Technical Implementation

The chart surface is initialized via the initChart prop, which creates a SciChartPolarSurface with angular and radial axes. React hooks manage state for the pole view preference (North/South) and geographic data loading.

Features and Capabilities

The component includes view toggle buttons that update the chart's flippedCoordinates property. Data is fetched asynchronously and processed using the same triangulation algorithm as the JavaScript version. The implementation leverages React's lifecycle management for clean resource disposal.

Integration and Best Practices

The example demonstrates proper integration of SciChart with React's state management and effect hooks. The SciChartReact component handles WASM context and surface lifecycle automatically.

react Chart Examples & Demos

See Also: Polar Charts (21 Demos)

React Polar Line Chart | React Charts | SciChart.js Demo

React Polar Line Chart

Explore the React Polar Line Chart example to create data labels, line interpolation, gradient palette stroke and startup animations. Try the SciChart Demo.

React Polar Spline Line Chart | React Charts | SciChart.js

React Polar Spline Line Chart

Try the React Polar Spline Line Chart example to see SciChart's GPU-accelerated rendering in action. Choose a cubic spline or polar interpolation. View demo.

React Multi-Cycle Polar Line | React Charts | SciChart.js

React Multi Cycle-Polar Line Example

Create a React Multi-Cycle Polar Chart to plot data over multiple cycles and visualize patterns over time. This example shows surface temperature by month.

React Polar Column Chart | React Polar Bar Chart | SciChart

React Polar Column | React Polar Bar

Try the React Polar Bar Chart example to render bars in a polar layout with gradient fills and animations. Use SciChart for seamless integration with React.

React Polar Column Category Chart | SciChart.js Demo

React Polar Column Category Chart

Create a React Polar Colum Category chart visualizing UK consumer price changes. Try the demo with a custom positive/negative threshold fill and stroke.

React Polar Range Column Chart | React Charts | SciChart.js

React Polar Range Column Chart

Create a React Polar Range Column Chart with SciChart. This example displays monthly minimum and maximum temperatures within a Polar layout. Try the demo.

React Windrose Plot | React Polar Stacked Radial Column Chart

React Windrose Plot | React Polar Stacked Radial Column Chart

View the React Windrose Chart example to display directional data with stacked columns in a polar layout. Try the polar chart demo with customizable labels.

React Polar Sunburst Chart | React Charts | SciChart.js

React Polar Sunburst Chart

See the React Sunburst Chart example with multiple levels, smooth animation transitions and dynamically updating segment colors. Try the SciChart demo.

React Polar Radial Column Chart | React Charts | SciChart.js

React Polar Radial Column Chart

View the React Radial Column Chart example to see the difference that SciChart has to offer. Switch radial and angular axes and add interactive modifiers.

React Stacked Radial Column Chart | Stacked Radial Bar Chart

React Stacked Radial Column Chart | Stacked Radial Bar Chart

This React Stacked Radial Bar Chart example shows Olympic medal data by country. Try the demo for yourself with async initialization and theme application.

React Polar Area Chart | Polar Mountain Chart | SciChart

React Polar Area Chart | Polar Mountain Chart

The React Polar Area Chart example, also known as Nightingale Rose Chart, renders an area series with polar coordinates with interactive legend controls.

React Polar Stacked Radial Mountain Chart | SciChart.js

React Polar Stacked Radial Mountain Chart

Try the React Stacked Radial Mountain Chart example to show multiple datasets on a polar layout with a stacked mountain series and animated transitions.

React Polar Band | Polar Error Bands Chart | SciChart.js

React Polar Band | Polar Error Bands Chart

Create a React Polar Chart with regular and interpolated error bands. Enhance a standard chart with shaded areas to show upper and lower data boundaries.

React Polar Scatter Chart | React Charts | SciChart.js Demo

React Polar Scatter Chart

Build a React Polar Scatter Chart with this example to render multiple scatter series on radial and angular axes. Try the flexible SciChart demo today.

React Polar Radar Chart | Spider Radar Chart | SciChart

React Polar Radar Chart

View the React Polar Radar Chart example. Also known as the Spider Radar Chart, view the scalability and stability that SciChart has to offer. Try demo.

React Polar Gauge Chart | React Circular Gauge | SciChart

React Gauge Charts

Create React Gauge Charts, including a React Circular Gauge Dashboard, with React-friendly initialization and responsive design. Give the SciChart demo a go.

React Arc Gauge & FIFO Scrolling Charts Dashboard | SciChart

React Arc Gauge & FIFO Scrolling Charts Dashboard Example

View React Arc Gauge Charts alongside FIFO Scrolling Charts, all on the same dashboard with real-time, high-performance data rendering. Try the demo.

React Polar Uniform Heatmap Chart | SciChart.js Demo

React Polar Uniform Heatmap Chart

Try SciChart's React Polar Heatmap example to combine a polar heatmap with a legend component. Supports responsive design and chart and legend separation.

React Polar Heatmap | B-Mode Image Ultrasound | Medical Heatmap

React Polar Heatmap | B-Mode Image Ultrasound | Medical Heatmap

No description available for this example yet

React Polar Partial Arc | React Charts | SciChart.js Demo

React Polar Partial Arc

Create a React Polar Partial Arc that bends from a full Polar Circle to a Cartesian-like arc. Try the demo to display an arc segment with Polar coordinates.

React Polar Axis Label Modes | React Charts | SciChart.js

React Polar Axis Label Modes

Create a React Polar Axis Label with SciChart. This demo shows the various label modes for Polar Axes – all optimised for pan, zoom, and mouse wheel.

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL.