@pushwoosh/kit-charts 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,18 +74,16 @@ function toCells(ctx) {
74
74
  }, []);
75
75
  }
76
76
  const fillOf = (ctx, cell, hovered) => {
77
- var _ctx$scales$color, _ctx$series$states;
78
- const scaled = cell.point.value === null ? undefined : (_ctx$scales$color = ctx.scales.color) === null || _ctx$scales$color === void 0 ? void 0 : _ctx$scales$color.map(cell.point.value);
77
+ const scaled = cell.point.value === null ? undefined : ctx.scales.color?.map(cell.point.value);
79
78
  const base = cell.point.color ?? scaled ?? ctx.color;
80
79
  if (!hovered) {
81
80
  return base;
82
81
  }
83
- return brighten(base, ((_ctx$series$states = ctx.series.states) === null || _ctx$series$states === void 0 || (_ctx$series$states = _ctx$series$states.hover) === null || _ctx$series$states === void 0 ? void 0 : _ctx$series$states.brightness) ?? DEFAULT_HOVER_BRIGHTNESS);
82
+ return brighten(base, ctx.series.states?.hover?.brightness ?? DEFAULT_HOVER_BRIGHTNESS);
84
83
  };
85
84
  const labelX = (ctx, cell) => {
86
- var _ctx$series$dataLabel, _ctx$series$dataLabel2;
87
- const padding = ((_ctx$series$dataLabel = ctx.series.dataLabels) === null || _ctx$series$dataLabel === void 0 ? void 0 : _ctx$series$dataLabel.padding) ?? VALUE_LABEL_GAP;
88
- const align = (_ctx$series$dataLabel2 = ctx.series.dataLabels) === null || _ctx$series$dataLabel2 === void 0 ? void 0 : _ctx$series$dataLabel2.align;
85
+ const padding = ctx.series.dataLabels?.padding ?? VALUE_LABEL_GAP;
86
+ const align = ctx.series.dataLabels?.align;
89
87
  if (align === 'left') {
90
88
  return cell.x + padding;
91
89
  }
@@ -117,12 +115,11 @@ export const heatmap = {
117
115
  };
118
116
  },
119
117
  render: ctx => {
120
- var _ctx$hovered;
121
118
  const cells = toCells(ctx);
122
119
  if (!cells.length) {
123
120
  return null;
124
121
  }
125
- const hoveredIndex = (_ctx$hovered = ctx.hovered) === null || _ctx$hovered === void 0 ? void 0 : _ctx$hovered.pointIndex;
122
+ const hoveredIndex = ctx.hovered?.pointIndex;
126
123
  const borderWidth = ctx.series.borderWidth ?? 0;
127
124
  const radius = ctx.series.borderRadius;
128
125
  return _jsxs("g", {
@@ -11,14 +11,13 @@ export const line = {
11
11
  },
12
12
  extendDomain: (_series, acc) => acc,
13
13
  render: ctx => {
14
- var _ctx$hovered, _ctx$series$marker;
15
14
  const slots = projectSeries(ctx);
16
15
  const projected = drawable(slots);
17
16
  if (!projected.length) {
18
17
  return null;
19
18
  }
20
19
  const color = ctx.color;
21
- const hoveredIndex = (_ctx$hovered = ctx.hovered) === null || _ctx$hovered === void 0 ? void 0 : _ctx$hovered.pointIndex;
20
+ const hoveredIndex = ctx.hovered?.pointIndex;
22
21
  const hovered = hoveredIndex === undefined ? undefined : projected.find(({
23
22
  point
24
23
  }) => point.index === hoveredIndex);
@@ -37,7 +36,7 @@ export const line = {
37
36
  }), hovered ? _jsx("circle", {
38
37
  cx: hovered.px,
39
38
  cy: hovered.py,
40
- r: ((_ctx$series$marker = ctx.series.marker) === null || _ctx$series$marker === void 0 || (_ctx$series$marker = _ctx$series$marker.states) === null || _ctx$series$marker === void 0 || (_ctx$series$marker = _ctx$series$marker.hover) === null || _ctx$series$marker === void 0 ? void 0 : _ctx$series$marker.radius) ?? 4,
39
+ r: ctx.series.marker?.states?.hover?.radius ?? 4,
41
40
  fill: color,
42
41
  stroke: "#FFFFFF",
43
42
  strokeWidth: 2
package/series/pie/pie.js CHANGED
@@ -95,11 +95,10 @@ function Labels({
95
95
  geometry
96
96
  }) {
97
97
  const labels = ctx.series.dataLabels;
98
- if (!(labels !== null && labels !== void 0 && labels.enabled)) {
98
+ if (!labels?.enabled) {
99
99
  return null;
100
100
  }
101
101
  return slices.filter(slice => !slice.hidden).map(slice => {
102
- var _labels$style, _labels$style2, _labels$style3, _labels$style4;
103
102
  const mid = (slice.from + slice.to) / 2;
104
103
  const at = polar(geometry.cx, geometry.cy, geometry.outer + LABEL_OFFSET, mid);
105
104
  const text = labels.formatter ? labels.formatter({
@@ -116,10 +115,10 @@ function Labels({
116
115
  y: at.y,
117
116
  textAnchor: Math.cos(mid) < 0 ? 'end' : 'start',
118
117
  dominantBaseline: "middle",
119
- fill: labels.color ?? ((_labels$style = labels.style) === null || _labels$style === void 0 ? void 0 : _labels$style.color),
120
- fontFamily: (_labels$style2 = labels.style) === null || _labels$style2 === void 0 ? void 0 : _labels$style2.fontFamily,
121
- fontSize: ((_labels$style3 = labels.style) === null || _labels$style3 === void 0 ? void 0 : _labels$style3.fontSize) ?? '11px',
122
- fontWeight: (_labels$style4 = labels.style) === null || _labels$style4 === void 0 ? void 0 : _labels$style4.fontWeight,
118
+ fill: labels.color ?? labels.style?.color,
119
+ fontFamily: labels.style?.fontFamily,
120
+ fontSize: labels.style?.fontSize ?? '11px',
121
+ fontWeight: labels.style?.fontWeight,
123
122
  children: text
124
123
  }, `label-${slice.point.index}`);
125
124
  });
@@ -134,7 +133,6 @@ function Labels({
134
133
  function Slices({
135
134
  ctx
136
135
  }) {
137
- var _ctx$hovered;
138
136
  const slices = toSlices(ctx);
139
137
  const alive = ctx.points.some(point => !ctx.hiddenPoints.has(point.index));
140
138
  const targets = [...slices.flatMap(slice => [slice.from, slice.to]), ctx.hidden || !alive ? 0 : 1];
@@ -144,7 +142,7 @@ function Slices({
144
142
  }
145
143
  const radiusScale = tweened[tweened.length - 1] ?? 1;
146
144
  const geometry = geometryOf(ctx, radiusScale);
147
- const hovered = (_ctx$hovered = ctx.hovered) === null || _ctx$hovered === void 0 ? void 0 : _ctx$hovered.pointIndex;
145
+ const hovered = ctx.hovered?.pointIndex;
148
146
  const drawn = slices.map((slice, index) => ({
149
147
  ...slice,
150
148
  from: tweened[index * 2] ?? slice.from,
@@ -13,11 +13,11 @@ export const labelAnchor = align => {
13
13
  return 'middle';
14
14
  };
15
15
  const textProps = style => ({
16
- fontFamily: style === null || style === void 0 ? void 0 : style.fontFamily,
17
- fontSize: style === null || style === void 0 ? void 0 : style.fontSize,
18
- fontWeight: style === null || style === void 0 ? void 0 : style.fontWeight,
19
- fontStyle: style === null || style === void 0 ? void 0 : style.fontStyle,
20
- paintOrder: (style === null || style === void 0 ? void 0 : style.textOutline) === 'none' ? undefined : 'stroke'
16
+ fontFamily: style?.fontFamily,
17
+ fontSize: style?.fontSize,
18
+ fontWeight: style?.fontWeight,
19
+ fontStyle: style?.fontStyle,
20
+ paintOrder: style?.textOutline === 'none' ? undefined : 'stroke'
21
21
  });
22
22
  /** No formatter and no format string: the chart's own number rule prints it. */
23
23
  const defaultLabel = (ctx, format, y) => {
@@ -44,7 +44,7 @@ export function DataLabels({
44
44
  positionOf
45
45
  }) {
46
46
  const options = ctx.series.dataLabels;
47
- if (!(options !== null && options !== void 0 && options.enabled)) {
47
+ if (!options?.enabled) {
48
48
  return null;
49
49
  }
50
50
  const turbo = ctx.series.turboThreshold;
@@ -110,12 +110,12 @@ export function DataLabels({
110
110
  x: at.x,
111
111
  y: y,
112
112
  textAnchor: anchor,
113
- fill: options.color ?? (style === null || style === void 0 ? void 0 : style.color) ?? DEFAULT_TEXT_COLOR,
113
+ fill: options.color ?? style?.color ?? DEFAULT_TEXT_COLOR,
114
114
  ...textProps(style),
115
115
  children: lines && lines.length > 1 ? lines.map((text, index) => _jsx("tspan", {
116
116
  x: at.x,
117
117
  dy: index === 0 ? 0 : textHeight(secondary ?? style),
118
- fill: index === 0 ? undefined : secondary === null || secondary === void 0 ? void 0 : secondary.color,
118
+ fill: index === 0 ? undefined : secondary?.color,
119
119
  ...(index === 0 ? {} : textProps(secondary)),
120
120
  children: text
121
121
  }, `line-${index}`)) : content
@@ -1,16 +1,16 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- const markerRadius = marker => (marker === null || marker === void 0 ? void 0 : marker.radius) ?? (marker !== null && marker !== void 0 && marker.width ? marker.width / 2 : 3);
2
+ const markerRadius = marker => marker?.radius ?? (marker?.width ? marker.width / 2 : 3);
3
3
  export function Markers({
4
4
  marker,
5
5
  projected,
6
6
  color
7
7
  }) {
8
- if ((marker === null || marker === void 0 ? void 0 : marker.enabled) === false || (marker === null || marker === void 0 ? void 0 : marker.symbol) === 'none') {
8
+ if (marker?.enabled === false || marker?.symbol === 'none') {
9
9
  return null;
10
10
  }
11
11
  const radius = markerRadius(marker);
12
- const fill = (marker === null || marker === void 0 ? void 0 : marker.fillColor) ?? color;
13
- const square = (marker === null || marker === void 0 ? void 0 : marker.symbol) === 'square';
12
+ const fill = marker?.fillColor ?? color;
13
+ const square = marker?.symbol === 'square';
14
14
  return projected.map(({
15
15
  point,
16
16
  px,
@@ -21,14 +21,14 @@ export function Markers({
21
21
  width: radius * 2,
22
22
  height: radius * 2,
23
23
  fill: fill,
24
- stroke: marker === null || marker === void 0 ? void 0 : marker.lineColor,
25
- strokeWidth: marker === null || marker === void 0 ? void 0 : marker.lineWidth
24
+ stroke: marker?.lineColor,
25
+ strokeWidth: marker?.lineWidth
26
26
  }, `m-${point.index}`) : _jsx("circle", {
27
27
  cx: px,
28
28
  cy: py,
29
29
  r: radius,
30
30
  fill: fill,
31
- stroke: marker === null || marker === void 0 ? void 0 : marker.lineColor,
32
- strokeWidth: marker === null || marker === void 0 ? void 0 : marker.lineWidth
31
+ stroke: marker?.lineColor,
32
+ strokeWidth: marker?.lineWidth
33
33
  }, `m-${point.index}`));
34
34
  }