Skip to content

Commit

Permalink
Merge pull request #58 from sgratzl/release/v4.3.0
Browse files Browse the repository at this point in the history
Release v4.3.0
  • Loading branch information
sgratzl authored Sep 16, 2023
2 parents b44ba7a + 2a84158 commit 2d227f6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
5 changes: 4 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export default defineConfig({
sidebar: [
{
text: 'Examples',
items: [{ text: 'Basic', link: '/examples/' }],
items: [
{ text: 'Basic', link: '/examples/' },
{ text: 'Stroke', link: '/examples/stroke' },
],
},
{
text: 'API',
Expand Down
15 changes: 15 additions & 0 deletions docs/examples/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,18 @@ export const config: ChartConfiguration<'wordCloud'> = {
data,
};
// #endregion config

// #region stroke
export const stroke: ChartConfiguration<'wordCloud'> = {
type: 'wordCloud',
data,
options: {
elements: {
word: {
strokeStyle: 'red',
strokeWidth: 8,
},
},
},
};
// #endregion stroke
28 changes: 28 additions & 0 deletions docs/examples/stroke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Stroke
---

# Stroke

<script setup>
import {stroke} from './basic';
</script>

## Word Cloud

<div style="height: 500px; max-height: 500px">
<WordCloudChart
:options="stroke.options"
:data="stroke.data"
/>
</div>

### Code

:::code-group

<<< ./basic.ts#stroke [config]

<<< ./basic.ts#data [data]

:::
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chartjs-chart-wordcloud",
"description": "Chart.js module for word clouds",
"version": "4.2.4",
"version": "4.3.0",
"author": {
"name": "Samuel Gratzl",
"email": "[email protected]",
Expand Down
22 changes: 18 additions & 4 deletions src/elements/WordElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { Element, FontSpec, VisualElement, ScriptableAndArrayOptions, Scriptable
import { toFont } from 'chart.js/helpers';

export interface IWordElementOptions extends FontSpec, Record<string, unknown> {
color: string;
color: CanvasRenderingContext2D['fillStyle'];
/**
* CanvasContext2D.strokeStyle config for rendering a stroke around the text
* @default undefined
*/
strokeStyle: string;
strokeStyle: CanvasRenderingContext2D['strokeStyle'];
/**
* CanvasContext2D.lineWith for stroke
* @default undefined
*/
strokeWidth?: CanvasRenderingContext2D['lineWidth'];
/**
* rotation of the word
* @default undefined then it will be randomly derived given the other constraints
Expand Down Expand Up @@ -39,7 +44,7 @@ export interface IWordElementHoverOptions {
/**
* hover variant of color
*/
hoverColor: string;
hoverColor: CanvasRenderingContext2D['fillStyle'];
/**
* hover variant of size
*/
Expand All @@ -56,7 +61,12 @@ export interface IWordElementHoverOptions {
* hover variant of stroke style
* @default undefined
*/
hoverStrokeStyle: string;
hoverStrokeStyle: CanvasRenderingContext2D['strokeStyle'];
/**
* hover variant of stroke width
* @default undefined
*/
hoverStrokeWidth?: CanvasRenderingContext2D['lineWidth'];
}

export interface IWordElementProps {
Expand All @@ -81,6 +91,7 @@ export class WordElement extends Element<IWordElementProps, IWordElementOptions>
rotationSteps: 2,
padding: 1,
strokeStyle: undefined,
strokeWidth: undefined,
size: (ctx) => {
const v = (ctx.parsed as unknown as { y: number }).y;
return v;
Expand Down Expand Up @@ -174,6 +185,9 @@ export class WordElement extends Element<IWordElementProps, IWordElementOptions>
// ctx.strokeRect(-props.width / 2, -props.height / 2, props.width, props.height);
ctx.rotate((options.rotate / 180) * Math.PI);
if (options.strokeStyle) {
if (options.strokeWidth != null) {
ctx.lineWidth = options.strokeWidth;
}
ctx.strokeStyle = options.strokeStyle;
ctx.strokeText(props.text, 0, 0);
}
Expand Down

0 comments on commit 2d227f6

Please sign in to comment.