Skip to content

Commit 9f66464

Browse files
committed
fix: fix patterns vertical offset
1 parent fd2cc79 commit 9f66464

File tree

11 files changed

+47
-19
lines changed

11 files changed

+47
-19
lines changed

example/src/components/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { SelectedData } from './charts/selected-data';
2323
import { WaterfallSettings } from './settings/waterfall-settings';
2424
import { MarksSettings } from './settings/marks-settings';
2525
import { TimeseriesSettings } from './settings/timeseries-settings';
26-
import { defaultPatterns, PatternsSettings } from './settings/patterns-settings';
26+
import { examplePatterns, PatternsSettings } from './settings/patterns-settings';
2727

2828
enum ChartType {
2929
Default = 'default',
@@ -44,7 +44,7 @@ const flameChartVariants = [
4444
export const App = () => {
4545
const [treeConfig, setTreeConfig] = useState<TreeConfig>();
4646
const [stylesSettings, setStylesSettings] = useState({});
47-
const [patternsSettings, setPatternsSettings] = useState(defaultPatterns);
47+
const [patternsSettings, setPatternsSettings] = useState(examplePatterns);
4848
const [currentChart, setCurrentChart] = useState(ChartType.Default);
4949
const [isGenerating, setIsGenerating] = useState(false);
5050
const [flameChartData, setFlameChartData] = useState<FlameChartNode[] | null>(null);

example/src/components/settings/patterns-settings.module.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
display: flex;
33
flex-direction: column;
44
width: 100%;
5-
height: 500px;
5+
height: 400px;
66
padding: 8px;
77
}
88

@@ -12,10 +12,16 @@
1212

1313
.input {
1414
width: 100%;
15-
height: 400px;
15+
height: 350px;
1616
box-sizing: border-box;
1717
}
1818

19+
.select {
20+
width: 100%;
21+
margin: 8px 0;
22+
font-size: 1rem;
23+
}
24+
1925
.sectionsWrapper {
2026
flex: 1;
2127
overflow: auto;

example/src/components/settings/patterns-settings.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useCallback, useState } from 'react';
22
import styles from './patterns-settings.module.css';
33
import { Button } from '../shared/button';
4-
import { DefaultPatterns } from '../../../../src';
4+
import { defaultPatterns, DefaultPatterns } from '../../../../src';
55

6-
export const defaultPatterns: DefaultPatterns[] = [
6+
export const examplePatterns: DefaultPatterns[] = [
77
{
8-
name: 'example-stripes-pattern',
8+
name: 'example-pattern-1',
99
type: 'triangles',
1010
config: {
1111
color: 'rgb(255,206,71)',
@@ -14,7 +14,7 @@ export const defaultPatterns: DefaultPatterns[] = [
1414
},
1515
},
1616
{
17-
name: 'example-combined-pattern',
17+
name: 'example-pattern-2',
1818
type: 'combined',
1919
config: [
2020
{
@@ -66,7 +66,7 @@ export const defaultPatterns: DefaultPatterns[] = [
6666
},
6767
];
6868

69-
export const defaultPatternsNames = defaultPatterns.map((pattern) => pattern.name);
69+
export const examplePatternsNames = examplePatterns.map((pattern) => pattern.name);
7070

7171
export const PatternsSettings = ({
7272
value = [],
@@ -92,8 +92,28 @@ export const PatternsSettings = ({
9292
<div className={styles.root}>
9393
<div className={styles.sectionsWrapper}>
9494
{patterns.map(({ name, type, config }, index) => (
95-
<div key={(name || type) + index} className={styles.section}>
96-
<div className={styles.sectionHeader}>{name || type}</div>
95+
<div key={name} className={styles.section}>
96+
<div className={styles.sectionHeader}>{name}</div>
97+
type:{' '}
98+
<select
99+
value={type}
100+
className={styles.select}
101+
onChange={(e) => {
102+
const newValue = e.target.value as keyof typeof defaultPatterns;
103+
104+
setPatterns(
105+
patterns.map((pattern, i) =>
106+
i === index ? { ...pattern, type: newValue } : pattern,
107+
),
108+
);
109+
}}
110+
>
111+
{Object.keys(defaultPatterns).map((type) => (
112+
<option key={type} value={type}>
113+
{type}
114+
</option>
115+
))}
116+
</select>
97117
<textarea
98118
className={styles.input}
99119
value={config}

example/src/test-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FlameChartNode, Mark, WaterfallIntervals, WaterfallItems } from '../../src';
22
import { ChartPoints } from '../../src/plugins/utils/chart-render';
3-
import { defaultPatternsNames } from './components/settings/patterns-settings';
3+
import { examplePatternsNames } from './components/settings/patterns-settings';
44

55
const chars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
66

@@ -202,7 +202,7 @@ export const generateRandomTree = ({
202202
let currentType = types[typesCounter];
203203

204204
rootNodes.forEach((item) => {
205-
item.pattern = rndItem(defaultPatternsNames);
205+
item.pattern = rndItem(examplePatternsNames);
206206

207207
item.children?.forEach(
208208
(item) =>

src/engines/basic-render-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export class BasicRenderEngine extends EventEmitter {
350350

351351
items.forEach((rect) => {
352352
if (pattern) {
353-
pattern.setTransform(matrix.translate(rect.x * scale, 0));
353+
pattern.setTransform(matrix.translate(rect.x * scale, rect.y * scale));
354354
}
355355

356356
this.renderBlock(rect.x, rect.y, rect.w, rect.h);

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ export type {
2323
CombinedPatternConfig,
2424
DotsPatternConfig,
2525
} from './patterns';
26+
27+
export { defaultPatterns } from './patterns';

src/patterns/combined-pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const combinedPattern =
5959
return combinedPatterns[pattern.type](pattern.config as any)(engine);
6060
});
6161

62-
const height = (engine.blockHeight + 1) * scale;
62+
const height = engine.blockHeight * scale;
6363
const width = findNumber(
6464
renderedPatterns.map(({ width = 1, scale: patternScale = 1 }) => width * (scale / patternScale)),
6565
engine.width * scale,

src/patterns/dots-pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const dotsPattern =
3131
const realVerticalSpacing = verticalSpicing * scale;
3232
const realHorizontalSpacing = horizontalSpicing * scale;
3333
const width = (size + realHorizontalSpacing / 4) * scale;
34-
const height = (engine.blockHeight + 1) * scale;
34+
const height = engine.blockHeight * scale;
3535
const rowsCount = rows ? rows : Math.floor(height / (realSize + realVerticalSpacing));
3636

3737
ctx.setTransform(scale, 0, 0, scale, 0, 0);

src/patterns/gradient-pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const gradientPattern =
1010
const scale = 4;
1111

1212
const width = scale;
13-
const height = (engine.blockHeight + 1) * scale;
13+
const height = engine.blockHeight * scale;
1414

1515
ctx.setTransform(scale, 0, 0, scale, 0, 0);
1616

src/patterns/stripes-pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const stripesPattern =
2424
const scale = 4;
2525

2626
ctx.setTransform(scale, 0, 0, scale, 0, 0);
27-
canvas.height = (engine.blockHeight + 1) * scale;
27+
canvas.height = engine.blockHeight * scale;
2828

2929
const realLineWidth = lineWidth * scale;
3030
const realSpacing = spacing * scale + realLineWidth;

src/patterns/triangles-pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const trianglesPattern =
3333
const maxHeight = Math.max(...points.map(({ y }) => y));
3434

3535
const fullWidth = maxWidth + spacing * scale;
36-
const fullHeight = (engine.blockHeight + 1) * scale;
36+
const fullHeight = engine.blockHeight * scale;
3737

3838
const delta = align === 'center' ? (fullHeight - maxHeight) / 2 : align === 'top' ? 0 : fullHeight - maxHeight;
3939

0 commit comments

Comments
 (0)