forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ScatterTracer and ScatterRenderer (algorithm-visualizer#298)
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "~common/stylesheet/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react' | ||
import {Scatter} from 'react-chartjs-2' | ||
import Array2DRenderer from '../Array2DRenderer' | ||
|
||
const convertToObjectArray = ([x, y]) => ({ x, y }) | ||
const colors = ['white', 'green', 'blue', 'red', 'yellow', 'cyan'] | ||
|
||
class ScatterRenderer extends Array2DRenderer { | ||
renderData() { | ||
const { data } = this.props.data | ||
|
||
const datasets = data.map((series, index) => ( | ||
{ | ||
backgroundColor: colors[index], | ||
data: series.map(s => convertToObjectArray(s.value)), | ||
label: Math.random(), | ||
radius: (index + 1) * 2, | ||
})) | ||
|
||
const chartData = { | ||
datasets, | ||
} | ||
|
||
return <Scatter data={chartData} options={{ | ||
legend: false, | ||
animation: false, | ||
layout: { | ||
padding: { | ||
left: 20, | ||
right: 20, | ||
top: 20, | ||
bottom: 20, | ||
}, | ||
}, | ||
scales: { | ||
yAxes: [ | ||
{ | ||
ticks: { | ||
beginAtZero: false, | ||
}, | ||
}], | ||
xAxes: [ | ||
{ | ||
ticks: { | ||
beginAtZero: false, | ||
}, | ||
}], | ||
}, | ||
}}/> | ||
} | ||
} | ||
|
||
export default ScatterRenderer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Array2DTracer } from 'core/tracers'; | ||
import { ScatterRenderer } from 'core/renderers'; | ||
|
||
class ScatterTracer extends Array2DTracer { | ||
getRendererClass() { | ||
return ScatterRenderer; | ||
} | ||
} | ||
|
||
export default ScatterTracer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters