@diagrammo/dgmo 0.8.0 → 0.8.1

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.
package/dist/index.cjs CHANGED
@@ -5676,10 +5676,10 @@ function buildScatterOption(parsed, palette, textColor, axisLineColor, gridOpaci
5676
5676
  };
5677
5677
  let series;
5678
5678
  if (hasCategories) {
5679
- const categories = [
5679
+ const categories2 = [
5680
5680
  ...new Set(points.map((p) => p.category).filter(Boolean))
5681
5681
  ];
5682
- series = categories.map((category, catIndex) => {
5682
+ series = categories2.map((category, catIndex) => {
5683
5683
  const categoryPoints = points.filter((p) => p.category === category);
5684
5684
  const catColor = parsed.categoryColors?.[category] ?? colors[catIndex % colors.length];
5685
5685
  const data = categoryPoints.map((p) => ({
@@ -5746,18 +5746,18 @@ function buildScatterOption(parsed, palette, textColor, axisLineColor, gridOpaci
5746
5746
  const axisYMax = Math.ceil(yMax + yPad);
5747
5747
  const gridLeft = parsed.ylabel ? 12 : 3;
5748
5748
  const gridRight = 4;
5749
- const gridBottom = parsed.xlabel ? 10 : 3;
5749
+ const gridBottom = hasCategories ? 15 : parsed.xlabel ? 10 : 3;
5750
5750
  const gridTop = parsed.title ? 15 : 5;
5751
5751
  let graphic;
5752
5752
  if (showLabels && points.length > 0) {
5753
5753
  const labelPoints = [];
5754
5754
  if (hasCategories) {
5755
- const categories = [
5755
+ const categories2 = [
5756
5756
  ...new Set(points.map((p) => p.category).filter(Boolean))
5757
5757
  ];
5758
5758
  for (let idx = 0; idx < points.length; idx++) {
5759
5759
  const pt = points[idx];
5760
- const catIndex = pt.category ? categories.indexOf(pt.category) : -1;
5760
+ const catIndex = pt.category ? categories2.indexOf(pt.category) : -1;
5761
5761
  const catColor = pt.category ? parsed.categoryColors?.[pt.category] ?? colors[catIndex % colors.length] : colors[idx % colors.length];
5762
5762
  const color = pt.color ?? catColor;
5763
5763
  const { px, py } = dataToPixel(
@@ -5806,9 +5806,12 @@ function buildScatterOption(parsed, palette, textColor, axisLineColor, gridOpaci
5806
5806
  bg
5807
5807
  );
5808
5808
  }
5809
+ const categories = hasCategories ? [...new Set(points.map((p) => p.category).filter(Boolean))] : [];
5810
+ const legendConfig = categories.length > 0 ? { data: categories, bottom: 10, textStyle: { color: textColor } } : void 0;
5809
5811
  return {
5810
5812
  ...CHART_BASE,
5811
5813
  title: titleConfig,
5814
+ ...legendConfig && { legend: legendConfig },
5812
5815
  tooltip,
5813
5816
  grid: {
5814
5817
  left: `${gridLeft}%`,
@@ -6186,11 +6189,6 @@ function buildBarOption(parsed, textColor, axisLineColor, splitLineColor, gridOp
6186
6189
  return {
6187
6190
  ...CHART_BASE,
6188
6191
  title: titleConfig,
6189
- tooltip: {
6190
- trigger: "axis",
6191
- ...tooltipTheme,
6192
- axisPointer: { type: "shadow" }
6193
- },
6194
6192
  grid: makeChartGrid({ xLabel, yLabel, hasTitle: !!parsed.title }),
6195
6193
  xAxis: isHorizontal ? valueAxis : categoryAxis,
6196
6194
  yAxis: isHorizontal ? categoryAxis : valueAxis,
@@ -6525,11 +6523,6 @@ function buildBarStackedOption(parsed, textColor, axisLineColor, splitLineColor,
6525
6523
  return {
6526
6524
  ...CHART_BASE,
6527
6525
  title: titleConfig,
6528
- tooltip: {
6529
- trigger: "axis",
6530
- ...tooltipTheme,
6531
- axisPointer: { type: "shadow" }
6532
- },
6533
6526
  legend: {
6534
6527
  data: seriesNames,
6535
6528
  bottom: 10,
@@ -24771,6 +24764,14 @@ function parseVisualization(content, palette) {
24771
24764
  if (result.type === "wordcloud") {
24772
24765
  if (colonIndex === -1 && !line10.includes(" ")) {
24773
24766
  result.words.push({ text: line10, weight: 10, lineNumber });
24767
+ } else if (colonIndex === -1) {
24768
+ const lastSpace = line10.lastIndexOf(" ");
24769
+ const maybeWeight = lastSpace >= 0 ? parseFloat(line10.substring(lastSpace + 1)) : NaN;
24770
+ if (lastSpace >= 0 && !isNaN(maybeWeight) && maybeWeight > 0) {
24771
+ result.words.push({ text: line10.substring(0, lastSpace).trim(), weight: maybeWeight, lineNumber });
24772
+ } else {
24773
+ freeformLines.push(line10);
24774
+ }
24774
24775
  } else {
24775
24776
  freeformLines.push(line10);
24776
24777
  }
@@ -26630,7 +26631,7 @@ function renderWordCloud(container, parsed, palette, _isDark, onClickItem, expor
26630
26631
  const range = maxWeight - minWeight || 1;
26631
26632
  const fontSize = (weight) => {
26632
26633
  const t = (weight - minWeight) / range;
26633
- return minSize + t * (maxSize - minSize);
26634
+ return minSize + Math.sqrt(t) * (maxSize - minSize);
26634
26635
  };
26635
26636
  const rotateFn = getRotateFn(cloudOptions.rotate);
26636
26637
  renderChartTitle(svg, title, parsed.titleLineNumber, width, textColor, onClickItem);
@@ -26638,7 +26639,7 @@ function renderWordCloud(container, parsed, palette, _isDark, onClickItem, expor
26638
26639
  "transform",
26639
26640
  `translate(${width / 2},${titleHeight + cloudHeight / 2})`
26640
26641
  );
26641
- (0, import_d3_cloud.default)().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(4).rotate(rotateFn).fontSize((d) => d.size).font(FONT_FAMILY).on("end", (layoutWords) => {
26642
+ (0, import_d3_cloud.default)().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(2).rotate(rotateFn).fontSize((d) => d.size).font(FONT_FAMILY).on("end", (layoutWords) => {
26642
26643
  g.selectAll("text").data(layoutWords).join("text").style("font-size", (d) => `${d.size}px`).style("font-family", FONT_FAMILY).style("font-weight", "600").style("fill", (_d, i) => colors[i % colors.length]).style(
26643
26644
  "cursor",
26644
26645
  (d) => onClickItem && d.lineNumber ? "pointer" : "default"
@@ -26680,7 +26681,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
26680
26681
  const range = maxWeight - minWeight || 1;
26681
26682
  const fontSize = (weight) => {
26682
26683
  const t = (weight - minWeight) / range;
26683
- return minSize + t * (maxSize - minSize);
26684
+ return minSize + Math.sqrt(t) * (maxSize - minSize);
26684
26685
  };
26685
26686
  const rotateFn = getRotateFn(cloudOptions.rotate);
26686
26687
  const svg = d3Selection13.select(container).append("svg").attr("width", width).attr("height", height).style("background", bgColor);
@@ -26689,7 +26690,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
26689
26690
  "transform",
26690
26691
  `translate(${width / 2},${titleHeight + cloudHeight / 2})`
26691
26692
  );
26692
- (0, import_d3_cloud.default)().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(4).rotate(rotateFn).fontSize((d) => d.size).font(FONT_FAMILY).on("end", (layoutWords) => {
26693
+ (0, import_d3_cloud.default)().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(2).rotate(rotateFn).fontSize((d) => d.size).font(FONT_FAMILY).on("end", (layoutWords) => {
26693
26694
  g.selectAll("text").data(layoutWords).join("text").style("font-size", (d) => `${d.size}px`).style("font-family", FONT_FAMILY).style("font-weight", "600").style("fill", (_d, i) => colors[i % colors.length]).attr("text-anchor", "middle").attr(
26694
26695
  "transform",
26695
26696
  (d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`