@opendata-ai/openchart-vanilla 2.4.0 → 2.6.0
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.js +19 -41
- package/dist/index.js.map +1 -1
- package/dist/styles.css +757 -0
- package/package.json +7 -4
- package/src/__tests__/svg-renderer.test.ts +19 -22
- package/src/svg-renderer.ts +30 -52
package/dist/index.js
CHANGED
|
@@ -2352,6 +2352,9 @@ function renderLineMark(mark, index) {
|
|
|
2352
2352
|
if (mark.strokeDasharray) {
|
|
2353
2353
|
path.setAttribute("stroke-dasharray", mark.strokeDasharray);
|
|
2354
2354
|
}
|
|
2355
|
+
if (mark.opacity != null) {
|
|
2356
|
+
path.setAttribute("opacity", String(mark.opacity));
|
|
2357
|
+
}
|
|
2355
2358
|
g.appendChild(path);
|
|
2356
2359
|
}
|
|
2357
2360
|
if (mark.label?.visible) {
|
|
@@ -2788,48 +2791,17 @@ var BRAND_FONT_SIZE = 20;
|
|
|
2788
2791
|
var BRAND_MIN_WIDTH2 = 120;
|
|
2789
2792
|
var BRAND_URL = "https://tryopendata.ai";
|
|
2790
2793
|
var XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
2791
|
-
function
|
|
2794
|
+
function renderBrand(parent, layout) {
|
|
2795
|
+
if (layout.dimensions.width < BRAND_MIN_WIDTH2) return;
|
|
2792
2796
|
const { width } = layout.dimensions;
|
|
2793
2797
|
const padding = layout.theme.spacing.padding;
|
|
2794
2798
|
const rightEdge = width - padding;
|
|
2799
|
+
const fill = layout.theme.colors.axis;
|
|
2795
2800
|
const { chrome } = layout;
|
|
2796
2801
|
const xAxisExtent = computeXAxisExtent(layout);
|
|
2797
2802
|
const bottomOffset = layout.area.y + layout.area.height + xAxisExtent;
|
|
2798
2803
|
const firstBottom = chrome.source ?? chrome.byline ?? chrome.footer;
|
|
2799
2804
|
const chromeY = firstBottom ? bottomOffset + firstBottom.y : bottomOffset + layout.theme.spacing.chartToFooter;
|
|
2800
|
-
const y = chromeY + BRAND_FONT_SIZE;
|
|
2801
|
-
const dataWidth = estimateTextWidth("Data", BRAND_FONT_SIZE, 600);
|
|
2802
|
-
const dataX = rightEdge - dataWidth;
|
|
2803
|
-
const openX = dataX;
|
|
2804
|
-
return { openX, dataX, y, fill: layout.theme.colors.axis };
|
|
2805
|
-
}
|
|
2806
|
-
function renderBrandOpen(parent, layout) {
|
|
2807
|
-
if (layout.dimensions.width < BRAND_MIN_WIDTH2) return;
|
|
2808
|
-
const { openX, y, fill } = brandPosition(layout);
|
|
2809
|
-
const a = createSVGElement("a");
|
|
2810
|
-
a.setAttribute("href", BRAND_URL);
|
|
2811
|
-
a.setAttributeNS(XLINK_NS, "xlink:href", BRAND_URL);
|
|
2812
|
-
a.setAttribute("target", "_blank");
|
|
2813
|
-
a.setAttribute("rel", "noopener");
|
|
2814
|
-
a.setAttribute("class", "viz-axis-ref");
|
|
2815
|
-
const text = createSVGElement("text");
|
|
2816
|
-
setAttrs(text, {
|
|
2817
|
-
x: openX,
|
|
2818
|
-
y,
|
|
2819
|
-
"font-family": layout.theme.fonts.family,
|
|
2820
|
-
"font-size": BRAND_FONT_SIZE,
|
|
2821
|
-
"font-weight": 500,
|
|
2822
|
-
"text-anchor": "end",
|
|
2823
|
-
"fill-opacity": 0.55
|
|
2824
|
-
});
|
|
2825
|
-
text.style.setProperty("fill", fill);
|
|
2826
|
-
text.textContent = "Open";
|
|
2827
|
-
a.appendChild(text);
|
|
2828
|
-
parent.appendChild(a);
|
|
2829
|
-
}
|
|
2830
|
-
function renderBrandData(parent, layout) {
|
|
2831
|
-
if (layout.dimensions.width < BRAND_MIN_WIDTH2) return;
|
|
2832
|
-
const { dataX, y, fill } = brandPosition(layout);
|
|
2833
2805
|
const a = createSVGElement("a");
|
|
2834
2806
|
a.setAttribute("href", BRAND_URL);
|
|
2835
2807
|
a.setAttributeNS(XLINK_NS, "xlink:href", BRAND_URL);
|
|
@@ -2838,16 +2810,23 @@ function renderBrandData(parent, layout) {
|
|
|
2838
2810
|
a.setAttribute("class", "viz-chrome-ref");
|
|
2839
2811
|
const text = createSVGElement("text");
|
|
2840
2812
|
setAttrs(text, {
|
|
2841
|
-
x:
|
|
2842
|
-
y,
|
|
2813
|
+
x: rightEdge,
|
|
2814
|
+
y: chromeY,
|
|
2843
2815
|
"font-family": layout.theme.fonts.family,
|
|
2844
2816
|
"font-size": BRAND_FONT_SIZE,
|
|
2845
|
-
"
|
|
2846
|
-
"
|
|
2817
|
+
"text-anchor": "end",
|
|
2818
|
+
"dominant-baseline": "hanging",
|
|
2847
2819
|
"fill-opacity": 0.55
|
|
2848
2820
|
});
|
|
2849
2821
|
text.style.setProperty("fill", fill);
|
|
2850
|
-
|
|
2822
|
+
const openSpan = createSVGElement("tspan");
|
|
2823
|
+
openSpan.setAttribute("font-weight", "500");
|
|
2824
|
+
openSpan.textContent = "Open";
|
|
2825
|
+
text.appendChild(openSpan);
|
|
2826
|
+
const dataSpan = createSVGElement("tspan");
|
|
2827
|
+
dataSpan.setAttribute("font-weight", "600");
|
|
2828
|
+
dataSpan.textContent = "Data";
|
|
2829
|
+
text.appendChild(dataSpan);
|
|
2851
2830
|
a.appendChild(text);
|
|
2852
2831
|
parent.appendChild(a);
|
|
2853
2832
|
}
|
|
@@ -2891,9 +2870,8 @@ function renderChartSVG(layout, container) {
|
|
|
2891
2870
|
svg.appendChild(clippedGroup);
|
|
2892
2871
|
renderAnnotations(svg, layout);
|
|
2893
2872
|
renderLegend(svg, layout.legend);
|
|
2894
|
-
renderBrandOpen(svg, layout);
|
|
2895
2873
|
renderChrome(svg, layout);
|
|
2896
|
-
|
|
2874
|
+
renderBrand(svg, layout);
|
|
2897
2875
|
container.appendChild(svg);
|
|
2898
2876
|
return svg;
|
|
2899
2877
|
}
|