Skip to content

Commit 5aaa21b

Browse files
committed
updated description, various fixes
1 parent 55f9d35 commit 5aaa21b

File tree

10 files changed

+1960
-50
lines changed

10 files changed

+1960
-50
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Custom Raw Chart(s)
1+
# Versus: a custom RAWGraphs chart
22

3-
## Install
3+
### Install
44

55
```sh
66
npm install
77
```
88

9-
## Run Sandbox
9+
### Run Sandbox
1010

1111
Develop your custom chart on your machine with livereload thanks to Webpack.
1212

@@ -16,11 +16,11 @@ npm run sandbox
1616

1717
You can find your charts at [http://localhost:9000](http://localhost:9000)
1818

19-
For an in depth guide to add a chart see [this](https://github.com/rawgraphs/rawgraphs-charts/blob/master/docs/add-a-new-chart.md)
19+
-
2020

2121
## Build
2222

23-
Build your chart to use it in RAW.
23+
Build your chart to use it in RAWGraphs.
2424

2525
```sh
2626
npm run build

example/configurations/hellochart01.js example/configurations/versus.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import versus from 'customcharts/versus'
2-
import data from '../datasets/hello.csv'
2+
import data from '../datasets/keywords.csv'
33

44
export default {
55
chart: versus,
@@ -14,5 +14,5 @@ export default {
1414
item: { value: ['keyword'] },
1515
strength: { value: ['strength'] },
1616
},
17-
visualOptions: {},
17+
visualOptions: { anticollision: false },
1818
}
File renamed without changes.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rawgraphs-versus",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Versus visual model",
55
"jsdelivr": "lib/index.umd.js",
66
"unpkg": "lib/index.umd.js",

src/versus-icon.ai

+1,837
Large diffs are not rendered by default.

src/versus/metadata.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import thumbnail from './template_thumb.svg'
2-
import icon from './template_icon.svg'
2+
import icon from './versus.svg'
33

44
export const metadata = {
55
name: 'Versus',
66
thumbnail,
77
icon,
88
id: 'customrawcharts.versus',
99
categories: ['networks'],
10-
description: 'Hello World custom RAW Chart ❤️',
11-
code: 'https://rawgraphs.io',
12-
tutorial: 'https://rawgraphs.io',
10+
description:
11+
'This chart represent groups as dots disposed on a circle. They act as attractors for the items, that will be disposed according to the streng of the link among them. Colour of items is also proprotional to the strength of the links.',
12+
code: 'https://github.com/rawgraphs/rawgraphs-versus',
13+
//tutorial: 'https://rawgraphs.io', @TODO: define how to add a tutorial
1314
}

src/versus/render.js

+42-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as d3 from 'd3'
22
import '../d3-styles.js'
3+
import { labelsOcclusion } from '@rawgraphs/rawgraphs-core'
34

45
export function render(
56
svgNode,
@@ -20,8 +21,13 @@ export function render(
2021
marginLeft,
2122
//chart
2223
nodePadding,
24+
anticollision,
2325
groupsDiameter,
2426
maxItemsDiameter,
27+
colorScale,
28+
showLabels,
29+
autoHideLabels,
30+
groupsFillColor, // @TODO: check how to expose it as option
2531
} = visualOptions
2632

2733
const margin = {
@@ -33,12 +39,25 @@ export function render(
3339

3440
const chartWidth = width - margin.right - margin.left
3541
const chartHeight = height - margin.top - margin.bottom
42+
3643
// compute radius
3744
const radius = (chartWidth < chartHeight ? chartWidth : chartHeight) / 2
3845

3946
// select the svg node
40-
const svg = d3
41-
.select(svgNode)
47+
const svg = d3.select(svgNode)
48+
49+
// add background
50+
d3.select(svgNode)
51+
.append('rect')
52+
.attr('width', width)
53+
.attr('height', height)
54+
.attr('x', 0)
55+
.attr('y', 0)
56+
.attr('fill', background)
57+
.attr('id', 'backgorund')
58+
59+
// add viz group
60+
const vizGroup = svg
4261
.append('g')
4362
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
4463
.attr('id', 'viz')
@@ -50,15 +69,6 @@ export function render(
5069
let groupNodes = graph.nodes.filter((d) => d.type == 'group')
5170
const groupNames = groupNodes.map((d) => d.name)
5271

53-
console.log(graph)
54-
console.log(d3.max(graph.nodes, (d) => d.strength))
55-
56-
// define colors
57-
let colorScale = d3
58-
.scaleOrdinal()
59-
.domain(groupNames)
60-
.range(d3.schemeCategory10)
61-
6272
// scele for edges strenghts
6373
let strengthScale = d3.scaleLinear(
6474
d3.extent(graph.edges, (d) => d.value),
@@ -97,9 +107,6 @@ export function render(
97107
d.color = d3.rgb(colr, colg, colb)
98108
})
99109

100-
// TODO: expose or remove
101-
const forceNode = d3.forceManyBody().strength(-5)
102-
103110
// define links (edges) force
104111
const forceLink = d3
105112
.forceLink(graph.edges)
@@ -127,9 +134,14 @@ export function render(
127134
const simulation = d3
128135
.forceSimulation(graph.nodes)
129136
.force('link', forceLink)
130-
.force('collisionForce', forceCollide)
131137
.on('tick', ticked)
132138

139+
// add collision force according to options
140+
141+
if (anticollision) {
142+
simulation.force('collisionForce', forceCollide)
143+
}
144+
133145
// run the simulation in background
134146
// @TODO move this to a web worker
135147
//console.log("---------------new simulation---------------")
@@ -147,7 +159,7 @@ export function render(
147159
//console.log("---------------end of simulation---------------")
148160

149161
// draw nodes
150-
const nodesLayer = svg
162+
const nodesLayer = vizGroup
151163
.append('g')
152164
.attr('id', 'labelsLayer')
153165
.attr('id', 'nodes')
@@ -160,7 +172,7 @@ export function render(
160172
nodesLayer
161173
.filter((d) => d.type == 'group')
162174
.attr('r', groupsDiameter / 2)
163-
.attr('fill', 'white')
175+
.attr('fill', 'white') //@TODO: check how to expose a single color. See https://github.com/rawgraphs/rawgraphs-core/issues/67
164176
.attr('stroke', (d) => colorScale(d.name))
165177

166178
// style item nodes
@@ -170,7 +182,7 @@ export function render(
170182
.attr('fill', (d) => d.color)
171183

172184
// add labels
173-
const labelsLayer = svg
185+
const labelsLayer = vizGroup
174186
.append('g')
175187
.attr('id', 'labelsLayer')
176188
.attr('text-anchor', 'middle')
@@ -179,7 +191,18 @@ export function render(
179191
.data(graph.nodes)
180192
.join('g')
181193

182-
labelsLayer.append('text').text((d) => d.name)
194+
// add texts according to option
195+
if (showLabels) {
196+
labelsLayer.append('text').text((d) => d.name)
197+
198+
labelsLayer.filter((d) => d.type == 'group').styles(styles.seriesLabel)
199+
labelsLayer.filter((d) => d.type == 'item').styles(styles.labelPrimary)
200+
}
201+
202+
// auto hide labels
203+
if (autoHideLabels) {
204+
labelsOcclusion(labelsLayer.selectAll('text'), (d) => sizeScale(d.strength))
205+
}
183206

184207
function ticked() {
185208
nodesLayer.attr('transform', (d) => 'translate(' + d.x + ',' + d.y + ')')

src/versus/template_icon.svg

-19
This file was deleted.

src/versus/versus.svg

+36
Loading

src/versus/visualOptions.js

+32
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ export const visualOptions = {
3333
default: 60,
3434
group: 'chart',
3535
},
36+
// groupsFillColor: {
37+
// type: 'colorScale',
38+
// label: 'Groups fill color',
39+
// dimension: 'groupsFillColor', // as called in the mapping
40+
// default: 'white',
41+
// // default: {
42+
// // scaleType: 'ordinal',
43+
// // interpolator: 'interpolateSpectral',
44+
// // },
45+
// group: 'chart',
46+
// },
3647

3748
maxItemsDiameter: {
3849
type: 'number',
@@ -41,6 +52,13 @@ export const visualOptions = {
4152
group: 'chart',
4253
},
4354

55+
anticollision: {
56+
type: 'boolean',
57+
label: 'Avoid nodes overlappings',
58+
default: true,
59+
group: 'chart',
60+
},
61+
4462
nodePadding: {
4563
type: 'number',
4664
label: 'Padding',
@@ -58,4 +76,18 @@ export const visualOptions = {
5876
},
5977
group: 'colors',
6078
},
79+
80+
showLabels: {
81+
type: 'boolean',
82+
label: 'Show labels',
83+
default: true,
84+
group: 'labels',
85+
},
86+
87+
autoHideLabels: {
88+
type: 'boolean',
89+
label: 'Auto hide labels',
90+
default: false,
91+
group: 'labels',
92+
},
6193
}

0 commit comments

Comments
 (0)