mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-15 01:15:25 +00:00
Graphs: labels keep paragraph settings and anti-aliasing when the graph is drawn again
Paragraph settings given to all of a graph label's text with text.setFormat (indents, spacing, hyphenation, Justification options, composer, direction, kashida, kinsoku, mojikumi, burasagari and the rest) and the label's anti-aliasing method were lost when the graph drew its labels again, because the graph kept only a character style for each kind of label. Each kind now also keeps its paragraph settings and anti-aliasing method, saved with the graph in its label styles, and the graph still sets each label's alignment for its place. The legend spaces its entries by the kept legend settings: Legend Across Top measures each label with its indents and spacing, both legend layouts make room for extra leading or paragraph spacing, and a label with a negative indent or negative space before moves right or down so it stays clear of its swatch and of the entry above it.
This commit is contained in:
@@ -2,7 +2,8 @@ use super::axis::{LABEL_SIZE, MAX_CATEGORY_TICKS, MAX_TICK_MARKS, one_line, rada
|
||||
use super::columns::{Allowance, ColumnArt, column_art, column_designs};
|
||||
use super::data::fmt_value;
|
||||
use super::labels::{
|
||||
Gen, Role, SHADOW_BUDGET, SHADOW_OPACITY, blank_label, filled_lines_on, label_size, label_width, polyline, recolour_text, runs, shadow_of,
|
||||
Gen, Role, SHADOW_BUDGET, SHADOW_OPACITY, blank_label, filled_lines_on, label_extra_height, label_shift, label_size, label_width, polyline,
|
||||
recolour_text, runs, shadow_of,
|
||||
};
|
||||
use super::markers::{MARKER_BUDGET, marker_cost, marker_designs};
|
||||
use super::series::{series_marks, with_series_opacity};
|
||||
@@ -901,6 +902,8 @@ impl<'a> Plot<'a> {
|
||||
|
||||
fn legend_label(&mut self, (x, y): (f64, f64), label: &str) -> Arc<Node> {
|
||||
let ls = self.ls;
|
||||
let (dx, dy) = label_shift(&self.g.label_styles, label);
|
||||
let (x, y) = (x + dx, y + dy);
|
||||
self.b.label(Role::Legend, Point::new(x + 12.0, y + 7.5 + (ls - LABEL_SIZE) * 0.35), label, Justify::Left, false)
|
||||
}
|
||||
|
||||
@@ -909,10 +912,11 @@ impl<'a> Plot<'a> {
|
||||
fn legend_across_top(&mut self) -> Vec<Arc<Node>> {
|
||||
let (g, r, ls) = (self.g, self.r, self.ls);
|
||||
let entries: Vec<(usize, String)> = (0..self.legend_series()).map(|s| (s, self.legend_text(s))).filter(|(_, l)| !blank_label(l)).collect();
|
||||
let mut rows: Vec<Vec<(usize, String, f64)>> = vec![vec![]];
|
||||
let mut rows: Vec<Vec<(usize, String, f64, f64)>> = vec![vec![]];
|
||||
let mut used = 0.0;
|
||||
for (s, label) in entries {
|
||||
let w = 12.0 + label_width(&g.label_styles, &label) + 12.0;
|
||||
let h = ls * 1.8 * label.split('|').count() as f64 + label_extra_height(&g.label_styles, &label);
|
||||
// The gap after an entry may run past the plot's edge.
|
||||
if used + w - 12.0 > r.width() && rows.last().is_some_and(|row| !row.is_empty()) {
|
||||
rows.push(vec![]);
|
||||
@@ -920,10 +924,10 @@ impl<'a> Plot<'a> {
|
||||
}
|
||||
used += w;
|
||||
if let Some(row) = rows.last_mut() {
|
||||
row.push((s, label, w));
|
||||
row.push((s, label, w, h));
|
||||
}
|
||||
}
|
||||
let height = |row: &[(usize, String, f64)]| ls * 1.8 * row.iter().map(|(_, l, _)| l.split('|').count()).max().unwrap_or(1) as f64;
|
||||
let height = |row: &[(usize, String, f64, f64)]| row.iter().map(|(.., h)| *h).fold(ls * 1.8, f64::max);
|
||||
// Above the plot and anything drawn over it (radar and stacked-pie labels).
|
||||
let top = self.b.out.iter().chain(self.on_top.iter()).filter_map(|n| n.geometric_bounds()).map(|bb| bb.y0).fold(r.y0, f64::min);
|
||||
let top = self.bars_reach.map_or(top, |b| top.min(b.y0));
|
||||
@@ -931,7 +935,7 @@ impl<'a> Plot<'a> {
|
||||
let mut labels = vec![];
|
||||
for row in &rows {
|
||||
let mut x = r.x0;
|
||||
for (s, label, w) in row {
|
||||
for (s, label, w, _) in row {
|
||||
self.legend_swatch(*s, (x, y));
|
||||
labels.push(self.legend_label((x, y), label));
|
||||
x += w;
|
||||
@@ -954,7 +958,7 @@ impl<'a> Plot<'a> {
|
||||
y += ls * 1.8;
|
||||
continue;
|
||||
}
|
||||
y += ls * 1.8 * label.split('|').count() as f64;
|
||||
y += ls * 1.8 * label.split('|').count() as f64 + label_extra_height(&self.g.label_styles, &label);
|
||||
self.legend_swatch(s, (x, row_y));
|
||||
labels.push(self.legend_label((x, row_y), &label));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user