public static int CountCharacters([NotNull] this PlotElement element, [NotNull, ItemNotNull] IReadOnlyCollection <Character> characters) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (characters == null) { throw new ArgumentNullException(nameof(characters)); } return(characters.Count(character => { if (element.TargetCharacters.Any(c => c.CharacterId == character.CharacterId)) { return true; } if (element.TargetGroups.Any(g => g.CharacterGroupId == element.Project.RootGroup.CharacterGroupId)) { return true; } var groups = character.GetParentGroupsToTop().Select(g => g.CharacterGroupId); return element.TargetGroups.Any(g => groups.Contains(g.CharacterGroupId)); })); }
private void Symbol_Loaded(object sender, RoutedEventArgs e) { if (!_showAnim) { return; } PlotElement pe = (PlotElement)sender; Storyboard stb = new Storyboard(); DoubleAnimation da = new DoubleAnimation(); da.From = -Canvas.GetTop(pe); da.To = -Canvas.GetTop(pe); da.Duration = new Duration(TimeSpan.FromSeconds(0.01)); Storyboard.SetTargetProperty(da, new PropertyPath("RenderTransform.Children[1].Y")); stb.Children.Add(da); da = new DoubleAnimation(); da.From = -Canvas.GetTop(pe); da.To = 0; if (pe.DataPoint != null && (sb.Value == 0 || chart.View.AxisX.Scale == 1.0)) { da.BeginTime = TimeSpan.FromSeconds(0.04 * (pe.DataPoint.PointIndex)); da.Duration = new Duration(TimeSpan.FromSeconds(1)); } else { da.Duration = new Duration(TimeSpan.FromSeconds(1.5)); } Storyboard.SetTargetProperty(da, new PropertyPath("RenderTransform.Children[1].Y")); stb.Children.Add(da); stb.Begin(pe); }
public static IEnumerable <IWorldObject> GetTargets([NotNull] this PlotElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } return(element.TargetCharacters.Cast <IWorldObject>().Union(element.TargetGroups)); }
protected override void AssertPlotElement(PlotElement model, PlotElementNode node) { var(testPlotElement, testNode) = GetTestPlotElement(); AssertPropertiesAreEqual(testPlotElement, model, nameof(model.Name), nameof(model.Description)); AssertPropertiesAreEqual(testNode, node, nameof(node.XPosition), nameof(node.YPosition)); }
void ds_PlotElementLoaded(object sender, EventArgs e) { PlotElement pe = sender as PlotElement; if (pe != null) { //pe.MouseEn } }
public HandoutReportItemViewModel(PlotElement element, IReadOnlyCollection <Character> characters) { Text = element.Texts.Content.ToPlainText().WithDefaultStringValue("(пустой текст)"); PlotElementId = element.PlotElementId; PlotFolderId = element.PlotFolderId; ProjectId = element.ProjectId; Count = element.CountCharacters(characters); Status = element.GetStatus(); }
public override bool ContainsText(string text) { string matchText = text.ToLowerInvariant(); return(Name.ToLowerInvariant().Contains(matchText) || PlotArchetype?.ToLowerInvariant().Contains(matchText) == true || PlotSubtype?.ToLowerInvariant().Contains(matchText) == true || PlotElement?.ToLowerInvariant().Contains(matchText) == true || CharacterConflict?.ToLowerInvariant().Contains(matchText) == true || Backgrounds?.ContainsText(matchText) == true || Resolutions?.ContainsText(matchText) == true || Traits?.ContainsText(matchText) == true || Settings?.ContainsText(matchText) == true || Themes?.ContainsText(matchText) == true || Genres?.ContainsText(matchText) == true); }
public EditPlotElementViewModel(PlotElement e) { PlotElementId = e.PlotElementId; Targets = e.GetElementBindingsForEdit(); Content = e.Texts.Content.Contents; TodoField = e.Texts.TodoField; ProjectId = e.PlotFolder.ProjectId; PlotFolderId = e.PlotFolderId; Status = e.GetStatus(); IsCompleted = e.IsCompleted; ElementType = (PlotElementTypeView)e.ElementType; }
private async Task UpdateElementTarget(int projectId, IReadOnlyCollection <int> targetGroups, IReadOnlyCollection <int> targetChars, PlotElement plotElement) { var characterGroups = await ProjectRepository.LoadGroups(projectId, targetGroups); if (characterGroups.Count != targetGroups.Distinct().Count()) { var missing = string.Join(", ", targetGroups.Except(characterGroups.Select(cg => cg.CharacterGroupId))); throw new Exception($"Groups {missing} doesn't belong to project"); } plotElement.TargetGroups.AssignLinksList(characterGroups); plotElement.TargetCharacters.AssignLinksList(await ValidateCharactersList(projectId, targetChars)); }
public EditPlotElementViewModel(PlotElement e, bool hasManageAccess, IUriService uriService) { PlotElementId = e.PlotElementId; Targets = e.GetElementBindingsForEdit(); Content = e.LastVersion().Content.Contents; TodoField = e.LastVersion().TodoField; ProjectId = e.PlotFolder.ProjectId; PlotFolderId = e.PlotFolderId; Status = e.GetStatus(); ElementType = (PlotElementTypeView)e.ElementType; HasManageAccess = hasManageAccess; HasPublishedVersion = e.Published != null; TargetsForDisplay = e.GetTargets().AsObjectLinks(uriService).ToList(); }
private void Series_Loaded(object sender, EventArgs e) { PlotElement pe = (PlotElement)sender; if (pe is HLOC) { TextBlock tb = (TextBlock)FindName("txtPrice"); tb.Foreground = pe.Stroke; } else { TextBlock tb = (TextBlock)FindName("txtVol"); tb.Foreground = pe.Stroke; } }
public PlotElementListItemViewModel(PlotElement e, int?currentUserId) { var renderer = new JoinrpgMarkdownLinkRenderer(e.Project); PlotElementId = e.PlotElementId; TargetsForDisplay = e.GetTargets().AsObjectLinks().ToList(); Content = e.Texts.Content.ToHtmlString(renderer); TodoField = e.Texts.TodoField; ProjectId = e.PlotFolder.ProjectId; PlotFolderId = e.PlotFolderId; Status = e.GetStatus(); ElementType = (PlotElementTypeView)e.ElementType; ShortContent = e.Texts.Content.TakeWords(10).ToPlainText(renderer).WithDefaultStringValue("***"); HasEditAccess = e.PlotFolder.HasMasterAccess(currentUserId, acl => acl.CanManagePlots) && e.Project.Active; HasMasterAccess = e.PlotFolder.HasMasterAccess(currentUserId); }
public static PlotStatus GetStatus(this PlotElement e) { if (!e.IsActive) { return(PlotStatus.Deleted); } if (e.Published == null) { return(PlotStatus.InWork); } if (e.LastVersion().Version == e.Published) { return(PlotStatus.Completed); } return(PlotStatus.HasNewVersion); }
public bool LoadCsv(string strContent) { if (strContent.Length == 0) { return(false); } m_mapElements.Clear(); m_vecAllElements.Clear(); int contentOffset = 0; List <string> vecLine; vecLine = GameAssist.readCsvLine(strContent, ref contentOffset); if (vecLine.Count != 2) { Ex.Logger.Log("Plot.csv中列数量与生成的代码不匹配!"); return(false); } if (vecLine[0] != "ID") { Ex.Logger.Log("Plot.csv中字段[ID]位置不对应"); return(false); } if (vecLine[1] != "FileName") { Ex.Logger.Log("Plot.csv中字段[FileName]位置不对应"); return(false); } while (true) { vecLine = GameAssist.readCsvLine(strContent, ref contentOffset); if ((int)vecLine.Count == 0) { break; } if ((int)vecLine.Count != (int)2) { return(false); } PlotElement member = new PlotElement(); member.ID = Convert.ToInt32(vecLine[0]); member.FileName = vecLine[1]; member.IsValidate = true; m_vecAllElements.Add(member); m_mapElements[member.ID] = member; } return(true); }
public bool LoadBin(byte[] binContent) { m_mapElements.Clear(); m_vecAllElements.Clear(); int nCol, nRow; int readPos = 0; readPos += GameAssist.ReadInt32Variant(binContent, readPos, out nCol); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out nRow); List <string> vecLine = new List <string>(nCol); List <int> vecHeadType = new List <int>(nCol); string tmpStr; int tmpInt; for (int i = 0; i < nCol; i++) { readPos += GameAssist.ReadString(binContent, readPos, out tmpStr); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out tmpInt); vecLine.Add(tmpStr); vecHeadType.Add(tmpInt); } if (vecLine.Count != 2) { Ex.Logger.Log("Plot.csv中列数量与生成的代码不匹配!"); return(false); } if (vecLine[0] != "ID") { Ex.Logger.Log("Plot.csv中字段[ID]位置不对应"); return(false); } if (vecLine[1] != "FileName") { Ex.Logger.Log("Plot.csv中字段[FileName]位置不对应"); return(false); } for (int i = 0; i < nRow; i++) { PlotElement member = new PlotElement(); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out member.ID); readPos += GameAssist.ReadString(binContent, readPos, out member.FileName); member.IsValidate = true; m_vecAllElements.Add(member); m_mapElements[member.ID] = member; } return(true); }
protected override (PlotElement model, PlotElementNode node) GetTestPlotElement() { var plotElement = new PlotElement() { Name = "PlotElementName", Description = "PlotElementDescription" }; var node = new PlotElementNode() { PlotElement = plotElement, XPosition = 10, YPosition = 20 }; return(plotElement, node); }
public async Task CreatePlotElement(int projectId, int plotFolderId, string content, string todoField, IReadOnlyCollection <int> targetGroups, IReadOnlyCollection <int> targetChars, PlotElementType elementType) { var folder = await LoadProjectSubEntityAsync <PlotFolder>(projectId, plotFolderId); folder.RequestMasterAccess(CurrentUserId); var now = DateTime.UtcNow; var characterGroups = await ProjectRepository.LoadGroups(projectId, targetGroups); if (characterGroups.Count != targetGroups.Distinct().Count()) { var missing = string.Join(", ", targetGroups.Except(characterGroups.Select(cg => cg.CharacterGroupId))); throw new Exception($"Groups {missing} doesn't belong to project"); } var plotElement = new PlotElement() { CreatedDateTime = now, ModifiedDateTime = now, IsActive = true, IsCompleted = false, ProjectId = projectId, PlotFolderId = plotFolderId, TargetGroups = characterGroups, TargetCharacters = await ValidateCharactersList(projectId, targetChars), ElementType = elementType, }; plotElement.Texts.Add(new PlotElementTexts() { Content = new MarkdownString(Required(content.Trim())), TodoField = todoField, Version = 0, ModifiedDateTime = now, AuthorUserId = CurrentUserId, }); folder.ModifiedDateTime = now; UnitOfWork.GetDbSet <PlotElement>().Add(plotElement); await UnitOfWork.SaveChangesAsync(); }
private void UpdateElementText(string contents, string todoField, PlotElement plotElement, DateTime now) { if (plotElement.LastVersion().Content.Contents == contents && plotElement.LastVersion().TodoField == todoField) { return; } var text = new PlotElementTexts() { Content = new MarkdownString(contents), TodoField = todoField, Version = plotElement.Texts.Select(t => t.Version).Max() + 1, PlotElementId = plotElement.PlotElementId, ModifiedDateTime = now, AuthorUserId = CurrentUserId, }; plotElement.Texts.Add(text); plotElement.IsCompleted = false; }
public PlotElementViewModel([NotNull] PlotElement p, [CanBeNull] Character character, int?currentUserId, ILinkRenderer linkRendrer) { if (p == null) { throw new ArgumentNullException(nameof(p)); } Content = p.Texts.Content.ToHtmlString(linkRendrer); TodoField = p.Texts.TodoField; HasMasterAccess = p.HasMasterAccess(currentUserId); HasEditAccess = p.HasMasterAccess(currentUserId) && p.Project.Active; HasPlayerAccess = character?.HasPlayerAccess(currentUserId) ?? false; PlotFolderId = p.PlotFolderId; PlotElementId = p.PlotElementId; ProjectId = p.ProjectId; Status = p.GetStatus(); TargetsForDisplay = p.GetTargets().AsObjectLinks().ToList(); CharacterId = character?.CharacterId; PublishMode = !HasMasterAccess && !HasPlayerAccess; }
public AggregateChart() { InitializeComponent(); _dict["red"] = CreateBrush(Colors.Red); _dict["blue"] = CreateBrush(Color.FromArgb(255, 2, 150, 252)); _dict["yellow"] = CreateBrush(Colors.Yellow); cb.ItemsSource = Utils.GetEnumValues(typeof(Aggregate)); cb.SelectedIndex = 0; cb.SelectionChanged += (s, e) => chart.Aggregate = (Aggregate)cb.SelectedIndex; int cnt = 30; chart.Data.ItemNames = CreateRandomStrings(cnt, new string[] { "blue", "red", "yellow" });; chart.View.AxisX.AnnoVisibility = AnnoVisibility.ShowAll; var vals = CreateRandomValues(cnt); var ds = new DataSeries() { ValuesSource = vals }; ds.PlotElementLoaded += (s, e) => { PlotElement pe = (PlotElement)s; if (_dict.ContainsKey(pe.DataPoint.Name)) { pe.Fill = _dict[pe.DataPoint.Name]; } pe.StrokeThickness = 0; }; chart.Data.Children.Add(ds); chart.View.AxisX.AnnoTemplate = chart.Resources["al_tmpl"]; BarColumnOptions.SetRadiusX(chart, 4); BarColumnOptions.SetRadiusY(chart, 4); }
void HandleMouseEvent(object sender, TappedRoutedEventArgs e) { ICollectionView itemsSource = ItemsSource as ICollectionView; PlotElement originalSource = e.OriginalSource as PlotElement; if (((originalSource != null) && (originalSource.DataPoint != null)) && (originalSource.DataPoint.PointIndex >= 0)) { DataSeries series = originalSource.DataPoint.Series; if (series.HasDataSource) { ICollectionView view2 = series.ItemsSource as ICollectionView; if (view2 != null) { view2.MoveCurrentToPosition(originalSource.DataPoint.PointIndex); } } else if (itemsSource != null) { itemsSource.MoveCurrentToPosition(originalSource.DataPoint.PointIndex); } } }
/// <summary> /// Fires when plot element was loaded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ds_Loaded(object sender, EventArgs e) { PlotElement pe = (PlotElement)sender; DataSeries dss = pe.DataPoint.Series; // "fix" the series color to avoid automatic palette if (pe is Lines) { dss.ConnectionFill = pe.Fill; dss.ConnectionStroke = pe.Stroke; } else { dss.SymbolFill = pe.Fill; dss.SymbolStroke = pe.Stroke; } pe.MouseDown += (se, ev) => { // start drag & drop with series label as data object System.Windows.DragDrop.DoDragDrop(pe, pe.DataPoint.Series.Label, DragDropEffects.Move); }; }
public PlotElementListItemViewModel(PlotElement e, int?currentUserId, IUriService uriService, int?currentVersion = null) { CurrentVersion = currentVersion ?? e.LastVersion().Version; var prevVersionText = e.SpecificVersion(CurrentVersion - 1); var currentVersionText = e.SpecificVersion(CurrentVersion); var nextVersionText = e.SpecificVersion(CurrentVersion + 1); if (currentVersionText == null) { throw new ArgumentOutOfRangeException(nameof(currentVersion)); } var renderer = new JoinrpgMarkdownLinkRenderer(e.Project); PlotElementId = e.PlotElementId; TargetsForDisplay = e.GetTargets().AsObjectLinks(uriService).ToList(); Content = currentVersionText.Content.ToHtmlString(renderer); TodoField = currentVersionText.TodoField; ProjectId = e.PlotFolder.ProjectId; PlotFolderId = e.PlotFolderId; Status = e.GetStatus(); ElementType = (PlotElementTypeView)e.ElementType; ShortContent = currentVersionText.Content.TakeWords(10) .ToPlainText(renderer).WithDefaultStringValue("***"); HasEditAccess = e.PlotFolder.HasMasterAccess(currentUserId, acl => acl.CanManagePlots) && e.Project.Active; HasMasterAccess = e.PlotFolder.HasMasterAccess(currentUserId); ModifiedDateTime = currentVersionText.ModifiedDateTime; Author = currentVersionText.AuthorUser; PrevModifiedDateTime = prevVersionText?.ModifiedDateTime; NextModifiedDateTime = nextVersionText?.ModifiedDateTime; PlotFolderMasterTitle = e.PlotFolder.MasterTitle; PublishedVersion = e.Published; }
static string GetKey(PlotElement pe) { return string.Format("s{0}p{1}", pe.DataPoint.SeriesIndex, pe.DataPoint.PointIndex); }
internal void SetData(double[] points, Brush fill, bool normalize) { double[] average(double[] fullData, int chunks) { double min = double.PositiveInfinity; double max = double.NegativeInfinity; double[] result = new double[chunks]; int chunkSize = fullData.Length / chunks; for (int chunkIndex = 0; chunkIndex < chunks; ++chunkIndex) { double sum = 0; int count = 0; int chunkStart = chunkIndex * chunkSize; for (int index = chunkIndex * chunkSize; index < chunkStart + chunkSize && index < fullData.Length; ++index) { double point = fullData[index]; sum += point; ++count; } //loop result[chunkIndex] = sum / count; } //loop if (normalize) { for (var index = 0; index < result.Length; ++index) { var point = result[index]; point *= point; if (point > max) { max = point; } if (point < min) { min = point; } } //loop max = System.Math.Sqrt(max); min = System.Math.Sqrt(min); for (var index = 0; index < result.Length; ++index) { result[index] = result[index] / (max - min); } } //if normalize return(result); } //average foreach (var item in this.pointList) { this.Children.Remove(item.Implementation); } this.pointList.Clear(); int steps = points.Length > (int)this.ActualWidth ? (int)this.ActualWidth : points.Length; points = average(points, steps); double step = (this.Domain.Right - this.Domain.Left) / points.Length; for (var index = 0; index < points.Length; ++index) { var domain = new Domain(index * step, (index + 1) * step, 0, points[index]); var element = new PlotElement(this, domain, fill); pointList.Add(element); } //loop this.ResizeHandler(); } //SetData
private static void UpdateElementMetadata(PlotElement plotElement, DateTime now) { plotElement.IsActive = true; plotElement.ModifiedDateTime = now; plotElement.PlotFolder.ModifiedDateTime = now; }
public static PlotStatus GetStatus(this PlotElement e) { return(!e.IsActive ? PlotStatus.Deleted : (e.IsCompleted ? PlotStatus.Completed : PlotStatus.InWork)); }
private void PlotElement_Loaded(object sender, RoutedEventArgs e) { PlotElement pe = (PlotElement)sender; pe.OpacityMask = (Brush)FindResource("lgb"); }
//TODO consider return NUll if deleted public static PlotElementTexts?PublishedVersion([NotNull] this PlotElement e) => e.Published != null?e.SpecificVersion((int)e.Published) : null;
public static PlotElementTexts?PrevVersion(this PlotElement e) => e.Texts.OrderByDescending(text => text.Version).Skip(1).FirstOrDefault();
public static IEnumerable <string> GetElementBindingsForEdit(this PlotElement e) => e.TargetGroups.Select(g => g.CharacterGroupId).PrefixAsGroups().Union(e.TargetCharacters.Select(c => c.CharacterId).PrefixAsCharacters());